@atbash/sdk 0.17.0-dev.0 → 0.19.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/LICENSE +202 -28
- package/NOTICE +10 -0
- package/README.md +76 -13
- package/THIRD-PARTY-NOTICES +10256 -0
- package/dist/browser.d.mts +323 -50
- package/dist/browser.mjs +231 -69
- package/dist/index.d.mts +323 -50
- package/dist/index.d.ts +323 -50
- package/dist/index.js +1072 -41482
- package/dist/index.mjs +2728 -43169
- package/index.d.ts +19 -0
- package/index.js +61 -54
- package/package.json +13 -8
package/dist/browser.mjs
CHANGED
|
@@ -40585,7 +40585,7 @@ function requireFailoverStrategies() {
|
|
|
40585
40585
|
exports.createTimeoutPromise = createTimeoutPromise;
|
|
40586
40586
|
const utils_12 = requireUtils$1();
|
|
40587
40587
|
const httpUtil_1 = httpUtil;
|
|
40588
|
-
const
|
|
40588
|
+
const logger3 = __importStar2(logger$3);
|
|
40589
40589
|
const http_utils_1 = httpUtils;
|
|
40590
40590
|
function getUnreachableDuration(statusCode, error4) {
|
|
40591
40591
|
if ((0, http_utils_1.isNetworkError)(error4)) {
|
|
@@ -40686,7 +40686,7 @@ function requireFailoverStrategies() {
|
|
|
40686
40686
|
while (true) {
|
|
40687
40687
|
if (groupedSuccessfulResponses.maxNumberOfEqualResponses() >= bftMajorityThreshold) {
|
|
40688
40688
|
if (groupedSuccessfulResponses.numberOfDistinctResponses() > 1) {
|
|
40689
|
-
|
|
40689
|
+
logger3.warning(`Got disagreeing responses, but could still reach BFT majority`);
|
|
40690
40690
|
}
|
|
40691
40691
|
return groupedSuccessfulResponses.majorityResponse();
|
|
40692
40692
|
}
|
|
@@ -40724,7 +40724,7 @@ function requireFailoverStrategies() {
|
|
|
40724
40724
|
if (!isError4 && !error4) {
|
|
40725
40725
|
return { error: error4, statusCode, rspBody, transactionTimestamp };
|
|
40726
40726
|
}
|
|
40727
|
-
|
|
40727
|
+
logger3.info(`${method} request failed on ${endpoint.url}. Attempt: ${attempt + 1} / ${config2.attemptsPerEndpoint}`);
|
|
40728
40728
|
yield (0, utils_12.sleep)(config2.attemptInterval);
|
|
40729
40729
|
}
|
|
40730
40730
|
return { error: error4, statusCode, rspBody, transactionTimestamp };
|
|
@@ -40760,7 +40760,7 @@ function requireFailoverStrategies() {
|
|
|
40760
40760
|
if (isServerError) {
|
|
40761
40761
|
const duration = getUnreachableDuration(statusCode !== null && statusCode !== void 0 ? statusCode : void 0, response.error);
|
|
40762
40762
|
nodeManager2.makeNodeUnavailable(node2.url, duration);
|
|
40763
|
-
|
|
40763
|
+
logger3.info(`request failed with server error on ${node2.url} trying next node`);
|
|
40764
40764
|
break;
|
|
40765
40765
|
}
|
|
40766
40766
|
if (isClientError) {
|
|
@@ -40768,11 +40768,11 @@ function requireFailoverStrategies() {
|
|
|
40768
40768
|
return { error: error4, statusCode, rspBody, transactionTimestamp };
|
|
40769
40769
|
}
|
|
40770
40770
|
if (!nodeManager2.useStickyNode) {
|
|
40771
|
-
|
|
40771
|
+
logger3.info(`request failed client error on ${node2.url} trying next node`);
|
|
40772
40772
|
break;
|
|
40773
40773
|
}
|
|
40774
40774
|
}
|
|
40775
|
-
|
|
40775
|
+
logger3.info(`${method} request failed on ${node2.url}. Attempt: ${attempt + 1} / ${config2.attemptsPerEndpoint}`);
|
|
40776
40776
|
if (config2.attemptInterval > 0) {
|
|
40777
40777
|
yield (0, utils_12.sleep)(config2.attemptInterval);
|
|
40778
40778
|
}
|
|
@@ -41001,7 +41001,7 @@ function requireUtils$1() {
|
|
|
41001
41001
|
exports.getBlockchainRidFromIid = getBlockchainRidFromIid;
|
|
41002
41002
|
exports.convertToPrintable = convertToPrintable;
|
|
41003
41003
|
const buffer_12 = buffer$3;
|
|
41004
|
-
const
|
|
41004
|
+
const logger3 = __importStar2(logger$3);
|
|
41005
41005
|
const errors_12 = errors;
|
|
41006
41006
|
const gtxTool = __importStar2(gtx$1);
|
|
41007
41007
|
const errors_2 = errors;
|
|
@@ -41084,7 +41084,7 @@ function requireUtils$1() {
|
|
|
41084
41084
|
function validTxRid(txRID) {
|
|
41085
41085
|
if (txRID.length != 32) {
|
|
41086
41086
|
const error4 = new errors_12.InvalidTxRidException(txRID);
|
|
41087
|
-
|
|
41087
|
+
logger3.error(error4.toString());
|
|
41088
41088
|
return false;
|
|
41089
41089
|
}
|
|
41090
41090
|
return true;
|
|
@@ -41487,7 +41487,7 @@ function requireUtils$1() {
|
|
|
41487
41487
|
function handleGetResponse(error4, statusCode, responseObject, callback) {
|
|
41488
41488
|
try {
|
|
41489
41489
|
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
41490
|
-
|
|
41490
|
+
logger3.debug(`error: ${error4}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
41491
41491
|
if (error4) {
|
|
41492
41492
|
return callback(error4, null);
|
|
41493
41493
|
}
|
|
@@ -41497,16 +41497,16 @@ function requireUtils$1() {
|
|
|
41497
41497
|
return callback(null, responseObject);
|
|
41498
41498
|
} catch (error5) {
|
|
41499
41499
|
callback(error5, null);
|
|
41500
|
-
|
|
41500
|
+
logger3.error(`client.handleGetResponse(): Failed to call the callback function. ${error5}`);
|
|
41501
41501
|
}
|
|
41502
41502
|
}
|
|
41503
41503
|
function handlePostResponse(error4, statusCode, responseObject, callback) {
|
|
41504
41504
|
var _a2;
|
|
41505
41505
|
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
41506
|
-
|
|
41506
|
+
logger3.debug(`error: ${error4}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
41507
41507
|
try {
|
|
41508
41508
|
if (error4) {
|
|
41509
|
-
|
|
41509
|
+
logger3.error(`In client post(). ${error4}`);
|
|
41510
41510
|
callback(error4, null);
|
|
41511
41511
|
} else if (!statusCode || !(0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
|
|
41512
41512
|
let errorMessage2 = `Unexpected status code from server. Code: ${statusCode}.`;
|
|
@@ -41514,14 +41514,14 @@ function requireUtils$1() {
|
|
|
41514
41514
|
if (responseObjectPrintable) {
|
|
41515
41515
|
errorMessage2 += ` Message: ${responseObjectPrintable}.`;
|
|
41516
41516
|
}
|
|
41517
|
-
|
|
41517
|
+
logger3.error(errorMessage2);
|
|
41518
41518
|
callback(new errors_12.UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, errorMessageInResponseBody || responseObjectPrintable), responseObject);
|
|
41519
41519
|
} else {
|
|
41520
|
-
|
|
41520
|
+
logger3.info(`Calling responseCallback with responseObject: ${responseObjectPrintable}`);
|
|
41521
41521
|
callback(null, responseObject);
|
|
41522
41522
|
}
|
|
41523
41523
|
} catch (error5) {
|
|
41524
|
-
|
|
41524
|
+
logger3.error(`client.handlePostResponse(): Failed to call callback function ${error5}`);
|
|
41525
41525
|
}
|
|
41526
41526
|
}
|
|
41527
41527
|
function getBlockchainRidFromIid(_a2) {
|
|
@@ -42259,7 +42259,7 @@ function requireBlockchainClient() {
|
|
|
42259
42259
|
const crypto_12 = requireCryptoBrowserify();
|
|
42260
42260
|
const cloneDeep_1$1 = __importDefault2(cloneDeep_1);
|
|
42261
42261
|
const IccfProofTxMaterialBuilder_1 = requireIccfProofTxMaterialBuilder();
|
|
42262
|
-
const
|
|
42262
|
+
const logger3 = __importStar2(logger$3);
|
|
42263
42263
|
const formatter_12 = formatter;
|
|
42264
42264
|
const serialization_12 = serialization$2;
|
|
42265
42265
|
const gtxTool = __importStar2(gtx$1);
|
|
@@ -42301,7 +42301,7 @@ function requireBlockchainClient() {
|
|
|
42301
42301
|
},
|
|
42302
42302
|
signTransaction(transaction, signMethod2, callback) {
|
|
42303
42303
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42304
|
-
|
|
42304
|
+
logger3.debug(`Signing transaction with ${!(0, utils_12.isKeyPair)(signMethod2) ? "signature provider containing " : ""}pubKey: ${(0, formatter_12.toString)(signMethod2.pubKey)}`);
|
|
42305
42305
|
const gtx2 = (0, utils_12.getGTXFromBufferOrTransactionOrOperation)(transaction, config2.blockchainRid);
|
|
42306
42306
|
try {
|
|
42307
42307
|
const signedTx = yield (0, utils_12.isKeyPair)(signMethod2) ? gtxTool.sign(gtx2, signMethod2.privKey, config2.merkleHashVersion, signMethod2.pubKey) : gtxTool.sign(gtx2, signMethod2, config2.merkleHashVersion);
|
|
@@ -42326,7 +42326,7 @@ function requireBlockchainClient() {
|
|
|
42326
42326
|
const promiEvent = new promiEvents_12.Web3PromiEvent((resolve2, reject) => __awaiter2(this, void 0, void 0, function* () {
|
|
42327
42327
|
let error4 = null;
|
|
42328
42328
|
for (let i = 0; i < config2.retryTransactionPolling.count; i++) {
|
|
42329
|
-
|
|
42329
|
+
logger3.info(`sendTransactionWithRetries attempt ${i + 1} of ${config2.retryTransactionPolling.count}`);
|
|
42330
42330
|
const tmpPromiEvent = sendOnce().on(enums_12.TransactionEvent.ClusterAnchoringConfirmation, (receipt) => {
|
|
42331
42331
|
promiEvent.emit(enums_12.TransactionEvent.ClusterAnchoringConfirmation, receipt);
|
|
42332
42332
|
}).on(enums_12.TransactionEvent.SystemAnchoringConfirmation, (receipt) => {
|
|
@@ -42338,7 +42338,7 @@ function requireBlockchainClient() {
|
|
|
42338
42338
|
}).on(enums_12.TransactionEvent.DappConfirmed, (receipt) => {
|
|
42339
42339
|
promiEvent.emit(enums_12.TransactionEvent.DappConfirmed, receipt);
|
|
42340
42340
|
}).catch((tmpError) => {
|
|
42341
|
-
|
|
42341
|
+
logger3.warning(`sendTransactionWithRetries error on attempt ${i + 1} of ${config2.retryTransactionPolling.count}: ${tmpError}`);
|
|
42342
42342
|
promiEvent.emit(enums_12.TransactionEvent.Rejected, tmpError);
|
|
42343
42343
|
error4 = tmpError;
|
|
42344
42344
|
});
|
|
@@ -43073,11 +43073,11 @@ function requireDecodeTransactionToGtx() {
|
|
|
43073
43073
|
Object.defineProperty(decodeTransactionToGtx, "__esModule", { value: true });
|
|
43074
43074
|
decodeTransactionToGtx.decodeTransactionToGtx = decodeTransactionToGtx$1;
|
|
43075
43075
|
const gtxTool = __importStar2(gtx$1);
|
|
43076
|
-
const
|
|
43076
|
+
const logger3 = __importStar2(logger$3);
|
|
43077
43077
|
const dump_1 = requireDump();
|
|
43078
43078
|
function decodeTransactionToGtx$1(encodedTransaction) {
|
|
43079
43079
|
const gtx2 = gtxTool.deserialize(encodedTransaction);
|
|
43080
|
-
|
|
43080
|
+
logger3.debug(`Output from deserializing a raw transaction: ${(0, dump_1.dumpGtv)(gtx2)}`);
|
|
43081
43081
|
return gtx2;
|
|
43082
43082
|
}
|
|
43083
43083
|
return decodeTransactionToGtx;
|
|
@@ -43455,6 +43455,17 @@ var native = {
|
|
|
43455
43455
|
defaultChromiaNodeUrls: () => [...DEFAULT_CHROMIA_NODE_URLS_ARR],
|
|
43456
43456
|
defaultPrivateNodeUrls: () => [...DEFAULT_PRIVATE_NODE_URLS_ARR],
|
|
43457
43457
|
// Server-only surfaces — throw at runtime, keep types satisfied.
|
|
43458
|
+
// The memory signers are here and not with the other signing shims because
|
|
43459
|
+
// their args are encrypted by `encryptMemoryContent`, which this build does
|
|
43460
|
+
// not have: a browser could sign the transaction but never produce one worth
|
|
43461
|
+
// sending.
|
|
43462
|
+
signAddAgentMemory: stub("signAddAgentMemory"),
|
|
43463
|
+
signRollbackAgentMemory: stub("signRollbackAgentMemory"),
|
|
43464
|
+
extractMemoryEdits: stub("extractMemoryEdits"),
|
|
43465
|
+
applyMemoryEdits: stub("applyMemoryEdits"),
|
|
43466
|
+
memorySlotForPath: stub("memorySlotForPath"),
|
|
43467
|
+
isSafeMemorySlot: stub("isSafeMemorySlot"),
|
|
43468
|
+
defaultAgentHomeDirs: stub("defaultAgentHomeDirs"),
|
|
43458
43469
|
classifyMemoryWrite: stub("classifyMemoryWrite"),
|
|
43459
43470
|
classifyMemoryRead: stub("classifyMemoryRead"),
|
|
43460
43471
|
defaultMemoryWriteToolNames: stub("defaultMemoryWriteToolNames"),
|
|
@@ -43531,6 +43542,32 @@ function randomHex(size) {
|
|
|
43531
43542
|
return hex;
|
|
43532
43543
|
}
|
|
43533
43544
|
|
|
43545
|
+
// src-ts/auth-bearer.ts
|
|
43546
|
+
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43547
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43548
|
+
var BEARER_TTL_MS = 4 * 60 * 1e3;
|
|
43549
|
+
var bearers = /* @__PURE__ */ new Map();
|
|
43550
|
+
function agentAuthBearer(auth, blockchainRid) {
|
|
43551
|
+
const key3 = `${auth.pubkey}:${blockchainRid}`;
|
|
43552
|
+
const now = Date.now();
|
|
43553
|
+
const cached = bearers.get(key3);
|
|
43554
|
+
if (cached && now - cached.issuedAt < BEARER_TTL_MS) return cached.hex;
|
|
43555
|
+
const hex = native.signLogToolCall(
|
|
43556
|
+
`auth-${now.toString(36)}-${randomHex(4)}`,
|
|
43557
|
+
`auth:${now}`,
|
|
43558
|
+
"",
|
|
43559
|
+
"auth-bearer",
|
|
43560
|
+
"",
|
|
43561
|
+
auth.privkey,
|
|
43562
|
+
blockchainRid
|
|
43563
|
+
);
|
|
43564
|
+
bearers.set(key3, { hex, issuedAt: now });
|
|
43565
|
+
return hex;
|
|
43566
|
+
}
|
|
43567
|
+
function agentAuthHeaders(auth, blockchainRid) {
|
|
43568
|
+
return { Authorization: `Bearer ${agentAuthBearer(auth, blockchainRid)}` };
|
|
43569
|
+
}
|
|
43570
|
+
|
|
43534
43571
|
// src-ts/chain-config.ts
|
|
43535
43572
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43536
43573
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
@@ -44687,6 +44724,61 @@ function canonicalAllow(data) {
|
|
|
44687
44724
|
return verdict === "ALLOW" || verdict === "GREEN";
|
|
44688
44725
|
}
|
|
44689
44726
|
|
|
44727
|
+
// src-ts/opentel/events.ts
|
|
44728
|
+
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44729
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44730
|
+
var SLOW_MS = 1500;
|
|
44731
|
+
var SUCCESS_SAMPLE_RATE = 10;
|
|
44732
|
+
var logger2 = null;
|
|
44733
|
+
var eventsEnabled = false;
|
|
44734
|
+
var sdkVersion = "";
|
|
44735
|
+
var eventSource = "sdk";
|
|
44736
|
+
var hashAgentKey = null;
|
|
44737
|
+
function eventsOptedOut() {
|
|
44738
|
+
const flag = process.env.ATBASH_TELEMETRY_EVENTS_DISABLED?.trim().toLowerCase();
|
|
44739
|
+
return Boolean(flag && ["1", "true", "yes", "on"].includes(flag));
|
|
44740
|
+
}
|
|
44741
|
+
function configureEvents(next, opts = {}) {
|
|
44742
|
+
logger2 = next;
|
|
44743
|
+
eventsEnabled = next !== null && !eventsOptedOut();
|
|
44744
|
+
if (opts.version) sdkVersion = opts.version;
|
|
44745
|
+
if (opts.source) eventSource = opts.source;
|
|
44746
|
+
hashAgentKey = opts.hashAgentKey ?? null;
|
|
44747
|
+
}
|
|
44748
|
+
function eventsAreOn() {
|
|
44749
|
+
return eventsEnabled && logger2 !== null;
|
|
44750
|
+
}
|
|
44751
|
+
function sampleRateFor(e) {
|
|
44752
|
+
if (e.status === "error") return 1;
|
|
44753
|
+
if (e.durationMs >= SLOW_MS) return 1;
|
|
44754
|
+
return Math.random() < 1 / SUCCESS_SAMPLE_RATE ? SUCCESS_SAMPLE_RATE : 0;
|
|
44755
|
+
}
|
|
44756
|
+
function recordEvent(e) {
|
|
44757
|
+
if (!eventsAreOn()) return;
|
|
44758
|
+
const sampleRate = sampleRateFor(e);
|
|
44759
|
+
if (sampleRate === 0) return;
|
|
44760
|
+
try {
|
|
44761
|
+
const attributes = {
|
|
44762
|
+
"function.name": e.functionName,
|
|
44763
|
+
"duration_ms": Math.round(e.durationMs),
|
|
44764
|
+
status: e.status,
|
|
44765
|
+
source: eventSource,
|
|
44766
|
+
// Honeycomb reweights counts and percentiles by this. It is per-event
|
|
44767
|
+
// because the sampling is biased by outcome and latency.
|
|
44768
|
+
sampleRate
|
|
44769
|
+
};
|
|
44770
|
+
if (sdkVersion) attributes["sdk.version"] = sdkVersion;
|
|
44771
|
+
if (e.agentPubkey && hashAgentKey) attributes["agent.hash"] = hashAgentKey(e.agentPubkey);
|
|
44772
|
+
if (e.chain) attributes["chain"] = e.chain;
|
|
44773
|
+
if (e.errorClass) attributes["error.class"] = e.errorClass;
|
|
44774
|
+
if (e.errorStatus !== void 0) attributes["error.status"] = e.errorStatus;
|
|
44775
|
+
if (e.errorPath) attributes["error.path"] = e.errorPath;
|
|
44776
|
+
if (e.outcome) attributes["outcome"] = e.outcome;
|
|
44777
|
+
logger2.emit({ body: e.functionName, attributes });
|
|
44778
|
+
} catch {
|
|
44779
|
+
}
|
|
44780
|
+
}
|
|
44781
|
+
|
|
44690
44782
|
// src-ts/browser/opentel/telemetry.ts
|
|
44691
44783
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44692
44784
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
@@ -44723,6 +44815,12 @@ function resolve(_key, flagValue) {
|
|
|
44723
44815
|
function forcedChainNetwork(flagValue) {
|
|
44724
44816
|
return flagValue === "public" || flagValue === "private" ? flagValue : void 0;
|
|
44725
44817
|
}
|
|
44818
|
+
function agentKeyFromEnv() {
|
|
44819
|
+
return "";
|
|
44820
|
+
}
|
|
44821
|
+
function strandedAgentKey() {
|
|
44822
|
+
return "";
|
|
44823
|
+
}
|
|
44726
44824
|
|
|
44727
44825
|
// src-ts/client.ts
|
|
44728
44826
|
function generateToolCallId() {
|
|
@@ -44748,6 +44846,13 @@ function resolveConstructorChain(options) {
|
|
|
44748
44846
|
}
|
|
44749
44847
|
return chainForNetwork(options.network ?? forcedChainNetwork() ?? "private");
|
|
44750
44848
|
}
|
|
44849
|
+
function errorDetail(err) {
|
|
44850
|
+
if (!(err instanceof AtbashAPIError)) return {};
|
|
44851
|
+
return {
|
|
44852
|
+
errorStatus: err.status,
|
|
44853
|
+
...err.path ? { errorPath: err.path } : {}
|
|
44854
|
+
};
|
|
44855
|
+
}
|
|
44751
44856
|
var Atbash = class _Atbash {
|
|
44752
44857
|
auth;
|
|
44753
44858
|
endpoint;
|
|
@@ -44806,16 +44911,6 @@ var Atbash = class _Atbash {
|
|
|
44806
44911
|
*/
|
|
44807
44912
|
_agentExistsCache = null;
|
|
44808
44913
|
static AGENT_EXISTS_TTL_MS = 5e3;
|
|
44809
|
-
/**
|
|
44810
|
-
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
44811
|
-
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
44812
|
-
* server-side replay protection windows never expire it mid-session.
|
|
44813
|
-
*/
|
|
44814
|
-
// Keyed by blockchainRid so bearers for the public and private chains can
|
|
44815
|
-
// coexist. The dashboard derives `authNetwork` from the BRID inside the
|
|
44816
|
-
// signed envelope, so a bearer signed for chain A cannot authenticate a
|
|
44817
|
-
// request routed to chain B — every chain the client talks to needs its own.
|
|
44818
|
-
_authBearers = /* @__PURE__ */ new Map();
|
|
44819
44914
|
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
44820
44915
|
static environmentLogged = false;
|
|
44821
44916
|
constructor(privkey, options = {}) {
|
|
@@ -44903,6 +44998,84 @@ var Atbash = class _Atbash {
|
|
|
44903
44998
|
* validated against the trusted allowlist / self-hosted policy; a
|
|
44904
44999
|
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
44905
45000
|
*/
|
|
45001
|
+
/**
|
|
45002
|
+
* Decide which key this client signs as.
|
|
45003
|
+
*
|
|
45004
|
+
* Most specific wins: a key passed in code, then a key file the host named,
|
|
45005
|
+
* then the environment, then the default key file. `config.json` is absent
|
|
45006
|
+
* from that list on purpose — it is a settings file, writable by anything
|
|
45007
|
+
* that can write the user's home and read by every Atbash integration on the
|
|
45008
|
+
* machine, so letting it name the key meant one stray value silently
|
|
45009
|
+
* re-pointed who each of them signed as.
|
|
45010
|
+
*
|
|
45011
|
+
* A named `keyPath` that does not exist throws rather than falling through.
|
|
45012
|
+
* The caller said which file holds its identity; quietly signing as a
|
|
45013
|
+
* different one is the outcome worth refusing.
|
|
45014
|
+
*
|
|
45015
|
+
* @param options - The `fromConfig` options, read for `agentKey` and `keyPath`.
|
|
45016
|
+
* @returns The resolved agent identity.
|
|
45017
|
+
* @throws When a named key file is missing, or no identity can be found.
|
|
45018
|
+
*/
|
|
45019
|
+
static resolveIdentity(options) {
|
|
45020
|
+
if (options.agentKey) return native.loadAgent(options.agentKey);
|
|
45021
|
+
if (options.keyPath) return loadAgentFromFile(options.keyPath);
|
|
45022
|
+
const fromEnv = agentKeyFromEnv();
|
|
45023
|
+
if (fromEnv) return native.loadAgent(fromEnv);
|
|
45024
|
+
try {
|
|
45025
|
+
return loadAgentFromFile();
|
|
45026
|
+
} catch (err) {
|
|
45027
|
+
throw _Atbash.explainStrandedKey(err);
|
|
45028
|
+
}
|
|
45029
|
+
}
|
|
45030
|
+
/**
|
|
45031
|
+
* Add the one thing a machine with no key file needs to hear.
|
|
45032
|
+
*
|
|
45033
|
+
* This is the only path where the operator cannot see what happened: no key
|
|
45034
|
+
* file, and the key they are looking for sits in `config.json`, which no
|
|
45035
|
+
* longer selects the identity. A bare "key file not found" sends them hunting
|
|
45036
|
+
* for a key they already have. Only this branch gets the hint — a caller who
|
|
45037
|
+
* named a `keyPath` is told about that path, where a stranded key is noise.
|
|
45038
|
+
*
|
|
45039
|
+
* @param err - The "key file not found" error from the default lookup.
|
|
45040
|
+
* @returns The same error, or one that also names the key in config.json.
|
|
45041
|
+
*/
|
|
45042
|
+
static explainStrandedKey(err) {
|
|
45043
|
+
const stranded = strandedAgentKey();
|
|
45044
|
+
if (!stranded) return err;
|
|
45045
|
+
let identity;
|
|
45046
|
+
try {
|
|
45047
|
+
identity = native.derivePublicKey(stranded);
|
|
45048
|
+
} catch {
|
|
45049
|
+
identity = "(unreadable)";
|
|
45050
|
+
}
|
|
45051
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
45052
|
+
return new Error(
|
|
45053
|
+
`${message}
|
|
45054
|
+
config.json still holds an "agentKey" (${identity}), but a settings file no longer chooses the signing key. Move it into one of the key files above, or set ATBASH_AGENT_KEY.`
|
|
45055
|
+
);
|
|
45056
|
+
}
|
|
45057
|
+
/**
|
|
45058
|
+
* Say so when `config.json` still holds an agent key.
|
|
45059
|
+
*
|
|
45060
|
+
* Nothing signs with it any more, and silence would leave an operator
|
|
45061
|
+
* believing one identity is in force while another is. The pubkey is named,
|
|
45062
|
+
* not the key, so the line is safe in a log.
|
|
45063
|
+
*
|
|
45064
|
+
* @param logger - The host logger, when one was supplied.
|
|
45065
|
+
*/
|
|
45066
|
+
static warnOnStrandedKey(logger3) {
|
|
45067
|
+
const stranded = strandedAgentKey();
|
|
45068
|
+
if (!stranded) return;
|
|
45069
|
+
let identity;
|
|
45070
|
+
try {
|
|
45071
|
+
identity = native.derivePublicKey(stranded);
|
|
45072
|
+
} catch {
|
|
45073
|
+
identity = "(unreadable)";
|
|
45074
|
+
}
|
|
45075
|
+
logger3?.warn?.(
|
|
45076
|
+
`[atbash] "agentKey" in config.json is ignored \u2014 settings do not choose the signing key. It holds ${identity}; this client signs as the key file or ATBASH_AGENT_KEY instead. Move it into the key file, or delete the field, to silence this.`
|
|
45077
|
+
);
|
|
45078
|
+
}
|
|
44906
45079
|
static fromConfig(options = {}) {
|
|
44907
45080
|
const configuredEndpoint = resolve("judgeEndpoint") || void 0;
|
|
44908
45081
|
const configuredVerifyPubKey = resolve("judgeVerifyPubKey") || void 0;
|
|
@@ -44918,8 +45091,8 @@ var Atbash = class _Atbash {
|
|
|
44918
45091
|
verifyPubKey: configuredVerifyPubKey
|
|
44919
45092
|
} : { endpoint: configuredEndpoint })
|
|
44920
45093
|
);
|
|
44921
|
-
const
|
|
44922
|
-
|
|
45094
|
+
const auth = _Atbash.resolveIdentity(options);
|
|
45095
|
+
_Atbash.warnOnStrandedKey(options.logger);
|
|
44923
45096
|
return new _Atbash(auth.privkey, {
|
|
44924
45097
|
endpoint: validated.url,
|
|
44925
45098
|
chain: options.chain,
|
|
@@ -45658,10 +45831,28 @@ var Atbash = class _Atbash {
|
|
|
45658
45831
|
recordCall(name2, void 0, agentPubkey);
|
|
45659
45832
|
try {
|
|
45660
45833
|
const result = await fn();
|
|
45661
|
-
|
|
45834
|
+
const durationMs = performance.now() - start;
|
|
45835
|
+
recordDuration(name2, durationMs, "success");
|
|
45836
|
+
recordEvent({
|
|
45837
|
+
functionName: name2,
|
|
45838
|
+
durationMs,
|
|
45839
|
+
status: "success",
|
|
45840
|
+
agentPubkey,
|
|
45841
|
+
chain: this.blockchainRid
|
|
45842
|
+
});
|
|
45662
45843
|
return result;
|
|
45663
45844
|
} catch (err) {
|
|
45664
|
-
|
|
45845
|
+
const durationMs = performance.now() - start;
|
|
45846
|
+
recordDuration(name2, durationMs, "error");
|
|
45847
|
+
recordEvent({
|
|
45848
|
+
functionName: name2,
|
|
45849
|
+
durationMs,
|
|
45850
|
+
status: "error",
|
|
45851
|
+
agentPubkey,
|
|
45852
|
+
chain: this.blockchainRid,
|
|
45853
|
+
errorClass: err instanceof Error ? err.constructor.name : typeof err,
|
|
45854
|
+
...errorDetail(err)
|
|
45855
|
+
});
|
|
45665
45856
|
throw err;
|
|
45666
45857
|
}
|
|
45667
45858
|
}
|
|
@@ -45699,25 +45890,10 @@ var Atbash = class _Atbash {
|
|
|
45699
45890
|
* trips the server's replay window.
|
|
45700
45891
|
*/
|
|
45701
45892
|
getAuthBearer(brid) {
|
|
45702
|
-
|
|
45703
|
-
const now = Date.now();
|
|
45704
|
-
const cached = this._authBearers.get(chainBrid);
|
|
45705
|
-
if (cached && now - cached.issuedAt < 4 * 60 * 1e3) return cached.hex;
|
|
45706
|
-
const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
|
|
45707
|
-
const hex = native.signLogToolCall(
|
|
45708
|
-
nonce,
|
|
45709
|
-
`auth:${now}`,
|
|
45710
|
-
"",
|
|
45711
|
-
"auth-bearer",
|
|
45712
|
-
"",
|
|
45713
|
-
this.auth.privkey,
|
|
45714
|
-
chainBrid
|
|
45715
|
-
);
|
|
45716
|
-
this._authBearers.set(chainBrid, { hex, issuedAt: now });
|
|
45717
|
-
return hex;
|
|
45893
|
+
return agentAuthBearer(this.auth, brid ?? this.blockchainRid);
|
|
45718
45894
|
}
|
|
45719
45895
|
authHeaders(brid) {
|
|
45720
|
-
return
|
|
45896
|
+
return agentAuthHeaders(this.auth, brid ?? this.blockchainRid);
|
|
45721
45897
|
}
|
|
45722
45898
|
async riskEngineGet(action, params, brid) {
|
|
45723
45899
|
let resp;
|
|
@@ -46108,22 +46284,6 @@ function bootSyncFailureLine(cause) {
|
|
|
46108
46284
|
);
|
|
46109
46285
|
}
|
|
46110
46286
|
|
|
46111
|
-
// src-ts/memory/_gtv_bytes.ts
|
|
46112
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46113
|
-
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
46114
|
-
function gtvToFfiSafe(value) {
|
|
46115
|
-
if (value instanceof Uint8Array) return Buffer.from(value).toString("hex");
|
|
46116
|
-
if (Array.isArray(value)) return value.map(gtvToFfiSafe);
|
|
46117
|
-
if (value !== null && typeof value === "object") {
|
|
46118
|
-
const out = {};
|
|
46119
|
-
for (const [key3, val] of Object.entries(value)) {
|
|
46120
|
-
out[key3] = gtvToFfiSafe(val);
|
|
46121
|
-
}
|
|
46122
|
-
return out;
|
|
46123
|
-
}
|
|
46124
|
-
return value;
|
|
46125
|
-
}
|
|
46126
|
-
|
|
46127
46287
|
// src-ts/memory/index.ts
|
|
46128
46288
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46129
46289
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
@@ -46466,6 +46626,7 @@ export {
|
|
|
46466
46626
|
classifyMemoryWrite,
|
|
46467
46627
|
columnAad,
|
|
46468
46628
|
commitMemoryVersion,
|
|
46629
|
+
configureEvents,
|
|
46469
46630
|
containsEvasionCharacters2 as containsEvasionCharacters,
|
|
46470
46631
|
containsSecret2 as containsSecret,
|
|
46471
46632
|
createFileLogger,
|
|
@@ -46481,6 +46642,7 @@ export {
|
|
|
46481
46642
|
encryptForOrg,
|
|
46482
46643
|
encryptMemoryContent2 as encryptMemoryContent,
|
|
46483
46644
|
encryptedLength,
|
|
46645
|
+
eventsAreOn,
|
|
46484
46646
|
flushTelemetry,
|
|
46485
46647
|
generateKeypair2 as generateKeypair,
|
|
46486
46648
|
getActiveAgentMemory,
|
|
@@ -46491,7 +46653,6 @@ export {
|
|
|
46491
46653
|
getMemoryHistory,
|
|
46492
46654
|
getRecentAgentMemory,
|
|
46493
46655
|
getRollbackHistory,
|
|
46494
|
-
gtvToFfiSafe,
|
|
46495
46656
|
guardMemoryWrite,
|
|
46496
46657
|
isEnvelope,
|
|
46497
46658
|
isValidPrivateKey2 as isValidPrivateKey,
|
|
@@ -46510,6 +46671,7 @@ export {
|
|
|
46510
46671
|
pubkeyToHex,
|
|
46511
46672
|
recordCall,
|
|
46512
46673
|
recordDuration,
|
|
46674
|
+
recordEvent,
|
|
46513
46675
|
redactJsonStrings,
|
|
46514
46676
|
redactSecrets2 as redactSecrets,
|
|
46515
46677
|
resolve,
|