@atbash/sdk 0.3.24 → 0.4.0-dev.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 +99 -321
- package/atbash.darwin-arm64.node +0 -0
- package/atbash.linux-arm64-gnu.node +0 -0
- package/atbash.linux-x64-gnu.node +0 -0
- package/atbash.win32-x64-msvc.node +0 -0
- package/dist/index.d.mts +560 -0
- package/dist/index.d.ts +463 -242
- package/dist/index.js +1196 -1348
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1334 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -32
- package/LICENSE +0 -28
- package/dist/index.cjs +0 -1616
- package/dist/index.d.cts +0 -339
package/dist/index.d.ts
CHANGED
|
@@ -1,58 +1,126 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
type JudgeEndpointConfig = {
|
|
2
|
+
policy?: "default";
|
|
3
|
+
endpoint?: string;
|
|
4
|
+
} | {
|
|
5
|
+
policy: "self-hosted";
|
|
6
|
+
endpoint: string;
|
|
7
|
+
verifyPubKey: string;
|
|
6
8
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
is_private_blockchain: boolean;
|
|
12
|
-
monthly_price: number;
|
|
13
|
-
yearly_price: number;
|
|
9
|
+
interface ValidatedEndpoint {
|
|
10
|
+
url: string;
|
|
11
|
+
policy: "default" | "self-hosted";
|
|
12
|
+
verifyPubKey: string | null;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
declare function validateJudgeEndpoint(judge?: JudgeEndpointConfig): ValidatedEndpoint;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* User-facing types. Two groups:
|
|
18
|
+
* - Core types — the exact shapes the Rust core emits across the NAPI
|
|
19
|
+
* boundary (field names match the serde output byte-for-byte).
|
|
20
|
+
* - SDK types — the HTTP-facing result shapes the `Atbash` client returns,
|
|
21
|
+
* already normalized (verdict casing, status).
|
|
22
|
+
*/
|
|
23
|
+
/** `generate_keypair` result. Note the `priv_key` / `pub_key` field names. */
|
|
24
|
+
interface KeyPair {
|
|
25
|
+
priv_key: string;
|
|
26
|
+
pub_key: string;
|
|
21
27
|
}
|
|
28
|
+
/** `load_agent` result. Note the `privkey` / `pubkey` field names. */
|
|
22
29
|
interface AgentAuth {
|
|
23
|
-
pubkey: string;
|
|
24
30
|
privkey: string;
|
|
31
|
+
pubkey: string;
|
|
25
32
|
}
|
|
26
|
-
interface
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
interface SecretMatch {
|
|
34
|
+
kind: string;
|
|
35
|
+
length: number;
|
|
36
|
+
}
|
|
37
|
+
interface RedactResult {
|
|
38
|
+
redacted: string;
|
|
39
|
+
found: SecretMatch[];
|
|
40
|
+
}
|
|
41
|
+
interface MemoryEntry {
|
|
42
|
+
key: string;
|
|
43
|
+
value: string;
|
|
44
|
+
source?: string;
|
|
45
|
+
timestamp?: number;
|
|
46
|
+
}
|
|
47
|
+
interface MemorySnapshot {
|
|
48
|
+
entries: MemoryEntry[];
|
|
49
|
+
takenAt: number;
|
|
50
|
+
}
|
|
51
|
+
interface ModifiedEntry {
|
|
52
|
+
key: string;
|
|
53
|
+
before: string;
|
|
54
|
+
after: string;
|
|
30
55
|
}
|
|
56
|
+
type AnomalyType = "behavioral_override" | "bulk_insertion" | "safety_bypass" | "privilege_escalation" | "gradual_drift";
|
|
57
|
+
type AnomalySeverity = "low" | "medium" | "high" | "critical";
|
|
58
|
+
interface MemoryAnomaly {
|
|
59
|
+
type: AnomalyType;
|
|
60
|
+
severity: AnomalySeverity;
|
|
61
|
+
description: string;
|
|
62
|
+
entries: string[];
|
|
63
|
+
}
|
|
64
|
+
interface MemoryDiffResult {
|
|
65
|
+
safe: boolean;
|
|
66
|
+
added: MemoryEntry[];
|
|
67
|
+
removed: MemoryEntry[];
|
|
68
|
+
modified: ModifiedEntry[];
|
|
69
|
+
anomalies: MemoryAnomaly[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Which Atbash chain an action runs against. `public` is the shared
|
|
73
|
+
* testnet (Free plan); `private` is reserved for Private / Swarm /
|
|
74
|
+
* Enterprise tier subscribers. The SDK resolves which one to use from
|
|
75
|
+
* the org's subscription via `orgName` — callers normally don't need
|
|
76
|
+
* to pass this manually.
|
|
77
|
+
*/
|
|
78
|
+
type Network = "public" | "private";
|
|
79
|
+
/**
|
|
80
|
+
* Per-call chain overrides. Pass exactly what you need to override —
|
|
81
|
+
* `network` selects between the SDK's known chains, `blockchainRid` /
|
|
82
|
+
* `nodeUrls` pin a fully custom chain. Pass none of these to fall back
|
|
83
|
+
* to the SDK's defaults (or to org-resolved chain when `orgName` is set).
|
|
84
|
+
*/
|
|
31
85
|
interface ChainOpts {
|
|
32
|
-
|
|
86
|
+
network?: Network;
|
|
33
87
|
blockchainRid?: string;
|
|
88
|
+
nodeUrls?: readonly string[];
|
|
89
|
+
}
|
|
90
|
+
/** Canonical verdict after normalization. */
|
|
91
|
+
type Verdict = "ALLOW" | "HOLD" | "BLOCK" | "No verdict";
|
|
92
|
+
/** Canonical judgment status after normalization. */
|
|
93
|
+
type JudgmentState = "pending" | "answered" | "error";
|
|
94
|
+
/**
|
|
95
|
+
* Provider attribution on a judged action. The trailing `string & {}`
|
|
96
|
+
* accepts custom provider names without losing autocompletion on the
|
|
97
|
+
* canonical ones.
|
|
98
|
+
*/
|
|
99
|
+
type Provider = "openai" | "google" | "microsoft" | "custom" | (string & {});
|
|
100
|
+
/** Verdict action_type carried in the judge response. */
|
|
101
|
+
type ActionType = "allow" | "hold_for_user_confirm" | "block" | (string & {});
|
|
102
|
+
/** Pubkey value as accepted on the wire — hex string, Buffer, or GTV bytes. */
|
|
103
|
+
type PubkeyValue = string | Buffer | {
|
|
104
|
+
data: number[];
|
|
105
|
+
};
|
|
106
|
+
interface LogToolCallResult {
|
|
107
|
+
success: boolean;
|
|
108
|
+
toolCallId: string | null;
|
|
109
|
+
signedHex?: string;
|
|
110
|
+
error?: string;
|
|
34
111
|
}
|
|
35
112
|
interface JudgeResult {
|
|
36
113
|
verdict: Verdict;
|
|
37
|
-
|
|
114
|
+
actionType: string;
|
|
38
115
|
reason: string;
|
|
39
116
|
confidence: number;
|
|
40
|
-
provider:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
interface JudgeOptions extends ClientOpts {
|
|
46
|
-
provider?: Provider;
|
|
47
|
-
model?: string;
|
|
48
|
-
toolName?: string;
|
|
49
|
-
toolArgsJson?: string;
|
|
50
|
-
orgName?: string;
|
|
51
|
-
chainOpts?: ChainOpts;
|
|
52
|
-
verifyPubKey?: string;
|
|
117
|
+
provider: string;
|
|
118
|
+
latencyMs: number;
|
|
119
|
+
toolCallId: string;
|
|
120
|
+
onChain: boolean;
|
|
53
121
|
}
|
|
54
122
|
interface JudgmentStatus {
|
|
55
|
-
status:
|
|
123
|
+
status: JudgmentState;
|
|
56
124
|
verdict: Verdict;
|
|
57
125
|
reason: string;
|
|
58
126
|
judgmentId: string;
|
|
@@ -60,56 +128,115 @@ interface JudgmentStatus {
|
|
|
60
128
|
cached?: boolean;
|
|
61
129
|
responseTimeMs?: number;
|
|
62
130
|
}
|
|
63
|
-
interface
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
131
|
+
interface TierInfo {
|
|
132
|
+
orgName: string;
|
|
133
|
+
tier: string;
|
|
134
|
+
verdictEnabled: boolean;
|
|
135
|
+
enforcementEnabled: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Plan-level subscription metadata. Returned by `org-subscription` —
|
|
139
|
+
* field names match the on-chain shape (snake_case) so the response
|
|
140
|
+
* can be inspected without renaming.
|
|
141
|
+
*/
|
|
142
|
+
interface Subscription {
|
|
143
|
+
subscription_name: string;
|
|
144
|
+
agent_number: number;
|
|
145
|
+
is_private_blockchain: boolean;
|
|
146
|
+
monthly_price: number;
|
|
147
|
+
yearly_price: number;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Org's binding to a subscription on a specific chain. The chain is
|
|
151
|
+
* implied by which BRID the query hit (controlled by the `network`
|
|
152
|
+
* query param when fetching).
|
|
153
|
+
*/
|
|
154
|
+
interface OrgSubscription extends Subscription {
|
|
70
155
|
org_name: string;
|
|
156
|
+
duration_months: number;
|
|
157
|
+
assigned_at: number;
|
|
158
|
+
expires_at: number;
|
|
159
|
+
is_active: boolean;
|
|
160
|
+
}
|
|
161
|
+
interface ToolCallRecord {
|
|
162
|
+
toolCallId: string;
|
|
163
|
+
agentPubkey: string;
|
|
164
|
+
toolName: string;
|
|
165
|
+
commandText: string;
|
|
166
|
+
toolArgsJson: string;
|
|
167
|
+
contextText: string;
|
|
168
|
+
orgName: string;
|
|
71
169
|
rowid: number;
|
|
72
170
|
}
|
|
73
171
|
interface ToolCallFull {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
172
|
+
toolCallId: string;
|
|
173
|
+
agentPubkey: string;
|
|
174
|
+
toolName: string;
|
|
175
|
+
commandText: string;
|
|
176
|
+
contextText: string;
|
|
177
|
+
orgName: string;
|
|
178
|
+
toolArgsJson?: string;
|
|
179
|
+
createdAt?: number;
|
|
180
|
+
actionType?: string;
|
|
181
|
+
resultStatus?: string;
|
|
182
|
+
verdictColor?: string;
|
|
183
|
+
verdictReason?: string;
|
|
184
|
+
verdictSource?: string;
|
|
185
|
+
verdictResponseTimeMs?: number;
|
|
88
186
|
}
|
|
89
187
|
interface HeldAction {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
188
|
+
judgmentId: string;
|
|
189
|
+
agentPubkey: string;
|
|
190
|
+
actionText: string;
|
|
191
|
+
actionContext: string;
|
|
94
192
|
verdict: Verdict;
|
|
95
193
|
reason: string;
|
|
96
|
-
|
|
194
|
+
createdAt: number;
|
|
97
195
|
}
|
|
98
196
|
interface HeldActionReview {
|
|
99
|
-
|
|
100
|
-
|
|
197
|
+
judgmentId: string;
|
|
198
|
+
actionText: string;
|
|
101
199
|
status: string;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
200
|
+
reviewNote: string;
|
|
201
|
+
reviewedAt: number;
|
|
202
|
+
createdAt: number;
|
|
203
|
+
reviewedBy?: string;
|
|
106
204
|
}
|
|
107
205
|
interface AgentPolicy {
|
|
108
206
|
policy: string;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
207
|
+
isJailed: boolean;
|
|
208
|
+
isCustom: boolean;
|
|
209
|
+
defaultPolicy: string;
|
|
210
|
+
}
|
|
211
|
+
/** Optional structured logger. */
|
|
212
|
+
interface AtbashLogger {
|
|
213
|
+
info?(...args: unknown[]): void;
|
|
214
|
+
warn?(...args: unknown[]): void;
|
|
215
|
+
}
|
|
216
|
+
/** Options accepted by the `Atbash` constructor. */
|
|
217
|
+
interface AtbashOptions {
|
|
218
|
+
endpoint?: string;
|
|
219
|
+
timeoutMs?: number;
|
|
220
|
+
nodeUrls?: readonly string[];
|
|
221
|
+
blockchainRid?: string;
|
|
222
|
+
/**
|
|
223
|
+
* Default org name. When set, `judgeAction` / `auditToolCall` resolve
|
|
224
|
+
* the chain via the `org_networks` map on every call (with the
|
|
225
|
+
* per-client cache short-circuiting the second hit onwards). Per-call
|
|
226
|
+
* overrides on the method options still win.
|
|
227
|
+
*/
|
|
228
|
+
orgName?: string;
|
|
229
|
+
/**
|
|
230
|
+
* Default response-signing pubkey for `judgeAction` verification. Set
|
|
231
|
+
* automatically by `Atbash.fromConfig` for self-hosted endpoints; a
|
|
232
|
+
* per-call `verifyPubKey` still overrides it.
|
|
233
|
+
*/
|
|
234
|
+
verifyPubKey?: string;
|
|
235
|
+
/** When true (default), `auditToolCall` denies on any error. */
|
|
236
|
+
failClosed?: boolean;
|
|
237
|
+
logger?: AtbashLogger;
|
|
112
238
|
}
|
|
239
|
+
/** Canonical decision returned by `auditToolCall`. */
|
|
113
240
|
type DecisionVerdict = "ALLOW" | "HOLD" | "BLOCK" | "ERROR";
|
|
114
241
|
interface Decision {
|
|
115
242
|
allow: boolean;
|
|
@@ -117,120 +244,259 @@ interface Decision {
|
|
|
117
244
|
reason?: string;
|
|
118
245
|
toolCallId?: string;
|
|
119
246
|
}
|
|
247
|
+
/** Input to `auditToolCall`. */
|
|
120
248
|
interface ToolCallInput {
|
|
121
249
|
toolName: string;
|
|
122
250
|
args?: unknown;
|
|
123
251
|
context?: string;
|
|
124
252
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
133
|
-
interface ValidatedEndpoint {
|
|
134
|
-
url: string;
|
|
135
|
-
policy: "default" | "self-hosted";
|
|
136
|
-
verifyPubKey: string | null;
|
|
137
|
-
}
|
|
138
|
-
interface MemoryEntry {
|
|
139
|
-
key: string;
|
|
140
|
-
value: string;
|
|
141
|
-
source?: string;
|
|
142
|
-
timestamp?: number;
|
|
143
|
-
}
|
|
144
|
-
type MemoryScanVerdict = "green" | "yellow" | "red";
|
|
145
|
-
type AnomalySeverity = "low" | "medium" | "high" | "critical";
|
|
146
|
-
type AnomalyType = "behavioral_override" | "bulk_insertion" | "safety_bypass" | "privilege_escalation" | "gradual_drift";
|
|
147
|
-
interface MemoryScanResult {
|
|
148
|
-
safe: boolean;
|
|
149
|
-
verdict: MemoryScanVerdict;
|
|
150
|
-
reason: string;
|
|
151
|
-
confidence: number;
|
|
152
|
-
toolCallId?: string;
|
|
153
|
-
}
|
|
154
|
-
interface MemoryScanOptions extends JudgeOptions {
|
|
155
|
-
/** Confidence threshold below which the entry is allowed (default 0.6). */
|
|
156
|
-
threshold?: number;
|
|
157
|
-
/** Stop batch scanning on the first red verdict (default true). */
|
|
158
|
-
stopOnRed?: boolean;
|
|
159
|
-
}
|
|
160
|
-
interface MemorySnapshot {
|
|
161
|
-
entries: MemoryEntry[];
|
|
162
|
-
takenAt: number;
|
|
163
|
-
}
|
|
164
|
-
interface MemoryAnomaly {
|
|
165
|
-
type: AnomalyType;
|
|
166
|
-
severity: AnomalySeverity;
|
|
167
|
-
description: string;
|
|
168
|
-
entries: string[];
|
|
169
|
-
}
|
|
170
|
-
interface MemoryDiffResult {
|
|
171
|
-
safe: boolean;
|
|
172
|
-
added: MemoryEntry[];
|
|
173
|
-
removed: MemoryEntry[];
|
|
174
|
-
modified: Array<{
|
|
175
|
-
key: string;
|
|
176
|
-
before: string;
|
|
177
|
-
after: string;
|
|
178
|
-
}>;
|
|
179
|
-
anomalies: MemoryAnomaly[];
|
|
180
|
-
}
|
|
181
|
-
interface AtbashClientConfig {
|
|
253
|
+
/** Options accepted by `Atbash.fromConfig`. All fields are explicit overrides. */
|
|
254
|
+
interface FromConfigOptions {
|
|
255
|
+
/** Inline private key. Overrides env / config-file / key-file resolution. */
|
|
256
|
+
agentKey?: string;
|
|
257
|
+
/** Path to the agent key file (default `~/.config/atbash/guard-client-key`). */
|
|
258
|
+
keyPath?: string;
|
|
259
|
+
/** Judge endpoint config — validated against the allowlist / self-hosted policy. */
|
|
182
260
|
judge?: JudgeEndpointConfig;
|
|
183
|
-
nodeUrls?: string[];
|
|
184
261
|
blockchainRid?: string;
|
|
262
|
+
timeoutMs?: number;
|
|
263
|
+
nodeUrls?: readonly string[];
|
|
264
|
+
/** Default org name — see {@link AtbashOptions.orgName}. */
|
|
185
265
|
orgName?: string;
|
|
186
|
-
keyPath?: string;
|
|
187
|
-
keyPair?: {
|
|
188
|
-
privKey: string;
|
|
189
|
-
pubKey: string;
|
|
190
|
-
};
|
|
191
266
|
failClosed?: boolean;
|
|
192
|
-
logger?:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
267
|
+
logger?: AtbashLogger;
|
|
268
|
+
}
|
|
269
|
+
/** Options accepted by `judgeAction`. */
|
|
270
|
+
interface JudgeOptions {
|
|
271
|
+
toolName?: string;
|
|
272
|
+
toolArgsJson?: string;
|
|
273
|
+
provider?: string;
|
|
274
|
+
model?: string;
|
|
275
|
+
verifyPubKey?: string;
|
|
276
|
+
/**
|
|
277
|
+
* Org name — when set, the SDK resolves which chain the agent lives
|
|
278
|
+
* on via the off-chain `org_networks` map (authoritative) before
|
|
279
|
+
* signing. Overrides any `chainOpts.blockchainRid` hint when the map
|
|
280
|
+
* has an entry.
|
|
281
|
+
*/
|
|
282
|
+
orgName?: string;
|
|
283
|
+
/**
|
|
284
|
+
* Explicit per-call chain override. Use to pin a specific chain for
|
|
285
|
+
* one call; otherwise the SDK uses the constructor defaults or the
|
|
286
|
+
* org-resolved chain.
|
|
287
|
+
*/
|
|
288
|
+
chainOpts?: ChainOpts;
|
|
289
|
+
}
|
|
290
|
+
/** Options accepted by `logToolCall`. */
|
|
291
|
+
interface LogToolCallOptions {
|
|
292
|
+
toolName?: string;
|
|
293
|
+
toolArgsJson?: string;
|
|
294
|
+
/** Per-call chain override — same semantics as `JudgeOptions.chainOpts`. */
|
|
295
|
+
chainOpts?: ChainOpts;
|
|
196
296
|
}
|
|
197
297
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
declare function generateKeyPair(): {
|
|
204
|
-
privKey: string;
|
|
205
|
-
pubKey: string;
|
|
206
|
-
};
|
|
207
|
-
declare function loadAgent(privkey: string): AgentAuth;
|
|
208
|
-
declare function toPubkeyHex(val: unknown): string;
|
|
209
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
210
|
-
declare function judgeAction(action: string, context: string | undefined, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
211
|
-
declare function getJudgmentStatus(judgmentId: string, agentPubkey: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
212
|
-
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
213
|
-
declare function getOrgToolCalls(orgName: string, maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
214
|
-
declare function getAgentToolCalls(agentPubkey: string, maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
215
|
-
declare function getToolCallCount(opts?: ClientOpts): Promise<number>;
|
|
216
|
-
declare function getToolCallFull(toolCallId: string, opts?: ClientOpts): Promise<ToolCallFull | null>;
|
|
217
|
-
declare function getOrgSubscription(orgName: string, opts?: ClientOpts): Promise<OrgSubscription | null>;
|
|
218
|
-
declare function getPendingHeldActions(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldAction[]>;
|
|
219
|
-
declare function getHeldActionReviews(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldActionReview[]>;
|
|
220
|
-
declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
221
|
-
declare function getAgentPolicy(agentPubkey: string, opts?: ClientOpts): Promise<AgentPolicy>;
|
|
222
|
-
declare function getSafetyStats(opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
298
|
+
interface ChainConfig {
|
|
299
|
+
readonly network: Network;
|
|
300
|
+
readonly blockchainRid: string;
|
|
301
|
+
readonly nodeUrls: readonly string[];
|
|
302
|
+
}
|
|
223
303
|
|
|
224
|
-
|
|
304
|
+
declare class Atbash {
|
|
305
|
+
readonly auth: AgentAuth;
|
|
306
|
+
readonly endpoint: string;
|
|
307
|
+
readonly nodeUrls: readonly string[];
|
|
308
|
+
readonly blockchainRid: string;
|
|
309
|
+
/** Default org name used by `auditToolCall` / `judgeAction`. */
|
|
310
|
+
readonly orgName?: string;
|
|
311
|
+
/** Default judge response-signing pubkey, if configured (see fromConfig). */
|
|
312
|
+
readonly verifyPubKey?: string;
|
|
313
|
+
/** When true (default), `auditToolCall` denies on any error. */
|
|
314
|
+
readonly failClosed: boolean;
|
|
315
|
+
private readonly logger;
|
|
316
|
+
private readonly http;
|
|
317
|
+
/**
|
|
318
|
+
* Per-client cache of resolved chains. Keyed by orgName so repeated
|
|
319
|
+
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
320
|
+
*/
|
|
321
|
+
private readonly _chainCache;
|
|
322
|
+
/**
|
|
323
|
+
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
324
|
+
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
325
|
+
* server-side replay protection windows never expire it mid-session.
|
|
326
|
+
*/
|
|
327
|
+
private _authBearer;
|
|
328
|
+
constructor(privkey: string, options?: AtbashOptions);
|
|
329
|
+
/**
|
|
330
|
+
* Construct from resolved config: explicit overrides → env vars → the
|
|
331
|
+
* `~/.config/atbash/config.json` file (see userConfig.resolve). The private
|
|
332
|
+
* key comes from `agentKey` (override/env/file) or, failing that, the agent
|
|
333
|
+
* key file (`~/.config/atbash/guard-client-key`). The judge endpoint is
|
|
334
|
+
* validated against the trusted allowlist / self-hosted policy; a
|
|
335
|
+
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
336
|
+
*/
|
|
337
|
+
static fromConfig(options?: FromConfigOptions): Atbash;
|
|
338
|
+
get pubkey(): string;
|
|
339
|
+
get privkey(): string;
|
|
340
|
+
/** GET /api/ai/exists?pubkey=… — defaults to this client's pubkey. */
|
|
341
|
+
checkAgentExists(pubkey?: string): Promise<boolean>;
|
|
342
|
+
/**
|
|
343
|
+
* Pre-flight `checkAgentExists`, then sign `log_tool_call` locally and
|
|
344
|
+
* return the signed tx hex. The server broadcasts to chain.
|
|
345
|
+
*/
|
|
346
|
+
logToolCall(action: string, context?: string, options?: LogToolCallOptions): Promise<LogToolCallResult>;
|
|
347
|
+
/**
|
|
348
|
+
* Sign log_tool_call + optionally judge_action, POST /api/v1/judge.
|
|
349
|
+
*
|
|
350
|
+
* `verifyPubKey` checks the `X-Atbash-Signature` header against the exact
|
|
351
|
+
* response bytes via the Rust core's `verifySignature`.
|
|
352
|
+
*/
|
|
353
|
+
judgeAction(action: string, context?: string, options?: JudgeOptions): Promise<JudgeResult>;
|
|
354
|
+
private _judgeAction;
|
|
355
|
+
/**
|
|
356
|
+
* High-level guard: redact secrets, submit for judgement, and collapse the
|
|
357
|
+
* result into an allow/deny `Decision`. Fails closed by default — any error
|
|
358
|
+
* (judge unreachable, unrecognized verdict) denies unless `failClosed` is
|
|
359
|
+
* explicitly false.
|
|
360
|
+
*/
|
|
225
361
|
auditToolCall(input: ToolCallInput): Promise<Decision>;
|
|
362
|
+
private fail;
|
|
363
|
+
getJudgmentStatus(judgmentId: string, agentPubkey?: string): Promise<JudgmentStatus>;
|
|
364
|
+
getToolCalls(maxCount: number): Promise<ToolCallRecord[]>;
|
|
365
|
+
getOrgToolCalls(orgName: string, maxCount: number): Promise<ToolCallRecord[]>;
|
|
366
|
+
getAgentToolCalls(agentPubkey: string, maxCount: number): Promise<ToolCallRecord[]>;
|
|
367
|
+
getToolCallCount(): Promise<number>;
|
|
368
|
+
getToolCallFull(toolCallId: string): Promise<ToolCallFull | null>;
|
|
369
|
+
getOrgTierInfo(orgName: string): Promise<TierInfo | null>;
|
|
370
|
+
getPendingHeldActions(orgName: string, maxCount: number): Promise<HeldAction[]>;
|
|
371
|
+
getHeldActionReviews(orgName: string, maxCount: number): Promise<HeldActionReview[]>;
|
|
372
|
+
getAgentDetail(agentPubkey: string): Promise<Record<string, unknown>>;
|
|
373
|
+
getAgentPolicy(agentPubkey: string): Promise<AgentPolicy>;
|
|
374
|
+
getSafetyStats(): Promise<Record<string, unknown>>;
|
|
375
|
+
/**
|
|
376
|
+
* Org's subscription on a specific chain. The `network` arg selects
|
|
377
|
+
* which chain to query; without it, the dashboard picks the default.
|
|
378
|
+
* Returns null when the org has no record on that chain.
|
|
379
|
+
*/
|
|
380
|
+
getOrgSubscription(orgName: string, network?: Network): Promise<OrgSubscription | null>;
|
|
381
|
+
/**
|
|
382
|
+
* Read the org's active network from the dashboard's off-chain
|
|
383
|
+
* `org_networks` map. The map is the authoritative source after a
|
|
384
|
+
* plan switch — subscription rows on the source chain go stale, but
|
|
385
|
+
* the map is updated on every assign. Returns null when there's no
|
|
386
|
+
* entry (caller falls back to per-chain subscription resolution).
|
|
387
|
+
*/
|
|
388
|
+
getActiveNetworkForOrg(orgName: string): Promise<Network | null>;
|
|
389
|
+
/**
|
|
390
|
+
* Resolve which chain an org's actions should run against. Cached
|
|
391
|
+
* per-client by orgName. Resolution order:
|
|
392
|
+
* 1. `org_networks` map (authoritative).
|
|
393
|
+
* 2. Per-chain subscription fallback — public + private records
|
|
394
|
+
* are fetched in parallel, with `is_private_blockchain` and
|
|
395
|
+
* `assigned_at` reconciling mixed states.
|
|
396
|
+
* Defaults to the public chain when nothing else resolves.
|
|
397
|
+
*/
|
|
398
|
+
resolveChainForOrg(orgName: string): Promise<ChainConfig>;
|
|
399
|
+
/**
|
|
400
|
+
* Resolve a chain given an already-fetched `org_networks` map result.
|
|
401
|
+
* Split out from {@link resolveChainForOrg} so callers that have already
|
|
402
|
+
* queried the map (the judge path) don't fetch /api/org-network twice.
|
|
403
|
+
* Caches per orgName like its caller.
|
|
404
|
+
*/
|
|
405
|
+
private resolveChainFromMap;
|
|
406
|
+
/** Drop any cached chain resolutions. Useful in tests. */
|
|
407
|
+
clearChainCache(): void;
|
|
408
|
+
/**
|
|
409
|
+
* Wrap an SDK method body in telemetry — records the call at start
|
|
410
|
+
* and a success/error duration at end. Re-throws on failure so the
|
|
411
|
+
* caller sees the original exception. Pass `agentPubkey` when the
|
|
412
|
+
* method is keyed to a specific agent; tracked methods that don't
|
|
413
|
+
* depend on an agent (read queries) pass `undefined`.
|
|
414
|
+
*/
|
|
415
|
+
private track;
|
|
416
|
+
/**
|
|
417
|
+
* Pick the BRID for a given per-call chain override. `blockchainRid`
|
|
418
|
+
* takes precedence; otherwise `network` maps to one of the known
|
|
419
|
+
* chains; otherwise the client's default.
|
|
420
|
+
*/
|
|
421
|
+
private bridFromChainOpts;
|
|
422
|
+
/**
|
|
423
|
+
* Get-or-create a Bearer token for dashboard reads. The token is a
|
|
424
|
+
* signed `log_tool_call` op (locally signed, never submitted) — the
|
|
425
|
+
* dashboard verifies the signature against the agent's pubkey. Cached
|
|
426
|
+
* for 4 minutes; refreshed after that so a long-lived client never
|
|
427
|
+
* trips the server's replay window.
|
|
428
|
+
*/
|
|
429
|
+
private getAuthBearer;
|
|
430
|
+
private authHeaders;
|
|
431
|
+
private riskEngineGet;
|
|
432
|
+
private riskEnginePost;
|
|
433
|
+
private riskEngineRecords;
|
|
434
|
+
private raiseIfError;
|
|
435
|
+
/** Wrap a failed HTTP *response* (non-2xx / non-200) as an AtbashAPIError. */
|
|
436
|
+
private httpError;
|
|
437
|
+
/** Wrap a *transport* failure (fetch threw, no response) as an AtbashAPIError. */
|
|
438
|
+
private transportError;
|
|
439
|
+
private json;
|
|
440
|
+
static generateKeypair(): KeyPair;
|
|
441
|
+
static isValidPrivateKey(hex: string): boolean;
|
|
442
|
+
static derivePublicKey(privkey: string): string;
|
|
443
|
+
static redactSecrets(text: string): RedactResult;
|
|
444
|
+
static normalizeForMatching(text: string): string;
|
|
445
|
+
static containsEvasionCharacters(text: string): boolean;
|
|
226
446
|
}
|
|
227
|
-
declare function createAtbashClient(config?: AtbashClientConfig): AtbashClient;
|
|
228
447
|
|
|
229
|
-
declare
|
|
448
|
+
declare const DEFAULT_ENDPOINT: string;
|
|
449
|
+
declare const DEFAULT_CHROMIA_NODE_URLS: readonly string[];
|
|
450
|
+
declare const DEFAULT_BLOCKCHAIN_RID: string;
|
|
451
|
+
|
|
452
|
+
declare class AtbashAPIError extends Error {
|
|
453
|
+
/** HTTP status code (or 0 if the request never completed). */
|
|
454
|
+
readonly status: number;
|
|
455
|
+
/** Raw response body text (may be empty). */
|
|
456
|
+
readonly body: string;
|
|
457
|
+
constructor(status: number, body: string, statusText?: string, endpoint?: string);
|
|
458
|
+
}
|
|
459
|
+
declare class SignatureVerificationError extends Error {
|
|
460
|
+
constructor(message: string);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** Normalize wire shapes (verdict casing, status, pubkey) to canonical forms. */
|
|
464
|
+
|
|
465
|
+
declare function normalizeVerdict(raw: unknown): Verdict;
|
|
466
|
+
declare function normalizeStatus(raw: unknown): JudgmentState;
|
|
467
|
+
/** Wire pubkey may be a hex string, a Buffer/Uint8Array, or `{ data: [...] }`. */
|
|
468
|
+
declare function pubkeyToHex(val: unknown): string;
|
|
469
|
+
|
|
470
|
+
interface AtbashUserConfig {
|
|
471
|
+
agentKey?: string;
|
|
472
|
+
orgName?: string;
|
|
473
|
+
judgeEndpoint?: string;
|
|
474
|
+
blockchainRid?: string;
|
|
475
|
+
provider?: string;
|
|
476
|
+
providerModel?: string;
|
|
477
|
+
}
|
|
478
|
+
declare function getConfigDir(): string;
|
|
479
|
+
declare function getConfigPath(): string;
|
|
480
|
+
declare function loadUserConfig(): AtbashUserConfig;
|
|
481
|
+
declare function saveUserConfig(config: AtbashUserConfig): void;
|
|
482
|
+
declare function resolve(key: keyof AtbashUserConfig, flagValue?: string): string;
|
|
230
483
|
|
|
231
484
|
declare function resolveKeyPath(input?: string): string;
|
|
232
485
|
declare function loadAgentFromFile(keyPath?: string): AgentAuth;
|
|
233
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Canonical secret kinds reported by the Rust core in `SecretMatch.kind`.
|
|
489
|
+
* Wire is permissive (modelled as a free string in {@link SecretMatch})
|
|
490
|
+
* so unknown kinds don't break callers; use this union when narrowing.
|
|
491
|
+
*/
|
|
492
|
+
type SecretKind = "anthropic" | "openai" | "openai_project" | "github" | "google" | "google_oauth" | "aws_access_key" | "aws_secret_key" | "stripe" | "slack" | "slack_webhook" | "sendgrid" | "twilio_sid" | "mailgun" | "npm_token" | "jwt" | "private_key_pem" | "context_secret" | "bearer" | "base64" | "generic_token";
|
|
493
|
+
/**
|
|
494
|
+
* Walk a JSON-shaped value and redact secrets inside every string leaf.
|
|
495
|
+
* Object keys are not touched; only values. Arrays and nested objects
|
|
496
|
+
* are recursed structurally so the returned value has the same shape.
|
|
497
|
+
*/
|
|
498
|
+
declare function redactJsonStrings<T>(value: T): T;
|
|
499
|
+
|
|
234
500
|
declare function verifyJudgeResponseSignature(bodyBytes: Uint8Array, signatureHex: string | null, pubKeyHex: string): {
|
|
235
501
|
ok: boolean;
|
|
236
502
|
reason?: string;
|
|
@@ -243,8 +509,9 @@ declare function verifyJudgeResponseSignature(bodyBytes: Uint8Array, signatureHe
|
|
|
243
509
|
* and agent identity. ON by default.
|
|
244
510
|
*
|
|
245
511
|
* Opt-out: create ~/.config/atbash/telemetry.json with { "enabled": false }
|
|
246
|
-
* The file must be
|
|
247
|
-
* Environment variables cannot disable
|
|
512
|
+
* The file must be readable by the SDK process. If missing, corrupted, or
|
|
513
|
+
* unreadable → telemetry stays ON. Environment variables cannot disable
|
|
514
|
+
* telemetry (prevents agent bypass via env-var injection).
|
|
248
515
|
*/
|
|
249
516
|
type ClientSource = "cli" | "sdk" | "plugin:openclaw" | "plugin:langchain" | "plugin:langgraph" | "plugin:hermes" | "plugin:eliza" | "plugin:crewai" | "plugin:mcp" | "plugin:autogen" | "plugin:jeenai" | (string & {});
|
|
250
517
|
interface TelemetryConfig {
|
|
@@ -257,83 +524,37 @@ interface TelemetryConfig {
|
|
|
257
524
|
}
|
|
258
525
|
declare function setupTelemetry(config: TelemetryConfig): void;
|
|
259
526
|
/**
|
|
260
|
-
*
|
|
527
|
+
* Record a function call. Call at the START of each tracked function.
|
|
528
|
+
* Safe to call even if telemetry is disabled — does nothing.
|
|
261
529
|
*/
|
|
262
|
-
declare function
|
|
263
|
-
|
|
264
|
-
interface AtbashUserConfig {
|
|
265
|
-
agentKey?: string;
|
|
266
|
-
orgName?: string;
|
|
267
|
-
judgeEndpoint?: string;
|
|
268
|
-
blockchainRid?: string;
|
|
269
|
-
network?: string;
|
|
270
|
-
provider?: string;
|
|
271
|
-
providerModel?: string;
|
|
272
|
-
}
|
|
273
|
-
declare function getConfigDir(): string;
|
|
274
|
-
declare function getConfigPath(): string;
|
|
275
|
-
declare function loadUserConfig(): AtbashUserConfig;
|
|
276
|
-
declare function saveUserConfig(config: AtbashUserConfig): void;
|
|
277
|
-
declare function resolve(key: keyof AtbashUserConfig, flagValue?: string): string;
|
|
278
|
-
|
|
530
|
+
declare function recordCall(functionName: string, source?: ClientSource, agentPubkey?: string): void;
|
|
279
531
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* Defence layers (in order):
|
|
283
|
-
* 1. **Regex pre-filter** — catches obvious attacks instantly, zero latency
|
|
284
|
-
* 2. **LLM-as-Judge** — catches semantic / rephrased attacks the regex misses
|
|
285
|
-
*
|
|
286
|
-
* Both layers run against unicode-normalized text. The entry is fenced
|
|
287
|
-
* in the judge prompt so attackers cannot meta-inject into the scanner.
|
|
288
|
-
* Every scan is logged on-chain via the judge API for forensic audit.
|
|
532
|
+
* Record function duration. Call at the END of each tracked function.
|
|
533
|
+
* Safe to call even if telemetry is disabled — does nothing.
|
|
289
534
|
*/
|
|
290
|
-
declare function
|
|
291
|
-
/**
|
|
292
|
-
* Scan multiple memory entries. By default stops on the first red
|
|
293
|
-
* verdict. Set `stopOnRed: false` to scan all entries regardless.
|
|
294
|
-
*/
|
|
295
|
-
declare function scanMemoryBatch(entries: MemoryEntry[], auth: AgentAuth, opts?: MemoryScanOptions): Promise<MemoryScanResult[]>;
|
|
296
|
-
|
|
535
|
+
declare function recordDuration(functionName: string, durationMs: number, status: "success" | "error", source?: ClientSource): void;
|
|
297
536
|
/**
|
|
298
|
-
*
|
|
537
|
+
* Force-flush pending metrics without shutting down.
|
|
538
|
+
* Use in short-lived processes (CLI) to ensure data is sent.
|
|
299
539
|
*/
|
|
300
|
-
declare function
|
|
540
|
+
declare function flushTelemetry(): Promise<void>;
|
|
301
541
|
/**
|
|
302
|
-
*
|
|
303
|
-
* detection heuristics on the result.
|
|
304
|
-
*
|
|
305
|
-
* Catches what other defenses miss:
|
|
306
|
-
* - HMAC detects external tampering, not entries the agent wrote itself
|
|
307
|
-
* - Provenance tagging neutralizes untrusted sources, but a trusted
|
|
308
|
-
* channel can still be exploited
|
|
309
|
-
* - Regex catches fixed phrases, but attackers rephrase
|
|
310
|
-
* - LLM-as-judge catches semantic manipulation on individual entries
|
|
311
|
-
* - This function catches the *cumulative effect* — gradual multi-step
|
|
312
|
-
* poisoning where entries shift agent behavior across sessions
|
|
542
|
+
* Flush pending metrics and shut down. Call before process exits.
|
|
313
543
|
*/
|
|
314
|
-
declare function
|
|
544
|
+
declare function shutdownTelemetry(): Promise<void>;
|
|
315
545
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
* 3. Map common confusable characters to their Latin equivalents
|
|
330
|
-
*/
|
|
331
|
-
declare function normalizeForMatching(input: string): string;
|
|
332
|
-
/**
|
|
333
|
-
* Check whether a string contains suspicious encoding that may indicate
|
|
334
|
-
* an evasion attempt (presence of confusables, invisible chars, etc.).
|
|
335
|
-
* Returns true if the raw and normalized forms differ.
|
|
336
|
-
*/
|
|
337
|
-
declare function containsEvasionCharacters(input: string): boolean;
|
|
546
|
+
declare function isValidPrivateKey(hex: string): boolean;
|
|
547
|
+
declare function derivePublicKey(privkey: string): string;
|
|
548
|
+
declare function generateKeypair(): KeyPair;
|
|
549
|
+
declare function loadAgent(privkey: string): AgentAuth;
|
|
550
|
+
declare function signLogToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, privkey: string, blockchainRid: string): string;
|
|
551
|
+
declare function signJudgeAction(judgmentId: string, action: string, context: string, extra: string, privkey: string, blockchainRid: string): string;
|
|
552
|
+
declare function verifySignature(body: Buffer, signatureHex: string, pubkeyHex: string): boolean;
|
|
553
|
+
declare function normalizeForMatching(text: string): string;
|
|
554
|
+
declare function containsEvasionCharacters(text: string): boolean;
|
|
555
|
+
declare function redactSecrets(text: string): RedactResult;
|
|
556
|
+
declare function containsSecret(text: string): boolean;
|
|
557
|
+
declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
|
|
558
|
+
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
338
559
|
|
|
339
|
-
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, type
|
|
560
|
+
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClientSource, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type Decision, type DecisionVerdict, type FromConfigOptions, type HeldAction, type HeldActionReview, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, type Provider, type PubkeyValue, type RedactResult, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, containsEvasionCharacters, containsSecret, createMemorySnapshot, derivePublicKey, diffMemorySnapshots, flushTelemetry, generateKeypair, getConfigDir, getConfigPath, isValidPrivateKey, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, normalizeStatus, normalizeVerdict, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, saveUserConfig, setupTelemetry, shutdownTelemetry, signJudgeAction, signLogToolCall, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
|