@atbash/sdk 0.10.0-dev.0 → 0.10.1-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/dist/browser.d.mts +31 -27
- package/dist/browser.mjs +68 -19
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +31 -27
- package/dist/index.d.ts +31 -27
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -0
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +5 -5
- package/index.js +193 -80
- package/package.json +5 -5
package/dist/browser.d.mts
CHANGED
|
@@ -1049,35 +1049,16 @@ declare function flushTelemetry(): Promise<void>;
|
|
|
1049
1049
|
declare function shutdownTelemetry(): Promise<void>;
|
|
1050
1050
|
|
|
1051
1051
|
/**
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
* this module is a thin wrapper. Browser callers get the pure-TS shim
|
|
1055
|
-
* at `src-ts/browser/encrypted-toolcall.ts` (NAPI can't run in-browser).
|
|
1056
|
-
*/
|
|
1057
|
-
/** Plaintext fields of a tool call, sealed into a single ECIES payload. */
|
|
1058
|
-
interface ToolCallPlaintext {
|
|
1059
|
-
tool_name: string;
|
|
1060
|
-
action: string;
|
|
1061
|
-
context: string;
|
|
1062
|
-
tool_args_json: string;
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Canonical form of an action for the retry-cache hash. Byte-identical to
|
|
1066
|
-
* the dashboard's `normalizeActionForHash` — diverging silently breaks
|
|
1067
|
-
* YELLOW-hold retry resolution.
|
|
1052
|
+
* Rust core does the work; `browser/encrypted-toolcall.ts` mirrors it for the
|
|
1053
|
+
* browser and must produce the same columns.
|
|
1068
1054
|
*/
|
|
1055
|
+
/** Must match `column_aad` in the core — the label binds a ciphertext to its column. */
|
|
1056
|
+
declare function columnAad(toolCallId: string, column: string): string;
|
|
1057
|
+
/** Byte-identical to the dashboard's copy — diverging breaks hold-retry resolution. */
|
|
1069
1058
|
declare function normalizeActionForHash(action: string): string;
|
|
1070
|
-
/**
|
|
1071
|
-
* Signed commitment to the plaintext claims the caller sends alongside the
|
|
1072
|
-
* ciphertext. The judge reads plaintext from the request body but holds no
|
|
1073
|
-
* org key; this hash lets it verify body-vs-ciphertext without decrypting.
|
|
1074
|
-
* Byte-identical to the dashboard's `claimHashHex`.
|
|
1075
|
-
*/
|
|
1059
|
+
/** Lets the judge check the request body against the ciphertext without an org key. */
|
|
1076
1060
|
declare function claimHashHex(toolName: string, action: string, context: string, toolArgsJson: string): string;
|
|
1077
|
-
/**
|
|
1078
|
-
* Build + sign a `log_encrypted_tool_call` transaction. Returns hex-encoded
|
|
1079
|
-
* signed tx, ready to POST as `signed_log_tool_call`.
|
|
1080
|
-
*/
|
|
1061
|
+
/** @returns hex-encoded signed tx, ready to POST as `signed_log_tool_call`. */
|
|
1081
1062
|
declare function signEncryptedToolCall(toolCallId: string, action: string, context: string, toolName: string, toolArgsJson: string, orgEncryptionPubKey: string, privkeyHex: string, blockchainRidHex: string): string;
|
|
1082
1063
|
|
|
1083
1064
|
/**
|
|
@@ -1126,6 +1107,29 @@ declare function decryptForOrg(payload: Uint8Array, orgPrivKeyHex: string, aad:
|
|
|
1126
1107
|
*/
|
|
1127
1108
|
declare function encryptedLength(plaintextByteLength: number): number;
|
|
1128
1109
|
|
|
1110
|
+
/**
|
|
1111
|
+
* atb1.<key-fingerprint>.<claim-hash>.<base64 ciphertext>
|
|
1112
|
+
*
|
|
1113
|
+
* Normative spec: `core/src/crypto_envelope.rs`. This mirrors it for the browser.
|
|
1114
|
+
*/
|
|
1115
|
+
interface Envelope {
|
|
1116
|
+
/** First 8 bytes of the recipient public key, hex. May be empty. */
|
|
1117
|
+
keyFingerprint: string;
|
|
1118
|
+
/** Commitment to the accompanying plaintext claims. May be empty. */
|
|
1119
|
+
claimHash: string;
|
|
1120
|
+
/** Raw ECIES payload. */
|
|
1121
|
+
payload: Uint8Array;
|
|
1122
|
+
}
|
|
1123
|
+
declare function packEnvelope(payload: Uint8Array, keyFingerprint?: string, claimHash?: string): string;
|
|
1124
|
+
/**
|
|
1125
|
+
* Stays true for a truncated envelope that `parseEnvelope` rejects — a severed
|
|
1126
|
+
* ciphertext is not plaintext, so callers must show a placeholder.
|
|
1127
|
+
*/
|
|
1128
|
+
declare function isEnvelope(value: string): boolean;
|
|
1129
|
+
/** Null, not a throw — pre-encryption records are plaintext. */
|
|
1130
|
+
declare function parseEnvelope(value: string): Envelope | null;
|
|
1131
|
+
declare function keyFingerprintOf(pubKeyHex: string): string;
|
|
1132
|
+
|
|
1129
1133
|
declare function isValidPrivateKey(hex: string): boolean;
|
|
1130
1134
|
declare function derivePublicKey(privkey: string): string;
|
|
1131
1135
|
declare function generateKeypair(): KeyPair;
|
|
@@ -1141,4 +1145,4 @@ declare function containsSecret(text: string): boolean;
|
|
|
1141
1145
|
declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
|
|
1142
1146
|
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
1143
1147
|
|
|
1144
|
-
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 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
|
|
1148
|
+
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, 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/browser.mjs
CHANGED
|
@@ -44126,6 +44126,44 @@ function encryptedLength(plaintextByteLength) {
|
|
|
44126
44126
|
return HEADER_LEN + plaintextByteLength + GCM_TAG_LEN;
|
|
44127
44127
|
}
|
|
44128
44128
|
|
|
44129
|
+
// src-ts/crypto/envelope.ts
|
|
44130
|
+
var PREFIX = "atb1";
|
|
44131
|
+
var SEPARATOR = ".";
|
|
44132
|
+
function toBase64(bytes) {
|
|
44133
|
+
let binary = "";
|
|
44134
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
44135
|
+
return btoa(binary);
|
|
44136
|
+
}
|
|
44137
|
+
function fromBase64(text) {
|
|
44138
|
+
const binary = atob(text);
|
|
44139
|
+
const out = new Uint8Array(binary.length);
|
|
44140
|
+
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
44141
|
+
return out;
|
|
44142
|
+
}
|
|
44143
|
+
function packEnvelope(payload, keyFingerprint = "", claimHash = "") {
|
|
44144
|
+
return [PREFIX, keyFingerprint, claimHash, toBase64(payload)].join(SEPARATOR);
|
|
44145
|
+
}
|
|
44146
|
+
function fieldWidthOk(value, hexChars) {
|
|
44147
|
+
return value.length === 0 ? true : value.length === hexChars && /^[0-9a-f]+$/.test(value);
|
|
44148
|
+
}
|
|
44149
|
+
function isEnvelope(value) {
|
|
44150
|
+
if (typeof value !== "string" || !value.startsWith(PREFIX + SEPARATOR)) return false;
|
|
44151
|
+
const parts = value.split(SEPARATOR);
|
|
44152
|
+
return parts.length >= 4 && fieldWidthOk(parts[1], 16) && fieldWidthOk(parts[2], 64);
|
|
44153
|
+
}
|
|
44154
|
+
function parseEnvelope(value) {
|
|
44155
|
+
if (!isEnvelope(value)) return null;
|
|
44156
|
+
const [, keyFingerprint, claimHash, ...rest] = value.split(SEPARATOR);
|
|
44157
|
+
try {
|
|
44158
|
+
return { keyFingerprint, claimHash, payload: fromBase64(rest.join(SEPARATOR)) };
|
|
44159
|
+
} catch {
|
|
44160
|
+
return null;
|
|
44161
|
+
}
|
|
44162
|
+
}
|
|
44163
|
+
function keyFingerprintOf(pubKeyHex) {
|
|
44164
|
+
return pubKeyHex.trim().replace(/^0x/i, "").toLowerCase().slice(0, 16);
|
|
44165
|
+
}
|
|
44166
|
+
|
|
44129
44167
|
// src-ts/browser/encrypted-toolcall.ts
|
|
44130
44168
|
var { Buffer: PolyBuffer, gtx: pcgtx2 } = index;
|
|
44131
44169
|
var MERKLE_HASH_VERSION2 = 2;
|
|
@@ -44138,6 +44176,9 @@ function claimHashHex(toolName, action, context, toolArgsJson) {
|
|
|
44138
44176
|
]);
|
|
44139
44177
|
return bytesToHex2(sha256(new TextEncoder().encode(canonical)));
|
|
44140
44178
|
}
|
|
44179
|
+
function columnAad(toolCallId, column) {
|
|
44180
|
+
return `${toolCallId}:${column}`;
|
|
44181
|
+
}
|
|
44141
44182
|
function normalizeActionForHash(action) {
|
|
44142
44183
|
action = action.trim();
|
|
44143
44184
|
try {
|
|
@@ -44183,31 +44224,34 @@ function signOpWithBytes(opName, args, privkeyHex, blockchainRidHex) {
|
|
|
44183
44224
|
return pcgtx2.serialize(g).toString("hex");
|
|
44184
44225
|
}
|
|
44185
44226
|
function signEncryptedToolCall(toolCallId, action, context, toolName, toolArgsJson, orgEncryptionPubKey, privkeyHex, blockchainRidHex) {
|
|
44186
|
-
const
|
|
44187
|
-
|
|
44188
|
-
|
|
44189
|
-
|
|
44190
|
-
|
|
44191
|
-
|
|
44192
|
-
|
|
44193
|
-
|
|
44194
|
-
|
|
44195
|
-
toolCallId,
|
|
44196
|
-
EciesDomain.toolCall
|
|
44227
|
+
const fingerprint = keyFingerprintOf(orgEncryptionPubKey);
|
|
44228
|
+
const seal = (text, column) => text === "" ? "" : packEnvelope(
|
|
44229
|
+
encryptForOrg(
|
|
44230
|
+
text,
|
|
44231
|
+
orgEncryptionPubKey,
|
|
44232
|
+
columnAad(toolCallId, column),
|
|
44233
|
+
EciesDomain.toolCall
|
|
44234
|
+
),
|
|
44235
|
+
fingerprint
|
|
44197
44236
|
);
|
|
44198
|
-
const
|
|
44199
|
-
|
|
44237
|
+
const actionColumn = packEnvelope(
|
|
44238
|
+
encryptForOrg(
|
|
44239
|
+
action,
|
|
44240
|
+
orgEncryptionPubKey,
|
|
44241
|
+
columnAad(toolCallId, "action"),
|
|
44242
|
+
EciesDomain.toolCall
|
|
44243
|
+
),
|
|
44244
|
+
fingerprint,
|
|
44245
|
+
claimHashHex(toolName, action, context, toolArgsJson)
|
|
44200
44246
|
);
|
|
44201
44247
|
return signOpWithBytes(
|
|
44202
|
-
"
|
|
44248
|
+
"log_tool_call",
|
|
44203
44249
|
[
|
|
44204
44250
|
toolCallId,
|
|
44251
|
+
actionColumn,
|
|
44252
|
+
seal(context, "context"),
|
|
44205
44253
|
toolName,
|
|
44206
|
-
|
|
44207
|
-
actionHash,
|
|
44208
|
-
// Empty = "org's current key"; chain resolves it.
|
|
44209
|
-
PolyBuffer.from(new Uint8Array(0)),
|
|
44210
|
-
claimHashHex(toolName, action, context, toolArgsJson)
|
|
44254
|
+
seal(toolArgsJson, "tool_args")
|
|
44211
44255
|
],
|
|
44212
44256
|
privkeyHex,
|
|
44213
44257
|
blockchainRidHex
|
|
@@ -45697,6 +45741,7 @@ export {
|
|
|
45697
45741
|
claimHashHex,
|
|
45698
45742
|
classifyMemoryRead,
|
|
45699
45743
|
classifyMemoryWrite,
|
|
45744
|
+
columnAad,
|
|
45700
45745
|
commitMemoryVersion,
|
|
45701
45746
|
containsEvasionCharacters2 as containsEvasionCharacters,
|
|
45702
45747
|
containsSecret2 as containsSecret,
|
|
@@ -45724,7 +45769,9 @@ export {
|
|
|
45724
45769
|
getMemoryHistory,
|
|
45725
45770
|
getRollbackHistory,
|
|
45726
45771
|
guardMemoryWrite,
|
|
45772
|
+
isEnvelope,
|
|
45727
45773
|
isValidPrivateKey2 as isValidPrivateKey,
|
|
45774
|
+
keyFingerprintOf,
|
|
45728
45775
|
loadAgent2 as loadAgent,
|
|
45729
45776
|
loadAgentFromFile,
|
|
45730
45777
|
loadUserConfig,
|
|
@@ -45732,6 +45779,8 @@ export {
|
|
|
45732
45779
|
normalizeForMatching2 as normalizeForMatching,
|
|
45733
45780
|
normalizeStatus,
|
|
45734
45781
|
normalizeVerdict,
|
|
45782
|
+
packEnvelope,
|
|
45783
|
+
parseEnvelope,
|
|
45735
45784
|
pubkeyToHex,
|
|
45736
45785
|
recordCall,
|
|
45737
45786
|
recordDuration,
|