@atbash/sdk 0.7.0-dev.0 → 0.7.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/dist/index.d.mts CHANGED
@@ -11,6 +11,23 @@ interface ValidatedEndpoint {
11
11
  policy: "default" | "self-hosted";
12
12
  verifyPubKey: string | null;
13
13
  }
14
+ /**
15
+ * Builds the trusted judge host set.
16
+ *
17
+ * The compiled-in default is always trusted: a `prod` build resolves it to
18
+ * atbash.ai, a dev build to whatever DEV_ENDPOINT was set at build time. No
19
+ * dev host is spelled out in source, and dev builds still validate their own
20
+ * default.
21
+ *
22
+ * Exported for tests only. The set is a build-time value and is deliberately
23
+ * never read from the process environment — an env var would let anyone widen
24
+ * the allowlist of an already-shipped artifact, which is the silent-redirection
25
+ * attack the allowlist exists to prevent (F-003). Asserting that requires
26
+ * calling this with the environment set, so it cannot stay module-private.
27
+ *
28
+ * @internal
29
+ */
30
+ declare function buildAllowedJudgeHosts(): ReadonlySet<string>;
14
31
  declare function validateJudgeEndpoint(judge?: JudgeEndpointConfig): ValidatedEndpoint;
15
32
 
16
33
  /**
@@ -160,6 +177,13 @@ interface JudgeResult {
160
177
  enforced: boolean;
161
178
  /** Server-reported protection mode: `off`, `monitor`, or `enforce`. */
162
179
  enforcementMode: string;
180
+ /**
181
+ * Server-reported response status. The judge sets `"logged"` on the AUDIT
182
+ * tier, where it deliberately returns no verdict. This is the ONLY signal
183
+ * that distinguishes "the server chose not to enforce" from "the verdict is
184
+ * missing" — never infer the former from a null verdict alone.
185
+ */
186
+ status: string;
163
187
  }
164
188
  interface JudgmentStatus {
165
189
  status: JudgmentState;
@@ -274,6 +298,16 @@ interface AtbashOptions {
274
298
  * per-call `verifyPubKey` still overrides it.
275
299
  */
276
300
  verifyPubKey?: string;
301
+ /**
302
+ * Org's encryption public key (33-byte compressed secp256k1, hex). When set,
303
+ * tool calls are sealed to it and signed as `log_encrypted_tool_call` instead
304
+ * of `log_tool_call`, so the action never reaches the block in clear.
305
+ *
306
+ * Required for any org that has registered a key — the contract refuses
307
+ * plaintext for those. Omitted, behaviour is unchanged. A per-call
308
+ * `orgEncryptionPubKey` overrides this, same as `verifyPubKey`.
309
+ */
310
+ orgEncryptionPubKey?: string;
277
311
  /** When true (default), `auditToolCall` denies on any error. */
278
312
  failClosed?: boolean;
279
313
  logger?: AtbashLogger;
@@ -325,6 +359,8 @@ interface JudgeOptions {
325
359
  provider?: string;
326
360
  model?: string;
327
361
  verifyPubKey?: string;
362
+ /** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
363
+ orgEncryptionPubKey?: string;
328
364
  /**
329
365
  * Org name — when set, the SDK resolves which chain the agent lives
330
366
  * on via the off-chain `org_networks` map (authoritative) before
@@ -353,6 +389,8 @@ interface LogToolCallOptions {
353
389
  toolArgsJson?: string;
354
390
  /** Per-call chain override — same semantics as `JudgeOptions.chainOpts`. */
355
391
  chainOpts?: ChainOpts;
392
+ /** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
393
+ orgEncryptionPubKey?: string;
356
394
  }
357
395
 
358
396
  interface ChainConfig {
@@ -370,8 +408,12 @@ declare class Atbash {
370
408
  readonly orgName?: string;
371
409
  /** Default judge response-signing pubkey, if configured (see fromConfig). */
372
410
  readonly verifyPubKey?: string;
411
+ /** Default org encryption key — see {@link AtbashOptions.orgEncryptionPubKey}. */
412
+ readonly orgEncryptionPubKey?: string;
373
413
  /** When true (default), `auditToolCall` denies on any error. */
374
414
  readonly failClosed: boolean;
415
+ /** Org key learned from the last agent-exists check, for this agent only. */
416
+ private _orgKeyFromChain;
375
417
  private readonly logger;
376
418
  private readonly http;
377
419
  /**
@@ -585,8 +627,8 @@ declare function decryptMemoryContent(ciphertext: Buffer, nonce: Buffer, key: Bu
585
627
  * Scan a single memory entry for poisoning.
586
628
  *
587
629
  * `auth` is the agent that signs the on-chain audit log for the
588
- * LLM-judge call. The LLM is authoritative; unicode-evasion presence
589
- * is surfaced to the prompt so the LLM can weight suspicion accordingly.
630
+ * LLM-judge call. Unicode-evasion presence is surfaced to the prompt
631
+ * so the LLM can weight suspicion accordingly.
590
632
  */
591
633
  declare function scanMemory(entry: MemoryEntry, auth: AgentAuth, opts?: MemoryScanOptions): Promise<MemoryScanResult>;
592
634
  /**
@@ -617,9 +659,7 @@ interface RollbackMemoryOptions {
617
659
  * deactivated on-chain.
618
660
  *
619
661
  * The caller is responsible for running `scanMemory` first when
620
- * appropriate — this function does not gate on the verdict. The
621
- * `score` parameter is the only metadata that flows in alongside
622
- * the ciphertext.
662
+ * appropriate — this function does not gate on the verdict.
623
663
  */
624
664
  declare function commitMemoryVersion(plaintext: string, auth: AgentAuth, opts?: CommitMemoryOptions): Promise<void>;
625
665
  /**
@@ -651,35 +691,28 @@ interface MemoryRollbackEvent {
651
691
  * Cheap version-pointer probe. Returns just the id of the current
652
692
  * active memory (or null if none). No ciphertext is transferred — the
653
693
  * response is a single integer, so this is safe to call on every
654
- * memory-read hot path. Callers that hold a decrypted local copy can
655
- * compare against a stored pointer and only refetch the full row via
656
- * `getActiveMemory` when the id has changed.
694
+ * memory-read hot path.
657
695
  */
658
696
  declare function getActiveMemoryId(auth: AgentAuth, chainOpts?: ChainOpts): Promise<number | null>;
659
697
  /**
660
698
  * Recent active memory entries — subset of active versions filtered
661
- * by the chain's `MEMORY_RECENT_WINDOW_MS` (10 days at time of
662
- * writing). Intended for prompt injection at agent runtime, where
663
- * stale memory is worse than missing memory. For a time-unbounded
664
- * view of every currently active version, use `getAllAgentMemory`.
699
+ * by the chain's `MEMORY_RECENT_WINDOW_MS`. For a time-unbounded view
700
+ * of every currently active version, use `getAllAgentMemory`.
665
701
  */
666
702
  declare function getActiveMemory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
667
703
  /**
668
704
  * All currently-active memory entries with no time cutoff. Use this
669
- * when you need every active version regardless of age — e.g., a
670
- * dashboard listing, or a long-running agent whose oldest active
671
- * versions may have fallen outside `getActiveMemory`'s recent window.
705
+ * when you need every active version regardless of age.
672
706
  */
673
707
  declare function getAllAgentMemory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
674
708
  /**
675
- * Full version history — active + inactive, most recent first.
676
- * Used by rollback UX to choose a target version.
709
+ * Full version history — active + inactive, most recent first. Used
710
+ * by rollback UX to choose a target version.
677
711
  */
678
712
  declare function getMemoryHistory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
679
713
  /**
680
714
  * Fetch a single memory entry by version id, including its current
681
- * `is_active` state. Useful for inspecting a historical version
682
- * before rolling back to it.
715
+ * `is_active` state.
683
716
  */
684
717
  declare function getMemoryById(id: number, auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry>;
685
718
  /**
@@ -693,29 +726,15 @@ declare function getRollbackHistory(auth: AgentAuth, chainOpts?: ChainOpts): Pro
693
726
  */
694
727
  declare function rollbackMemory(toId: number, reason: string, auth: AgentAuth, opts?: RollbackMemoryOptions): Promise<void>;
695
728
 
696
- /**
697
- * Classify a plugin tool-call event as a memory write.
698
- *
699
- * Plugins receive `before_tool_call` events from their host runtime
700
- * (openclaw, Claude API, MCP, etc.) with varying argument shapes. This
701
- * module normalizes across shapes and returns a `MemoryEntry` when the
702
- * call is writing to a memory-like path, or `null` when the SDK should
703
- * skip the memory-scan path entirely.
704
- *
705
- * `event` and `ctx` are typed `unknown` so any plugin can pass its
706
- * native hook payloads without adaptation — the classifier probes
707
- * common key names at runtime.
708
- */
709
-
710
729
  /**
711
730
  * Tool names that indicate a memory write. Lowercase — matched
712
- * case-insensitively so both OpenClaw (lowercase) and Claude API
713
- * family (TitleCase) hit.
731
+ * case-insensitively so OpenClaw (lowercase) and Claude API family
732
+ * (TitleCase) both hit.
714
733
  */
715
734
  declare const DEFAULT_MEMORY_WRITE_TOOL_NAMES: ReadonlyArray<string>;
716
735
  /**
717
736
  * File path substrings that indicate a memory-shaped target. Callers
718
- * can extend or override this list via `classifyMemoryWrite` options.
737
+ * extend or override via `classifyMemoryWrite` options.
719
738
  */
720
739
  declare const DEFAULT_MEMORY_PATH_PATTERNS: ReadonlyArray<string>;
721
740
  /**
@@ -911,7 +930,7 @@ declare function createFileLogger(filePath: string, upstream?: UpstreamLogger):
911
930
  /** Default log-file location — `<workspaceDir>/.atbash/plugin.log`. */
912
931
  declare function defaultPluginLogPath(workspaceDir?: string): string;
913
932
 
914
- /** Dedicated memory-read tool names, matched case-insensitively. Extend via options. */
933
+ /** Dedicated memory-read tool names, matched case-insensitively. */
915
934
  declare const DEFAULT_MEMORY_READ_TOOL_NAMES: ReadonlyArray<string>;
916
935
  interface ClassifyMemoryReadOptions {
917
936
  /** Tool names that always count as memory reads. Merged with defaults. */
@@ -925,6 +944,10 @@ interface ClassifyMemoryReadOptions {
925
944
  * Returns `true` when this tool call is a memory read — either a
926
945
  * dedicated memory-read tool from `readToolNames`, or a generic read
927
946
  * tool (`read` / `read_file`) targeting a memory-shaped path.
947
+ *
948
+ * Caller-supplied `patterns` are MERGED with the defaults (matches
949
+ * Node's original behavior — extending in one plugin doesn't disable
950
+ * standard coverage).
928
951
  */
929
952
  declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
930
953
 
@@ -1044,11 +1067,94 @@ declare function flushTelemetry(): Promise<void>;
1044
1067
  */
1045
1068
  declare function shutdownTelemetry(): Promise<void>;
1046
1069
 
1070
+ /**
1071
+ * Rust core does the work; `browser/encrypted-toolcall.ts` mirrors it for the
1072
+ * browser and must produce the same columns.
1073
+ */
1074
+ /** Must match `column_aad` in the core — the label binds a ciphertext to its column. */
1075
+ declare function columnAad(toolCallId: string, column: string): string;
1076
+ /** Byte-identical to the dashboard's copy — diverging breaks hold-retry resolution. */
1077
+ declare function normalizeActionForHash(action: string): string;
1078
+ /** Lets the judge check the request body against the ciphertext without an org key. */
1079
+ declare function claimHashHex(toolName: string, action: string, context: string, toolArgsJson: string): string;
1080
+ /** @returns hex-encoded signed tx, ready to POST as `signed_log_tool_call`. */
1081
+ declare function signEncryptedToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, orgEncryptionPubKey: string, privkeyHex: string, blockchainRidHex: string): string;
1082
+
1083
+ /**
1084
+ * Cryptographic domain per payload kind. Each kind derives a distinct
1085
+ * key from the same handshake — a verdict payload handed to the
1086
+ * tool-call reader fails authentication rather than silently decoding.
1087
+ *
1088
+ * Values here are the SHORT domain names the Rust core recognizes.
1089
+ * The full HKDF `info` strings (`atbash:chain-encryption:v1:<kind>`)
1090
+ * live inside the core and never surface at the API boundary.
1091
+ */
1092
+ declare const EciesDomain: {
1093
+ readonly toolCall: "toolcall";
1094
+ readonly verdict: "verdict";
1095
+ readonly note: "note";
1096
+ readonly policy: "policy";
1097
+ readonly raw: "raw";
1098
+ };
1099
+ type EciesDomain = (typeof EciesDomain)[keyof typeof EciesDomain];
1100
+ /**
1101
+ * Encrypt `plaintext` so that only the holder of `orgPubKeyHex` can read it.
1102
+ *
1103
+ * @param plaintext UTF-8 text to protect.
1104
+ * @param orgPubKeyHex Org's compressed secp256k1 public key (33 bytes hex).
1105
+ * @param aad Context bound to the ciphertext — pass the record's id.
1106
+ * @returns raw payload for a Rell `byte_array` column.
1107
+ */
1108
+ declare function encryptForOrg(plaintext: string, orgPubKeyHex: string, aad: string, domain?: EciesDomain): Uint8Array;
1109
+ /**
1110
+ * Decrypt a payload produced by {@link encryptForOrg}.
1111
+ *
1112
+ * Throws if the key is wrong, the `aad` does not match the one used at
1113
+ * encrypt time, or the ciphertext was tampered with — GCM authentication
1114
+ * makes all three indistinguishable by design.
1115
+ *
1116
+ * @param payload Value read from the on-chain `byte_array` column.
1117
+ * @param orgPrivKeyHex Org's secp256k1 private key (32 bytes hex).
1118
+ * @param aad Must equal the `aad` used when encrypting.
1119
+ */
1120
+ declare function decryptForOrg(payload: Uint8Array, orgPrivKeyHex: string, aad: string, domain?: EciesDomain): string;
1121
+ /**
1122
+ * Size in bytes of the encrypted payload for a given plaintext length.
1123
+ * Lets callers check against the on-chain column cap
1124
+ * (`MAX_CONTENT_CIPHER_SIZE`) before submitting a transaction the
1125
+ * contract would reject.
1126
+ */
1127
+ declare function encryptedLength(plaintextByteLength: number): number;
1128
+
1129
+ /**
1130
+ * atb1.<key-fingerprint>.<claim-hash>.<base64 ciphertext>
1131
+ *
1132
+ * Normative spec: `core/src/crypto_envelope.rs`. This mirrors it for the browser.
1133
+ */
1134
+ interface Envelope {
1135
+ /** First 8 bytes of the recipient public key, hex. May be empty. */
1136
+ keyFingerprint: string;
1137
+ /** Commitment to the accompanying plaintext claims. May be empty. */
1138
+ claimHash: string;
1139
+ /** Raw ECIES payload. */
1140
+ payload: Uint8Array;
1141
+ }
1142
+ declare function packEnvelope(payload: Uint8Array, keyFingerprint?: string, claimHash?: string): string;
1143
+ /**
1144
+ * Stays true for a truncated envelope that `parseEnvelope` rejects — a severed
1145
+ * ciphertext is not plaintext, so callers must show a placeholder.
1146
+ */
1147
+ declare function isEnvelope(value: string): boolean;
1148
+ /** Null, not a throw — pre-encryption records are plaintext. */
1149
+ declare function parseEnvelope(value: string): Envelope | null;
1150
+ declare function keyFingerprintOf(pubKeyHex: string): string;
1151
+
1047
1152
  declare function isValidPrivateKey(hex: string): boolean;
1048
1153
  declare function derivePublicKey(privkey: string): string;
1049
1154
  declare function generateKeypair(): KeyPair;
1050
1155
  declare function loadAgent(privkey: string): AgentAuth;
1051
1156
  declare function signLogToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, privkey: string, blockchainRid: string): string;
1157
+
1052
1158
  declare function signJudgeAction(judgmentId: string, action: string, context: string, extra: string, privkey: string, blockchainRid: string): string;
1053
1159
  declare function verifySignature(body: Buffer, signatureHex: string, pubkeyHex: string): boolean;
1054
1160
  declare function normalizeForMatching(text: string): string;
@@ -1058,4 +1164,4 @@ declare function containsSecret(text: string): boolean;
1058
1164
  declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
1059
1165
  declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
1060
1166
 
1061
- export { type ActionType, type AgentAuth, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, type EncryptedMemory, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, classifyMemoryRead, classifyMemoryWrite, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptMemoryContent, flushTelemetry, generateKeypair, getActiveMemory, getActiveMemoryId, getAllAgentMemory, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRollbackHistory, guardMemoryWrite, isValidPrivateKey, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, normalizeStatus, normalizeVerdict, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
1167
+ export { type ActionType, type AgentAuth, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, EciesDomain, type EncryptedMemory, type Envelope, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, buildAllowedJudgeHosts, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, flushTelemetry, generateKeypair, getActiveMemory, getActiveMemoryId, getAllAgentMemory, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRollbackHistory, guardMemoryWrite, isEnvelope, isValidPrivateKey, keyFingerprintOf, loadAgent, loadAgentFromFile, loadUserConfig, normalizeActionForHash, normalizeForMatching, normalizeStatus, normalizeVerdict, packEnvelope, parseEnvelope, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signEncryptedToolCall, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
package/dist/index.d.ts CHANGED
@@ -11,6 +11,23 @@ interface ValidatedEndpoint {
11
11
  policy: "default" | "self-hosted";
12
12
  verifyPubKey: string | null;
13
13
  }
14
+ /**
15
+ * Builds the trusted judge host set.
16
+ *
17
+ * The compiled-in default is always trusted: a `prod` build resolves it to
18
+ * atbash.ai, a dev build to whatever DEV_ENDPOINT was set at build time. No
19
+ * dev host is spelled out in source, and dev builds still validate their own
20
+ * default.
21
+ *
22
+ * Exported for tests only. The set is a build-time value and is deliberately
23
+ * never read from the process environment — an env var would let anyone widen
24
+ * the allowlist of an already-shipped artifact, which is the silent-redirection
25
+ * attack the allowlist exists to prevent (F-003). Asserting that requires
26
+ * calling this with the environment set, so it cannot stay module-private.
27
+ *
28
+ * @internal
29
+ */
30
+ declare function buildAllowedJudgeHosts(): ReadonlySet<string>;
14
31
  declare function validateJudgeEndpoint(judge?: JudgeEndpointConfig): ValidatedEndpoint;
15
32
 
16
33
  /**
@@ -160,6 +177,13 @@ interface JudgeResult {
160
177
  enforced: boolean;
161
178
  /** Server-reported protection mode: `off`, `monitor`, or `enforce`. */
162
179
  enforcementMode: string;
180
+ /**
181
+ * Server-reported response status. The judge sets `"logged"` on the AUDIT
182
+ * tier, where it deliberately returns no verdict. This is the ONLY signal
183
+ * that distinguishes "the server chose not to enforce" from "the verdict is
184
+ * missing" — never infer the former from a null verdict alone.
185
+ */
186
+ status: string;
163
187
  }
164
188
  interface JudgmentStatus {
165
189
  status: JudgmentState;
@@ -274,6 +298,16 @@ interface AtbashOptions {
274
298
  * per-call `verifyPubKey` still overrides it.
275
299
  */
276
300
  verifyPubKey?: string;
301
+ /**
302
+ * Org's encryption public key (33-byte compressed secp256k1, hex). When set,
303
+ * tool calls are sealed to it and signed as `log_encrypted_tool_call` instead
304
+ * of `log_tool_call`, so the action never reaches the block in clear.
305
+ *
306
+ * Required for any org that has registered a key — the contract refuses
307
+ * plaintext for those. Omitted, behaviour is unchanged. A per-call
308
+ * `orgEncryptionPubKey` overrides this, same as `verifyPubKey`.
309
+ */
310
+ orgEncryptionPubKey?: string;
277
311
  /** When true (default), `auditToolCall` denies on any error. */
278
312
  failClosed?: boolean;
279
313
  logger?: AtbashLogger;
@@ -325,6 +359,8 @@ interface JudgeOptions {
325
359
  provider?: string;
326
360
  model?: string;
327
361
  verifyPubKey?: string;
362
+ /** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
363
+ orgEncryptionPubKey?: string;
328
364
  /**
329
365
  * Org name — when set, the SDK resolves which chain the agent lives
330
366
  * on via the off-chain `org_networks` map (authoritative) before
@@ -353,6 +389,8 @@ interface LogToolCallOptions {
353
389
  toolArgsJson?: string;
354
390
  /** Per-call chain override — same semantics as `JudgeOptions.chainOpts`. */
355
391
  chainOpts?: ChainOpts;
392
+ /** Per-call override of {@link AtbashOptions.orgEncryptionPubKey}. */
393
+ orgEncryptionPubKey?: string;
356
394
  }
357
395
 
358
396
  interface ChainConfig {
@@ -370,8 +408,12 @@ declare class Atbash {
370
408
  readonly orgName?: string;
371
409
  /** Default judge response-signing pubkey, if configured (see fromConfig). */
372
410
  readonly verifyPubKey?: string;
411
+ /** Default org encryption key — see {@link AtbashOptions.orgEncryptionPubKey}. */
412
+ readonly orgEncryptionPubKey?: string;
373
413
  /** When true (default), `auditToolCall` denies on any error. */
374
414
  readonly failClosed: boolean;
415
+ /** Org key learned from the last agent-exists check, for this agent only. */
416
+ private _orgKeyFromChain;
375
417
  private readonly logger;
376
418
  private readonly http;
377
419
  /**
@@ -585,8 +627,8 @@ declare function decryptMemoryContent(ciphertext: Buffer, nonce: Buffer, key: Bu
585
627
  * Scan a single memory entry for poisoning.
586
628
  *
587
629
  * `auth` is the agent that signs the on-chain audit log for the
588
- * LLM-judge call. The LLM is authoritative; unicode-evasion presence
589
- * is surfaced to the prompt so the LLM can weight suspicion accordingly.
630
+ * LLM-judge call. Unicode-evasion presence is surfaced to the prompt
631
+ * so the LLM can weight suspicion accordingly.
590
632
  */
591
633
  declare function scanMemory(entry: MemoryEntry, auth: AgentAuth, opts?: MemoryScanOptions): Promise<MemoryScanResult>;
592
634
  /**
@@ -617,9 +659,7 @@ interface RollbackMemoryOptions {
617
659
  * deactivated on-chain.
618
660
  *
619
661
  * The caller is responsible for running `scanMemory` first when
620
- * appropriate — this function does not gate on the verdict. The
621
- * `score` parameter is the only metadata that flows in alongside
622
- * the ciphertext.
662
+ * appropriate — this function does not gate on the verdict.
623
663
  */
624
664
  declare function commitMemoryVersion(plaintext: string, auth: AgentAuth, opts?: CommitMemoryOptions): Promise<void>;
625
665
  /**
@@ -651,35 +691,28 @@ interface MemoryRollbackEvent {
651
691
  * Cheap version-pointer probe. Returns just the id of the current
652
692
  * active memory (or null if none). No ciphertext is transferred — the
653
693
  * response is a single integer, so this is safe to call on every
654
- * memory-read hot path. Callers that hold a decrypted local copy can
655
- * compare against a stored pointer and only refetch the full row via
656
- * `getActiveMemory` when the id has changed.
694
+ * memory-read hot path.
657
695
  */
658
696
  declare function getActiveMemoryId(auth: AgentAuth, chainOpts?: ChainOpts): Promise<number | null>;
659
697
  /**
660
698
  * Recent active memory entries — subset of active versions filtered
661
- * by the chain's `MEMORY_RECENT_WINDOW_MS` (10 days at time of
662
- * writing). Intended for prompt injection at agent runtime, where
663
- * stale memory is worse than missing memory. For a time-unbounded
664
- * view of every currently active version, use `getAllAgentMemory`.
699
+ * by the chain's `MEMORY_RECENT_WINDOW_MS`. For a time-unbounded view
700
+ * of every currently active version, use `getAllAgentMemory`.
665
701
  */
666
702
  declare function getActiveMemory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
667
703
  /**
668
704
  * All currently-active memory entries with no time cutoff. Use this
669
- * when you need every active version regardless of age — e.g., a
670
- * dashboard listing, or a long-running agent whose oldest active
671
- * versions may have fallen outside `getActiveMemory`'s recent window.
705
+ * when you need every active version regardless of age.
672
706
  */
673
707
  declare function getAllAgentMemory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
674
708
  /**
675
- * Full version history — active + inactive, most recent first.
676
- * Used by rollback UX to choose a target version.
709
+ * Full version history — active + inactive, most recent first. Used
710
+ * by rollback UX to choose a target version.
677
711
  */
678
712
  declare function getMemoryHistory(auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry[]>;
679
713
  /**
680
714
  * Fetch a single memory entry by version id, including its current
681
- * `is_active` state. Useful for inspecting a historical version
682
- * before rolling back to it.
715
+ * `is_active` state.
683
716
  */
684
717
  declare function getMemoryById(id: number, auth: AgentAuth, chainOpts?: ChainOpts): Promise<AgentMemoryEntry>;
685
718
  /**
@@ -693,29 +726,15 @@ declare function getRollbackHistory(auth: AgentAuth, chainOpts?: ChainOpts): Pro
693
726
  */
694
727
  declare function rollbackMemory(toId: number, reason: string, auth: AgentAuth, opts?: RollbackMemoryOptions): Promise<void>;
695
728
 
696
- /**
697
- * Classify a plugin tool-call event as a memory write.
698
- *
699
- * Plugins receive `before_tool_call` events from their host runtime
700
- * (openclaw, Claude API, MCP, etc.) with varying argument shapes. This
701
- * module normalizes across shapes and returns a `MemoryEntry` when the
702
- * call is writing to a memory-like path, or `null` when the SDK should
703
- * skip the memory-scan path entirely.
704
- *
705
- * `event` and `ctx` are typed `unknown` so any plugin can pass its
706
- * native hook payloads without adaptation — the classifier probes
707
- * common key names at runtime.
708
- */
709
-
710
729
  /**
711
730
  * Tool names that indicate a memory write. Lowercase — matched
712
- * case-insensitively so both OpenClaw (lowercase) and Claude API
713
- * family (TitleCase) hit.
731
+ * case-insensitively so OpenClaw (lowercase) and Claude API family
732
+ * (TitleCase) both hit.
714
733
  */
715
734
  declare const DEFAULT_MEMORY_WRITE_TOOL_NAMES: ReadonlyArray<string>;
716
735
  /**
717
736
  * File path substrings that indicate a memory-shaped target. Callers
718
- * can extend or override this list via `classifyMemoryWrite` options.
737
+ * extend or override via `classifyMemoryWrite` options.
719
738
  */
720
739
  declare const DEFAULT_MEMORY_PATH_PATTERNS: ReadonlyArray<string>;
721
740
  /**
@@ -911,7 +930,7 @@ declare function createFileLogger(filePath: string, upstream?: UpstreamLogger):
911
930
  /** Default log-file location — `<workspaceDir>/.atbash/plugin.log`. */
912
931
  declare function defaultPluginLogPath(workspaceDir?: string): string;
913
932
 
914
- /** Dedicated memory-read tool names, matched case-insensitively. Extend via options. */
933
+ /** Dedicated memory-read tool names, matched case-insensitively. */
915
934
  declare const DEFAULT_MEMORY_READ_TOOL_NAMES: ReadonlyArray<string>;
916
935
  interface ClassifyMemoryReadOptions {
917
936
  /** Tool names that always count as memory reads. Merged with defaults. */
@@ -925,6 +944,10 @@ interface ClassifyMemoryReadOptions {
925
944
  * Returns `true` when this tool call is a memory read — either a
926
945
  * dedicated memory-read tool from `readToolNames`, or a generic read
927
946
  * tool (`read` / `read_file`) targeting a memory-shaped path.
947
+ *
948
+ * Caller-supplied `patterns` are MERGED with the defaults (matches
949
+ * Node's original behavior — extending in one plugin doesn't disable
950
+ * standard coverage).
928
951
  */
929
952
  declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
930
953
 
@@ -1044,11 +1067,94 @@ declare function flushTelemetry(): Promise<void>;
1044
1067
  */
1045
1068
  declare function shutdownTelemetry(): Promise<void>;
1046
1069
 
1070
+ /**
1071
+ * Rust core does the work; `browser/encrypted-toolcall.ts` mirrors it for the
1072
+ * browser and must produce the same columns.
1073
+ */
1074
+ /** Must match `column_aad` in the core — the label binds a ciphertext to its column. */
1075
+ declare function columnAad(toolCallId: string, column: string): string;
1076
+ /** Byte-identical to the dashboard's copy — diverging breaks hold-retry resolution. */
1077
+ declare function normalizeActionForHash(action: string): string;
1078
+ /** Lets the judge check the request body against the ciphertext without an org key. */
1079
+ declare function claimHashHex(toolName: string, action: string, context: string, toolArgsJson: string): string;
1080
+ /** @returns hex-encoded signed tx, ready to POST as `signed_log_tool_call`. */
1081
+ declare function signEncryptedToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, orgEncryptionPubKey: string, privkeyHex: string, blockchainRidHex: string): string;
1082
+
1083
+ /**
1084
+ * Cryptographic domain per payload kind. Each kind derives a distinct
1085
+ * key from the same handshake — a verdict payload handed to the
1086
+ * tool-call reader fails authentication rather than silently decoding.
1087
+ *
1088
+ * Values here are the SHORT domain names the Rust core recognizes.
1089
+ * The full HKDF `info` strings (`atbash:chain-encryption:v1:<kind>`)
1090
+ * live inside the core and never surface at the API boundary.
1091
+ */
1092
+ declare const EciesDomain: {
1093
+ readonly toolCall: "toolcall";
1094
+ readonly verdict: "verdict";
1095
+ readonly note: "note";
1096
+ readonly policy: "policy";
1097
+ readonly raw: "raw";
1098
+ };
1099
+ type EciesDomain = (typeof EciesDomain)[keyof typeof EciesDomain];
1100
+ /**
1101
+ * Encrypt `plaintext` so that only the holder of `orgPubKeyHex` can read it.
1102
+ *
1103
+ * @param plaintext UTF-8 text to protect.
1104
+ * @param orgPubKeyHex Org's compressed secp256k1 public key (33 bytes hex).
1105
+ * @param aad Context bound to the ciphertext — pass the record's id.
1106
+ * @returns raw payload for a Rell `byte_array` column.
1107
+ */
1108
+ declare function encryptForOrg(plaintext: string, orgPubKeyHex: string, aad: string, domain?: EciesDomain): Uint8Array;
1109
+ /**
1110
+ * Decrypt a payload produced by {@link encryptForOrg}.
1111
+ *
1112
+ * Throws if the key is wrong, the `aad` does not match the one used at
1113
+ * encrypt time, or the ciphertext was tampered with — GCM authentication
1114
+ * makes all three indistinguishable by design.
1115
+ *
1116
+ * @param payload Value read from the on-chain `byte_array` column.
1117
+ * @param orgPrivKeyHex Org's secp256k1 private key (32 bytes hex).
1118
+ * @param aad Must equal the `aad` used when encrypting.
1119
+ */
1120
+ declare function decryptForOrg(payload: Uint8Array, orgPrivKeyHex: string, aad: string, domain?: EciesDomain): string;
1121
+ /**
1122
+ * Size in bytes of the encrypted payload for a given plaintext length.
1123
+ * Lets callers check against the on-chain column cap
1124
+ * (`MAX_CONTENT_CIPHER_SIZE`) before submitting a transaction the
1125
+ * contract would reject.
1126
+ */
1127
+ declare function encryptedLength(plaintextByteLength: number): number;
1128
+
1129
+ /**
1130
+ * atb1.<key-fingerprint>.<claim-hash>.<base64 ciphertext>
1131
+ *
1132
+ * Normative spec: `core/src/crypto_envelope.rs`. This mirrors it for the browser.
1133
+ */
1134
+ interface Envelope {
1135
+ /** First 8 bytes of the recipient public key, hex. May be empty. */
1136
+ keyFingerprint: string;
1137
+ /** Commitment to the accompanying plaintext claims. May be empty. */
1138
+ claimHash: string;
1139
+ /** Raw ECIES payload. */
1140
+ payload: Uint8Array;
1141
+ }
1142
+ declare function packEnvelope(payload: Uint8Array, keyFingerprint?: string, claimHash?: string): string;
1143
+ /**
1144
+ * Stays true for a truncated envelope that `parseEnvelope` rejects — a severed
1145
+ * ciphertext is not plaintext, so callers must show a placeholder.
1146
+ */
1147
+ declare function isEnvelope(value: string): boolean;
1148
+ /** Null, not a throw — pre-encryption records are plaintext. */
1149
+ declare function parseEnvelope(value: string): Envelope | null;
1150
+ declare function keyFingerprintOf(pubKeyHex: string): string;
1151
+
1047
1152
  declare function isValidPrivateKey(hex: string): boolean;
1048
1153
  declare function derivePublicKey(privkey: string): string;
1049
1154
  declare function generateKeypair(): KeyPair;
1050
1155
  declare function loadAgent(privkey: string): AgentAuth;
1051
1156
  declare function signLogToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, privkey: string, blockchainRid: string): string;
1157
+
1052
1158
  declare function signJudgeAction(judgmentId: string, action: string, context: string, extra: string, privkey: string, blockchainRid: string): string;
1053
1159
  declare function verifySignature(body: Buffer, signatureHex: string, pubkeyHex: string): boolean;
1054
1160
  declare function normalizeForMatching(text: string): string;
@@ -1058,4 +1164,4 @@ declare function containsSecret(text: string): boolean;
1058
1164
  declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
1059
1165
  declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
1060
1166
 
1061
- export { type ActionType, type AgentAuth, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, type EncryptedMemory, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, classifyMemoryRead, classifyMemoryWrite, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptMemoryContent, flushTelemetry, generateKeypair, getActiveMemory, getActiveMemoryId, getAllAgentMemory, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRollbackHistory, guardMemoryWrite, isValidPrivateKey, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, normalizeStatus, normalizeVerdict, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
1167
+ export { type ActionType, type AgentAuth, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, EciesDomain, type EncryptedMemory, type Envelope, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, buildAllowedJudgeHosts, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, flushTelemetry, generateKeypair, getActiveMemory, getActiveMemoryId, getAllAgentMemory, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRollbackHistory, guardMemoryWrite, isEnvelope, isValidPrivateKey, keyFingerprintOf, loadAgent, loadAgentFromFile, loadUserConfig, normalizeActionForHash, normalizeForMatching, normalizeStatus, normalizeVerdict, packEnvelope, parseEnvelope, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signEncryptedToolCall, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };