@atbash/sdk 0.4.0-dev.2 → 0.4.0-dev.3
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 +5 -6
- package/dist/browser.d.mts +568 -0
- package/dist/browser.mjs +44582 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ bindings/node/
|
|
|
26
26
|
│ ├── types.ts, constants.ts, errors.ts, normalize.ts
|
|
27
27
|
│ └── ...
|
|
28
28
|
├── dist/ # tsup output (gitignored) — what gets published
|
|
29
|
-
└── __test__/ # native parity
|
|
29
|
+
└── __test__/ # native parity, config, and live health tests
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
## Setup
|
|
@@ -51,13 +51,12 @@ Native artifacts (`*.node`, `index.js`, `index.d.ts`) and `dist/` are
|
|
|
51
51
|
## Test
|
|
52
52
|
|
|
53
53
|
```bash
|
|
54
|
-
npm test
|
|
55
|
-
|
|
54
|
+
npm run test:native # native vector parity
|
|
55
|
+
npm run test:live # real SDK health, skipped unless ATBASH_LIVE_HEALTH=1
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
The SDK
|
|
59
|
-
|
|
60
|
-
end-to-end; signing is real through the NAPI core.
|
|
58
|
+
The live SDK health test uses real HTTP responses only. It verifies BRID
|
|
59
|
+
signing, key loading, and a real judge call when live credentials are present.
|
|
61
60
|
|
|
62
61
|
## Usage
|
|
63
62
|
|
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
type JudgeEndpointConfig = {
|
|
2
|
+
policy?: "default";
|
|
3
|
+
endpoint?: string;
|
|
4
|
+
} | {
|
|
5
|
+
policy: "self-hosted";
|
|
6
|
+
endpoint: string;
|
|
7
|
+
verifyPubKey: string;
|
|
8
|
+
};
|
|
9
|
+
interface ValidatedEndpoint {
|
|
10
|
+
url: string;
|
|
11
|
+
policy: "default" | "self-hosted";
|
|
12
|
+
verifyPubKey: string | null;
|
|
13
|
+
}
|
|
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;
|
|
27
|
+
}
|
|
28
|
+
/** `load_agent` result. Note the `privkey` / `pubkey` field names. */
|
|
29
|
+
interface AgentAuth {
|
|
30
|
+
privkey: string;
|
|
31
|
+
pubkey: string;
|
|
32
|
+
}
|
|
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;
|
|
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
|
+
*/
|
|
85
|
+
interface ChainOpts {
|
|
86
|
+
network?: Network;
|
|
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;
|
|
111
|
+
}
|
|
112
|
+
interface JudgeResult {
|
|
113
|
+
verdict: Verdict;
|
|
114
|
+
actionType: string;
|
|
115
|
+
reason: string;
|
|
116
|
+
confidence: number;
|
|
117
|
+
provider: string;
|
|
118
|
+
latencyMs: number;
|
|
119
|
+
toolCallId: string;
|
|
120
|
+
onChain: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the org's protection mode actually acts on a HOLD/BLOCK verdict.
|
|
123
|
+
* `false` in Monitor mode (verdict is logged for observation, agent is NOT
|
|
124
|
+
* jailed and the action is not held); `true` in Enforce mode.
|
|
125
|
+
*/
|
|
126
|
+
enforced: boolean;
|
|
127
|
+
/** Server-reported protection mode: `off`, `monitor`, or `enforce`. */
|
|
128
|
+
enforcementMode: string;
|
|
129
|
+
}
|
|
130
|
+
interface JudgmentStatus {
|
|
131
|
+
status: JudgmentState;
|
|
132
|
+
verdict: Verdict;
|
|
133
|
+
reason: string;
|
|
134
|
+
judgmentId: string;
|
|
135
|
+
onChain?: boolean;
|
|
136
|
+
cached?: boolean;
|
|
137
|
+
responseTimeMs?: number;
|
|
138
|
+
}
|
|
139
|
+
interface TierInfo {
|
|
140
|
+
orgName: string;
|
|
141
|
+
tier: string;
|
|
142
|
+
verdictEnabled: boolean;
|
|
143
|
+
enforcementEnabled: boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Plan-level subscription metadata. Returned by `org-subscription` —
|
|
147
|
+
* field names match the on-chain shape (snake_case) so the response
|
|
148
|
+
* can be inspected without renaming.
|
|
149
|
+
*/
|
|
150
|
+
interface Subscription {
|
|
151
|
+
subscription_name: string;
|
|
152
|
+
agent_number: number;
|
|
153
|
+
is_private_blockchain: boolean;
|
|
154
|
+
monthly_price: number;
|
|
155
|
+
yearly_price: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Org's binding to a subscription on a specific chain. The chain is
|
|
159
|
+
* implied by which BRID the query hit (controlled by the `network`
|
|
160
|
+
* query param when fetching).
|
|
161
|
+
*/
|
|
162
|
+
interface OrgSubscription extends Subscription {
|
|
163
|
+
org_name: string;
|
|
164
|
+
duration_months: number;
|
|
165
|
+
assigned_at: number;
|
|
166
|
+
expires_at: number;
|
|
167
|
+
is_active: boolean;
|
|
168
|
+
}
|
|
169
|
+
interface ToolCallRecord {
|
|
170
|
+
toolCallId: string;
|
|
171
|
+
agentPubkey: string;
|
|
172
|
+
toolName: string;
|
|
173
|
+
commandText: string;
|
|
174
|
+
toolArgsJson: string;
|
|
175
|
+
contextText: string;
|
|
176
|
+
orgName: string;
|
|
177
|
+
rowid: number;
|
|
178
|
+
}
|
|
179
|
+
interface ToolCallFull {
|
|
180
|
+
toolCallId: string;
|
|
181
|
+
agentPubkey: string;
|
|
182
|
+
toolName: string;
|
|
183
|
+
commandText: string;
|
|
184
|
+
contextText: string;
|
|
185
|
+
orgName: string;
|
|
186
|
+
toolArgsJson?: string;
|
|
187
|
+
createdAt?: number;
|
|
188
|
+
actionType?: string;
|
|
189
|
+
resultStatus?: string;
|
|
190
|
+
verdictColor?: string;
|
|
191
|
+
verdictReason?: string;
|
|
192
|
+
verdictSource?: string;
|
|
193
|
+
verdictResponseTimeMs?: number;
|
|
194
|
+
}
|
|
195
|
+
interface HeldAction {
|
|
196
|
+
judgmentId: string;
|
|
197
|
+
agentPubkey: string;
|
|
198
|
+
actionText: string;
|
|
199
|
+
actionContext: string;
|
|
200
|
+
verdict: Verdict;
|
|
201
|
+
reason: string;
|
|
202
|
+
createdAt: number;
|
|
203
|
+
}
|
|
204
|
+
interface HeldActionReview {
|
|
205
|
+
judgmentId: string;
|
|
206
|
+
actionText: string;
|
|
207
|
+
status: string;
|
|
208
|
+
reviewNote: string;
|
|
209
|
+
reviewedAt: number;
|
|
210
|
+
createdAt: number;
|
|
211
|
+
reviewedBy?: string;
|
|
212
|
+
}
|
|
213
|
+
interface AgentPolicy {
|
|
214
|
+
policy: string;
|
|
215
|
+
isJailed: boolean;
|
|
216
|
+
isCustom: boolean;
|
|
217
|
+
defaultPolicy: string;
|
|
218
|
+
}
|
|
219
|
+
/** Optional structured logger. */
|
|
220
|
+
interface AtbashLogger {
|
|
221
|
+
info?(...args: unknown[]): void;
|
|
222
|
+
warn?(...args: unknown[]): void;
|
|
223
|
+
}
|
|
224
|
+
/** Options accepted by the `Atbash` constructor. */
|
|
225
|
+
interface AtbashOptions {
|
|
226
|
+
endpoint?: string;
|
|
227
|
+
timeoutMs?: number;
|
|
228
|
+
nodeUrls?: readonly string[];
|
|
229
|
+
blockchainRid?: string;
|
|
230
|
+
/**
|
|
231
|
+
* Default org name. When set, `judgeAction` / `auditToolCall` resolve
|
|
232
|
+
* the chain via the `org_networks` map on every call (with the
|
|
233
|
+
* per-client cache short-circuiting the second hit onwards). Per-call
|
|
234
|
+
* overrides on the method options still win.
|
|
235
|
+
*/
|
|
236
|
+
orgName?: string;
|
|
237
|
+
/**
|
|
238
|
+
* Default response-signing pubkey for `judgeAction` verification. Set
|
|
239
|
+
* automatically by `Atbash.fromConfig` for self-hosted endpoints; a
|
|
240
|
+
* per-call `verifyPubKey` still overrides it.
|
|
241
|
+
*/
|
|
242
|
+
verifyPubKey?: string;
|
|
243
|
+
/** When true (default), `auditToolCall` denies on any error. */
|
|
244
|
+
failClosed?: boolean;
|
|
245
|
+
logger?: AtbashLogger;
|
|
246
|
+
}
|
|
247
|
+
/** Canonical decision returned by `auditToolCall`. */
|
|
248
|
+
type DecisionVerdict = "ALLOW" | "HOLD" | "BLOCK" | "ERROR";
|
|
249
|
+
interface Decision {
|
|
250
|
+
allow: boolean;
|
|
251
|
+
verdict: DecisionVerdict;
|
|
252
|
+
reason?: string;
|
|
253
|
+
toolCallId?: string;
|
|
254
|
+
}
|
|
255
|
+
/** Input to `auditToolCall`. */
|
|
256
|
+
interface ToolCallInput {
|
|
257
|
+
toolName: string;
|
|
258
|
+
args?: unknown;
|
|
259
|
+
context?: string;
|
|
260
|
+
}
|
|
261
|
+
/** Options accepted by `Atbash.fromConfig`. All fields are explicit overrides. */
|
|
262
|
+
interface FromConfigOptions {
|
|
263
|
+
/** Inline private key. Overrides env / config-file / key-file resolution. */
|
|
264
|
+
agentKey?: string;
|
|
265
|
+
/** Path to the agent key file (default `~/.config/atbash/guard-client-key`). */
|
|
266
|
+
keyPath?: string;
|
|
267
|
+
/** Judge endpoint config — validated against the allowlist / self-hosted policy. */
|
|
268
|
+
judge?: JudgeEndpointConfig;
|
|
269
|
+
blockchainRid?: string;
|
|
270
|
+
timeoutMs?: number;
|
|
271
|
+
nodeUrls?: readonly string[];
|
|
272
|
+
/** Default org name — see {@link AtbashOptions.orgName}. */
|
|
273
|
+
orgName?: string;
|
|
274
|
+
failClosed?: boolean;
|
|
275
|
+
logger?: AtbashLogger;
|
|
276
|
+
}
|
|
277
|
+
/** Options accepted by `judgeAction`. */
|
|
278
|
+
interface JudgeOptions {
|
|
279
|
+
toolName?: string;
|
|
280
|
+
toolArgsJson?: string;
|
|
281
|
+
provider?: string;
|
|
282
|
+
model?: string;
|
|
283
|
+
verifyPubKey?: string;
|
|
284
|
+
/**
|
|
285
|
+
* Org name — when set, the SDK resolves which chain the agent lives
|
|
286
|
+
* on via the off-chain `org_networks` map (authoritative) before
|
|
287
|
+
* signing. Overrides any `chainOpts.blockchainRid` hint when the map
|
|
288
|
+
* has an entry.
|
|
289
|
+
*/
|
|
290
|
+
orgName?: string;
|
|
291
|
+
/**
|
|
292
|
+
* Explicit per-call chain override. Use to pin a specific chain for
|
|
293
|
+
* one call; otherwise the SDK uses the constructor defaults or the
|
|
294
|
+
* org-resolved chain.
|
|
295
|
+
*/
|
|
296
|
+
chainOpts?: ChainOpts;
|
|
297
|
+
}
|
|
298
|
+
/** Options accepted by `logToolCall`. */
|
|
299
|
+
interface LogToolCallOptions {
|
|
300
|
+
toolName?: string;
|
|
301
|
+
toolArgsJson?: string;
|
|
302
|
+
/** Per-call chain override — same semantics as `JudgeOptions.chainOpts`. */
|
|
303
|
+
chainOpts?: ChainOpts;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
interface ChainConfig {
|
|
307
|
+
readonly network: Network;
|
|
308
|
+
readonly blockchainRid: string;
|
|
309
|
+
readonly nodeUrls: readonly string[];
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
declare class Atbash {
|
|
313
|
+
readonly auth: AgentAuth;
|
|
314
|
+
readonly endpoint: string;
|
|
315
|
+
readonly nodeUrls: readonly string[];
|
|
316
|
+
readonly blockchainRid: string;
|
|
317
|
+
/** Default org name used by `auditToolCall` / `judgeAction`. */
|
|
318
|
+
readonly orgName?: string;
|
|
319
|
+
/** Default judge response-signing pubkey, if configured (see fromConfig). */
|
|
320
|
+
readonly verifyPubKey?: string;
|
|
321
|
+
/** When true (default), `auditToolCall` denies on any error. */
|
|
322
|
+
readonly failClosed: boolean;
|
|
323
|
+
private readonly logger;
|
|
324
|
+
private readonly http;
|
|
325
|
+
/**
|
|
326
|
+
* Per-client cache of resolved chains. Keyed by orgName so repeated
|
|
327
|
+
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
328
|
+
*/
|
|
329
|
+
private readonly _chainCache;
|
|
330
|
+
/**
|
|
331
|
+
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
332
|
+
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
333
|
+
* server-side replay protection windows never expire it mid-session.
|
|
334
|
+
*/
|
|
335
|
+
private _authBearer;
|
|
336
|
+
constructor(privkey: string, options?: AtbashOptions);
|
|
337
|
+
/**
|
|
338
|
+
* Construct from resolved config: explicit overrides → env vars → the
|
|
339
|
+
* `~/.config/atbash/config.json` file (see userConfig.resolve). The private
|
|
340
|
+
* key comes from `agentKey` (override/env/file) or, failing that, the agent
|
|
341
|
+
* key file (`~/.config/atbash/guard-client-key`). The judge endpoint is
|
|
342
|
+
* validated against the trusted allowlist / self-hosted policy; a
|
|
343
|
+
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
344
|
+
*/
|
|
345
|
+
static fromConfig(options?: FromConfigOptions): Atbash;
|
|
346
|
+
get pubkey(): string;
|
|
347
|
+
get privkey(): string;
|
|
348
|
+
/** GET /api/ai/exists?pubkey=… — defaults to this client's pubkey. */
|
|
349
|
+
checkAgentExists(pubkey?: string): Promise<boolean>;
|
|
350
|
+
/**
|
|
351
|
+
* Pre-flight `checkAgentExists`, then sign `log_tool_call` locally and
|
|
352
|
+
* return the signed tx hex. The server broadcasts to chain.
|
|
353
|
+
*/
|
|
354
|
+
logToolCall(action: string, context?: string, options?: LogToolCallOptions): Promise<LogToolCallResult>;
|
|
355
|
+
/**
|
|
356
|
+
* Sign log_tool_call + optionally judge_action, POST /api/v1/judge.
|
|
357
|
+
*
|
|
358
|
+
* `verifyPubKey` checks the `X-Atbash-Signature` header against the exact
|
|
359
|
+
* response bytes via the Rust core's `verifySignature`.
|
|
360
|
+
*/
|
|
361
|
+
judgeAction(action: string, context?: string, options?: JudgeOptions): Promise<JudgeResult>;
|
|
362
|
+
private _judgeAction;
|
|
363
|
+
/**
|
|
364
|
+
* High-level guard: redact secrets, submit for judgement, and collapse the
|
|
365
|
+
* result into an allow/deny `Decision`. Fails closed by default — any error
|
|
366
|
+
* (judge unreachable, unrecognized verdict) denies unless `failClosed` is
|
|
367
|
+
* explicitly false.
|
|
368
|
+
*/
|
|
369
|
+
auditToolCall(input: ToolCallInput): Promise<Decision>;
|
|
370
|
+
private fail;
|
|
371
|
+
getJudgmentStatus(judgmentId: string, agentPubkey?: string): Promise<JudgmentStatus>;
|
|
372
|
+
getToolCalls(maxCount: number): Promise<ToolCallRecord[]>;
|
|
373
|
+
getOrgToolCalls(orgName: string, maxCount: number): Promise<ToolCallRecord[]>;
|
|
374
|
+
getAgentToolCalls(agentPubkey: string, maxCount: number): Promise<ToolCallRecord[]>;
|
|
375
|
+
getToolCallCount(): Promise<number>;
|
|
376
|
+
getToolCallFull(toolCallId: string): Promise<ToolCallFull | null>;
|
|
377
|
+
getOrgTierInfo(orgName: string): Promise<TierInfo | null>;
|
|
378
|
+
getPendingHeldActions(orgName: string, maxCount: number): Promise<HeldAction[]>;
|
|
379
|
+
getHeldActionReviews(orgName: string, maxCount: number): Promise<HeldActionReview[]>;
|
|
380
|
+
getAgentDetail(agentPubkey: string): Promise<Record<string, unknown>>;
|
|
381
|
+
getAgentPolicy(agentPubkey: string): Promise<AgentPolicy>;
|
|
382
|
+
getSafetyStats(): Promise<Record<string, unknown>>;
|
|
383
|
+
/**
|
|
384
|
+
* Org's subscription on a specific chain. The `network` arg selects
|
|
385
|
+
* which chain to query; without it, the dashboard picks the default.
|
|
386
|
+
* Returns null when the org has no record on that chain.
|
|
387
|
+
*/
|
|
388
|
+
getOrgSubscription(orgName: string, network?: Network): Promise<OrgSubscription | null>;
|
|
389
|
+
/**
|
|
390
|
+
* Read the org's active network from the dashboard's off-chain
|
|
391
|
+
* `org_networks` map. The map is the authoritative source after a
|
|
392
|
+
* plan switch — subscription rows on the source chain go stale, but
|
|
393
|
+
* the map is updated on every assign. Returns null when there's no
|
|
394
|
+
* entry (caller falls back to per-chain subscription resolution).
|
|
395
|
+
*/
|
|
396
|
+
getActiveNetworkForOrg(orgName: string): Promise<Network | null>;
|
|
397
|
+
/**
|
|
398
|
+
* Resolve which chain an org's actions should run against. Cached
|
|
399
|
+
* per-client by orgName. Resolution order:
|
|
400
|
+
* 1. `org_networks` map (authoritative).
|
|
401
|
+
* 2. Per-chain subscription fallback — public + private records
|
|
402
|
+
* are fetched in parallel, with `is_private_blockchain` and
|
|
403
|
+
* `assigned_at` reconciling mixed states.
|
|
404
|
+
* Defaults to the public chain when nothing else resolves.
|
|
405
|
+
*/
|
|
406
|
+
resolveChainForOrg(orgName: string): Promise<ChainConfig>;
|
|
407
|
+
/**
|
|
408
|
+
* Resolve a chain given an already-fetched `org_networks` map result.
|
|
409
|
+
* Split out from {@link resolveChainForOrg} so callers that have already
|
|
410
|
+
* queried the map (the judge path) don't fetch /api/org-network twice.
|
|
411
|
+
* Caches per orgName like its caller.
|
|
412
|
+
*/
|
|
413
|
+
private resolveChainFromMap;
|
|
414
|
+
/** Drop any cached chain resolutions. Useful in tests. */
|
|
415
|
+
clearChainCache(): void;
|
|
416
|
+
/**
|
|
417
|
+
* Wrap an SDK method body in telemetry — records the call at start
|
|
418
|
+
* and a success/error duration at end. Re-throws on failure so the
|
|
419
|
+
* caller sees the original exception. Pass `agentPubkey` when the
|
|
420
|
+
* method is keyed to a specific agent; tracked methods that don't
|
|
421
|
+
* depend on an agent (read queries) pass `undefined`.
|
|
422
|
+
*/
|
|
423
|
+
private track;
|
|
424
|
+
/**
|
|
425
|
+
* Pick the BRID for a given per-call chain override. `blockchainRid`
|
|
426
|
+
* takes precedence; otherwise `network` maps to one of the known
|
|
427
|
+
* chains; otherwise the client's default.
|
|
428
|
+
*/
|
|
429
|
+
private bridFromChainOpts;
|
|
430
|
+
/**
|
|
431
|
+
* Get-or-create a Bearer token for dashboard reads. The token is a
|
|
432
|
+
* signed `log_tool_call` op (locally signed, never submitted) — the
|
|
433
|
+
* dashboard verifies the signature against the agent's pubkey. Cached
|
|
434
|
+
* for 4 minutes; refreshed after that so a long-lived client never
|
|
435
|
+
* trips the server's replay window.
|
|
436
|
+
*/
|
|
437
|
+
private getAuthBearer;
|
|
438
|
+
private authHeaders;
|
|
439
|
+
private riskEngineGet;
|
|
440
|
+
private riskEnginePost;
|
|
441
|
+
private riskEngineRecords;
|
|
442
|
+
private raiseIfError;
|
|
443
|
+
/** Wrap a failed HTTP *response* (non-2xx / non-200) as an AtbashAPIError. */
|
|
444
|
+
private httpError;
|
|
445
|
+
/** Wrap a *transport* failure (fetch threw, no response) as an AtbashAPIError. */
|
|
446
|
+
private transportError;
|
|
447
|
+
private json;
|
|
448
|
+
static generateKeypair(): KeyPair;
|
|
449
|
+
static isValidPrivateKey(hex: string): boolean;
|
|
450
|
+
static derivePublicKey(privkey: string): string;
|
|
451
|
+
static redactSecrets(text: string): RedactResult;
|
|
452
|
+
static normalizeForMatching(text: string): string;
|
|
453
|
+
static containsEvasionCharacters(text: string): boolean;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
declare const DEFAULT_ENDPOINT: string;
|
|
457
|
+
declare const DEFAULT_CHROMIA_NODE_URLS: readonly string[];
|
|
458
|
+
declare const DEFAULT_BLOCKCHAIN_RID: string;
|
|
459
|
+
|
|
460
|
+
declare class AtbashAPIError extends Error {
|
|
461
|
+
/** HTTP status code (or 0 if the request never completed). */
|
|
462
|
+
readonly status: number;
|
|
463
|
+
/** Raw response body text (may be empty). */
|
|
464
|
+
readonly body: string;
|
|
465
|
+
constructor(status: number, body: string, statusText?: string, endpoint?: string);
|
|
466
|
+
}
|
|
467
|
+
declare class SignatureVerificationError extends Error {
|
|
468
|
+
constructor(message: string);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Normalize wire shapes (verdict casing, status, pubkey) to canonical forms. */
|
|
472
|
+
|
|
473
|
+
declare function normalizeVerdict(raw: unknown): Verdict;
|
|
474
|
+
declare function normalizeStatus(raw: unknown): JudgmentState;
|
|
475
|
+
/** Wire pubkey may be a hex string, a Buffer/Uint8Array, or `{ data: [...] }`. */
|
|
476
|
+
declare function pubkeyToHex(val: unknown): string;
|
|
477
|
+
|
|
478
|
+
interface AtbashUserConfig {
|
|
479
|
+
agentKey?: string;
|
|
480
|
+
orgName?: string;
|
|
481
|
+
judgeEndpoint?: string;
|
|
482
|
+
blockchainRid?: string;
|
|
483
|
+
provider?: string;
|
|
484
|
+
providerModel?: string;
|
|
485
|
+
}
|
|
486
|
+
declare function getConfigDir(): string;
|
|
487
|
+
declare function getConfigPath(): string;
|
|
488
|
+
declare function loadUserConfig(): AtbashUserConfig;
|
|
489
|
+
declare function saveUserConfig(config: AtbashUserConfig): void;
|
|
490
|
+
declare function resolve(key: keyof AtbashUserConfig, flagValue?: string): string;
|
|
491
|
+
|
|
492
|
+
declare function resolveKeyPath(input?: string): string;
|
|
493
|
+
declare function loadAgentFromFile(keyPath?: string): AgentAuth;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Canonical secret kinds reported by the Rust core in `SecretMatch.kind`.
|
|
497
|
+
* Wire is permissive (modelled as a free string in {@link SecretMatch})
|
|
498
|
+
* so unknown kinds don't break callers; use this union when narrowing.
|
|
499
|
+
*/
|
|
500
|
+
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";
|
|
501
|
+
/**
|
|
502
|
+
* Walk a JSON-shaped value and redact secrets inside every string leaf.
|
|
503
|
+
* Object keys are not touched; only values. Arrays and nested objects
|
|
504
|
+
* are recursed structurally so the returned value has the same shape.
|
|
505
|
+
*/
|
|
506
|
+
declare function redactJsonStrings<T>(value: T): T;
|
|
507
|
+
|
|
508
|
+
declare function verifyJudgeResponseSignature(bodyBytes: Uint8Array, signatureHex: string | null, pubKeyHex: string): {
|
|
509
|
+
ok: boolean;
|
|
510
|
+
reason?: string;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Atbash SDK Telemetry — OpenTelemetry metrics for usage tracking.
|
|
515
|
+
*
|
|
516
|
+
* Tracks: function call counts, latency, source (CLI/plugin/SDK),
|
|
517
|
+
* and agent identity. ON by default.
|
|
518
|
+
*
|
|
519
|
+
* Opt-out: create ~/.config/atbash/telemetry.json with { "enabled": false }
|
|
520
|
+
* The file must be readable by the SDK process. If missing, corrupted, or
|
|
521
|
+
* unreadable → telemetry stays ON. Environment variables cannot disable
|
|
522
|
+
* telemetry (prevents agent bypass via env-var injection).
|
|
523
|
+
*/
|
|
524
|
+
type ClientSource = "cli" | "sdk" | "plugin:openclaw" | "plugin:langchain" | "plugin:langgraph" | "plugin:hermes" | "plugin:eliza" | "plugin:crewai" | "plugin:mcp" | "plugin:autogen" | "plugin:jeenai" | (string & {});
|
|
525
|
+
interface TelemetryConfig {
|
|
526
|
+
/** Must be true to send any telemetry. Default: false */
|
|
527
|
+
enabled: boolean;
|
|
528
|
+
/** Where calls originate */
|
|
529
|
+
source?: ClientSource;
|
|
530
|
+
/** Flush interval in ms. Default: 60000 */
|
|
531
|
+
exportIntervalMs?: number;
|
|
532
|
+
}
|
|
533
|
+
declare function setupTelemetry(config: TelemetryConfig): void;
|
|
534
|
+
/**
|
|
535
|
+
* Record a function call. Call at the START of each tracked function.
|
|
536
|
+
* Safe to call even if telemetry is disabled — does nothing.
|
|
537
|
+
*/
|
|
538
|
+
declare function recordCall(functionName: string, source?: ClientSource, agentPubkey?: string): void;
|
|
539
|
+
/**
|
|
540
|
+
* Record function duration. Call at the END of each tracked function.
|
|
541
|
+
* Safe to call even if telemetry is disabled — does nothing.
|
|
542
|
+
*/
|
|
543
|
+
declare function recordDuration(functionName: string, durationMs: number, status: "success" | "error", source?: ClientSource): void;
|
|
544
|
+
/**
|
|
545
|
+
* Force-flush pending metrics without shutting down.
|
|
546
|
+
* Use in short-lived processes (CLI) to ensure data is sent.
|
|
547
|
+
*/
|
|
548
|
+
declare function flushTelemetry(): Promise<void>;
|
|
549
|
+
/**
|
|
550
|
+
* Flush pending metrics and shut down. Call before process exits.
|
|
551
|
+
*/
|
|
552
|
+
declare function shutdownTelemetry(): Promise<void>;
|
|
553
|
+
|
|
554
|
+
declare function isValidPrivateKey(hex: string): boolean;
|
|
555
|
+
declare function derivePublicKey(privkey: string): string;
|
|
556
|
+
declare function generateKeypair(): KeyPair;
|
|
557
|
+
declare function loadAgent(privkey: string): AgentAuth;
|
|
558
|
+
declare function signLogToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, privkey: string, blockchainRid: string): string;
|
|
559
|
+
declare function signJudgeAction(judgmentId: string, action: string, context: string, extra: string, privkey: string, blockchainRid: string): string;
|
|
560
|
+
declare function verifySignature(body: Buffer, signatureHex: string, pubkeyHex: string): boolean;
|
|
561
|
+
declare function normalizeForMatching(text: string): string;
|
|
562
|
+
declare function containsEvasionCharacters(text: string): boolean;
|
|
563
|
+
declare function redactSecrets(text: string): RedactResult;
|
|
564
|
+
declare function containsSecret(text: string): boolean;
|
|
565
|
+
declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
|
|
566
|
+
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
567
|
+
|
|
568
|
+
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 };
|