@atbash/sdk 0.10.12-dev.0 → 0.11.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 +172 -30
- package/THIRD-PARTY-NOTICES +10256 -0
- package/dist/browser.d.mts +699 -76
- package/dist/browser.mjs +1210 -652
- package/dist/index.d.mts +699 -76
- package/dist/index.d.ts +699 -76
- package/dist/index.js +2430 -41898
- package/dist/index.mjs +3206 -42710
- package/index.d.ts +56 -24
- package/index.js +177 -88
- package/package.json +18 -8
- package/dist/browser.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/browser.mjs
CHANGED
|
@@ -33,19 +33,11 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
33
33
|
mod2
|
|
34
34
|
));
|
|
35
35
|
|
|
36
|
-
// <define:__ATBASH_CHROMIA_NODE_URLS__>
|
|
37
|
-
var define_ATBASH_CHROMIA_NODE_URLS_default;
|
|
38
|
-
var init_define_ATBASH_CHROMIA_NODE_URLS = __esm({
|
|
39
|
-
"<define:__ATBASH_CHROMIA_NODE_URLS__>"() {
|
|
40
|
-
define_ATBASH_CHROMIA_NODE_URLS_default = ["https://node0.testnet.chromia.com:7740", "https://node1.testnet.chromia.com:7740", "https://node3.testnet.chromia.com:7740"];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
36
|
// <define:__ATBASH_PRIVATE_NODE_URLS__>
|
|
45
37
|
var define_ATBASH_PRIVATE_NODE_URLS_default;
|
|
46
38
|
var init_define_ATBASH_PRIVATE_NODE_URLS = __esm({
|
|
47
39
|
"<define:__ATBASH_PRIVATE_NODE_URLS__>"() {
|
|
48
|
-
define_ATBASH_PRIVATE_NODE_URLS_default = ["https://node0-pvn-testnet.dynamic.chromia.dev"];
|
|
40
|
+
define_ATBASH_PRIVATE_NODE_URLS_default = ["https://node0-pvn-testnet.dynamic.chromia.dev:7740", "https://node1-pvn-testnet.dynamic.chromia.dev:7740", "https://node2-pvn-testnet.dynamic.chromia.dev:7740"];
|
|
49
41
|
}
|
|
50
42
|
});
|
|
51
43
|
|
|
@@ -53,7 +45,6 @@ var init_define_ATBASH_PRIVATE_NODE_URLS = __esm({
|
|
|
53
45
|
var require_buffer = __commonJS({
|
|
54
46
|
"(disabled):node_modules/buffer/index.js"() {
|
|
55
47
|
"use strict";
|
|
56
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
57
48
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
58
49
|
}
|
|
59
50
|
});
|
|
@@ -62,7 +53,6 @@ var require_buffer = __commonJS({
|
|
|
62
53
|
var require_bn = __commonJS({
|
|
63
54
|
"node_modules/bn.js/lib/bn.js"(exports, module) {
|
|
64
55
|
"use strict";
|
|
65
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
66
56
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
67
57
|
(function(module2, exports2) {
|
|
68
58
|
"use strict";
|
|
@@ -2882,27 +2872,21 @@ var require_bn = __commonJS({
|
|
|
2882
2872
|
});
|
|
2883
2873
|
|
|
2884
2874
|
// src-ts/index.ts
|
|
2885
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
2886
2875
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
2887
2876
|
|
|
2888
2877
|
// src-ts/browser/native.ts
|
|
2889
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
2890
2878
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
2891
2879
|
|
|
2892
2880
|
// node_modules/@noble/curves/secp256k1.js
|
|
2893
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
2894
2881
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
2895
2882
|
|
|
2896
2883
|
// node_modules/@noble/hashes/sha2.js
|
|
2897
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
2898
2884
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
2899
2885
|
|
|
2900
2886
|
// node_modules/@noble/hashes/_md.js
|
|
2901
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
2902
2887
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
2903
2888
|
|
|
2904
2889
|
// node_modules/@noble/hashes/utils.js
|
|
2905
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
2906
2890
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
2907
2891
|
function isBytes(a) {
|
|
2908
2892
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
@@ -3325,11 +3309,9 @@ var sha256 = /* @__PURE__ */ createHasher(
|
|
|
3325
3309
|
);
|
|
3326
3310
|
|
|
3327
3311
|
// node_modules/@noble/curves/abstract/curve.js
|
|
3328
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
3329
3312
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
3330
3313
|
|
|
3331
3314
|
// node_modules/@noble/curves/utils.js
|
|
3332
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
3333
3315
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
3334
3316
|
var abytes2 = (value, length, title) => abytes(value, length, title);
|
|
3335
3317
|
var anumber2 = anumber;
|
|
@@ -3483,7 +3465,6 @@ function validateObject(object, fields = {}, optFields = {}) {
|
|
|
3483
3465
|
}
|
|
3484
3466
|
|
|
3485
3467
|
// node_modules/@noble/curves/abstract/modular.js
|
|
3486
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
3487
3468
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
3488
3469
|
var _0n2 = /* @__PURE__ */ BigInt(0);
|
|
3489
3470
|
var _1n2 = /* @__PURE__ */ BigInt(1);
|
|
@@ -4133,11 +4114,9 @@ function createKeygen(randomSecretKey, getPublicKey) {
|
|
|
4133
4114
|
}
|
|
4134
4115
|
|
|
4135
4116
|
// node_modules/@noble/curves/abstract/weierstrass.js
|
|
4136
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
4137
4117
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
4138
4118
|
|
|
4139
4119
|
// node_modules/@noble/hashes/hmac.js
|
|
4140
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
4141
4120
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
4142
4121
|
var _HMAC = class {
|
|
4143
4122
|
oHash;
|
|
@@ -5170,7 +5149,6 @@ var Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
|
|
|
5170
5149
|
var secp256k1 = /* @__PURE__ */ ecdsa(Pointk1, sha256);
|
|
5171
5150
|
|
|
5172
5151
|
// node_modules/postchain-client/built/esm/index.js
|
|
5173
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
5174
5152
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
5175
5153
|
var import_bn = __toESM(require_bn(), 1);
|
|
5176
5154
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
@@ -10054,8 +10032,8 @@ Reporter$3.prototype.wrapResult = function wrapResult(result) {
|
|
|
10054
10032
|
errors: state2.errors
|
|
10055
10033
|
};
|
|
10056
10034
|
};
|
|
10057
|
-
function ReporterError$1(
|
|
10058
|
-
this.path =
|
|
10035
|
+
function ReporterError$1(path3, msg) {
|
|
10036
|
+
this.path = path3;
|
|
10059
10037
|
this.rethrow(msg);
|
|
10060
10038
|
}
|
|
10061
10039
|
inherits$v(ReporterError$1, Error);
|
|
@@ -12126,7 +12104,7 @@ function requireBuffer_list() {
|
|
|
12126
12104
|
}
|
|
12127
12105
|
}, {
|
|
12128
12106
|
key: "join",
|
|
12129
|
-
value: function
|
|
12107
|
+
value: function join2(s2) {
|
|
12130
12108
|
if (this.length === 0) return "";
|
|
12131
12109
|
var p = this.head;
|
|
12132
12110
|
var ret = "" + p.data;
|
|
@@ -16208,7 +16186,7 @@ function requireBufferList() {
|
|
|
16208
16186
|
this.head = this.tail = null;
|
|
16209
16187
|
this.length = 0;
|
|
16210
16188
|
};
|
|
16211
|
-
BufferList2.prototype.join = function
|
|
16189
|
+
BufferList2.prototype.join = function join2(s2) {
|
|
16212
16190
|
if (this.length === 0) return "";
|
|
16213
16191
|
var p = this.head;
|
|
16214
16192
|
var ret = "" + p.data;
|
|
@@ -21769,23 +21747,23 @@ Splitter$1.prototype.flush = function() {
|
|
|
21769
21747
|
return Buffer$9.concat([this.cache, padBuff]);
|
|
21770
21748
|
};
|
|
21771
21749
|
function createCipheriv$1(suite, password, iv) {
|
|
21772
|
-
var
|
|
21773
|
-
if (!
|
|
21750
|
+
var config3 = MODES$1[suite.toLowerCase()];
|
|
21751
|
+
if (!config3) throw new TypeError("invalid suite type");
|
|
21774
21752
|
if (typeof password === "string") password = Buffer$9.from(password);
|
|
21775
|
-
if (password.length !==
|
|
21753
|
+
if (password.length !== config3.key / 8) throw new TypeError("invalid key length " + password.length);
|
|
21776
21754
|
if (typeof iv === "string") iv = Buffer$9.from(iv);
|
|
21777
|
-
if (
|
|
21778
|
-
if (
|
|
21779
|
-
return new StreamCipher$1(
|
|
21780
|
-
} else if (
|
|
21781
|
-
return new AuthCipher$1(
|
|
21755
|
+
if (config3.mode !== "GCM" && iv.length !== config3.iv) throw new TypeError("invalid iv length " + iv.length);
|
|
21756
|
+
if (config3.type === "stream") {
|
|
21757
|
+
return new StreamCipher$1(config3.module, password, iv);
|
|
21758
|
+
} else if (config3.type === "auth") {
|
|
21759
|
+
return new AuthCipher$1(config3.module, password, iv);
|
|
21782
21760
|
}
|
|
21783
|
-
return new Cipher(
|
|
21761
|
+
return new Cipher(config3.module, password, iv);
|
|
21784
21762
|
}
|
|
21785
21763
|
function createCipher$1(suite, password) {
|
|
21786
|
-
var
|
|
21787
|
-
if (!
|
|
21788
|
-
var keys2 = ebtk$2(password, false,
|
|
21764
|
+
var config3 = MODES$1[suite.toLowerCase()];
|
|
21765
|
+
if (!config3) throw new TypeError("invalid suite type");
|
|
21766
|
+
var keys2 = ebtk$2(password, false, config3.key, config3.iv);
|
|
21789
21767
|
return createCipheriv$1(suite, keys2.key, keys2.iv);
|
|
21790
21768
|
}
|
|
21791
21769
|
encrypter.createCipheriv = createCipheriv$1;
|
|
@@ -21873,23 +21851,23 @@ function unpad(last) {
|
|
|
21873
21851
|
return last.slice(0, 16 - padded);
|
|
21874
21852
|
}
|
|
21875
21853
|
function createDecipheriv$1(suite, password, iv) {
|
|
21876
|
-
var
|
|
21877
|
-
if (!
|
|
21854
|
+
var config3 = MODES[suite.toLowerCase()];
|
|
21855
|
+
if (!config3) throw new TypeError("invalid suite type");
|
|
21878
21856
|
if (typeof iv === "string") iv = Buffer$8.from(iv);
|
|
21879
|
-
if (
|
|
21857
|
+
if (config3.mode !== "GCM" && iv.length !== config3.iv) throw new TypeError("invalid iv length " + iv.length);
|
|
21880
21858
|
if (typeof password === "string") password = Buffer$8.from(password);
|
|
21881
|
-
if (password.length !==
|
|
21882
|
-
if (
|
|
21883
|
-
return new StreamCipher(
|
|
21884
|
-
} else if (
|
|
21885
|
-
return new AuthCipher(
|
|
21859
|
+
if (password.length !== config3.key / 8) throw new TypeError("invalid key length " + password.length);
|
|
21860
|
+
if (config3.type === "stream") {
|
|
21861
|
+
return new StreamCipher(config3.module, password, iv, true);
|
|
21862
|
+
} else if (config3.type === "auth") {
|
|
21863
|
+
return new AuthCipher(config3.module, password, iv, true);
|
|
21886
21864
|
}
|
|
21887
|
-
return new Decipher(
|
|
21865
|
+
return new Decipher(config3.module, password, iv);
|
|
21888
21866
|
}
|
|
21889
21867
|
function createDecipher$1(suite, password) {
|
|
21890
|
-
var
|
|
21891
|
-
if (!
|
|
21892
|
-
var keys2 = ebtk$1(password, false,
|
|
21868
|
+
var config3 = MODES[suite.toLowerCase()];
|
|
21869
|
+
if (!config3) throw new TypeError("invalid suite type");
|
|
21870
|
+
var keys2 = ebtk$1(password, false, config3.key, config3.iv);
|
|
21893
21871
|
return createDecipheriv$1(suite, keys2.key, keys2.iv);
|
|
21894
21872
|
}
|
|
21895
21873
|
decrypter.createDecipher = createDecipher$1;
|
|
@@ -30276,8 +30254,8 @@ Reporter.prototype.wrapResult = function wrapResult2(result) {
|
|
|
30276
30254
|
errors: state2.errors
|
|
30277
30255
|
};
|
|
30278
30256
|
};
|
|
30279
|
-
function ReporterError(
|
|
30280
|
-
this.path =
|
|
30257
|
+
function ReporterError(path3, msg) {
|
|
30258
|
+
this.path = path3;
|
|
30281
30259
|
this.rethrow(msg);
|
|
30282
30260
|
}
|
|
30283
30261
|
inherits(ReporterError, Error);
|
|
@@ -30372,7 +30350,7 @@ function requireBuffer() {
|
|
|
30372
30350
|
}
|
|
30373
30351
|
}
|
|
30374
30352
|
buffer.EncoderBuffer = EncoderBuffer2;
|
|
30375
|
-
EncoderBuffer2.prototype.join = function
|
|
30353
|
+
EncoderBuffer2.prototype.join = function join2(out, offset) {
|
|
30376
30354
|
if (!out)
|
|
30377
30355
|
out = new Buffer5(this.length);
|
|
30378
30356
|
if (!offset)
|
|
@@ -33307,8 +33285,8 @@ var parseUtil = {};
|
|
|
33307
33285
|
const errors_js_12 = errors$3;
|
|
33308
33286
|
const en_js_12 = __importDefault2(en);
|
|
33309
33287
|
const makeIssue = (params) => {
|
|
33310
|
-
const { data, path:
|
|
33311
|
-
const fullPath = [...
|
|
33288
|
+
const { data, path: path3, errorMaps, issueData } = params;
|
|
33289
|
+
const fullPath = [...path3, ...issueData.path || []];
|
|
33312
33290
|
const fullIssue = {
|
|
33313
33291
|
...issueData,
|
|
33314
33292
|
path: fullPath
|
|
@@ -33445,11 +33423,11 @@ var errorUtil_js_1 = errorUtil$1;
|
|
|
33445
33423
|
var parseUtil_js_1 = parseUtil;
|
|
33446
33424
|
var util_js_1 = util;
|
|
33447
33425
|
var ParseInputLazyPath = class {
|
|
33448
|
-
constructor(parent, value,
|
|
33426
|
+
constructor(parent, value, path3, key3) {
|
|
33449
33427
|
this._cachedPath = [];
|
|
33450
33428
|
this.parent = parent;
|
|
33451
33429
|
this.data = value;
|
|
33452
|
-
this._path =
|
|
33430
|
+
this._path = path3;
|
|
33453
33431
|
this._key = key3;
|
|
33454
33432
|
}
|
|
33455
33433
|
get path() {
|
|
@@ -40355,21 +40333,21 @@ function createTimeoutController(timeout) {
|
|
|
40355
40333
|
const timeoutId = setTimeout(() => controller.abort(timeoutError), timeout);
|
|
40356
40334
|
return { controller, timeoutId };
|
|
40357
40335
|
}
|
|
40358
|
-
function handleRequest(method,
|
|
40336
|
+
function handleRequest(method, path3, endpoint, timeout, postObject) {
|
|
40359
40337
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40360
40338
|
if (method == enums_1$2.Method.GET) {
|
|
40361
|
-
return yield get(
|
|
40339
|
+
return yield get(path3, endpoint, timeout);
|
|
40362
40340
|
} else {
|
|
40363
|
-
return yield post(
|
|
40341
|
+
return yield post(path3, endpoint, timeout, postObject);
|
|
40364
40342
|
}
|
|
40365
40343
|
});
|
|
40366
40344
|
}
|
|
40367
|
-
function get(
|
|
40345
|
+
function get(path3, endpoint, timeout) {
|
|
40368
40346
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40369
|
-
logger.debug(`GET URL ${new URL(
|
|
40347
|
+
logger.debug(`GET URL ${new URL(path3, endpoint).href}`);
|
|
40370
40348
|
try {
|
|
40371
40349
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
40372
|
-
const response = yield fetch(new URL(
|
|
40350
|
+
const response = yield fetch(new URL(path3, endpoint).href, {
|
|
40373
40351
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
40374
40352
|
});
|
|
40375
40353
|
if (timeoutId)
|
|
@@ -40407,9 +40385,9 @@ function constructBufferResponseBody(response) {
|
|
|
40407
40385
|
return responseText ? responseText : response.statusText;
|
|
40408
40386
|
});
|
|
40409
40387
|
}
|
|
40410
|
-
function post(
|
|
40388
|
+
function post(path3, endpoint, timeout, requestBody) {
|
|
40411
40389
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
40412
|
-
logger.debug(`POST URL ${new URL(
|
|
40390
|
+
logger.debug(`POST URL ${new URL(path3, endpoint).href}`);
|
|
40413
40391
|
logger.debug(`POST body ${JSON.stringify(requestBody)}`);
|
|
40414
40392
|
if (buffer_1.Buffer.isBuffer(requestBody)) {
|
|
40415
40393
|
try {
|
|
@@ -40423,7 +40401,7 @@ function post(path4, endpoint, timeout, requestBody) {
|
|
|
40423
40401
|
},
|
|
40424
40402
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
40425
40403
|
};
|
|
40426
|
-
const response = yield fetch(new URL(
|
|
40404
|
+
const response = yield fetch(new URL(path3, endpoint).href, requestOptions);
|
|
40427
40405
|
if (timeoutId)
|
|
40428
40406
|
clearTimeout(timeoutId);
|
|
40429
40407
|
const transactionTimestamp = response.headers.get("X-Transaction-Timestamp");
|
|
@@ -40434,7 +40412,7 @@ function post(path4, endpoint, timeout, requestBody) {
|
|
|
40434
40412
|
} else {
|
|
40435
40413
|
try {
|
|
40436
40414
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
40437
|
-
const response = yield fetch(new URL(
|
|
40415
|
+
const response = yield fetch(new URL(path3, endpoint).href, {
|
|
40438
40416
|
method: "post",
|
|
40439
40417
|
body: JSON.stringify(requestBody),
|
|
40440
40418
|
headers: {
|
|
@@ -40585,7 +40563,7 @@ function requireFailoverStrategies() {
|
|
|
40585
40563
|
exports.createTimeoutPromise = createTimeoutPromise;
|
|
40586
40564
|
const utils_12 = requireUtils$1();
|
|
40587
40565
|
const httpUtil_1 = httpUtil;
|
|
40588
|
-
const
|
|
40566
|
+
const logger3 = __importStar2(logger$3);
|
|
40589
40567
|
const http_utils_1 = httpUtils;
|
|
40590
40568
|
function getUnreachableDuration(statusCode, error4) {
|
|
40591
40569
|
if ((0, http_utils_1.isNetworkError)(error4)) {
|
|
@@ -40614,29 +40592,29 @@ function requireFailoverStrategies() {
|
|
|
40614
40592
|
}
|
|
40615
40593
|
}
|
|
40616
40594
|
function abortOnError(_a2) {
|
|
40617
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40595
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config3, postObject, timeoutOverride }) {
|
|
40618
40596
|
return yield retryRequest({
|
|
40619
40597
|
method,
|
|
40620
|
-
path:
|
|
40621
|
-
config:
|
|
40598
|
+
path: path3,
|
|
40599
|
+
config: config3,
|
|
40622
40600
|
postObject,
|
|
40623
40601
|
timeoutOverride,
|
|
40624
40602
|
useNextNodeOnError: false,
|
|
40625
|
-
recoveryThreshold:
|
|
40603
|
+
recoveryThreshold: config3.recoveryThreshold
|
|
40626
40604
|
// Use user config or let nodeManager use default
|
|
40627
40605
|
});
|
|
40628
40606
|
});
|
|
40629
40607
|
}
|
|
40630
40608
|
function tryNextOnError(_a2) {
|
|
40631
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40609
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config3, postObject, timeoutOverride }) {
|
|
40632
40610
|
return yield retryRequest({
|
|
40633
40611
|
method,
|
|
40634
|
-
path:
|
|
40635
|
-
config:
|
|
40612
|
+
path: path3,
|
|
40613
|
+
config: config3,
|
|
40636
40614
|
postObject,
|
|
40637
40615
|
timeoutOverride,
|
|
40638
40616
|
useNextNodeOnError: true,
|
|
40639
|
-
recoveryThreshold:
|
|
40617
|
+
recoveryThreshold: config3.recoveryThreshold
|
|
40640
40618
|
});
|
|
40641
40619
|
});
|
|
40642
40620
|
}
|
|
@@ -40647,18 +40625,18 @@ function requireFailoverStrategies() {
|
|
|
40647
40625
|
return endpointPoolLength - (endpointPoolLength - 1) / 3;
|
|
40648
40626
|
}
|
|
40649
40627
|
function queryMajority(_a2) {
|
|
40650
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40628
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config3, postObject, timeoutOverride }) {
|
|
40651
40629
|
var _b;
|
|
40652
|
-
const bftMajorityThreshold = calculateBftMajorityThreshold(
|
|
40653
|
-
const failureThreshold =
|
|
40654
|
-
const { nodeManager: nodeManager2 } =
|
|
40630
|
+
const bftMajorityThreshold = calculateBftMajorityThreshold(config3.endpointPool.length);
|
|
40631
|
+
const failureThreshold = config3.endpointPool.length - bftMajorityThreshold + 1;
|
|
40632
|
+
const { nodeManager: nodeManager2 } = config3;
|
|
40655
40633
|
const timeout = 15e3;
|
|
40656
|
-
const availableNodes = nodeManager2.getAvailableNodes((_b =
|
|
40634
|
+
const availableNodes = nodeManager2.getAvailableNodes((_b = config3.recoveryThreshold) !== null && _b !== void 0 ? _b : bftMajorityThreshold);
|
|
40657
40635
|
const outcomes = [];
|
|
40658
40636
|
const promises = availableNodes.map((node2) => __awaiter2(this, void 0, void 0, function* () {
|
|
40659
40637
|
try {
|
|
40660
|
-
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride :
|
|
40661
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40638
|
+
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config3.responseTimeout;
|
|
40639
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path3, node2.url, requestTimeout, postObject);
|
|
40662
40640
|
const { statusCode } = response;
|
|
40663
40641
|
if (statusCode && (0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
|
|
40664
40642
|
outcomes.push({ type: "SUCCESS", result: response });
|
|
@@ -40686,7 +40664,7 @@ function requireFailoverStrategies() {
|
|
|
40686
40664
|
while (true) {
|
|
40687
40665
|
if (groupedSuccessfulResponses.maxNumberOfEqualResponses() >= bftMajorityThreshold) {
|
|
40688
40666
|
if (groupedSuccessfulResponses.numberOfDistinctResponses() > 1) {
|
|
40689
|
-
|
|
40667
|
+
logger3.warning(`Got disagreeing responses, but could still reach BFT majority`);
|
|
40690
40668
|
}
|
|
40691
40669
|
return groupedSuccessfulResponses.majorityResponse();
|
|
40692
40670
|
}
|
|
@@ -40697,7 +40675,7 @@ function requireFailoverStrategies() {
|
|
|
40697
40675
|
throw errorOutcomes[0].result;
|
|
40698
40676
|
}
|
|
40699
40677
|
}
|
|
40700
|
-
if (outcomes.length >=
|
|
40678
|
+
if (outcomes.length >= config3.endpointPool.length) {
|
|
40701
40679
|
throw new Error(exports.errorMessages.NO_CONSENSUS);
|
|
40702
40680
|
}
|
|
40703
40681
|
remainingPromises = yield racePromisesWithTimeout(remainingPromises, timeout);
|
|
@@ -40705,18 +40683,18 @@ function requireFailoverStrategies() {
|
|
|
40705
40683
|
});
|
|
40706
40684
|
}
|
|
40707
40685
|
function singleEndpoint(_a2) {
|
|
40708
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40686
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config3, postObject, timeoutOverride }) {
|
|
40709
40687
|
let statusCode = null;
|
|
40710
40688
|
let rspBody = null;
|
|
40711
40689
|
let error4 = null;
|
|
40712
40690
|
let transactionTimestamp = void 0;
|
|
40713
|
-
const endpoint =
|
|
40691
|
+
const endpoint = config3.nodeManager.getNode();
|
|
40714
40692
|
if (!endpoint) {
|
|
40715
40693
|
throw new Error("No nodes available after recovery attempt. Check node configuration.");
|
|
40716
40694
|
}
|
|
40717
|
-
for (let attempt = 0; attempt <
|
|
40718
|
-
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride :
|
|
40719
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40695
|
+
for (let attempt = 0; attempt < config3.attemptsPerEndpoint; attempt++) {
|
|
40696
|
+
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config3.responseTimeout;
|
|
40697
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path3, endpoint.url, requestTimeout, postObject);
|
|
40720
40698
|
if (response) {
|
|
40721
40699
|
({ error: error4, statusCode, rspBody, transactionTimestamp } = response);
|
|
40722
40700
|
}
|
|
@@ -40724,25 +40702,25 @@ function requireFailoverStrategies() {
|
|
|
40724
40702
|
if (!isError4 && !error4) {
|
|
40725
40703
|
return { error: error4, statusCode, rspBody, transactionTimestamp };
|
|
40726
40704
|
}
|
|
40727
|
-
|
|
40728
|
-
yield (0, utils_12.sleep)(
|
|
40705
|
+
logger3.info(`${method} request failed on ${endpoint.url}. Attempt: ${attempt + 1} / ${config3.attemptsPerEndpoint}`);
|
|
40706
|
+
yield (0, utils_12.sleep)(config3.attemptInterval);
|
|
40729
40707
|
}
|
|
40730
40708
|
return { error: error4, statusCode, rspBody, transactionTimestamp };
|
|
40731
40709
|
});
|
|
40732
40710
|
}
|
|
40733
40711
|
function retryRequest(_a2) {
|
|
40734
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
40712
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path3, config: config3, postObject, useNextNodeOnError, recoveryThreshold, timeoutOverride }) {
|
|
40735
40713
|
var _b, _c, _d;
|
|
40736
40714
|
let statusCode = null;
|
|
40737
40715
|
let rspBody = null;
|
|
40738
40716
|
let error4 = null;
|
|
40739
40717
|
let transactionTimestamp = void 0;
|
|
40740
|
-
const { nodeManager: nodeManager2 } =
|
|
40718
|
+
const { nodeManager: nodeManager2 } = config3;
|
|
40741
40719
|
const availableNodes = nodeManager2.getAvailableNodes(recoveryThreshold);
|
|
40742
40720
|
for (const node2 of availableNodes) {
|
|
40743
|
-
for (let attempt = 0; attempt <
|
|
40744
|
-
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride :
|
|
40745
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
40721
|
+
for (let attempt = 0; attempt < config3.attemptsPerEndpoint; attempt++) {
|
|
40722
|
+
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config3.responseTimeout;
|
|
40723
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path3, node2.url, requestTimeout, postObject);
|
|
40746
40724
|
error4 = (_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : null;
|
|
40747
40725
|
statusCode = (_c = response === null || response === void 0 ? void 0 : response.statusCode) !== null && _c !== void 0 ? _c : null;
|
|
40748
40726
|
rspBody = (_d = response === null || response === void 0 ? void 0 : response.rspBody) !== null && _d !== void 0 ? _d : null;
|
|
@@ -40760,7 +40738,7 @@ function requireFailoverStrategies() {
|
|
|
40760
40738
|
if (isServerError) {
|
|
40761
40739
|
const duration = getUnreachableDuration(statusCode !== null && statusCode !== void 0 ? statusCode : void 0, response.error);
|
|
40762
40740
|
nodeManager2.makeNodeUnavailable(node2.url, duration);
|
|
40763
|
-
|
|
40741
|
+
logger3.info(`request failed with server error on ${node2.url} trying next node`);
|
|
40764
40742
|
break;
|
|
40765
40743
|
}
|
|
40766
40744
|
if (isClientError) {
|
|
@@ -40768,13 +40746,13 @@ function requireFailoverStrategies() {
|
|
|
40768
40746
|
return { error: error4, statusCode, rspBody, transactionTimestamp };
|
|
40769
40747
|
}
|
|
40770
40748
|
if (!nodeManager2.useStickyNode) {
|
|
40771
|
-
|
|
40749
|
+
logger3.info(`request failed client error on ${node2.url} trying next node`);
|
|
40772
40750
|
break;
|
|
40773
40751
|
}
|
|
40774
40752
|
}
|
|
40775
|
-
|
|
40776
|
-
if (
|
|
40777
|
-
yield (0, utils_12.sleep)(
|
|
40753
|
+
logger3.info(`${method} request failed on ${node2.url}. Attempt: ${attempt + 1} / ${config3.attemptsPerEndpoint}`);
|
|
40754
|
+
if (config3.attemptInterval > 0) {
|
|
40755
|
+
yield (0, utils_12.sleep)(config3.attemptInterval);
|
|
40778
40756
|
}
|
|
40779
40757
|
}
|
|
40780
40758
|
}
|
|
@@ -40885,21 +40863,21 @@ function requireRequestWithFailoverStrategy() {
|
|
|
40885
40863
|
const enums_12 = enums;
|
|
40886
40864
|
const failoverStrategies_1 = requireFailoverStrategies();
|
|
40887
40865
|
function requestWithFailoverStrategy$1(method_1, path_1, config_1, postObject_1) {
|
|
40888
|
-
return __awaiter2(this, arguments, void 0, function* (method,
|
|
40889
|
-
switch (
|
|
40866
|
+
return __awaiter2(this, arguments, void 0, function* (method, path3, config3, postObject, forceSingleEndpoint = false, timeoutOverride) {
|
|
40867
|
+
switch (config3.failoverStrategy) {
|
|
40890
40868
|
case enums_12.FailoverStrategy.AbortOnError:
|
|
40891
|
-
return yield (0, failoverStrategies_1.abortOnError)({ method, path:
|
|
40869
|
+
return yield (0, failoverStrategies_1.abortOnError)({ method, path: path3, config: config3, postObject, timeoutOverride });
|
|
40892
40870
|
case enums_12.FailoverStrategy.TryNextOnError:
|
|
40893
|
-
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path:
|
|
40871
|
+
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path: path3, config: config3, postObject, timeoutOverride });
|
|
40894
40872
|
case enums_12.FailoverStrategy.SingleEndpoint:
|
|
40895
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40873
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path3, config: config3, postObject, timeoutOverride });
|
|
40896
40874
|
case enums_12.FailoverStrategy.QueryMajority:
|
|
40897
40875
|
if (forceSingleEndpoint) {
|
|
40898
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40876
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path3, config: config3, postObject, timeoutOverride });
|
|
40899
40877
|
}
|
|
40900
|
-
return yield (0, failoverStrategies_1.queryMajority)({ method, path:
|
|
40878
|
+
return yield (0, failoverStrategies_1.queryMajority)({ method, path: path3, config: config3, postObject, timeoutOverride });
|
|
40901
40879
|
default:
|
|
40902
|
-
throw new Error(`Unsupported failover strategy: ${
|
|
40880
|
+
throw new Error(`Unsupported failover strategy: ${config3.failoverStrategy}`);
|
|
40903
40881
|
}
|
|
40904
40882
|
});
|
|
40905
40883
|
}
|
|
@@ -41001,7 +40979,7 @@ function requireUtils$1() {
|
|
|
41001
40979
|
exports.getBlockchainRidFromIid = getBlockchainRidFromIid;
|
|
41002
40980
|
exports.convertToPrintable = convertToPrintable;
|
|
41003
40981
|
const buffer_12 = buffer$3;
|
|
41004
|
-
const
|
|
40982
|
+
const logger3 = __importStar2(logger$3);
|
|
41005
40983
|
const errors_12 = errors;
|
|
41006
40984
|
const gtxTool = __importStar2(gtx$1);
|
|
41007
40985
|
const errors_2 = errors;
|
|
@@ -41068,11 +41046,11 @@ function requireUtils$1() {
|
|
|
41068
41046
|
return Object.assign(Object.assign(Object.assign({ endpointPool, nodeManager: nodeManager2 }, settings.blockedNodeUrlSubstrings !== void 0 ? { blockedNodeUrlSubstrings: settings.blockedNodeUrlSubstrings } : {}), settings.nodeUrlFilter !== void 0 ? { nodeUrlFilter: settings.nodeUrlFilter } : {}), { blockchainRid: blockchainRidToUse, merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e : constants_12.MERKLE_HASH_VERSIONS.UNSET, dappStatusPolling: setStatusPolling(settings.dappStatusPolling), clusterAnchoringStatusPolling: setStatusPolling(settings.clusterAnchoringStatusPolling), systemAnchoringStatusPolling: setStatusPolling(settings.systemAnchoringStatusPolling), retryTransactionPolling: setRetryTransactionPolling(settings.retryTransactionPolling), failoverStrategy: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.strategy) || exports.defaultFailoverConfig.strategy, attemptsPerEndpoint: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptsPerEndpoint) || exports.defaultFailoverConfig.attemptsPerEndpoint, attemptInterval: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.attemptInterval) || exports.defaultFailoverConfig.attemptInterval, unreachableDuration: ((_j = settings.failOverConfig) === null || _j === void 0 ? void 0 : _j.unreachableDuration) || exports.defaultFailoverConfig.unreachableDuration, directoryChainRid: settings.directoryChainRid || directoryChainRid, connectTimeout: settings.connectTimeout, responseTimeout: settings.responseTimeout });
|
|
41069
41047
|
});
|
|
41070
41048
|
}
|
|
41071
|
-
function getMerkleHashVersionFromDapp(
|
|
41049
|
+
function getMerkleHashVersionFromDapp(config3) {
|
|
41072
41050
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
41073
41051
|
var _a2;
|
|
41074
41052
|
try {
|
|
41075
|
-
const response = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/config/${
|
|
41053
|
+
const response = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/config/${config3.blockchainRid}/features`, config3, void 0, false, (_a2 = config3.connectTimeout) !== null && _a2 !== void 0 ? _a2 : config3.responseTimeout);
|
|
41076
41054
|
const validatedResponse = (0, merkleHash_1.validateMerkleHash)(response.rspBody);
|
|
41077
41055
|
return validatedResponse.merkle_hash_version;
|
|
41078
41056
|
} catch (error4) {
|
|
@@ -41084,7 +41062,7 @@ function requireUtils$1() {
|
|
|
41084
41062
|
function validTxRid(txRID) {
|
|
41085
41063
|
if (txRID.length != 32) {
|
|
41086
41064
|
const error4 = new errors_12.InvalidTxRidException(txRID);
|
|
41087
|
-
|
|
41065
|
+
logger3.error(error4.toString());
|
|
41088
41066
|
return false;
|
|
41089
41067
|
}
|
|
41090
41068
|
return true;
|
|
@@ -41487,7 +41465,7 @@ function requireUtils$1() {
|
|
|
41487
41465
|
function handleGetResponse(error4, statusCode, responseObject, callback) {
|
|
41488
41466
|
try {
|
|
41489
41467
|
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
41490
|
-
|
|
41468
|
+
logger3.debug(`error: ${error4}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
41491
41469
|
if (error4) {
|
|
41492
41470
|
return callback(error4, null);
|
|
41493
41471
|
}
|
|
@@ -41497,16 +41475,16 @@ function requireUtils$1() {
|
|
|
41497
41475
|
return callback(null, responseObject);
|
|
41498
41476
|
} catch (error5) {
|
|
41499
41477
|
callback(error5, null);
|
|
41500
|
-
|
|
41478
|
+
logger3.error(`client.handleGetResponse(): Failed to call the callback function. ${error5}`);
|
|
41501
41479
|
}
|
|
41502
41480
|
}
|
|
41503
41481
|
function handlePostResponse(error4, statusCode, responseObject, callback) {
|
|
41504
41482
|
var _a2;
|
|
41505
41483
|
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
41506
|
-
|
|
41484
|
+
logger3.debug(`error: ${error4}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
41507
41485
|
try {
|
|
41508
41486
|
if (error4) {
|
|
41509
|
-
|
|
41487
|
+
logger3.error(`In client post(). ${error4}`);
|
|
41510
41488
|
callback(error4, null);
|
|
41511
41489
|
} else if (!statusCode || !(0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
|
|
41512
41490
|
let errorMessage2 = `Unexpected status code from server. Code: ${statusCode}.`;
|
|
@@ -41514,21 +41492,21 @@ function requireUtils$1() {
|
|
|
41514
41492
|
if (responseObjectPrintable) {
|
|
41515
41493
|
errorMessage2 += ` Message: ${responseObjectPrintable}.`;
|
|
41516
41494
|
}
|
|
41517
|
-
|
|
41495
|
+
logger3.error(errorMessage2);
|
|
41518
41496
|
callback(new errors_12.UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, errorMessageInResponseBody || responseObjectPrintable), responseObject);
|
|
41519
41497
|
} else {
|
|
41520
|
-
|
|
41498
|
+
logger3.info(`Calling responseCallback with responseObject: ${responseObjectPrintable}`);
|
|
41521
41499
|
callback(null, responseObject);
|
|
41522
41500
|
}
|
|
41523
41501
|
} catch (error5) {
|
|
41524
|
-
|
|
41502
|
+
logger3.error(`client.handlePostResponse(): Failed to call callback function ${error5}`);
|
|
41525
41503
|
}
|
|
41526
41504
|
}
|
|
41527
41505
|
function getBlockchainRidFromIid(_a2) {
|
|
41528
41506
|
return __awaiter2(this, arguments, void 0, function* ({ endpointPool, chainId, failOverConfig = {}, nodeManager: nodeManager2, connectTimeout, responseTimeout }) {
|
|
41529
41507
|
var _b;
|
|
41530
41508
|
const mergedFailOverConfig = Object.assign(Object.assign({}, exports.defaultFailoverConfig), failOverConfig);
|
|
41531
|
-
const
|
|
41509
|
+
const config3 = {
|
|
41532
41510
|
endpointPool,
|
|
41533
41511
|
nodeManager: nodeManager2,
|
|
41534
41512
|
dappStatusPolling: setStatusPolling(),
|
|
@@ -41543,7 +41521,7 @@ function requireUtils$1() {
|
|
|
41543
41521
|
connectTimeout,
|
|
41544
41522
|
responseTimeout
|
|
41545
41523
|
};
|
|
41546
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/brid/iid_${chainId}`,
|
|
41524
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/brid/iid_${chainId}`, config3, void 0, false, (_b = config3.connectTimeout) !== null && _b !== void 0 ? _b : config3.responseTimeout);
|
|
41547
41525
|
const blockchainRid = (0, requests_1.isString)(rspBody);
|
|
41548
41526
|
if (!blockchainRid) {
|
|
41549
41527
|
throw error4;
|
|
@@ -42096,7 +42074,7 @@ var networkSettings = {};
|
|
|
42096
42074
|
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings2);
|
|
42097
42075
|
if ("error" in restNetworkSettingsValidationContext) {
|
|
42098
42076
|
const { error: { issues } = {} } = restNetworkSettingsValidationContext;
|
|
42099
|
-
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path:
|
|
42077
|
+
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path: path3 }) => `${path3[0]}: ${message}`).join(", ");
|
|
42100
42078
|
if (throwOnError) {
|
|
42101
42079
|
throw new Error(errorMessage2);
|
|
42102
42080
|
}
|
|
@@ -42259,7 +42237,7 @@ function requireBlockchainClient() {
|
|
|
42259
42237
|
const crypto_12 = requireCryptoBrowserify();
|
|
42260
42238
|
const cloneDeep_1$1 = __importDefault2(cloneDeep_1);
|
|
42261
42239
|
const IccfProofTxMaterialBuilder_1 = requireIccfProofTxMaterialBuilder();
|
|
42262
|
-
const
|
|
42240
|
+
const logger3 = __importStar2(logger$3);
|
|
42263
42241
|
const formatter_12 = formatter;
|
|
42264
42242
|
const serialization_12 = serialization$2;
|
|
42265
42243
|
const gtxTool = __importStar2(gtx$1);
|
|
@@ -42279,10 +42257,10 @@ function requireBlockchainClient() {
|
|
|
42279
42257
|
function createClient(settings) {
|
|
42280
42258
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42281
42259
|
(0, networkSettings_1.isNetworkSettingValid)(settings, { throwOnError: true });
|
|
42282
|
-
const
|
|
42283
|
-
|
|
42260
|
+
const config3 = yield (0, utils_12.getClientConfigFromSettings)(settings);
|
|
42261
|
+
config3.merkleHashVersion = yield getMerkleHashVersion(settings);
|
|
42284
42262
|
return {
|
|
42285
|
-
config:
|
|
42263
|
+
config: config3,
|
|
42286
42264
|
query(nameOrQueryObject, args, callback) {
|
|
42287
42265
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42288
42266
|
let _name, _args;
|
|
@@ -42293,7 +42271,7 @@ function requireBlockchainClient() {
|
|
|
42293
42271
|
_name = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.name;
|
|
42294
42272
|
_args = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.args;
|
|
42295
42273
|
}
|
|
42296
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.POST, `query_gtv/${
|
|
42274
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.POST, `query_gtv/${config3.blockchainRid}`, config3, (0, serialization_12.encodeValue)((0, formatter_12.toQueryObjectGTV)(_name, _args)));
|
|
42297
42275
|
return new Promise((resolve2, reject) => {
|
|
42298
42276
|
(0, utils_12.handlePostResponse)(error4, statusCode, (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, resolve2, callback));
|
|
42299
42277
|
});
|
|
@@ -42301,10 +42279,10 @@ function requireBlockchainClient() {
|
|
|
42301
42279
|
},
|
|
42302
42280
|
signTransaction(transaction, signMethod2, callback) {
|
|
42303
42281
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42304
|
-
|
|
42305
|
-
const gtx2 = (0, utils_12.getGTXFromBufferOrTransactionOrOperation)(transaction,
|
|
42282
|
+
logger3.debug(`Signing transaction with ${!(0, utils_12.isKeyPair)(signMethod2) ? "signature provider containing " : ""}pubKey: ${(0, formatter_12.toString)(signMethod2.pubKey)}`);
|
|
42283
|
+
const gtx2 = (0, utils_12.getGTXFromBufferOrTransactionOrOperation)(transaction, config3.blockchainRid);
|
|
42306
42284
|
try {
|
|
42307
|
-
const signedTx = yield (0, utils_12.isKeyPair)(signMethod2) ? gtxTool.sign(gtx2, signMethod2.privKey,
|
|
42285
|
+
const signedTx = yield (0, utils_12.isKeyPair)(signMethod2) ? gtxTool.sign(gtx2, signMethod2.privKey, config3.merkleHashVersion, signMethod2.pubKey) : gtxTool.sign(gtx2, signMethod2, config3.merkleHashVersion);
|
|
42308
42286
|
const gtxBytes = (0, utils_12.getSerializedGTX)(signedTx);
|
|
42309
42287
|
if (typeof callback === "function") {
|
|
42310
42288
|
callback(null, gtxBytes);
|
|
@@ -42325,8 +42303,8 @@ function requireBlockchainClient() {
|
|
|
42325
42303
|
}
|
|
42326
42304
|
const promiEvent = new promiEvents_12.Web3PromiEvent((resolve2, reject) => __awaiter2(this, void 0, void 0, function* () {
|
|
42327
42305
|
let error4 = null;
|
|
42328
|
-
for (let i = 0; i <
|
|
42329
|
-
|
|
42306
|
+
for (let i = 0; i < config3.retryTransactionPolling.count; i++) {
|
|
42307
|
+
logger3.info(`sendTransactionWithRetries attempt ${i + 1} of ${config3.retryTransactionPolling.count}`);
|
|
42330
42308
|
const tmpPromiEvent = sendOnce().on(enums_12.TransactionEvent.ClusterAnchoringConfirmation, (receipt) => {
|
|
42331
42309
|
promiEvent.emit(enums_12.TransactionEvent.ClusterAnchoringConfirmation, receipt);
|
|
42332
42310
|
}).on(enums_12.TransactionEvent.SystemAnchoringConfirmation, (receipt) => {
|
|
@@ -42338,7 +42316,7 @@ function requireBlockchainClient() {
|
|
|
42338
42316
|
}).on(enums_12.TransactionEvent.DappConfirmed, (receipt) => {
|
|
42339
42317
|
promiEvent.emit(enums_12.TransactionEvent.DappConfirmed, receipt);
|
|
42340
42318
|
}).catch((tmpError) => {
|
|
42341
|
-
|
|
42319
|
+
logger3.warning(`sendTransactionWithRetries error on attempt ${i + 1} of ${config3.retryTransactionPolling.count}: ${tmpError}`);
|
|
42342
42320
|
promiEvent.emit(enums_12.TransactionEvent.Rejected, tmpError);
|
|
42343
42321
|
error4 = tmpError;
|
|
42344
42322
|
});
|
|
@@ -42347,7 +42325,7 @@ function requireBlockchainClient() {
|
|
|
42347
42325
|
resolve2(tmpReceipt);
|
|
42348
42326
|
return;
|
|
42349
42327
|
}
|
|
42350
|
-
yield (0, utils_12.sleep)(
|
|
42328
|
+
yield (0, utils_12.sleep)(config3.retryTransactionPolling.interval);
|
|
42351
42329
|
}
|
|
42352
42330
|
reject(error4);
|
|
42353
42331
|
}));
|
|
@@ -42357,13 +42335,13 @@ function requireBlockchainClient() {
|
|
|
42357
42335
|
const promiEvent = new promiEvents_12.Web3PromiEvent((resolve2, reject) => __awaiter2(this, void 0, void 0, function* () {
|
|
42358
42336
|
var _a2, _b;
|
|
42359
42337
|
try {
|
|
42360
|
-
const gtx2 = (0, utils_12.getGTXFromBufferOrTransactionOrOperation)(transaction,
|
|
42338
|
+
const gtx2 = (0, utils_12.getGTXFromBufferOrTransactionOrOperation)(transaction, config3.blockchainRid);
|
|
42361
42339
|
if (gtx2.signers.length !== ((_a2 = gtx2.signatures) === null || _a2 === void 0 ? void 0 : _a2.length)) {
|
|
42362
42340
|
reject(new errors_12.NumberOfSignersAndSignaturesException());
|
|
42363
42341
|
}
|
|
42364
42342
|
const gtxBytes = (0, utils_12.getSerializedGTX)(gtx2);
|
|
42365
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.POST, `tx/${
|
|
42366
|
-
const transactionRid = gtxTool.getDigestToSign(gtx2,
|
|
42343
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.POST, `tx/${config3.blockchainRid}`, config3, gtxBytes);
|
|
42344
|
+
const transactionRid = gtxTool.getDigestToSign(gtx2, config3.merkleHashVersion);
|
|
42367
42345
|
try {
|
|
42368
42346
|
yield (0, utils_12.handlePostResponsePromisified)(error4, statusCode, (0, requests_1.isRawGtv)(rspBody));
|
|
42369
42347
|
if (typeof callback === "function") {
|
|
@@ -42371,7 +42349,7 @@ function requireBlockchainClient() {
|
|
|
42371
42349
|
status: enums_12.ResponseStatus.Waiting,
|
|
42372
42350
|
statusCode,
|
|
42373
42351
|
transactionRid,
|
|
42374
|
-
node: (_b =
|
|
42352
|
+
node: (_b = config3.nodeManager.lastUsedNode) === null || _b === void 0 ? void 0 : _b.url
|
|
42375
42353
|
});
|
|
42376
42354
|
}
|
|
42377
42355
|
} catch (_error) {
|
|
@@ -42434,7 +42412,7 @@ function requireBlockchainClient() {
|
|
|
42434
42412
|
callback === null || callback === void 0 ? void 0 : callback(error5, null);
|
|
42435
42413
|
throw error5;
|
|
42436
42414
|
}
|
|
42437
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `tx/${
|
|
42415
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `tx/${config3.blockchainRid}/${(0, formatter_12.ensureString)(transactionRid)}`, config3);
|
|
42438
42416
|
const transaction = (0, requests_1.isTransaction)(rspBody);
|
|
42439
42417
|
return new Promise((resolve2, reject) => {
|
|
42440
42418
|
(0, utils_12.handleGetResponse)(error4, statusCode, statusCode === 200 && transaction ? (0, formatter_12.toBuffer)(transaction.tx) : (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, resolve2, callback));
|
|
@@ -42449,7 +42427,7 @@ function requireBlockchainClient() {
|
|
|
42449
42427
|
callback === null || callback === void 0 ? void 0 : callback(error5, null);
|
|
42450
42428
|
throw error5;
|
|
42451
42429
|
}
|
|
42452
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `tx/${
|
|
42430
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `tx/${config3.blockchainRid}/${transactionRid.toString("hex")}/status`, config3);
|
|
42453
42431
|
return new Promise((resolve2, reject) => {
|
|
42454
42432
|
(0, utils_12.handleGetResponse)(error4, statusCode, (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, (result) => resolve2((0, transactionStatusReponse_1.validateTransactionStatusReponse)({
|
|
42455
42433
|
statusCode,
|
|
@@ -42472,7 +42450,7 @@ function requireBlockchainClient() {
|
|
|
42472
42450
|
const beforeTimeQueryParam = beforeTime ? `&before-time=${beforeTime.getTime()}` : "";
|
|
42473
42451
|
const afterTimeQueryParam = afterTime ? `&after-time=${afterTime.getTime()}` : "";
|
|
42474
42452
|
const signerQueryParam = signerPubKey ? `&signer=${signerPubKey}` : "";
|
|
42475
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `transactions/${
|
|
42453
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `transactions/${config3.blockchainRid}?limit=${limit}${beforeTimeQueryParam}${afterTimeQueryParam}${signerQueryParam}`, config3);
|
|
42476
42454
|
const transactionsInfoResponseArray = (0, requests_1.isTransactionInfoResponseArray)(rspBody);
|
|
42477
42455
|
const body = statusCode === 200 && transactionsInfoResponseArray ? transactionsInfoResponseArray.map(utils_12.formatTransactionInfoResponse) : rspBody;
|
|
42478
42456
|
return new Promise((resolve2, reject) => {
|
|
@@ -42488,7 +42466,7 @@ function requireBlockchainClient() {
|
|
|
42488
42466
|
callback === null || callback === void 0 ? void 0 : callback(error5, null);
|
|
42489
42467
|
throw error5;
|
|
42490
42468
|
}
|
|
42491
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `transactions/${
|
|
42469
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `transactions/${config3.blockchainRid}/${(0, formatter_12.ensureString)(transactionRid)}`, config3);
|
|
42492
42470
|
const transactionInfoResponse = (0, requests_1.isTransactionInfoResponse)(rspBody);
|
|
42493
42471
|
const body = statusCode === 200 && transactionInfoResponse ? (0, utils_12.formatTransactionInfoResponse)(transactionInfoResponse) : rspBody;
|
|
42494
42472
|
return new Promise((resolve2, reject) => {
|
|
@@ -42500,7 +42478,7 @@ function requireBlockchainClient() {
|
|
|
42500
42478
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42501
42479
|
const client = this;
|
|
42502
42480
|
const result = { status: enums_12.AnchoringStatus.NotAnchored };
|
|
42503
|
-
const clusterAnchoredTx = yield (0, utils_2.awaitGetAnchoringTransactionForBlockRid)(anchoringClient, (0, formatter_12.ensureBuffer)(client.config.blockchainRid), (0, formatter_12.ensureBuffer)(blockRid),
|
|
42481
|
+
const clusterAnchoredTx = yield (0, utils_2.awaitGetAnchoringTransactionForBlockRid)(anchoringClient, (0, formatter_12.ensureBuffer)(client.config.blockchainRid), (0, formatter_12.ensureBuffer)(blockRid), config3.clusterAnchoringStatusPolling);
|
|
42504
42482
|
if (!clusterAnchoredTx) {
|
|
42505
42483
|
return result;
|
|
42506
42484
|
}
|
|
@@ -42510,7 +42488,7 @@ function requireBlockchainClient() {
|
|
|
42510
42488
|
}
|
|
42511
42489
|
result.status = enums_12.AnchoringStatus.ClusterAnchored;
|
|
42512
42490
|
result.clusterAnchoredTx = anchoringTransactionValidation.data;
|
|
42513
|
-
const systemAnchoredTransaction = yield (0, utils_12.getSystemAnchoringTransaction)(
|
|
42491
|
+
const systemAnchoredTransaction = yield (0, utils_12.getSystemAnchoringTransaction)(config3.endpointPool, anchoringTransactionValidation.data.txRid, anchoringClient, systemAnchoringChainRid, config3.systemAnchoringStatusPolling, config3.merkleHashVersion, config3.blockedNodeUrlSubstrings, config3.nodeUrlFilter);
|
|
42514
42492
|
if (!systemAnchoredTransaction) {
|
|
42515
42493
|
return result;
|
|
42516
42494
|
}
|
|
@@ -42574,7 +42552,7 @@ function requireBlockchainClient() {
|
|
|
42574
42552
|
},
|
|
42575
42553
|
getTransactionCount(callback) {
|
|
42576
42554
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42577
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `transactions/${
|
|
42555
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `transactions/${config3.blockchainRid}/count`, config3, void 0, true);
|
|
42578
42556
|
const transactionsCount = (0, requests_1.isTransactionsCount)(rspBody);
|
|
42579
42557
|
return new Promise((resolve2, reject) => {
|
|
42580
42558
|
(0, utils_12.handleGetResponse)(error4, statusCode, statusCode === 200 ? transactionsCount === null || transactionsCount === void 0 ? void 0 : transactionsCount.transactionsCount : (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, resolve2, callback));
|
|
@@ -42585,7 +42563,7 @@ function requireBlockchainClient() {
|
|
|
42585
42563
|
return __awaiter2(this, arguments, void 0, function* (blockIdentifier2, txs = false, callback) {
|
|
42586
42564
|
(0, blockIdentifier_1.isBlockIdentifierValid)(blockIdentifier2, { throwOnError: true });
|
|
42587
42565
|
const queryString = typeof blockIdentifier2 === "string" ? blockIdentifier2 : `height/${blockIdentifier2}`;
|
|
42588
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `blocks/${
|
|
42566
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `blocks/${config3.blockchainRid}/${queryString}?txs=${txs}`, config3);
|
|
42589
42567
|
const blockInfoResponse = (0, requests_1.isBlockInfoResponse)(rspBody);
|
|
42590
42568
|
return new Promise((resolve2, reject) => {
|
|
42591
42569
|
(0, utils_12.handleGetResponse)(error4, statusCode, statusCode === 200 && blockInfoResponse !== null && blockInfoResponse ? (0, utils_12.formatBlockInfoResponse)(blockInfoResponse) : (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, resolve2, callback));
|
|
@@ -42595,7 +42573,7 @@ function requireBlockchainClient() {
|
|
|
42595
42573
|
getLatestBlock() {
|
|
42596
42574
|
return __awaiter2(this, arguments, void 0, function* (txs = false, callback) {
|
|
42597
42575
|
const shouldIncludeFullTransaction = txs ? `&txs=${txs}` : "";
|
|
42598
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `blocks/${
|
|
42576
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `blocks/${config3.blockchainRid}?limit=1${shouldIncludeFullTransaction}`, config3, void 0, true);
|
|
42599
42577
|
const indexOfLatestBlock = 0;
|
|
42600
42578
|
const blockInfoResponseArray = (0, requests_1.isBlockInfoResponseArray)(rspBody);
|
|
42601
42579
|
return new Promise((resolve2, reject) => {
|
|
@@ -42620,7 +42598,7 @@ function requireBlockchainClient() {
|
|
|
42620
42598
|
searchParams.append(key3, value.toString());
|
|
42621
42599
|
}
|
|
42622
42600
|
}
|
|
42623
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `blocks/${
|
|
42601
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `blocks/${config3.blockchainRid}?${searchParams}`, config3);
|
|
42624
42602
|
const blockInfoResponseArray = (0, requests_1.isBlockInfoResponseArray)(rspBody);
|
|
42625
42603
|
return new Promise((resolve2, reject) => {
|
|
42626
42604
|
(0, utils_12.handleGetResponse)(error4, statusCode, statusCode === 200 && blockInfoResponseArray ? blockInfoResponseArray.map(utils_12.formatBlockInfoResponse) : (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, resolve2, callback));
|
|
@@ -42628,7 +42606,7 @@ function requireBlockchainClient() {
|
|
|
42628
42606
|
});
|
|
42629
42607
|
},
|
|
42630
42608
|
getClientNodeUrlPool() {
|
|
42631
|
-
return
|
|
42609
|
+
return config3.endpointPool.map((endpoint) => endpoint.url);
|
|
42632
42610
|
},
|
|
42633
42611
|
/**
|
|
42634
42612
|
* Retrieves a confirmation proof for a transaction with the specified sha256
|
|
@@ -42663,7 +42641,7 @@ function requireBlockchainClient() {
|
|
|
42663
42641
|
callback === null || callback === void 0 ? void 0 : callback(error5, null);
|
|
42664
42642
|
throw error5;
|
|
42665
42643
|
}
|
|
42666
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `tx/${
|
|
42644
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `tx/${config3.blockchainRid}/${(0, formatter_12.ensureString)(txRid2)}/confirmationProof`, config3);
|
|
42667
42645
|
const confirmationProof = {
|
|
42668
42646
|
merkleProofTree: "",
|
|
42669
42647
|
txIndex: 0
|
|
@@ -42727,13 +42705,13 @@ function requireBlockchainClient() {
|
|
|
42727
42705
|
callback === null || callback === void 0 ? void 0 : callback(error4, null);
|
|
42728
42706
|
throw error4;
|
|
42729
42707
|
}
|
|
42730
|
-
const systemAnchoringTransactionTransaction = yield (0, utils_12.getSystemAnchoringTransaction)(
|
|
42708
|
+
const systemAnchoringTransactionTransaction = yield (0, utils_12.getSystemAnchoringTransaction)(config3.endpointPool, anchoredTxRid, anchoringClient, systemAnchoringChainRid, config3.systemAnchoringStatusPolling, config3.merkleHashVersion, config3.blockedNodeUrlSubstrings, config3.nodeUrlFilter);
|
|
42731
42709
|
return systemAnchoringTransactionTransaction;
|
|
42732
42710
|
});
|
|
42733
42711
|
},
|
|
42734
42712
|
getWaitingTransactions(blockchainRid, callback) {
|
|
42735
42713
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42736
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/tx/${(0, formatter_12.ensureString)(blockchainRid)}/waiting`,
|
|
42714
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/tx/${(0, formatter_12.ensureString)(blockchainRid)}/waiting`, config3);
|
|
42737
42715
|
return new Promise((resolve2, reject) => {
|
|
42738
42716
|
(0, utils_12.handleGetResponse)(error4, statusCode, (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, resolve2, callback));
|
|
42739
42717
|
});
|
|
@@ -42741,7 +42719,7 @@ function requireBlockchainClient() {
|
|
|
42741
42719
|
},
|
|
42742
42720
|
getWaitingTransaction(blockchainRid, txRid2, callback) {
|
|
42743
42721
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42744
|
-
const { error: error4, statusCode, rspBody, transactionTimestamp } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/tx/${(0, formatter_12.ensureString)(blockchainRid)}/waiting/${(0, formatter_12.ensureString)(txRid2)}`,
|
|
42722
|
+
const { error: error4, statusCode, rspBody, transactionTimestamp } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/tx/${(0, formatter_12.ensureString)(blockchainRid)}/waiting/${(0, formatter_12.ensureString)(txRid2)}`, config3);
|
|
42745
42723
|
const transaction = (0, requests_1.isTransaction)(rspBody);
|
|
42746
42724
|
const result = transaction ? (0, formatter_12.toBuffer)(transaction.tx) : (0, requests_1.isRawGtv)(rspBody);
|
|
42747
42725
|
return new Promise((resolve2, reject) => {
|
|
@@ -42754,7 +42732,7 @@ function requireBlockchainClient() {
|
|
|
42754
42732
|
},
|
|
42755
42733
|
getRejectedTransactions(blockchainRid, callback) {
|
|
42756
42734
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42757
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/tx/${(0, formatter_12.ensureString)(blockchainRid)}/rejected`,
|
|
42735
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/tx/${(0, formatter_12.ensureString)(blockchainRid)}/rejected`, config3);
|
|
42758
42736
|
const rejectedTransactionsArray = (0, requests_1.isRejectedTransactionResponseArray)(rspBody);
|
|
42759
42737
|
const validResponseBody = statusCode === 200 && rejectedTransactionsArray ? rejectedTransactionsArray.map((rejectedTransaction) => (0, utils_12.formatRejectedTransactionFromResponse)(rejectedTransaction)) : rspBody;
|
|
42760
42738
|
return new Promise((resolve2, reject) => {
|
|
@@ -42768,7 +42746,7 @@ function requireBlockchainClient() {
|
|
|
42768
42746
|
*/
|
|
42769
42747
|
getAppStructure(callback) {
|
|
42770
42748
|
return __awaiter2(this, void 0, void 0, function* () {
|
|
42771
|
-
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/query/${
|
|
42749
|
+
const { error: error4, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_12.Method.GET, `/query/${config3.blockchainRid}?type=rell.get_app_structure`, config3);
|
|
42772
42750
|
return new Promise((resolve2, reject) => {
|
|
42773
42751
|
(0, utils_12.handleGetResponse)(error4, statusCode, (0, requests_1.isRawGtv)(rspBody), (0, utils_12.callbackPromiseBuilder)(reject, resolve2, callback));
|
|
42774
42752
|
});
|
|
@@ -42781,7 +42759,7 @@ function requireBlockchainClient() {
|
|
|
42781
42759
|
if (settings2.merkleHashVersion !== void 0) {
|
|
42782
42760
|
merkleHashVersion = settings2.merkleHashVersion;
|
|
42783
42761
|
} else {
|
|
42784
|
-
merkleHashVersion = yield (0, utils_12.getMerkleHashVersionFromDapp)(
|
|
42762
|
+
merkleHashVersion = yield (0, utils_12.getMerkleHashVersionFromDapp)(config3);
|
|
42785
42763
|
}
|
|
42786
42764
|
return merkleHashVersion;
|
|
42787
42765
|
});
|
|
@@ -43073,11 +43051,11 @@ function requireDecodeTransactionToGtx() {
|
|
|
43073
43051
|
Object.defineProperty(decodeTransactionToGtx, "__esModule", { value: true });
|
|
43074
43052
|
decodeTransactionToGtx.decodeTransactionToGtx = decodeTransactionToGtx$1;
|
|
43075
43053
|
const gtxTool = __importStar2(gtx$1);
|
|
43076
|
-
const
|
|
43054
|
+
const logger3 = __importStar2(logger$3);
|
|
43077
43055
|
const dump_1 = requireDump();
|
|
43078
43056
|
function decodeTransactionToGtx$1(encodedTransaction) {
|
|
43079
43057
|
const gtx2 = gtxTool.deserialize(encodedTransaction);
|
|
43080
|
-
|
|
43058
|
+
logger3.debug(`Output from deserializing a raw transaction: ${(0, dump_1.dumpGtv)(gtx2)}`);
|
|
43081
43059
|
return gtx2;
|
|
43082
43060
|
}
|
|
43083
43061
|
return decodeTransactionToGtx;
|
|
@@ -43294,10 +43272,8 @@ var index = /* @__PURE__ */ getDefaultExportFromCjs(builtExports);
|
|
|
43294
43272
|
|
|
43295
43273
|
// src-ts/browser/native.ts
|
|
43296
43274
|
var { Buffer: Buffer3, gtx: pcgtx } = index;
|
|
43297
|
-
var ATBASH_ENDPOINT = "https://
|
|
43298
|
-
var
|
|
43299
|
-
var ATBASH_PRIVATE_BLOCKCHAIN_RID = "2603569AE8DC3F254323F719C8D4347BBA964E874E781291F8474236BE8B6493";
|
|
43300
|
-
var DEFAULT_CHROMIA_NODE_URLS_ARR = define_ATBASH_CHROMIA_NODE_URLS_default;
|
|
43275
|
+
var ATBASH_ENDPOINT = "https://atbash.ai";
|
|
43276
|
+
var ATBASH_PRIVATE_BLOCKCHAIN_RID = "39FFD3557D0296CB2C57FDC6A3B8C024E95639CF4964DA08141AC20C6344D408";
|
|
43301
43277
|
var DEFAULT_PRIVATE_NODE_URLS_ARR = define_ATBASH_PRIVATE_NODE_URLS_default;
|
|
43302
43278
|
var MERKLE_HASH_VERSION = 2;
|
|
43303
43279
|
function stripHex(s2) {
|
|
@@ -43449,12 +43425,21 @@ var native = {
|
|
|
43449
43425
|
deriveMemoryKey,
|
|
43450
43426
|
encryptMemoryContent,
|
|
43451
43427
|
decryptMemoryContent,
|
|
43452
|
-
DEFAULT_BLOCKCHAIN_RID: ATBASH_BLOCKCHAIN_RID,
|
|
43453
43428
|
DEFAULT_PRIVATE_BLOCKCHAIN_RID: ATBASH_PRIVATE_BLOCKCHAIN_RID,
|
|
43454
43429
|
DEFAULT_ENDPOINT: ATBASH_ENDPOINT,
|
|
43455
|
-
defaultChromiaNodeUrls: () => [...DEFAULT_CHROMIA_NODE_URLS_ARR],
|
|
43456
43430
|
defaultPrivateNodeUrls: () => [...DEFAULT_PRIVATE_NODE_URLS_ARR],
|
|
43457
43431
|
// Server-only surfaces — throw at runtime, keep types satisfied.
|
|
43432
|
+
// The memory signers are here and not with the other signing shims because
|
|
43433
|
+
// their args are encrypted by `encryptMemoryContent`, which this build does
|
|
43434
|
+
// not have: a browser could sign the transaction but never produce one worth
|
|
43435
|
+
// sending.
|
|
43436
|
+
signAddAgentMemory: stub("signAddAgentMemory"),
|
|
43437
|
+
signRollbackAgentMemory: stub("signRollbackAgentMemory"),
|
|
43438
|
+
extractMemoryEdits: stub("extractMemoryEdits"),
|
|
43439
|
+
applyMemoryEdits: stub("applyMemoryEdits"),
|
|
43440
|
+
memorySlotForPath: stub("memorySlotForPath"),
|
|
43441
|
+
isSafeMemorySlot: stub("isSafeMemorySlot"),
|
|
43442
|
+
defaultAgentHomeDirs: stub("defaultAgentHomeDirs"),
|
|
43458
43443
|
classifyMemoryWrite: stub("classifyMemoryWrite"),
|
|
43459
43444
|
classifyMemoryRead: stub("classifyMemoryRead"),
|
|
43460
43445
|
defaultMemoryWriteToolNames: stub("defaultMemoryWriteToolNames"),
|
|
@@ -43478,9 +43463,10 @@ var native = {
|
|
|
43478
43463
|
validateMemoryId: stub("validateMemoryId"),
|
|
43479
43464
|
validateRollbackReason: stub("validateRollbackReason"),
|
|
43480
43465
|
validateMemoryNonce: stub("validateMemoryNonce"),
|
|
43466
|
+
validateFilePath: stub("validateFilePath"),
|
|
43481
43467
|
buildGetActiveMemoryIdQuery: stub("buildGetActiveMemoryIdQuery"),
|
|
43482
|
-
|
|
43483
|
-
|
|
43468
|
+
buildGetRecentAgentMemoryQuery: stub("buildGetRecentAgentMemoryQuery"),
|
|
43469
|
+
buildGetActiveAgentMemoryQuery: stub("buildGetActiveAgentMemoryQuery"),
|
|
43484
43470
|
buildGetAgentMemoryHistoryQuery: stub("buildGetAgentMemoryHistoryQuery"),
|
|
43485
43471
|
buildGetAgentMemoryRollbackHistoryQuery: stub("buildGetAgentMemoryRollbackHistoryQuery"),
|
|
43486
43472
|
buildGetAgentMemoryByIdQuery: stub("buildGetAgentMemoryByIdQuery"),
|
|
@@ -43499,21 +43485,20 @@ var native = {
|
|
|
43499
43485
|
OP_ROLLBACK_AGENT_MEMORY: "rollback_agent_memory",
|
|
43500
43486
|
OP_LOG_ENCRYPTED_TOOL_CALL: "log_encrypted_tool_call",
|
|
43501
43487
|
QUERY_GET_ACTIVE_MEMORY_ID: "get_active_memory_id",
|
|
43502
|
-
|
|
43503
|
-
|
|
43488
|
+
QUERY_GET_RECENT_AGENT_MEMORY: "get_recent_agent_memory",
|
|
43489
|
+
QUERY_GET_ACTIVE_AGENT_MEMORY: "get_active_agent_memory",
|
|
43504
43490
|
QUERY_GET_AGENT_MEMORY_HISTORY: "get_agent_memory_history",
|
|
43505
43491
|
QUERY_GET_AGENT_MEMORY_BY_ID: "get_agent_memory_by_id",
|
|
43506
43492
|
QUERY_GET_AGENT_MEMORY_ROLLBACK_HISTORY: "get_agent_memory_rollback_history",
|
|
43507
43493
|
ARG_AGENT_PUBKEY: "agent_pubkey",
|
|
43508
|
-
ARG_ID: "id"
|
|
43494
|
+
ARG_ID: "id",
|
|
43495
|
+
ARG_FILE_PATH: "file_path"
|
|
43509
43496
|
};
|
|
43510
43497
|
|
|
43511
43498
|
// src-ts/client.ts
|
|
43512
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43513
43499
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43514
43500
|
|
|
43515
43501
|
// src-ts/random.ts
|
|
43516
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43517
43502
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43518
43503
|
function randomBytes4(size) {
|
|
43519
43504
|
const buf = new Uint8Array(size);
|
|
@@ -43529,45 +43514,62 @@ function randomHex(size) {
|
|
|
43529
43514
|
return hex;
|
|
43530
43515
|
}
|
|
43531
43516
|
|
|
43532
|
-
// src-ts/
|
|
43533
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43534
|
-
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43535
|
-
|
|
43536
|
-
// src-ts/constants.ts
|
|
43537
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43517
|
+
// src-ts/auth-bearer.ts
|
|
43538
43518
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43539
|
-
var
|
|
43540
|
-
var
|
|
43541
|
-
|
|
43542
|
-
|
|
43543
|
-
|
|
43519
|
+
var BEARER_TTL_MS = 4 * 60 * 1e3;
|
|
43520
|
+
var bearers = /* @__PURE__ */ new Map();
|
|
43521
|
+
function agentAuthBearer(auth, blockchainRid) {
|
|
43522
|
+
const key3 = `${auth.pubkey}:${blockchainRid}`;
|
|
43523
|
+
const now = Date.now();
|
|
43524
|
+
const cached = bearers.get(key3);
|
|
43525
|
+
if (cached && now - cached.issuedAt < BEARER_TTL_MS) return cached.hex;
|
|
43526
|
+
const hex = native.signLogToolCall(
|
|
43527
|
+
`auth-${now.toString(36)}-${randomHex(4)}`,
|
|
43528
|
+
`auth:${now}`,
|
|
43529
|
+
"",
|
|
43530
|
+
"auth-bearer",
|
|
43531
|
+
"",
|
|
43532
|
+
auth.privkey,
|
|
43533
|
+
blockchainRid
|
|
43534
|
+
);
|
|
43535
|
+
bearers.set(key3, { hex, issuedAt: now });
|
|
43536
|
+
return hex;
|
|
43537
|
+
}
|
|
43538
|
+
function agentAuthHeaders(auth, blockchainRid) {
|
|
43539
|
+
return { Authorization: `Bearer ${agentAuthBearer(auth, blockchainRid)}` };
|
|
43540
|
+
}
|
|
43544
43541
|
|
|
43545
43542
|
// src-ts/chain-config.ts
|
|
43543
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43546
43544
|
var DEFAULT_PRIVATE_NODE_URLS = Object.freeze(
|
|
43547
43545
|
native.defaultPrivateNodeUrls()
|
|
43548
43546
|
);
|
|
43549
43547
|
var DEFAULT_PRIVATE_BLOCKCHAIN_RID = native.DEFAULT_PRIVATE_BLOCKCHAIN_RID;
|
|
43550
|
-
var PUBLIC_CHAIN = {
|
|
43551
|
-
network: "public",
|
|
43552
|
-
blockchainRid: DEFAULT_BLOCKCHAIN_RID,
|
|
43553
|
-
nodeUrls: DEFAULT_CHROMIA_NODE_URLS
|
|
43554
|
-
};
|
|
43555
43548
|
var PRIVATE_CHAIN = {
|
|
43556
43549
|
network: "private",
|
|
43557
43550
|
blockchainRid: DEFAULT_PRIVATE_BLOCKCHAIN_RID,
|
|
43558
43551
|
nodeUrls: DEFAULT_PRIVATE_NODE_URLS
|
|
43559
43552
|
};
|
|
43553
|
+
function chainForNetwork(network) {
|
|
43554
|
+
if (network !== "private") {
|
|
43555
|
+
throw new Error(
|
|
43556
|
+
`network must be "private" (the public chain is retired), got ${JSON.stringify(network)}`
|
|
43557
|
+
);
|
|
43558
|
+
}
|
|
43559
|
+
return PRIVATE_CHAIN;
|
|
43560
|
+
}
|
|
43561
|
+
|
|
43562
|
+
// src-ts/constants.ts
|
|
43563
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43564
|
+
var DEFAULT_ENDPOINT = native.DEFAULT_ENDPOINT;
|
|
43560
43565
|
|
|
43561
43566
|
// src-ts/browser/encrypted-toolcall.ts
|
|
43562
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43563
43567
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43564
43568
|
|
|
43565
43569
|
// src-ts/browser/crypto-ecies.ts
|
|
43566
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43567
43570
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43568
43571
|
|
|
43569
43572
|
// node_modules/@noble/hashes/hkdf.js
|
|
43570
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43571
43573
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43572
43574
|
function extract(hash3, ikm, salt) {
|
|
43573
43575
|
ahash(hash3);
|
|
@@ -43609,15 +43611,12 @@ function expand2(hash3, prk, info2, length = 32) {
|
|
|
43609
43611
|
var hkdf = (hash3, ikm, salt, info2, length) => expand2(hash3, extract(hash3, ikm, salt), info2, length);
|
|
43610
43612
|
|
|
43611
43613
|
// node_modules/@noble/ciphers/aes.js
|
|
43612
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43613
43614
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43614
43615
|
|
|
43615
43616
|
// node_modules/@noble/ciphers/_polyval.js
|
|
43616
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43617
43617
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43618
43618
|
|
|
43619
43619
|
// node_modules/@noble/ciphers/utils.js
|
|
43620
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43621
43620
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43622
43621
|
function isBytes3(a) {
|
|
43623
43622
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
@@ -44211,7 +44210,6 @@ function encryptedLength(plaintextByteLength) {
|
|
|
44211
44210
|
}
|
|
44212
44211
|
|
|
44213
44212
|
// src-ts/crypto/envelope.ts
|
|
44214
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44215
44213
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44216
44214
|
var PREFIX = "atb1";
|
|
44217
44215
|
var SEPARATOR = ".";
|
|
@@ -44345,7 +44343,6 @@ function signEncryptedToolCall(toolCallId, action, context, toolName, toolArgsJs
|
|
|
44345
44343
|
}
|
|
44346
44344
|
|
|
44347
44345
|
// src-ts/endpoint.ts
|
|
44348
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44349
44346
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44350
44347
|
function buildAllowedJudgeHosts() {
|
|
44351
44348
|
return /* @__PURE__ */ new Set([
|
|
@@ -44355,6 +44352,13 @@ function buildAllowedJudgeHosts() {
|
|
|
44355
44352
|
]);
|
|
44356
44353
|
}
|
|
44357
44354
|
var ALLOWED_JUDGE_HOSTS = buildAllowedJudgeHosts();
|
|
44355
|
+
function isAllowlistedJudgeHost(endpoint) {
|
|
44356
|
+
try {
|
|
44357
|
+
return ALLOWED_JUDGE_HOSTS.has(new URL(endpoint).hostname.toLowerCase());
|
|
44358
|
+
} catch {
|
|
44359
|
+
return false;
|
|
44360
|
+
}
|
|
44361
|
+
}
|
|
44358
44362
|
function validateJudgeEndpoint(judge) {
|
|
44359
44363
|
const policy = judge?.policy === "self-hosted" ? "self-hosted" : "default";
|
|
44360
44364
|
const candidate = judge?.endpoint?.trim() || DEFAULT_ENDPOINT;
|
|
@@ -44397,18 +44401,29 @@ function validateJudgeEndpoint(judge) {
|
|
|
44397
44401
|
}
|
|
44398
44402
|
|
|
44399
44403
|
// src-ts/errors.ts
|
|
44400
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44401
44404
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44402
44405
|
var AtbashAPIError = class extends Error {
|
|
44403
44406
|
/** HTTP status code (or 0 if the request never completed). */
|
|
44404
44407
|
status;
|
|
44405
44408
|
/** Raw response body text (may be empty). */
|
|
44406
44409
|
body;
|
|
44407
|
-
|
|
44408
|
-
|
|
44410
|
+
/**
|
|
44411
|
+
* Request path this status came from, e.g. `/api/v1/judge` — absent when the
|
|
44412
|
+
* request never reached a response (transport failures carry status 0).
|
|
44413
|
+
*
|
|
44414
|
+
* A status alone does not say what failed. Several routes answer one call, and
|
|
44415
|
+
* more than one of them can 404: a caller reading only `404` cannot tell "this
|
|
44416
|
+
* agent is not registered" from "the chain-routing lookup did not resolve", and
|
|
44417
|
+
* has to guess from the body's prose — which a 404 raised before any handler
|
|
44418
|
+
* ran does not carry. The path is the fact that settles it.
|
|
44419
|
+
*/
|
|
44420
|
+
path;
|
|
44421
|
+
constructor(status, body, statusText = "", endpoint = DEFAULT_ENDPOINT, path3) {
|
|
44422
|
+
super(enrich(status, body, statusText, endpoint, path3));
|
|
44409
44423
|
this.name = "AtbashAPIError";
|
|
44410
44424
|
this.status = status;
|
|
44411
44425
|
this.body = body;
|
|
44426
|
+
this.path = path3;
|
|
44412
44427
|
}
|
|
44413
44428
|
};
|
|
44414
44429
|
var SignatureVerificationError = class extends Error {
|
|
@@ -44417,9 +44432,18 @@ var SignatureVerificationError = class extends Error {
|
|
|
44417
44432
|
this.name = "SignatureVerificationError";
|
|
44418
44433
|
}
|
|
44419
44434
|
};
|
|
44420
|
-
|
|
44435
|
+
var JudgeRefusalError = class extends Error {
|
|
44436
|
+
constructor(message) {
|
|
44437
|
+
super(message);
|
|
44438
|
+
this.name = "JudgeRefusalError";
|
|
44439
|
+
}
|
|
44440
|
+
};
|
|
44441
|
+
function isRefusalStatus(status) {
|
|
44442
|
+
return status >= 400 && status < 500 && status !== 408;
|
|
44443
|
+
}
|
|
44444
|
+
function enrich(status, body, statusText, endpoint, path3) {
|
|
44421
44445
|
const dashboard = endpoint.replace(/\/+$/, "") || DEFAULT_ENDPOINT;
|
|
44422
|
-
let msg = `API error ${status}: ${body || statusText}`;
|
|
44446
|
+
let msg = `API error ${status}${path3 ? ` from ${path3}` : ""}: ${body || statusText}`;
|
|
44423
44447
|
const lowered = body.toLowerCase();
|
|
44424
44448
|
if (lowered.includes("agent not registered")) {
|
|
44425
44449
|
msg += `
|
|
@@ -44440,8 +44464,63 @@ function enrich(status, body, statusText, endpoint) {
|
|
|
44440
44464
|
return msg;
|
|
44441
44465
|
}
|
|
44442
44466
|
|
|
44467
|
+
// src-ts/jail-hold.ts
|
|
44468
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44469
|
+
var DEFAULTS = { ceilingMs: 3e4, pollMs: 1e3 };
|
|
44470
|
+
var holds = /* @__PURE__ */ new Map();
|
|
44471
|
+
var blockedAt = /* @__PURE__ */ new Map();
|
|
44472
|
+
var BLOCK_MEMORY_MS = 10 * 6e4;
|
|
44473
|
+
var config2 = { ...DEFAULTS };
|
|
44474
|
+
function isJailHeld(pubkey) {
|
|
44475
|
+
return holds.has(pubkey);
|
|
44476
|
+
}
|
|
44477
|
+
function recordBlock(pubkey) {
|
|
44478
|
+
const now = Date.now();
|
|
44479
|
+
for (const [key3, at] of blockedAt) if (now - at > BLOCK_MEMORY_MS) blockedAt.delete(key3);
|
|
44480
|
+
blockedAt.set(pubkey, now);
|
|
44481
|
+
}
|
|
44482
|
+
function blockedSince(pubkey, startedAt) {
|
|
44483
|
+
const at = blockedAt.get(pubkey);
|
|
44484
|
+
return at !== void 0 && startedAt <= at;
|
|
44485
|
+
}
|
|
44486
|
+
function holdJail(pubkey, confirmJailed, onGiveUp) {
|
|
44487
|
+
if (holds.has(pubkey)) return;
|
|
44488
|
+
const hold = { timer: null };
|
|
44489
|
+
holds.set(pubkey, hold);
|
|
44490
|
+
const deadline = Date.now() + config2.ceilingMs;
|
|
44491
|
+
const tick = async () => {
|
|
44492
|
+
if (holds.get(pubkey) !== hold) return;
|
|
44493
|
+
let jailed = false;
|
|
44494
|
+
try {
|
|
44495
|
+
jailed = await confirmJailed();
|
|
44496
|
+
} catch {
|
|
44497
|
+
}
|
|
44498
|
+
if (holds.get(pubkey) !== hold) return;
|
|
44499
|
+
if (jailed) {
|
|
44500
|
+
holds.delete(pubkey);
|
|
44501
|
+
return;
|
|
44502
|
+
}
|
|
44503
|
+
if (Date.now() >= deadline) {
|
|
44504
|
+
holds.delete(pubkey);
|
|
44505
|
+
onGiveUp?.();
|
|
44506
|
+
return;
|
|
44507
|
+
}
|
|
44508
|
+
const timer = setTimeout(() => void tick(), config2.pollMs);
|
|
44509
|
+
timer.unref?.();
|
|
44510
|
+
hold.timer = timer;
|
|
44511
|
+
};
|
|
44512
|
+
void tick();
|
|
44513
|
+
}
|
|
44514
|
+
function releaseJailHolds() {
|
|
44515
|
+
for (const hold of holds.values()) if (hold.timer) clearTimeout(hold.timer);
|
|
44516
|
+
holds.clear();
|
|
44517
|
+
blockedAt.clear();
|
|
44518
|
+
}
|
|
44519
|
+
function configureJailHold(next) {
|
|
44520
|
+
config2 = { ...DEFAULTS, ...next };
|
|
44521
|
+
}
|
|
44522
|
+
|
|
44443
44523
|
// src-ts/http/client.ts
|
|
44444
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44445
44524
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44446
44525
|
var HttpClient = class {
|
|
44447
44526
|
baseUrl;
|
|
@@ -44450,8 +44529,8 @@ var HttpClient = class {
|
|
|
44450
44529
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
44451
44530
|
this.timeoutMs = timeoutMs;
|
|
44452
44531
|
}
|
|
44453
|
-
buildUrl(
|
|
44454
|
-
const url = new URL(this.baseUrl +
|
|
44532
|
+
buildUrl(path3, query) {
|
|
44533
|
+
const url = new URL(this.baseUrl + path3);
|
|
44455
44534
|
if (query) {
|
|
44456
44535
|
for (const [k, v] of Object.entries(query)) {
|
|
44457
44536
|
if (v !== void 0 && v !== null && v !== "") {
|
|
@@ -44461,14 +44540,14 @@ var HttpClient = class {
|
|
|
44461
44540
|
}
|
|
44462
44541
|
return url.toString();
|
|
44463
44542
|
}
|
|
44464
|
-
async get(
|
|
44465
|
-
return this.fetch(this.buildUrl(
|
|
44543
|
+
async get(path3, query, headers) {
|
|
44544
|
+
return this.fetch(this.buildUrl(path3, query), {
|
|
44466
44545
|
method: "GET",
|
|
44467
44546
|
...headers && { headers }
|
|
44468
44547
|
});
|
|
44469
44548
|
}
|
|
44470
|
-
async post(
|
|
44471
|
-
return this.fetch(this.buildUrl(
|
|
44549
|
+
async post(path3, body, headers) {
|
|
44550
|
+
return this.fetch(this.buildUrl(path3), {
|
|
44472
44551
|
method: "POST",
|
|
44473
44552
|
headers: { "Content-Type": "application/json", ...headers },
|
|
44474
44553
|
body: JSON.stringify(body)
|
|
@@ -44511,6 +44590,13 @@ function classifyTransportError(err, url, method, timeoutMs) {
|
|
|
44511
44590
|
{ cause: err }
|
|
44512
44591
|
);
|
|
44513
44592
|
}
|
|
44593
|
+
if (code2 === "UND_ERR_CONNECT_TIMEOUT") {
|
|
44594
|
+
return new HttpTransportError(
|
|
44595
|
+
"timeout",
|
|
44596
|
+
`${method} ${url} could not establish a connection before the transport deadline \u2014 check the endpoint and network`,
|
|
44597
|
+
{ cause: err }
|
|
44598
|
+
);
|
|
44599
|
+
}
|
|
44514
44600
|
if (code2 === "ENOTFOUND" || code2 === "EAI_AGAIN") {
|
|
44515
44601
|
return new HttpTransportError(
|
|
44516
44602
|
"dns",
|
|
@@ -44540,7 +44626,6 @@ function classifyTransportError(err, url, method, timeoutMs) {
|
|
|
44540
44626
|
}
|
|
44541
44627
|
|
|
44542
44628
|
// src-ts/browser/keyLoader.ts
|
|
44543
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44544
44629
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44545
44630
|
var NOT_AVAILABLE = "keyLoader is not available in the browser bundle \u2014 pass `agentKey` explicitly to Atbash.fromConfig or use `new Atbash(privkey, opts)`.";
|
|
44546
44631
|
function resolveKeyPath(_input) {
|
|
@@ -44550,19 +44635,34 @@ function loadAgentFromFile(_keyPath) {
|
|
|
44550
44635
|
throw new Error(NOT_AVAILABLE);
|
|
44551
44636
|
}
|
|
44552
44637
|
|
|
44638
|
+
// src-ts/decision.ts
|
|
44639
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44640
|
+
|
|
44553
44641
|
// src-ts/normalize.ts
|
|
44554
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44555
44642
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44643
|
+
function wireText(raw2, fallback = "") {
|
|
44644
|
+
if (raw2 === null || raw2 === void 0) return fallback;
|
|
44645
|
+
if (typeof raw2 === "object" || typeof raw2 === "function") return fallback;
|
|
44646
|
+
return String(raw2);
|
|
44647
|
+
}
|
|
44648
|
+
function wireNumber(raw2, fallback = 0) {
|
|
44649
|
+
if (raw2 === null || raw2 === void 0) return fallback;
|
|
44650
|
+
if (typeof raw2 === "object" || typeof raw2 === "function") return fallback;
|
|
44651
|
+
return Number(raw2);
|
|
44652
|
+
}
|
|
44556
44653
|
function normalizeVerdict(raw2) {
|
|
44557
44654
|
if (raw2 === null || raw2 === void 0) return "No verdict";
|
|
44558
|
-
const v =
|
|
44655
|
+
const v = wireText(raw2).trim().toUpperCase();
|
|
44559
44656
|
if (v === "ALLOW" || v === "GREEN") return "ALLOW";
|
|
44560
44657
|
if (v === "HOLD" || v === "YELLOW") return "HOLD";
|
|
44561
44658
|
if (v === "BLOCK" || v === "RED") return "BLOCK";
|
|
44562
44659
|
return "HOLD";
|
|
44563
44660
|
}
|
|
44661
|
+
function normalizeActionType(raw2) {
|
|
44662
|
+
return typeof raw2 === "string" ? raw2.trim().toLowerCase() : "";
|
|
44663
|
+
}
|
|
44564
44664
|
function normalizeStatus(raw2) {
|
|
44565
|
-
const s2 =
|
|
44665
|
+
const s2 = wireText(raw2).toLowerCase();
|
|
44566
44666
|
if (s2 === "pending" || s2 === "answered" || s2 === "error") return s2;
|
|
44567
44667
|
return "error";
|
|
44568
44668
|
}
|
|
@@ -44577,8 +44677,134 @@ function pubkeyToHex(val) {
|
|
|
44577
44677
|
return "";
|
|
44578
44678
|
}
|
|
44579
44679
|
|
|
44680
|
+
// src-ts/decision.ts
|
|
44681
|
+
function isRecord(value) {
|
|
44682
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44683
|
+
}
|
|
44684
|
+
function allowSignalsPermit(data) {
|
|
44685
|
+
const signals = [];
|
|
44686
|
+
if (Object.hasOwn(data, "allow")) signals.push(data.allow);
|
|
44687
|
+
if (isRecord(data.decision) && Object.hasOwn(data.decision, "allow")) {
|
|
44688
|
+
signals.push(data.decision.allow);
|
|
44689
|
+
}
|
|
44690
|
+
return signals.length === 0 || signals.every((value) => value === true);
|
|
44691
|
+
}
|
|
44692
|
+
function explicitRefusal(data) {
|
|
44693
|
+
let hold = false;
|
|
44694
|
+
for (const source of decisionSources(data)) {
|
|
44695
|
+
const verdict = verdictOf(source);
|
|
44696
|
+
if (verdict === "BLOCK" || verdict === "RED") return "BLOCK";
|
|
44697
|
+
if (verdict === "HOLD" || verdict === "YELLOW") hold = true;
|
|
44698
|
+
const actionType = actionTypeOf(source);
|
|
44699
|
+
if (actionType === "block") return "BLOCK";
|
|
44700
|
+
if (actionType === "hold_for_user_confirm") hold = true;
|
|
44701
|
+
}
|
|
44702
|
+
if (!allowSignalsPermit(data)) return "BLOCK";
|
|
44703
|
+
return hold ? "HOLD" : "";
|
|
44704
|
+
}
|
|
44705
|
+
function decisionSources(data) {
|
|
44706
|
+
return [data, isRecord(data.decision) ? data.decision : {}];
|
|
44707
|
+
}
|
|
44708
|
+
function verdictOf(source) {
|
|
44709
|
+
return typeof source.verdict === "string" ? source.verdict.trim().toUpperCase() : "";
|
|
44710
|
+
}
|
|
44711
|
+
function actionTypeRank(actionType) {
|
|
44712
|
+
if (actionType === "block") return 4;
|
|
44713
|
+
if (actionType === "hold_for_user_confirm") return 3;
|
|
44714
|
+
if (actionType === "") return 1;
|
|
44715
|
+
if (actionType === "allow") return 0;
|
|
44716
|
+
return 2;
|
|
44717
|
+
}
|
|
44718
|
+
function actionTypeOf(source) {
|
|
44719
|
+
let winner = "";
|
|
44720
|
+
for (const key3 of ["action_type", "actionType"]) {
|
|
44721
|
+
const raw2 = source[key3];
|
|
44722
|
+
if (raw2 === void 0 || raw2 === null) continue;
|
|
44723
|
+
const actionType = normalizeActionType(raw2);
|
|
44724
|
+
if (actionTypeRank(actionType) > actionTypeRank(winner)) winner = actionType;
|
|
44725
|
+
}
|
|
44726
|
+
return winner;
|
|
44727
|
+
}
|
|
44728
|
+
function wireActionType(data) {
|
|
44729
|
+
for (const source of decisionSources(data)) {
|
|
44730
|
+
const actionType = actionTypeOf(source);
|
|
44731
|
+
if (actionType !== "") return actionType;
|
|
44732
|
+
}
|
|
44733
|
+
return "";
|
|
44734
|
+
}
|
|
44735
|
+
function isAuditTier(data) {
|
|
44736
|
+
const absentVerdict = data.verdict === null || data.verdict === void 0;
|
|
44737
|
+
return absentVerdict && data.status === "logged";
|
|
44738
|
+
}
|
|
44739
|
+
function isAuditTierBody(data) {
|
|
44740
|
+
return isAuditTier(data);
|
|
44741
|
+
}
|
|
44742
|
+
function canonicalAllow(data) {
|
|
44743
|
+
if (explicitRefusal(data) !== "") return false;
|
|
44744
|
+
const actionType = wireActionType(data);
|
|
44745
|
+
if (actionType && actionType !== "allow") return false;
|
|
44746
|
+
if (isAuditTier(data)) return true;
|
|
44747
|
+
if (typeof data.verdict !== "string") return false;
|
|
44748
|
+
const verdict = data.verdict.trim().toUpperCase();
|
|
44749
|
+
return verdict === "ALLOW" || verdict === "GREEN";
|
|
44750
|
+
}
|
|
44751
|
+
|
|
44752
|
+
// src-ts/opentel/events.ts
|
|
44753
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44754
|
+
var SLOW_MS = 1500;
|
|
44755
|
+
var SUCCESS_SAMPLE_RATE = 10;
|
|
44756
|
+
var logger2 = null;
|
|
44757
|
+
var eventsEnabled = false;
|
|
44758
|
+
var sdkVersion = "";
|
|
44759
|
+
var eventSource = "sdk";
|
|
44760
|
+
var hashAgentKey = null;
|
|
44761
|
+
function eventsOptedOut() {
|
|
44762
|
+
const flag = process.env.ATBASH_TELEMETRY_EVENTS_DISABLED?.trim().toLowerCase();
|
|
44763
|
+
return Boolean(flag && ["1", "true", "yes", "on"].includes(flag));
|
|
44764
|
+
}
|
|
44765
|
+
var SOURCE_SHAPE = /^(?:sdk|cli|plugin:[a-z0-9][a-z0-9._-]{0,31})$/;
|
|
44766
|
+
function configureEvents(next, opts = {}) {
|
|
44767
|
+
logger2 = next;
|
|
44768
|
+
eventsEnabled = next !== null && !eventsOptedOut();
|
|
44769
|
+
if (opts.version) sdkVersion = opts.version;
|
|
44770
|
+
if (opts.source && SOURCE_SHAPE.test(opts.source)) eventSource = opts.source;
|
|
44771
|
+
hashAgentKey = opts.hashAgentKey ?? null;
|
|
44772
|
+
}
|
|
44773
|
+
function eventsAreOn() {
|
|
44774
|
+
return eventsEnabled && logger2 !== null;
|
|
44775
|
+
}
|
|
44776
|
+
function sampleRateFor(e) {
|
|
44777
|
+
if (e.status === "error") return 1;
|
|
44778
|
+
if (e.durationMs >= SLOW_MS) return 1;
|
|
44779
|
+
return Math.random() < 1 / SUCCESS_SAMPLE_RATE ? SUCCESS_SAMPLE_RATE : 0;
|
|
44780
|
+
}
|
|
44781
|
+
function recordEvent(e) {
|
|
44782
|
+
if (!eventsAreOn()) return;
|
|
44783
|
+
const sampleRate = sampleRateFor(e);
|
|
44784
|
+
if (sampleRate === 0) return;
|
|
44785
|
+
try {
|
|
44786
|
+
const attributes = {
|
|
44787
|
+
"function.name": e.functionName,
|
|
44788
|
+
"duration_ms": Math.round(e.durationMs),
|
|
44789
|
+
status: e.status,
|
|
44790
|
+
source: eventSource,
|
|
44791
|
+
// Honeycomb reweights counts and percentiles by this. It is per-event
|
|
44792
|
+
// because the sampling is biased by outcome and latency.
|
|
44793
|
+
sampleRate
|
|
44794
|
+
};
|
|
44795
|
+
if (sdkVersion) attributes["sdk.version"] = sdkVersion;
|
|
44796
|
+
if (e.agentPubkey && hashAgentKey) attributes["agent.hash"] = hashAgentKey(e.agentPubkey);
|
|
44797
|
+
if (e.chain) attributes["chain"] = e.chain;
|
|
44798
|
+
if (e.errorClass) attributes["error.class"] = e.errorClass;
|
|
44799
|
+
if (e.errorStatus !== void 0) attributes["error.status"] = e.errorStatus;
|
|
44800
|
+
if (e.errorPath) attributes["error.path"] = e.errorPath;
|
|
44801
|
+
if (e.outcome) attributes["outcome"] = e.outcome;
|
|
44802
|
+
logger2.emit({ body: e.functionName, attributes });
|
|
44803
|
+
} catch {
|
|
44804
|
+
}
|
|
44805
|
+
}
|
|
44806
|
+
|
|
44580
44807
|
// src-ts/browser/opentel/telemetry.ts
|
|
44581
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44582
44808
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44583
44809
|
function setupTelemetry(_config) {
|
|
44584
44810
|
}
|
|
@@ -44592,7 +44818,6 @@ async function shutdownTelemetry() {
|
|
|
44592
44818
|
}
|
|
44593
44819
|
|
|
44594
44820
|
// src-ts/browser/userConfig.ts
|
|
44595
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
44596
44821
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
44597
44822
|
var NOT_AVAILABLE2 = "userConfig file I/O is not available in the browser bundle.";
|
|
44598
44823
|
function getConfigDir() {
|
|
@@ -44610,11 +44835,46 @@ function saveUserConfig(_) {
|
|
|
44610
44835
|
function resolve(_key, flagValue) {
|
|
44611
44836
|
return flagValue ?? "";
|
|
44612
44837
|
}
|
|
44838
|
+
function forcedChainNetwork(flagValue) {
|
|
44839
|
+
return flagValue === "private" ? flagValue : void 0;
|
|
44840
|
+
}
|
|
44841
|
+
function agentKeyFromEnv() {
|
|
44842
|
+
return "";
|
|
44843
|
+
}
|
|
44844
|
+
function strandedAgentKey() {
|
|
44845
|
+
return "";
|
|
44846
|
+
}
|
|
44613
44847
|
|
|
44614
44848
|
// src-ts/client.ts
|
|
44849
|
+
var AGENT_NOT_REGISTERED = "Agent not registered. Onboard the agent at the dashboard before submitting actions.";
|
|
44615
44850
|
function generateToolCallId() {
|
|
44616
44851
|
return `tc-${Date.now()}-${randomHex(4)}`;
|
|
44617
44852
|
}
|
|
44853
|
+
function resolveConstructorChain(options) {
|
|
44854
|
+
if (options.chain) return options.chain;
|
|
44855
|
+
const hasNodeUrls = options.nodeUrls !== void 0;
|
|
44856
|
+
const hasBrid = options.blockchainRid !== void 0;
|
|
44857
|
+
if (hasNodeUrls !== hasBrid) {
|
|
44858
|
+
throw new Error(
|
|
44859
|
+
'nodeUrls and blockchainRid must be provided together \u2014 passing one without the other 404s every chain request. Prefer `chain: PRIVATE_CHAIN` or `network: "private"`.'
|
|
44860
|
+
);
|
|
44861
|
+
}
|
|
44862
|
+
if (hasNodeUrls && hasBrid) {
|
|
44863
|
+
return {
|
|
44864
|
+
network: "private",
|
|
44865
|
+
blockchainRid: options.blockchainRid,
|
|
44866
|
+
nodeUrls: options.nodeUrls
|
|
44867
|
+
};
|
|
44868
|
+
}
|
|
44869
|
+
return chainForNetwork(options.network ?? forcedChainNetwork() ?? "private");
|
|
44870
|
+
}
|
|
44871
|
+
function errorDetail(err) {
|
|
44872
|
+
if (!(err instanceof AtbashAPIError)) return {};
|
|
44873
|
+
return {
|
|
44874
|
+
errorStatus: err.status,
|
|
44875
|
+
...err.path ? { errorPath: err.path } : {}
|
|
44876
|
+
};
|
|
44877
|
+
}
|
|
44618
44878
|
var Atbash = class _Atbash {
|
|
44619
44879
|
auth;
|
|
44620
44880
|
endpoint;
|
|
@@ -44628,6 +44888,10 @@ var Atbash = class _Atbash {
|
|
|
44628
44888
|
orgEncryptionPubKey;
|
|
44629
44889
|
/** When true (default), `auditToolCall` denies on any error. */
|
|
44630
44890
|
failClosed;
|
|
44891
|
+
/** When true (default), an unenforced (audit-tier) answer is refused. */
|
|
44892
|
+
requireEnforcement;
|
|
44893
|
+
/** Overall deadline for one auditToolCall decision, in ms. */
|
|
44894
|
+
decisionTimeoutMs;
|
|
44631
44895
|
/** Org key learned from the last agent-exists check, for this agent only. */
|
|
44632
44896
|
_orgKeyFromChain = null;
|
|
44633
44897
|
debug;
|
|
@@ -44638,6 +44902,27 @@ var Atbash = class _Atbash {
|
|
|
44638
44902
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
44639
44903
|
*/
|
|
44640
44904
|
_chainCache = /* @__PURE__ */ new Map();
|
|
44905
|
+
/**
|
|
44906
|
+
* The chain the constructor settled on. Used only where a lookup returns no
|
|
44907
|
+
* answer — see {@link resolveChainFromMap}.
|
|
44908
|
+
*/
|
|
44909
|
+
_defaultChain;
|
|
44910
|
+
/**
|
|
44911
|
+
* True when the caller named a chain outright — `chain`, `network`, or the
|
|
44912
|
+
* paired `blockchainRid` + `nodeUrls`.
|
|
44913
|
+
*
|
|
44914
|
+
* Such a client is never re-pointed: not by the migration switch, and not by
|
|
44915
|
+
* where an org turns out to live. Naming a chain is the caller saying "talk
|
|
44916
|
+
* to this one", and silently routing elsewhere would make the argument a
|
|
44917
|
+
* suggestion. A client that names nothing is the one that follows the org.
|
|
44918
|
+
*/
|
|
44919
|
+
_explicitChain;
|
|
44920
|
+
/**
|
|
44921
|
+
* The fleet-wide chain switch, read once at construction. `resolve()` hits
|
|
44922
|
+
* the config file on disk, so re-reading it per call would put a file read
|
|
44923
|
+
* on every judge.
|
|
44924
|
+
*/
|
|
44925
|
+
_forcedNetwork;
|
|
44641
44926
|
/**
|
|
44642
44927
|
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
44643
44928
|
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
@@ -44648,26 +44933,33 @@ var Atbash = class _Atbash {
|
|
|
44648
44933
|
*/
|
|
44649
44934
|
_agentExistsCache = null;
|
|
44650
44935
|
static AGENT_EXISTS_TTL_MS = 5e3;
|
|
44651
|
-
/**
|
|
44652
|
-
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
44653
|
-
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
44654
|
-
* server-side replay protection windows never expire it mid-session.
|
|
44655
|
-
*/
|
|
44656
|
-
_authBearer = null;
|
|
44657
44936
|
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
44658
44937
|
static environmentLogged = false;
|
|
44659
44938
|
constructor(privkey, options = {}) {
|
|
44660
44939
|
this.auth = native.loadAgent(privkey);
|
|
44661
|
-
|
|
44662
|
-
|
|
44663
|
-
|
|
44940
|
+
const validated = validateJudgeEndpoint(
|
|
44941
|
+
options.verifyPubKey ? {
|
|
44942
|
+
policy: "self-hosted",
|
|
44943
|
+
endpoint: options.endpoint ?? DEFAULT_ENDPOINT,
|
|
44944
|
+
verifyPubKey: options.verifyPubKey
|
|
44945
|
+
} : { endpoint: options.endpoint }
|
|
44946
|
+
);
|
|
44947
|
+
this.endpoint = validated.url;
|
|
44948
|
+
const resolvedChain = resolveConstructorChain(options);
|
|
44949
|
+
this.nodeUrls = [...resolvedChain.nodeUrls];
|
|
44950
|
+
this.blockchainRid = resolvedChain.blockchainRid;
|
|
44951
|
+
this._defaultChain = resolvedChain;
|
|
44952
|
+
this._explicitChain = options.chain !== void 0 || options.network !== void 0 || options.blockchainRid !== void 0 && options.nodeUrls !== void 0;
|
|
44953
|
+
this._forcedNetwork = forcedChainNetwork();
|
|
44664
44954
|
this.orgName = options.orgName;
|
|
44665
|
-
this.verifyPubKey =
|
|
44955
|
+
this.verifyPubKey = validated.verifyPubKey ?? void 0;
|
|
44666
44956
|
this.orgEncryptionPubKey = options.orgEncryptionPubKey;
|
|
44667
44957
|
this.failClosed = options.failClosed !== false;
|
|
44958
|
+
this.requireEnforcement = options.requireEnforcement !== false;
|
|
44959
|
+
this.decisionTimeoutMs = options.decisionTimeoutMs ?? DEFAULT_DECISION_TIMEOUT_MS;
|
|
44668
44960
|
this.debug = options.debug === true;
|
|
44669
44961
|
this.logger = options.logger ?? {};
|
|
44670
|
-
this.http = new HttpClient(this.endpoint, options.timeoutMs ??
|
|
44962
|
+
this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 12e4);
|
|
44671
44963
|
this.logEnvironmentOnce();
|
|
44672
44964
|
if (this.endpoint !== DEFAULT_ENDPOINT) {
|
|
44673
44965
|
this.logger.warn?.("[atbash] running on non-default judge endpoint", {
|
|
@@ -44675,15 +44967,24 @@ var Atbash = class _Atbash {
|
|
|
44675
44967
|
verifying: this.verifyPubKey ? "with response-signature pubkey configured" : "without signature verification"
|
|
44676
44968
|
});
|
|
44677
44969
|
}
|
|
44678
|
-
|
|
44679
|
-
|
|
44680
|
-
|
|
44681
|
-
|
|
44682
|
-
|
|
44683
|
-
|
|
44684
|
-
|
|
44685
|
-
|
|
44686
|
-
|
|
44970
|
+
if (isAllowlistedJudgeHost(this.endpoint)) {
|
|
44971
|
+
try {
|
|
44972
|
+
setupTelemetry({
|
|
44973
|
+
enabled: true,
|
|
44974
|
+
endpoint: this.endpoint,
|
|
44975
|
+
getAuthHeaders: () => this.authHeaders()
|
|
44976
|
+
});
|
|
44977
|
+
} catch (err) {
|
|
44978
|
+
this.logger.warn?.(
|
|
44979
|
+
"[atbash] telemetry setup failed \u2014 continuing without metrics",
|
|
44980
|
+
{ error: String(err) }
|
|
44981
|
+
);
|
|
44982
|
+
}
|
|
44983
|
+
} else {
|
|
44984
|
+
this.logger.info?.(
|
|
44985
|
+
"[atbash] telemetry disabled \u2014 the agent bearer is only sent to hosts that already receive it, and this judge endpoint is not one",
|
|
44986
|
+
{ endpoint: this.endpoint }
|
|
44987
|
+
);
|
|
44687
44988
|
}
|
|
44688
44989
|
}
|
|
44689
44990
|
/**
|
|
@@ -44701,10 +45002,9 @@ var Atbash = class _Atbash {
|
|
|
44701
45002
|
_Atbash.environmentLogged = true;
|
|
44702
45003
|
const brief = (rid) => rid ? `${rid.slice(0, 8)}\u2026` : "(unset)";
|
|
44703
45004
|
this.logger.info?.(
|
|
44704
|
-
`[atbash] environment \u2014 judge=${this.endpoint}
|
|
45005
|
+
`[atbash] environment \u2014 judge=${this.endpoint} privateChain=${brief(native.DEFAULT_PRIVATE_BLOCKCHAIN_RID)} activeChain=${brief(this.blockchainRid)} responseSignatureCheck=${this.verifyPubKey ? "on" : "off"}`,
|
|
44705
45006
|
{
|
|
44706
45007
|
judgeEndpoint: this.endpoint,
|
|
44707
|
-
publicBlockchainRid: native.DEFAULT_BLOCKCHAIN_RID,
|
|
44708
45008
|
privateBlockchainRid: native.DEFAULT_PRIVATE_BLOCKCHAIN_RID,
|
|
44709
45009
|
activeBlockchainRid: this.blockchainRid,
|
|
44710
45010
|
responseSignatureCheck: Boolean(this.verifyPubKey)
|
|
@@ -44719,21 +45019,113 @@ var Atbash = class _Atbash {
|
|
|
44719
45019
|
* validated against the trusted allowlist / self-hosted policy; a
|
|
44720
45020
|
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
44721
45021
|
*/
|
|
45022
|
+
/**
|
|
45023
|
+
* Decide which key this client signs as.
|
|
45024
|
+
*
|
|
45025
|
+
* Most specific wins: a key passed in code, then a key file the host named,
|
|
45026
|
+
* then the environment, then the default key file. `config.json` is absent
|
|
45027
|
+
* from that list on purpose — it is a settings file, writable by anything
|
|
45028
|
+
* that can write the user's home and read by every Atbash integration on the
|
|
45029
|
+
* machine, so letting it name the key meant one stray value silently
|
|
45030
|
+
* re-pointed who each of them signed as.
|
|
45031
|
+
*
|
|
45032
|
+
* A named `keyPath` that does not exist throws rather than falling through.
|
|
45033
|
+
* The caller said which file holds its identity; quietly signing as a
|
|
45034
|
+
* different one is the outcome worth refusing.
|
|
45035
|
+
*
|
|
45036
|
+
* @param options - The `fromConfig` options, read for `agentKey` and `keyPath`.
|
|
45037
|
+
* @returns The resolved agent identity.
|
|
45038
|
+
* @throws When a named key file is missing, or no identity can be found.
|
|
45039
|
+
*/
|
|
45040
|
+
static resolveIdentity(options) {
|
|
45041
|
+
if (options.agentKey) return native.loadAgent(options.agentKey);
|
|
45042
|
+
if (options.keyPath) return loadAgentFromFile(options.keyPath);
|
|
45043
|
+
const fromEnv = agentKeyFromEnv();
|
|
45044
|
+
if (fromEnv) return native.loadAgent(fromEnv);
|
|
45045
|
+
try {
|
|
45046
|
+
return loadAgentFromFile();
|
|
45047
|
+
} catch (err) {
|
|
45048
|
+
throw _Atbash.explainStrandedKey(err);
|
|
45049
|
+
}
|
|
45050
|
+
}
|
|
45051
|
+
/**
|
|
45052
|
+
* Add the one thing a machine with no key file needs to hear.
|
|
45053
|
+
*
|
|
45054
|
+
* This is the only path where the operator cannot see what happened: no key
|
|
45055
|
+
* file, and the key they are looking for sits in `config.json`, which no
|
|
45056
|
+
* longer selects the identity. A bare "key file not found" sends them hunting
|
|
45057
|
+
* for a key they already have. Only this branch gets the hint — a caller who
|
|
45058
|
+
* named a `keyPath` is told about that path, where a stranded key is noise.
|
|
45059
|
+
*
|
|
45060
|
+
* @param err - The "key file not found" error from the default lookup.
|
|
45061
|
+
* @returns The same error, or one that also names the key in config.json.
|
|
45062
|
+
*/
|
|
45063
|
+
static explainStrandedKey(err) {
|
|
45064
|
+
const stranded = strandedAgentKey();
|
|
45065
|
+
if (!stranded) return err;
|
|
45066
|
+
let identity;
|
|
45067
|
+
try {
|
|
45068
|
+
identity = native.derivePublicKey(stranded);
|
|
45069
|
+
} catch {
|
|
45070
|
+
identity = "(unreadable)";
|
|
45071
|
+
}
|
|
45072
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
45073
|
+
return new Error(
|
|
45074
|
+
`${message}
|
|
45075
|
+
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.`
|
|
45076
|
+
);
|
|
45077
|
+
}
|
|
45078
|
+
/**
|
|
45079
|
+
* Say so when `config.json` still holds an agent key.
|
|
45080
|
+
*
|
|
45081
|
+
* Nothing signs with it any more, and silence would leave an operator
|
|
45082
|
+
* believing one identity is in force while another is. The pubkey is named,
|
|
45083
|
+
* not the key, so the line is safe in a log.
|
|
45084
|
+
*
|
|
45085
|
+
* @param logger - The host logger, when one was supplied.
|
|
45086
|
+
*/
|
|
45087
|
+
static warnOnStrandedKey(logger3) {
|
|
45088
|
+
const stranded = strandedAgentKey();
|
|
45089
|
+
if (!stranded) return;
|
|
45090
|
+
let identity;
|
|
45091
|
+
try {
|
|
45092
|
+
identity = native.derivePublicKey(stranded);
|
|
45093
|
+
} catch {
|
|
45094
|
+
identity = "(unreadable)";
|
|
45095
|
+
}
|
|
45096
|
+
logger3?.warn?.(
|
|
45097
|
+
`[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.`
|
|
45098
|
+
);
|
|
45099
|
+
}
|
|
44722
45100
|
static fromConfig(options = {}) {
|
|
45101
|
+
const configuredEndpoint = resolve("judgeEndpoint") || void 0;
|
|
45102
|
+
const configuredVerifyPubKey = resolve("judgeVerifyPubKey") || void 0;
|
|
45103
|
+
if (!options.judge && configuredVerifyPubKey && !configuredEndpoint) {
|
|
45104
|
+
throw new Error(
|
|
45105
|
+
"judgeVerifyPubKey / ATBASH_JUDGE_VERIFY_PUBKEY is set but no judge endpoint is configured: set judgeEndpoint / ATBASH_ENDPOINT to the self-hosted judge"
|
|
45106
|
+
);
|
|
45107
|
+
}
|
|
44723
45108
|
const validated = validateJudgeEndpoint(
|
|
44724
|
-
options.judge ??
|
|
45109
|
+
options.judge ?? (configuredVerifyPubKey && configuredEndpoint ? {
|
|
45110
|
+
policy: "self-hosted",
|
|
45111
|
+
endpoint: configuredEndpoint,
|
|
45112
|
+
verifyPubKey: configuredVerifyPubKey
|
|
45113
|
+
} : { endpoint: configuredEndpoint })
|
|
44725
45114
|
);
|
|
44726
|
-
const
|
|
44727
|
-
|
|
44728
|
-
const blockchainRid = resolve("blockchainRid", options.blockchainRid) || void 0;
|
|
45115
|
+
const auth = _Atbash.resolveIdentity(options);
|
|
45116
|
+
_Atbash.warnOnStrandedKey(options.logger);
|
|
44729
45117
|
return new _Atbash(auth.privkey, {
|
|
44730
45118
|
endpoint: validated.url,
|
|
44731
|
-
|
|
45119
|
+
chain: options.chain,
|
|
45120
|
+
network: options.network,
|
|
45121
|
+
blockchainRid: options.blockchainRid,
|
|
44732
45122
|
timeoutMs: options.timeoutMs,
|
|
44733
45123
|
nodeUrls: options.nodeUrls,
|
|
44734
45124
|
orgName: options.orgName,
|
|
44735
45125
|
verifyPubKey: validated.verifyPubKey ?? void 0,
|
|
44736
45126
|
failClosed: options.failClosed,
|
|
45127
|
+
requireEnforcement: options.requireEnforcement,
|
|
45128
|
+
decisionTimeoutMs: options.decisionTimeoutMs,
|
|
44737
45129
|
// ATBASH_DEBUG lets an operator turn diagnostics on without editing a
|
|
44738
45130
|
// host's plugin config, which is usually the harder half.
|
|
44739
45131
|
debug: options.debug ?? /^(1|true|yes)$/i.test(resolve("debug")),
|
|
@@ -44769,10 +45161,11 @@ var Atbash = class _Atbash {
|
|
|
44769
45161
|
return this.track("checkAgentExists", pk, async () => {
|
|
44770
45162
|
const query = { pubkey: pk };
|
|
44771
45163
|
if (network) query.network = network;
|
|
45164
|
+
const brid = network ? this.bridFromChainOpts({ network }) : await this.defaultOrgBrid();
|
|
44772
45165
|
const resp = await this.http.get(
|
|
44773
45166
|
"/api/ai/exists",
|
|
44774
45167
|
query,
|
|
44775
|
-
this.authHeaders()
|
|
45168
|
+
this.authHeaders(brid)
|
|
44776
45169
|
);
|
|
44777
45170
|
await this.raiseIfError(resp);
|
|
44778
45171
|
const data = await this.json(resp);
|
|
@@ -44799,6 +45192,15 @@ var Atbash = class _Atbash {
|
|
|
44799
45192
|
* return the signed tx hex. The server broadcasts to chain.
|
|
44800
45193
|
*/
|
|
44801
45194
|
async logToolCall(action, context = "", options = {}) {
|
|
45195
|
+
return this._logToolCall(action, context, options, false);
|
|
45196
|
+
}
|
|
45197
|
+
/**
|
|
45198
|
+
* `raisePreflightErrors` (the judge path, like Python's
|
|
45199
|
+
* `raise_preflight_errors`): a failed registration check throws instead of
|
|
45200
|
+
* becoming `{ success: false }`, so the caller can tell Atbash's "no"
|
|
45201
|
+
* (not registered, or a 4xx) from an outage.
|
|
45202
|
+
*/
|
|
45203
|
+
async _logToolCall(action, context, options, raisePreflightErrors) {
|
|
44802
45204
|
const start = performance.now();
|
|
44803
45205
|
recordCall("logToolCall", void 0, this.auth.pubkey);
|
|
44804
45206
|
let exists;
|
|
@@ -44808,18 +45210,20 @@ var Atbash = class _Atbash {
|
|
|
44808
45210
|
});
|
|
44809
45211
|
} catch (err) {
|
|
44810
45212
|
recordDuration("logToolCall", performance.now() - start, "error");
|
|
45213
|
+
if (raisePreflightErrors) throw err;
|
|
44811
45214
|
return { success: false, toolCallId: null, error: errorMessage(err) };
|
|
44812
45215
|
}
|
|
44813
45216
|
if (!exists) {
|
|
44814
45217
|
recordDuration("logToolCall", performance.now() - start, "error");
|
|
45218
|
+
if (raisePreflightErrors) throw new JudgeRefusalError(AGENT_NOT_REGISTERED);
|
|
44815
45219
|
return {
|
|
44816
45220
|
success: false,
|
|
44817
45221
|
toolCallId: null,
|
|
44818
|
-
error:
|
|
45222
|
+
error: AGENT_NOT_REGISTERED
|
|
44819
45223
|
};
|
|
44820
45224
|
}
|
|
44821
45225
|
const toolCallId = generateToolCallId();
|
|
44822
|
-
const brid = this.
|
|
45226
|
+
const brid = await this.callBrid(options.chainOpts);
|
|
44823
45227
|
const orgKey = options.orgEncryptionPubKey ?? this.orgEncryptionPubKey ?? this._orgKeyFromChain;
|
|
44824
45228
|
try {
|
|
44825
45229
|
const signedHex = orgKey ? signEncryptedToolCall(
|
|
@@ -44869,44 +45273,52 @@ var Atbash = class _Atbash {
|
|
|
44869
45273
|
if (!action?.trim()) {
|
|
44870
45274
|
throw new Error("action is required and cannot be empty.");
|
|
44871
45275
|
}
|
|
45276
|
+
if (isJailHeld(this.auth.pubkey)) return this.localJailBlock();
|
|
45277
|
+
const startedAt = Date.now();
|
|
44872
45278
|
let chainOpts = options.chainOpts;
|
|
44873
|
-
if (options.orgName) {
|
|
45279
|
+
if (options.orgName && this._explicitChain) {
|
|
45280
|
+
chainOpts = options.chainOpts ?? {
|
|
45281
|
+
blockchainRid: this._defaultChain.blockchainRid
|
|
45282
|
+
};
|
|
45283
|
+
} else if (options.orgName && this.forcedNetwork()) {
|
|
45284
|
+
chainOpts = { network: this.forcedNetwork() };
|
|
45285
|
+
} else if (options.orgName) {
|
|
44874
45286
|
const cached = this._chainCache.get(options.orgName);
|
|
44875
45287
|
if (cached) {
|
|
44876
45288
|
chainOpts = { network: cached.network };
|
|
44877
45289
|
} else {
|
|
44878
45290
|
const mapNetwork = await this.getActiveNetworkForOrg(options.orgName);
|
|
44879
45291
|
if (mapNetwork) {
|
|
44880
|
-
|
|
44881
|
-
this._chainCache.set(options.orgName, chain);
|
|
45292
|
+
this._chainCache.set(options.orgName, chainForNetwork(mapNetwork));
|
|
44882
45293
|
chainOpts = { network: mapNetwork };
|
|
44883
45294
|
} else if (!chainOpts?.blockchainRid) {
|
|
44884
|
-
const resolved = await this.resolveChainFromMap(
|
|
45295
|
+
const resolved = await this.resolveChainFromMap(
|
|
45296
|
+
options.orgName,
|
|
45297
|
+
null
|
|
45298
|
+
);
|
|
44885
45299
|
chainOpts = { ...chainOpts, network: resolved.network };
|
|
44886
45300
|
}
|
|
44887
45301
|
}
|
|
44888
45302
|
}
|
|
44889
|
-
const brid = this.
|
|
44890
|
-
const logResult = await this.
|
|
44891
|
-
|
|
44892
|
-
|
|
44893
|
-
chainOpts
|
|
44894
|
-
|
|
45303
|
+
const brid = await this.callBrid(chainOpts);
|
|
45304
|
+
const logResult = await this._logToolCall(
|
|
45305
|
+
action,
|
|
45306
|
+
context,
|
|
45307
|
+
{ toolName: options.toolName, toolArgsJson: options.toolArgsJson, chainOpts },
|
|
45308
|
+
true
|
|
45309
|
+
);
|
|
44895
45310
|
if (!logResult.success || !logResult.toolCallId || !logResult.signedHex) {
|
|
44896
45311
|
throw new Error(logResult.error || "Failed to sign log_tool_call");
|
|
44897
45312
|
}
|
|
44898
|
-
|
|
44899
|
-
|
|
44900
|
-
|
|
44901
|
-
|
|
44902
|
-
|
|
44903
|
-
|
|
44904
|
-
|
|
44905
|
-
|
|
44906
|
-
|
|
44907
|
-
brid
|
|
44908
|
-
);
|
|
44909
|
-
}
|
|
45313
|
+
const judgmentId = generateToolCallId();
|
|
45314
|
+
const signedJudgeAction = native.signJudgeAction(
|
|
45315
|
+
judgmentId,
|
|
45316
|
+
action,
|
|
45317
|
+
context || "",
|
|
45318
|
+
"",
|
|
45319
|
+
this.auth.privkey,
|
|
45320
|
+
brid
|
|
45321
|
+
);
|
|
44910
45322
|
const body = {
|
|
44911
45323
|
tool_call_id: logResult.toolCallId,
|
|
44912
45324
|
agent_pubkey: this.auth.pubkey,
|
|
@@ -44915,10 +45327,8 @@ var Atbash = class _Atbash {
|
|
|
44915
45327
|
};
|
|
44916
45328
|
if (signedJudgeAction) body.signed_judge_action = signedJudgeAction;
|
|
44917
45329
|
if (context) body.context = context;
|
|
44918
|
-
if (options.provider) body.provider = options.provider;
|
|
44919
45330
|
if (options.toolName) body.tool_name = options.toolName;
|
|
44920
45331
|
if (options.toolArgsJson) body.tool_args_json = options.toolArgsJson;
|
|
44921
|
-
if (options.model) body.model = options.model;
|
|
44922
45332
|
if (options.resolved) body.resolved = options.resolved;
|
|
44923
45333
|
if (options.mode) body.mode = options.mode;
|
|
44924
45334
|
let resp;
|
|
@@ -44929,44 +45339,73 @@ var Atbash = class _Atbash {
|
|
|
44929
45339
|
}
|
|
44930
45340
|
if (!resp.ok) throw await this.httpError(resp);
|
|
44931
45341
|
const bodyBytes = Buffer.from(await resp.arrayBuffer());
|
|
44932
|
-
const verifyPubKey = options.verifyPubKey
|
|
45342
|
+
const verifyPubKey = this.effectiveVerifyKey(options.verifyPubKey);
|
|
44933
45343
|
if (verifyPubKey !== void 0) {
|
|
44934
|
-
|
|
44935
|
-
|
|
44936
|
-
|
|
44937
|
-
|
|
44938
|
-
|
|
44939
|
-
|
|
44940
|
-
|
|
44941
|
-
try {
|
|
44942
|
-
ok = native.verifySignature(bodyBytes, sig, verifyPubKey);
|
|
44943
|
-
} catch (err) {
|
|
44944
|
-
throw new SignatureVerificationError(
|
|
44945
|
-
`signature verification threw: ${errorMessage(err)}`
|
|
44946
|
-
);
|
|
44947
|
-
}
|
|
44948
|
-
if (!ok) {
|
|
44949
|
-
throw new SignatureVerificationError(
|
|
44950
|
-
"signature does not verify against configured verifyPubKey"
|
|
44951
|
-
);
|
|
44952
|
-
}
|
|
45344
|
+
verifyResponseSignature(bodyBytes, resp, verifyPubKey);
|
|
45345
|
+
}
|
|
45346
|
+
const parsed = tryParseJson(bodyBytes.toString("utf-8"));
|
|
45347
|
+
if (!isRecord2(parsed)) {
|
|
45348
|
+
throw new JudgeRefusalError(
|
|
45349
|
+
"The judge's reply could not be read, so the action was not approved."
|
|
45350
|
+
);
|
|
44953
45351
|
}
|
|
44954
|
-
const data =
|
|
45352
|
+
const data = parsed;
|
|
44955
45353
|
const rawScore = data.score;
|
|
44956
45354
|
const score = typeof rawScore === "number" && Number.isInteger(rawScore) && rawScore >= 1 && rawScore <= 10 ? rawScore : void 0;
|
|
44957
|
-
|
|
45355
|
+
const result = {
|
|
44958
45356
|
verdict: normalizeVerdict(data.verdict),
|
|
44959
|
-
|
|
44960
|
-
|
|
44961
|
-
|
|
44962
|
-
|
|
44963
|
-
|
|
44964
|
-
|
|
45357
|
+
allow: this.executable(data),
|
|
45358
|
+
actionType: normalizeActionType(data.action_type),
|
|
45359
|
+
reason: wireText(data.reason),
|
|
45360
|
+
confidence: wireNumber(data.confidence),
|
|
45361
|
+
provider: wireText(data.provider),
|
|
45362
|
+
latencyMs: wireNumber(data.latency_ms),
|
|
45363
|
+
toolCallId: wireText(data.tool_call_id, logResult.toolCallId),
|
|
44965
45364
|
onChain: Boolean(data.on_chain),
|
|
44966
45365
|
enforced: Boolean(data.enforced),
|
|
44967
|
-
enforcementMode:
|
|
44968
|
-
status:
|
|
44969
|
-
score
|
|
45366
|
+
enforcementMode: wireText(data.enforcement_mode),
|
|
45367
|
+
status: wireText(data.status),
|
|
45368
|
+
score,
|
|
45369
|
+
refusal: explicitRefusal(data)
|
|
45370
|
+
};
|
|
45371
|
+
return this.applyJailHold(result, startedAt);
|
|
45372
|
+
}
|
|
45373
|
+
/**
|
|
45374
|
+
* Start a local hold on an enforced, on-chain BLOCK (the verdict that jails).
|
|
45375
|
+
* Refuse any other result that lands while the agent is held, or whose
|
|
45376
|
+
* request was already in flight when the block arrived: the server judged it
|
|
45377
|
+
* on pre-jail state.
|
|
45378
|
+
*/
|
|
45379
|
+
applyJailHold(result, startedAt) {
|
|
45380
|
+
const pubkey = this.auth.pubkey;
|
|
45381
|
+
if (result.verdict === "BLOCK" && result.enforced && result.onChain) {
|
|
45382
|
+
recordBlock(pubkey);
|
|
45383
|
+
holdJail(
|
|
45384
|
+
pubkey,
|
|
45385
|
+
() => this.getAgentPolicy(pubkey).then((p) => p.isJailed),
|
|
45386
|
+
() => this.logger.warn?.("[atbash] local jail hold released: the chain did not confirm the jail in time")
|
|
45387
|
+
);
|
|
45388
|
+
return result;
|
|
45389
|
+
}
|
|
45390
|
+
return isJailHeld(pubkey) || blockedSince(pubkey, startedAt) ? this.localJailBlock(result.toolCallId) : result;
|
|
45391
|
+
}
|
|
45392
|
+
/** The server's jailed refusal, produced locally while the agent is held. */
|
|
45393
|
+
localJailBlock(toolCallId = generateToolCallId()) {
|
|
45394
|
+
return {
|
|
45395
|
+
verdict: "BLOCK",
|
|
45396
|
+
allow: false,
|
|
45397
|
+
actionType: "block",
|
|
45398
|
+
reason: "Agent is jailed. All actions are blocked until the organization owner unjails this agent.",
|
|
45399
|
+
confidence: 1,
|
|
45400
|
+
provider: "policy",
|
|
45401
|
+
latencyMs: 0,
|
|
45402
|
+
toolCallId,
|
|
45403
|
+
onChain: false,
|
|
45404
|
+
enforced: true,
|
|
45405
|
+
enforcementMode: "enforce",
|
|
45406
|
+
status: "",
|
|
45407
|
+
score: void 0,
|
|
45408
|
+
refusal: "BLOCK"
|
|
44970
45409
|
};
|
|
44971
45410
|
}
|
|
44972
45411
|
/* ── audit_tool_call (redact → judge → decision) ───────────────────────── */
|
|
@@ -44999,77 +45438,137 @@ var Atbash = class _Atbash {
|
|
|
44999
45438
|
}
|
|
45000
45439
|
try {
|
|
45001
45440
|
this.logger.info?.("[atbash] judge API called", { tool: toolName });
|
|
45002
|
-
const result = await
|
|
45003
|
-
|
|
45004
|
-
|
|
45005
|
-
|
|
45006
|
-
|
|
45007
|
-
|
|
45008
|
-
|
|
45009
|
-
|
|
45010
|
-
|
|
45011
|
-
|
|
45012
|
-
|
|
45013
|
-
|
|
45014
|
-
|
|
45015
|
-
|
|
45016
|
-
}
|
|
45017
|
-
return {
|
|
45018
|
-
allow: true,
|
|
45019
|
-
verdict: "ALLOW",
|
|
45020
|
-
reason: result.reason || "audit tier \u2014 request logged on-chain, no AI enforcement",
|
|
45021
|
-
toolCallId: result.toolCallId
|
|
45022
|
-
};
|
|
45023
|
-
}
|
|
45024
|
-
const action = result.actionType;
|
|
45025
|
-
if (action === "block") {
|
|
45441
|
+
const result = await withDeadline(
|
|
45442
|
+
this.judgeAction(actionText, contextText, {
|
|
45443
|
+
toolName,
|
|
45444
|
+
toolArgsJson: argsJson,
|
|
45445
|
+
orgName: this.orgName,
|
|
45446
|
+
// Passed through unredacted — caller vouches for the contents.
|
|
45447
|
+
resolved: input.resolved
|
|
45448
|
+
}),
|
|
45449
|
+
this.decisionTimeoutMs
|
|
45450
|
+
);
|
|
45451
|
+
return this.decide(result);
|
|
45452
|
+
} catch (err) {
|
|
45453
|
+
if (err instanceof SignatureVerificationError) {
|
|
45454
|
+
this.failJudge(errorMessage(err), err);
|
|
45026
45455
|
return {
|
|
45027
45456
|
allow: false,
|
|
45028
|
-
verdict: "
|
|
45029
|
-
reason:
|
|
45030
|
-
toolCallId: result.toolCallId
|
|
45457
|
+
verdict: "ERROR",
|
|
45458
|
+
reason: `The judge's reply failed its signature check (${errorMessage(err)}), so it was not trusted.`
|
|
45031
45459
|
};
|
|
45032
45460
|
}
|
|
45033
|
-
if (
|
|
45034
|
-
return {
|
|
45035
|
-
allow: false,
|
|
45036
|
-
verdict: "HOLD",
|
|
45037
|
-
reason: result.reason || "held for human confirmation",
|
|
45038
|
-
toolCallId: result.toolCallId
|
|
45039
|
-
};
|
|
45461
|
+
if (err instanceof JudgeRefusalError || err instanceof AtbashAPIError && isRefusalStatus(err.status)) {
|
|
45462
|
+
return { ...this.failJudge(errorMessage(err), err), allow: false };
|
|
45040
45463
|
}
|
|
45041
|
-
|
|
45042
|
-
|
|
45043
|
-
|
|
45044
|
-
|
|
45045
|
-
|
|
45046
|
-
|
|
45047
|
-
|
|
45048
|
-
|
|
45049
|
-
|
|
45050
|
-
|
|
45051
|
-
|
|
45052
|
-
|
|
45053
|
-
|
|
45054
|
-
|
|
45055
|
-
|
|
45056
|
-
|
|
45057
|
-
|
|
45464
|
+
return this.failJudge(errorMessage(err), err);
|
|
45465
|
+
}
|
|
45466
|
+
}
|
|
45467
|
+
/**
|
|
45468
|
+
* The verify key for one call (R4, governor tier-2 review). A per-call key
|
|
45469
|
+
* may only narrow what the client accepts: on a client pinned to a judge
|
|
45470
|
+
* key it must be that same key, never a replacement; on an unpinned client
|
|
45471
|
+
* it adds the check.
|
|
45472
|
+
*/
|
|
45473
|
+
effectiveVerifyKey(perCall) {
|
|
45474
|
+
if (perCall === void 0) return this.verifyPubKey;
|
|
45475
|
+
const key3 = perCall.trim().toLowerCase();
|
|
45476
|
+
if (this.verifyPubKey !== void 0 && key3 !== this.verifyPubKey) {
|
|
45477
|
+
throw new SignatureVerificationError(
|
|
45478
|
+
"a per-call verifyPubKey cannot replace the judge key this client is pinned to"
|
|
45479
|
+
);
|
|
45480
|
+
}
|
|
45481
|
+
return key3;
|
|
45482
|
+
}
|
|
45483
|
+
/**
|
|
45484
|
+
* Collapse a judge result into a {@link Decision}. The most restrictive
|
|
45485
|
+
* signal wins (security review 2026-09-30, H1): `action_type`, `verdict`
|
|
45486
|
+
* and the canonical `allow` are each able to deny, and only a result where
|
|
45487
|
+
* all three agree may execute. A present `allow` / `decision.allow` that is
|
|
45488
|
+
* not exactly `true` is the judge declining to grant permission, so it
|
|
45489
|
+
* denies even under `failClosed: false` — that option relaxes *errors*, it
|
|
45490
|
+
* never overrides a refusal.
|
|
45491
|
+
*/
|
|
45492
|
+
decide(result) {
|
|
45493
|
+
const inner = this.decideInner(result);
|
|
45494
|
+
if (!result.enforcementMode) return inner;
|
|
45495
|
+
return {
|
|
45496
|
+
...inner,
|
|
45497
|
+
enforced: result.enforced,
|
|
45498
|
+
enforcementMode: result.enforcementMode
|
|
45499
|
+
};
|
|
45500
|
+
}
|
|
45501
|
+
decideInner(result) {
|
|
45502
|
+
const toolCallId = result.toolCallId;
|
|
45503
|
+
const deny = (verdict, reason) => ({
|
|
45504
|
+
allow: false,
|
|
45505
|
+
verdict,
|
|
45506
|
+
reason,
|
|
45507
|
+
toolCallId
|
|
45508
|
+
});
|
|
45509
|
+
const notGranted = "the judge response did not grant permission";
|
|
45510
|
+
const held = deny("HOLD", result.reason || "held for human confirmation");
|
|
45511
|
+
const blocked = deny("BLOCK", result.reason || notGranted);
|
|
45512
|
+
if (result.refusal === "BLOCK") return blocked;
|
|
45513
|
+
if (result.verdict === "No verdict") {
|
|
45514
|
+
if (result.actionType === "block") {
|
|
45515
|
+
return blocked;
|
|
45516
|
+
}
|
|
45517
|
+
if (result.actionType === "hold_for_user_confirm") {
|
|
45518
|
+
return held;
|
|
45519
|
+
}
|
|
45520
|
+
if (result.refusal === "HOLD") return held;
|
|
45521
|
+
if (result.status !== "logged") {
|
|
45522
|
+
return this.failJudge(
|
|
45523
|
+
`judge returned no verdict without an audit-tier marker (status: ${result.status || "absent"})`,
|
|
45524
|
+
void 0,
|
|
45525
|
+
toolCallId
|
|
45526
|
+
);
|
|
45527
|
+
}
|
|
45528
|
+
if (this.requireEnforcement) {
|
|
45529
|
+
this.logger.warn?.(
|
|
45530
|
+
"[atbash] judge did not enforce this action (audit tier) and requireEnforcement is on: denied",
|
|
45531
|
+
{ toolCallId }
|
|
45532
|
+
);
|
|
45058
45533
|
return {
|
|
45059
|
-
allow:
|
|
45060
|
-
verdict: "
|
|
45061
|
-
reason:
|
|
45062
|
-
toolCallId
|
|
45534
|
+
allow: false,
|
|
45535
|
+
verdict: "ERROR",
|
|
45536
|
+
reason: "Atbash logged this action but did not check it (audit-tier plan), and this client requires a checked decision. Upgrade the plan, or set requireEnforcement: false for log-only mode.",
|
|
45537
|
+
toolCallId
|
|
45063
45538
|
};
|
|
45064
45539
|
}
|
|
45065
|
-
return
|
|
45066
|
-
|
|
45067
|
-
|
|
45068
|
-
|
|
45069
|
-
|
|
45070
|
-
|
|
45071
|
-
|
|
45540
|
+
if (result.allow !== true) return deny("BLOCK", notGranted);
|
|
45541
|
+
return {
|
|
45542
|
+
allow: true,
|
|
45543
|
+
verdict: "ALLOW",
|
|
45544
|
+
reason: result.reason || "audit tier \u2014 request logged on-chain, no AI enforcement",
|
|
45545
|
+
toolCallId
|
|
45546
|
+
};
|
|
45547
|
+
}
|
|
45548
|
+
const action = result.actionType;
|
|
45549
|
+
if (action === "block") {
|
|
45550
|
+
return deny("BLOCK", result.reason || "Blocked by your organisation's Atbash policy.");
|
|
45551
|
+
}
|
|
45552
|
+
if (action === "hold_for_user_confirm") {
|
|
45553
|
+
return held;
|
|
45072
45554
|
}
|
|
45555
|
+
if (result.refusal === "HOLD") return held;
|
|
45556
|
+
if (action === "allow") {
|
|
45557
|
+
if (result.verdict === "HOLD") return held;
|
|
45558
|
+
if (result.verdict === "BLOCK") return blocked;
|
|
45559
|
+
if (result.allow !== true) return deny("BLOCK", notGranted);
|
|
45560
|
+
return {
|
|
45561
|
+
allow: true,
|
|
45562
|
+
verdict: "ALLOW",
|
|
45563
|
+
reason: result.reason,
|
|
45564
|
+
toolCallId
|
|
45565
|
+
};
|
|
45566
|
+
}
|
|
45567
|
+
return this.failJudge(
|
|
45568
|
+
"unrecognized action_type from judge",
|
|
45569
|
+
void 0,
|
|
45570
|
+
toolCallId
|
|
45571
|
+
);
|
|
45073
45572
|
}
|
|
45074
45573
|
/**
|
|
45075
45574
|
* One exit for every judge failure.
|
|
@@ -45081,41 +45580,74 @@ var Atbash = class _Atbash {
|
|
|
45081
45580
|
*/
|
|
45082
45581
|
failJudge(reason, cause, toolCallId) {
|
|
45083
45582
|
const api2 = cause instanceof AtbashAPIError ? cause : null;
|
|
45583
|
+
const userReason = userFacingReason(reason, api2);
|
|
45084
45584
|
const status = api2 ? ` status=${api2.status || "no-response"}` : "";
|
|
45585
|
+
const detail = this.debug ? ` detail=${truncate(reason, 500)}` : "";
|
|
45085
45586
|
const body = this.debug && api2?.body ? ` body=${truncate(api2.body, 500)}` : "";
|
|
45086
45587
|
this.logger.warn?.(
|
|
45087
|
-
`[atbash] judge API failed \u2014${status} reason=${truncate(
|
|
45588
|
+
`[atbash] judge API failed \u2014${status} reason=${truncate(userReason, 300)}${detail}${body}`,
|
|
45088
45589
|
{
|
|
45089
|
-
reason,
|
|
45090
|
-
...api2 ? { status: api2.status
|
|
45590
|
+
reason: userReason,
|
|
45591
|
+
...api2 ? { status: api2.status } : {},
|
|
45592
|
+
...this.debug && api2 ? { body: api2.body, detail: reason } : {},
|
|
45091
45593
|
endpoint: this.endpoint,
|
|
45092
45594
|
...toolCallId ? { toolCallId } : {}
|
|
45093
45595
|
}
|
|
45094
45596
|
);
|
|
45095
|
-
return this.fail(
|
|
45597
|
+
return this.fail(userReason, toolCallId);
|
|
45598
|
+
}
|
|
45599
|
+
/**
|
|
45600
|
+
* The canonical permission for a response body under this client's
|
|
45601
|
+
* settings: {@link canonicalAllow}, minus the audit tier when
|
|
45602
|
+
* `requireEnforcement` is on. Never more permissive than `auditToolCall`.
|
|
45603
|
+
*/
|
|
45604
|
+
executable(data) {
|
|
45605
|
+
if (!canonicalAllow(data)) return false;
|
|
45606
|
+
return !(this.requireEnforcement && isAuditTierBody(data));
|
|
45096
45607
|
}
|
|
45097
45608
|
fail(reason, toolCallId) {
|
|
45098
45609
|
return { allow: !this.failClosed, verdict: "ERROR", reason, toolCallId };
|
|
45099
45610
|
}
|
|
45100
45611
|
/* ── judgment status ───────────────────────────────────────────────────── */
|
|
45101
|
-
|
|
45612
|
+
/**
|
|
45613
|
+
* Return the current status of a previously submitted judgment.
|
|
45614
|
+
*
|
|
45615
|
+
* `chainOpts` names which chain the judgment was signed against; the SDK
|
|
45616
|
+
* sends it as the `brid` query param the server routes by. Without it the
|
|
45617
|
+
* read uses the same chain `judgeAction` signs for (see `callBrid`): the
|
|
45618
|
+
* client's org chain when it has an `orgName`, else the client default.
|
|
45619
|
+
* A judgment signed with an explicit per-call `chainOpts` (or a per-call
|
|
45620
|
+
* `orgName` on another chain) must be polled with that same `chainOpts`.
|
|
45621
|
+
*/
|
|
45622
|
+
async getJudgmentStatus(judgmentId, agentPubkey, chainOpts) {
|
|
45102
45623
|
const pk = agentPubkey ?? this.auth.pubkey;
|
|
45103
45624
|
return this.track("getJudgmentStatus", pk, async () => {
|
|
45625
|
+
const brid = await this.callBrid(chainOpts);
|
|
45104
45626
|
const resp = await this.http.get(
|
|
45105
45627
|
"/api/v1/judge",
|
|
45106
|
-
{ tool_call_id: judgmentId, agent_pubkey: pk },
|
|
45107
|
-
this.authHeaders()
|
|
45628
|
+
{ tool_call_id: judgmentId, agent_pubkey: pk, brid },
|
|
45629
|
+
this.authHeaders(brid)
|
|
45108
45630
|
);
|
|
45109
45631
|
await this.raiseIfError(resp);
|
|
45110
|
-
const
|
|
45632
|
+
const bytes = Buffer.from(await resp.arrayBuffer());
|
|
45633
|
+
if (this.verifyPubKey !== void 0) {
|
|
45634
|
+
verifyResponseSignature(bytes, resp, this.verifyPubKey);
|
|
45635
|
+
}
|
|
45636
|
+
const parsed = tryParseJson(bytes.toString("utf-8"));
|
|
45637
|
+
const data = isRecord2(parsed) ? parsed : {};
|
|
45638
|
+
const rawId = data.tool_call_id ?? data.judgmentId;
|
|
45639
|
+
const statedId = wireText(rawId);
|
|
45640
|
+
const sameCall = rawId === void 0 || rawId === null || statedId === judgmentId;
|
|
45111
45641
|
return {
|
|
45112
45642
|
status: normalizeStatus(data.status),
|
|
45113
45643
|
verdict: normalizeVerdict(data.verdict),
|
|
45114
|
-
|
|
45115
|
-
|
|
45644
|
+
allow: sameCall && this.executable(data),
|
|
45645
|
+
reason: wireText(data.reason),
|
|
45646
|
+
judgmentId: statedId || judgmentId,
|
|
45116
45647
|
onChain: optBool(data.onChain),
|
|
45117
45648
|
cached: optBool(data.cached),
|
|
45118
|
-
responseTimeMs
|
|
45649
|
+
// The Dashboard sends response_time_ms; responseTimeMs is the spec name.
|
|
45650
|
+
responseTimeMs: optNumber(data.responseTimeMs ?? data.response_time_ms)
|
|
45119
45651
|
};
|
|
45120
45652
|
});
|
|
45121
45653
|
}
|
|
@@ -45124,49 +45656,65 @@ var Atbash = class _Atbash {
|
|
|
45124
45656
|
return this.track(
|
|
45125
45657
|
"getToolCalls",
|
|
45126
45658
|
void 0,
|
|
45127
|
-
() => this.riskEngineRecords(
|
|
45659
|
+
async () => this.riskEngineRecords(
|
|
45660
|
+
"tool-calls",
|
|
45661
|
+
{ limit: maxCount },
|
|
45662
|
+
await this.defaultOrgBrid()
|
|
45663
|
+
)
|
|
45128
45664
|
);
|
|
45129
45665
|
}
|
|
45130
|
-
getOrgToolCalls(orgName, maxCount) {
|
|
45131
|
-
return this.track(
|
|
45132
|
-
|
|
45133
|
-
|
|
45134
|
-
|
|
45135
|
-
org: orgName,
|
|
45136
|
-
|
|
45137
|
-
|
|
45138
|
-
);
|
|
45666
|
+
async getOrgToolCalls(orgName, maxCount) {
|
|
45667
|
+
return this.track("getOrgToolCalls", void 0, async () => {
|
|
45668
|
+
const brid = await this.bridForOrg(orgName);
|
|
45669
|
+
return this.riskEngineRecords(
|
|
45670
|
+
"org-tool-calls",
|
|
45671
|
+
{ org: orgName, limit: maxCount },
|
|
45672
|
+
brid
|
|
45673
|
+
);
|
|
45674
|
+
});
|
|
45139
45675
|
}
|
|
45140
45676
|
getAgentToolCalls(agentPubkey, maxCount) {
|
|
45141
45677
|
return this.track(
|
|
45142
45678
|
"getAgentToolCalls",
|
|
45143
45679
|
agentPubkey,
|
|
45144
|
-
() => this.riskEngineRecords(
|
|
45145
|
-
agent
|
|
45146
|
-
limit: maxCount
|
|
45147
|
-
|
|
45680
|
+
async () => this.riskEngineRecords(
|
|
45681
|
+
"agent-tool-calls",
|
|
45682
|
+
{ agent: agentPubkey, limit: maxCount },
|
|
45683
|
+
await this.defaultOrgBrid()
|
|
45684
|
+
)
|
|
45148
45685
|
);
|
|
45149
45686
|
}
|
|
45150
45687
|
async getToolCallCount() {
|
|
45151
45688
|
return this.track("getToolCallCount", void 0, async () => {
|
|
45152
|
-
const raw2 = await this.riskEngineGet(
|
|
45689
|
+
const raw2 = await this.riskEngineGet(
|
|
45690
|
+
"tool-call-count",
|
|
45691
|
+
{},
|
|
45692
|
+
await this.defaultOrgBrid()
|
|
45693
|
+
);
|
|
45153
45694
|
const n = Number(raw2);
|
|
45154
45695
|
return Number.isFinite(n) ? n : 0;
|
|
45155
45696
|
});
|
|
45156
45697
|
}
|
|
45157
45698
|
async getToolCallFull(toolCallId) {
|
|
45158
45699
|
return this.track("getToolCallFull", void 0, async () => {
|
|
45159
|
-
const raw2 = await this.riskEngineGet(
|
|
45160
|
-
|
|
45161
|
-
|
|
45162
|
-
|
|
45700
|
+
const raw2 = await this.riskEngineGet(
|
|
45701
|
+
"tool-call-full",
|
|
45702
|
+
{ tool_call_id: toolCallId },
|
|
45703
|
+
await this.defaultOrgBrid()
|
|
45704
|
+
);
|
|
45705
|
+
if (!isRecord2(raw2)) return null;
|
|
45163
45706
|
return toToolCallFull(raw2);
|
|
45164
45707
|
});
|
|
45165
45708
|
}
|
|
45166
45709
|
async getOrgTierInfo(orgName) {
|
|
45167
45710
|
return this.track("getOrgTierInfo", void 0, async () => {
|
|
45168
|
-
const
|
|
45169
|
-
|
|
45711
|
+
const brid = await this.bridForOrg(orgName);
|
|
45712
|
+
const raw2 = await this.riskEngineGet(
|
|
45713
|
+
"org-tier-info",
|
|
45714
|
+
{ org: orgName },
|
|
45715
|
+
brid
|
|
45716
|
+
);
|
|
45717
|
+
if (!isRecord2(raw2)) return null;
|
|
45170
45718
|
return {
|
|
45171
45719
|
orgName: String(raw2.org_name ?? ""),
|
|
45172
45720
|
tier: String(raw2.tier ?? ""),
|
|
@@ -45177,20 +45725,24 @@ var Atbash = class _Atbash {
|
|
|
45177
45725
|
}
|
|
45178
45726
|
async getPendingHeldActions(orgName, maxCount) {
|
|
45179
45727
|
return this.track("getPendingHeldActions", void 0, async () => {
|
|
45180
|
-
const
|
|
45181
|
-
|
|
45182
|
-
|
|
45183
|
-
|
|
45728
|
+
const brid = await this.bridForOrg(orgName);
|
|
45729
|
+
const raw2 = await this.riskEngineGet(
|
|
45730
|
+
"pending-held-actions",
|
|
45731
|
+
{ org: orgName, limit: maxCount },
|
|
45732
|
+
brid
|
|
45733
|
+
);
|
|
45184
45734
|
if (!Array.isArray(raw2)) return [];
|
|
45185
45735
|
return raw2.map((item) => toHeldAction(item));
|
|
45186
45736
|
});
|
|
45187
45737
|
}
|
|
45188
45738
|
async getHeldActionReviews(orgName, maxCount) {
|
|
45189
45739
|
return this.track("getHeldActionReviews", void 0, async () => {
|
|
45190
|
-
const
|
|
45191
|
-
|
|
45192
|
-
|
|
45193
|
-
|
|
45740
|
+
const brid = await this.bridForOrg(orgName);
|
|
45741
|
+
const raw2 = await this.riskEngineGet(
|
|
45742
|
+
"held-action-reviews",
|
|
45743
|
+
{ org: orgName, limit: maxCount },
|
|
45744
|
+
brid
|
|
45745
|
+
);
|
|
45194
45746
|
if (!Array.isArray(raw2)) return [];
|
|
45195
45747
|
return raw2.map(
|
|
45196
45748
|
(item) => toHeldActionReview(item)
|
|
@@ -45201,21 +45753,25 @@ var Atbash = class _Atbash {
|
|
|
45201
45753
|
async getAgentDetail(agentPubkey, options = {}) {
|
|
45202
45754
|
return this.track("getAgentDetail", agentPubkey, async () => {
|
|
45203
45755
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
45756
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
45204
45757
|
return this.riskEnginePost(
|
|
45205
45758
|
{ action: "agent-detail-batch", agent: agentPubkey },
|
|
45206
|
-
network
|
|
45759
|
+
network,
|
|
45760
|
+
brid
|
|
45207
45761
|
);
|
|
45208
45762
|
});
|
|
45209
45763
|
}
|
|
45210
45764
|
async getAgentPolicy(agentPubkey, options = {}) {
|
|
45211
45765
|
return this.track("getAgentPolicy", agentPubkey, async () => {
|
|
45212
45766
|
const network = await this.resolveAgentLookupNetwork(options);
|
|
45767
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
45213
45768
|
const raw2 = await this.riskEnginePost(
|
|
45214
45769
|
{
|
|
45215
45770
|
action: "agent-policy-batch",
|
|
45216
45771
|
agent: agentPubkey
|
|
45217
45772
|
},
|
|
45218
|
-
network
|
|
45773
|
+
network,
|
|
45774
|
+
brid
|
|
45219
45775
|
);
|
|
45220
45776
|
return {
|
|
45221
45777
|
policy: String(raw2.policy ?? ""),
|
|
@@ -45231,11 +45787,11 @@ var Atbash = class _Atbash {
|
|
|
45231
45787
|
const resp = await this.http.get(
|
|
45232
45788
|
"/api/insurance",
|
|
45233
45789
|
{ action: "safety-stats" },
|
|
45234
|
-
this.authHeaders()
|
|
45790
|
+
this.authHeaders(await this.defaultOrgBrid())
|
|
45235
45791
|
);
|
|
45236
45792
|
await this.raiseIfError(resp);
|
|
45237
45793
|
const data = await this.json(resp) ?? {};
|
|
45238
|
-
if (
|
|
45794
|
+
if (isRecord2(data.data)) return data.data;
|
|
45239
45795
|
return data;
|
|
45240
45796
|
});
|
|
45241
45797
|
}
|
|
@@ -45249,8 +45805,9 @@ var Atbash = class _Atbash {
|
|
|
45249
45805
|
return this.track("getOrgSubscription", void 0, async () => {
|
|
45250
45806
|
const params = { org: orgName };
|
|
45251
45807
|
if (network) params.network = network;
|
|
45252
|
-
const
|
|
45253
|
-
|
|
45808
|
+
const brid = network ? this.bridFromChainOpts({ network }) : void 0;
|
|
45809
|
+
const raw2 = await this.riskEngineGet("org-subscription", params, brid);
|
|
45810
|
+
if (!isRecord2(raw2)) return null;
|
|
45254
45811
|
return coerceOrgSubscription(raw2, orgName);
|
|
45255
45812
|
});
|
|
45256
45813
|
}
|
|
@@ -45262,36 +45819,38 @@ var Atbash = class _Atbash {
|
|
|
45262
45819
|
* entry (caller falls back to per-chain subscription resolution).
|
|
45263
45820
|
*/
|
|
45264
45821
|
async getActiveNetworkForOrg(orgName) {
|
|
45822
|
+
let resp;
|
|
45265
45823
|
try {
|
|
45266
|
-
|
|
45824
|
+
resp = await this.http.get(
|
|
45267
45825
|
"/api/org-network",
|
|
45268
|
-
{ org: orgName },
|
|
45826
|
+
{ org: orgName.trim() },
|
|
45269
45827
|
this.authHeaders()
|
|
45270
45828
|
);
|
|
45271
|
-
|
|
45272
|
-
|
|
45273
|
-
if (data?.network === "public" || data?.network === "private") {
|
|
45274
|
-
return data.network;
|
|
45275
|
-
}
|
|
45276
|
-
return null;
|
|
45277
|
-
} catch {
|
|
45278
|
-
return null;
|
|
45829
|
+
} catch (err) {
|
|
45830
|
+
throw this.transportError(err);
|
|
45279
45831
|
}
|
|
45832
|
+
if (resp.status !== 200) throw await this.httpError(resp);
|
|
45833
|
+
const data = await this.json(resp);
|
|
45834
|
+
if (data?.network === "private") return data.network;
|
|
45835
|
+
return null;
|
|
45280
45836
|
}
|
|
45281
45837
|
/**
|
|
45282
45838
|
* Resolve which chain an org's actions should run against. Cached
|
|
45283
45839
|
* per-client by orgName. Resolution order:
|
|
45284
45840
|
* 1. `org_networks` map (authoritative).
|
|
45285
|
-
* 2.
|
|
45286
|
-
*
|
|
45287
|
-
*
|
|
45288
|
-
* Defaults to the public chain when nothing else resolves.
|
|
45841
|
+
* 2. Subscription fallback — the org's subscription row on the chain.
|
|
45842
|
+
* A lookup that finds the org wins outright. Where it finds nothing (a
|
|
45843
|
+
* brand-new org), the client's configured default decides.
|
|
45289
45844
|
*/
|
|
45290
45845
|
async resolveChainForOrg(orgName) {
|
|
45291
|
-
const
|
|
45846
|
+
const name2 = orgName.trim();
|
|
45847
|
+
if (this._explicitChain) return this._defaultChain;
|
|
45848
|
+
const forced = this.forcedNetwork();
|
|
45849
|
+
if (forced) return chainForNetwork(forced);
|
|
45850
|
+
const cached = this._chainCache.get(name2);
|
|
45292
45851
|
if (cached) return cached;
|
|
45293
|
-
const mapNetwork = await this.getActiveNetworkForOrg(
|
|
45294
|
-
return this.resolveChainFromMap(
|
|
45852
|
+
const mapNetwork = await this.getActiveNetworkForOrg(name2);
|
|
45853
|
+
return this.resolveChainFromMap(name2, mapNetwork);
|
|
45295
45854
|
}
|
|
45296
45855
|
/**
|
|
45297
45856
|
* Resolve a chain given an already-fetched `org_networks` map result.
|
|
@@ -45303,36 +45862,28 @@ var Atbash = class _Atbash {
|
|
|
45303
45862
|
const cached = this._chainCache.get(orgName);
|
|
45304
45863
|
if (cached) return cached;
|
|
45305
45864
|
if (mapNetwork) {
|
|
45306
|
-
const chain = mapNetwork
|
|
45865
|
+
const chain = chainForNetwork(mapNetwork);
|
|
45307
45866
|
this._chainCache.set(orgName, chain);
|
|
45308
45867
|
return chain;
|
|
45309
45868
|
}
|
|
45869
|
+
let privSub;
|
|
45310
45870
|
try {
|
|
45311
|
-
|
|
45312
|
-
|
|
45313
|
-
|
|
45314
|
-
|
|
45315
|
-
|
|
45316
|
-
|
|
45317
|
-
|
|
45318
|
-
|
|
45319
|
-
|
|
45320
|
-
|
|
45321
|
-
|
|
45322
|
-
|
|
45323
|
-
|
|
45324
|
-
if (pubSub) {
|
|
45325
|
-
this._chainCache.set(orgName, PUBLIC_CHAIN);
|
|
45326
|
-
return PUBLIC_CHAIN;
|
|
45327
|
-
}
|
|
45328
|
-
if (privSub?.is_private_blockchain) {
|
|
45329
|
-
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
45330
|
-
return PRIVATE_CHAIN;
|
|
45331
|
-
}
|
|
45332
|
-
} catch {
|
|
45871
|
+
privSub = await this.getOrgSubscription(orgName, "private");
|
|
45872
|
+
} catch (failure) {
|
|
45873
|
+
const detail = failure instanceof Error ? failure.message : String(failure);
|
|
45874
|
+
throw new AtbashAPIError(
|
|
45875
|
+
failure instanceof AtbashAPIError ? failure.status : 0,
|
|
45876
|
+
`could not resolve the chain for org "${orgName}": ${detail}`,
|
|
45877
|
+
"",
|
|
45878
|
+
this.endpoint
|
|
45879
|
+
);
|
|
45880
|
+
}
|
|
45881
|
+
if (privSub) {
|
|
45882
|
+
this._chainCache.set(orgName, PRIVATE_CHAIN);
|
|
45883
|
+
return PRIVATE_CHAIN;
|
|
45333
45884
|
}
|
|
45334
|
-
this._chainCache.set(orgName,
|
|
45335
|
-
return
|
|
45885
|
+
this._chainCache.set(orgName, this._defaultChain);
|
|
45886
|
+
return this._defaultChain;
|
|
45336
45887
|
}
|
|
45337
45888
|
/** Drop any cached chain resolutions. Useful in tests. */
|
|
45338
45889
|
clearChainCache() {
|
|
@@ -45355,10 +45906,28 @@ var Atbash = class _Atbash {
|
|
|
45355
45906
|
recordCall(name2, void 0, agentPubkey);
|
|
45356
45907
|
try {
|
|
45357
45908
|
const result = await fn();
|
|
45358
|
-
|
|
45909
|
+
const durationMs = performance.now() - start;
|
|
45910
|
+
recordDuration(name2, durationMs, "success");
|
|
45911
|
+
recordEvent({
|
|
45912
|
+
functionName: name2,
|
|
45913
|
+
durationMs,
|
|
45914
|
+
status: "success",
|
|
45915
|
+
agentPubkey,
|
|
45916
|
+
chain: this.blockchainRid
|
|
45917
|
+
});
|
|
45359
45918
|
return result;
|
|
45360
45919
|
} catch (err) {
|
|
45361
|
-
|
|
45920
|
+
const durationMs = performance.now() - start;
|
|
45921
|
+
recordDuration(name2, durationMs, "error");
|
|
45922
|
+
recordEvent({
|
|
45923
|
+
functionName: name2,
|
|
45924
|
+
durationMs,
|
|
45925
|
+
status: "error",
|
|
45926
|
+
agentPubkey,
|
|
45927
|
+
chain: this.blockchainRid,
|
|
45928
|
+
errorClass: err instanceof Error ? err.constructor.name : typeof err,
|
|
45929
|
+
...errorDetail(err)
|
|
45930
|
+
});
|
|
45362
45931
|
throw err;
|
|
45363
45932
|
}
|
|
45364
45933
|
}
|
|
@@ -45369,10 +45938,21 @@ var Atbash = class _Atbash {
|
|
|
45369
45938
|
*/
|
|
45370
45939
|
bridFromChainOpts(chainOpts) {
|
|
45371
45940
|
if (chainOpts?.blockchainRid) return chainOpts.blockchainRid;
|
|
45372
|
-
if (chainOpts?.network
|
|
45373
|
-
if (chainOpts?.network === "public") return PUBLIC_CHAIN.blockchainRid;
|
|
45941
|
+
if (chainOpts?.network) return chainForNetwork(chainOpts.network).blockchainRid;
|
|
45374
45942
|
return this.blockchainRid;
|
|
45375
45943
|
}
|
|
45944
|
+
/**
|
|
45945
|
+
* The chain one call's transactions are signed for: the per-call override
|
|
45946
|
+
* when given, otherwise the client's org, otherwise the client default.
|
|
45947
|
+
* log_tool_call, judge_action and the judgment-status read all use this, so
|
|
45948
|
+
* a request never pairs transactions signed for two different chains.
|
|
45949
|
+
*/
|
|
45950
|
+
async callBrid(chainOpts) {
|
|
45951
|
+
if (chainOpts?.blockchainRid || chainOpts?.network) {
|
|
45952
|
+
return this.bridFromChainOpts(chainOpts);
|
|
45953
|
+
}
|
|
45954
|
+
return await this.defaultOrgBrid() ?? this.blockchainRid;
|
|
45955
|
+
}
|
|
45376
45956
|
/**
|
|
45377
45957
|
* Resolve the dashboard chain used by agent metadata/policy reads.
|
|
45378
45958
|
* Explicit per-call network overrides win; otherwise use the supplied org
|
|
@@ -45383,6 +45963,7 @@ var Atbash = class _Atbash {
|
|
|
45383
45963
|
async resolveAgentLookupNetwork(options) {
|
|
45384
45964
|
if (options.chainOpts?.network) return options.chainOpts.network;
|
|
45385
45965
|
if (options.chainOpts?.blockchainRid) return void 0;
|
|
45966
|
+
if (this._explicitChain) return this._defaultChain.network;
|
|
45386
45967
|
const orgName = options.orgName ?? this.orgName;
|
|
45387
45968
|
if (!orgName) return void 0;
|
|
45388
45969
|
return (await this.resolveChainForOrg(orgName)).network;
|
|
@@ -45394,34 +45975,19 @@ var Atbash = class _Atbash {
|
|
|
45394
45975
|
* for 4 minutes; refreshed after that so a long-lived client never
|
|
45395
45976
|
* trips the server's replay window.
|
|
45396
45977
|
*/
|
|
45397
|
-
getAuthBearer() {
|
|
45398
|
-
|
|
45399
|
-
if (this._authBearer && now - this._authBearer.issuedAt < 4 * 60 * 1e3) {
|
|
45400
|
-
return this._authBearer.hex;
|
|
45401
|
-
}
|
|
45402
|
-
const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
|
|
45403
|
-
const hex = native.signLogToolCall(
|
|
45404
|
-
nonce,
|
|
45405
|
-
`auth:${now}`,
|
|
45406
|
-
"",
|
|
45407
|
-
"auth-bearer",
|
|
45408
|
-
"",
|
|
45409
|
-
this.auth.privkey,
|
|
45410
|
-
this.blockchainRid
|
|
45411
|
-
);
|
|
45412
|
-
this._authBearer = { hex, issuedAt: now };
|
|
45413
|
-
return hex;
|
|
45978
|
+
getAuthBearer(brid) {
|
|
45979
|
+
return agentAuthBearer(this.auth, brid ?? this.blockchainRid);
|
|
45414
45980
|
}
|
|
45415
|
-
authHeaders() {
|
|
45416
|
-
return
|
|
45981
|
+
authHeaders(brid) {
|
|
45982
|
+
return agentAuthHeaders(this.auth, brid ?? this.blockchainRid);
|
|
45417
45983
|
}
|
|
45418
|
-
async riskEngineGet(action, params) {
|
|
45984
|
+
async riskEngineGet(action, params, brid) {
|
|
45419
45985
|
let resp;
|
|
45420
45986
|
try {
|
|
45421
45987
|
resp = await this.http.get(
|
|
45422
45988
|
"/api/risk-engine",
|
|
45423
45989
|
{ action, ...params },
|
|
45424
|
-
this.authHeaders()
|
|
45990
|
+
this.authHeaders(brid)
|
|
45425
45991
|
);
|
|
45426
45992
|
} catch (err) {
|
|
45427
45993
|
throw this.transportError(err);
|
|
@@ -45429,23 +45995,60 @@ var Atbash = class _Atbash {
|
|
|
45429
45995
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
45430
45996
|
return this.json(resp);
|
|
45431
45997
|
}
|
|
45432
|
-
async riskEnginePost(body, network) {
|
|
45998
|
+
async riskEnginePost(body, network, brid) {
|
|
45433
45999
|
let resp;
|
|
45434
46000
|
try {
|
|
45435
|
-
const
|
|
45436
|
-
resp = await this.http.post(
|
|
46001
|
+
const path3 = network ? `/api/risk-engine?network=${encodeURIComponent(network)}` : "/api/risk-engine";
|
|
46002
|
+
resp = await this.http.post(path3, body, this.authHeaders(brid));
|
|
45437
46003
|
} catch (err) {
|
|
45438
46004
|
throw this.transportError(err);
|
|
45439
46005
|
}
|
|
45440
46006
|
if (resp.status !== 200) throw await this.httpError(resp);
|
|
45441
46007
|
const data = await this.json(resp);
|
|
45442
|
-
return
|
|
46008
|
+
return isRecord2(data) ? data : {};
|
|
45443
46009
|
}
|
|
45444
|
-
async riskEngineRecords(action, params) {
|
|
45445
|
-
const raw2 = await this.riskEngineGet(action, params);
|
|
46010
|
+
async riskEngineRecords(action, params, brid) {
|
|
46011
|
+
const raw2 = await this.riskEngineGet(action, params, brid);
|
|
45446
46012
|
if (!Array.isArray(raw2)) return [];
|
|
45447
46013
|
return raw2.map((item) => toToolCallRecord(item));
|
|
45448
46014
|
}
|
|
46015
|
+
/**
|
|
46016
|
+
* BRID for an org — one round-trip to the map, honoring the client's chain
|
|
46017
|
+
* cache. A "brand-new org" (nothing anywhere names its chain) is not an
|
|
46018
|
+
* error — `resolveChainForOrg` returns the client default for that case and
|
|
46019
|
+
* this helper returns its BRID. A transport failure or non-200 from
|
|
46020
|
+
* `/api/org-network` IS an error and propagates: the caller cannot fall
|
|
46021
|
+
* back to the default chain on outage, because with multi-chain live that
|
|
46022
|
+
* silently reads from the wrong chain. Matches the Python binding's
|
|
46023
|
+
* `_brid_for_org` semantics.
|
|
46024
|
+
*/
|
|
46025
|
+
async bridForOrg(orgName) {
|
|
46026
|
+
return (await this.resolveChainForOrg(orgName)).blockchainRid;
|
|
46027
|
+
}
|
|
46028
|
+
/**
|
|
46029
|
+
* BRID for the client's configured default org, if it has one.
|
|
46030
|
+
*
|
|
46031
|
+
* Calls that carry no `orgName` argument are not chain-less: they still
|
|
46032
|
+
* belong to `this.orgName`, and that org lives on exactly one chain. Routing
|
|
46033
|
+
* them by the constructor's chain instead means a client configured
|
|
46034
|
+
* `network: "private"` reads the private chain for an org that lives on
|
|
46035
|
+
* public, and gets an empty answer rather than an error. So where an org is
|
|
46036
|
+
* known the org decides the chain, and the constructor's chain is what is
|
|
46037
|
+
* left when no org is known at all — the order `resolveAgentLookupNetwork`
|
|
46038
|
+
* already applies to agent metadata reads, and the order the dashboard
|
|
46039
|
+
* applies in `resolveChainForWallet`.
|
|
46040
|
+
*
|
|
46041
|
+
* Undefined when there is no default org, so callers keep falling back to
|
|
46042
|
+
* the client default.
|
|
46043
|
+
*/
|
|
46044
|
+
/** The switch's chain, unless this client named one of its own. */
|
|
46045
|
+
forcedNetwork() {
|
|
46046
|
+
return this._explicitChain ? void 0 : this._forcedNetwork;
|
|
46047
|
+
}
|
|
46048
|
+
async defaultOrgBrid() {
|
|
46049
|
+
if (this._explicitChain || !this.orgName) return void 0;
|
|
46050
|
+
return this.bridForOrg(this.orgName);
|
|
46051
|
+
}
|
|
45449
46052
|
async raiseIfError(resp) {
|
|
45450
46053
|
if (resp.ok) return;
|
|
45451
46054
|
throw await this.httpError(resp);
|
|
@@ -45456,7 +46059,8 @@ var Atbash = class _Atbash {
|
|
|
45456
46059
|
resp.status,
|
|
45457
46060
|
await safeText(resp),
|
|
45458
46061
|
resp.statusText,
|
|
45459
|
-
this.endpoint
|
|
46062
|
+
this.endpoint,
|
|
46063
|
+
requestPath(resp.url)
|
|
45460
46064
|
);
|
|
45461
46065
|
}
|
|
45462
46066
|
/**
|
|
@@ -45469,14 +46073,11 @@ var Atbash = class _Atbash {
|
|
|
45469
46073
|
transportError(err) {
|
|
45470
46074
|
if (err instanceof HttpTransportError) {
|
|
45471
46075
|
if (this.debug) {
|
|
45472
|
-
this.logger.warn?.(
|
|
45473
|
-
|
|
45474
|
-
|
|
45475
|
-
|
|
45476
|
-
|
|
45477
|
-
endpoint: this.endpoint
|
|
45478
|
-
}
|
|
45479
|
-
);
|
|
46076
|
+
this.logger.warn?.(`[atbash] transport failed \u2014 kind=${err.kind}`, {
|
|
46077
|
+
kind: err.kind,
|
|
46078
|
+
cause: err.cause instanceof Error ? err.cause.message : String(err.cause ?? ""),
|
|
46079
|
+
endpoint: this.endpoint
|
|
46080
|
+
});
|
|
45480
46081
|
}
|
|
45481
46082
|
return new AtbashAPIError(0, err.message, "", this.endpoint);
|
|
45482
46083
|
}
|
|
@@ -45508,6 +46109,66 @@ var Atbash = class _Atbash {
|
|
|
45508
46109
|
return native.containsEvasionCharacters(text);
|
|
45509
46110
|
}
|
|
45510
46111
|
};
|
|
46112
|
+
function userFacingReason(reason, api2) {
|
|
46113
|
+
if (api2 && api2.status > 0) {
|
|
46114
|
+
const where = ` (HTTP ${api2.status}${api2.path ? ` from ${api2.path}` : ""})`;
|
|
46115
|
+
const b = api2.body.toLowerCase();
|
|
46116
|
+
if (b.includes("agent not registered")) {
|
|
46117
|
+
return `Agent not registered with Atbash: onboard it in the Atbash dashboard${where}.`;
|
|
46118
|
+
}
|
|
46119
|
+
if (b.includes("jailed")) {
|
|
46120
|
+
return `This agent is jailed; unjail it in the Atbash dashboard${where}.`;
|
|
46121
|
+
}
|
|
46122
|
+
if (b.includes("agent has no policy") || b.includes("no policy configured")) {
|
|
46123
|
+
return `This agent has no policy; attach one in the Atbash dashboard${where}.`;
|
|
46124
|
+
}
|
|
46125
|
+
if (b.includes("audit tier") || b.includes("verdict disabled") || b.includes("verdict not supported")) {
|
|
46126
|
+
return `The organisation's plan does not include checked decisions${where}.`;
|
|
46127
|
+
}
|
|
46128
|
+
return `The Atbash judge answered with an error${where}, so the action was not approved.`;
|
|
46129
|
+
}
|
|
46130
|
+
const text = api2 ? api2.body || reason : reason;
|
|
46131
|
+
return truncate(text.replace(/https?:\/\/[^\s)]+/g, "the judge"), 300);
|
|
46132
|
+
}
|
|
46133
|
+
var DEFAULT_DECISION_TIMEOUT_MS = 6e4;
|
|
46134
|
+
async function withDeadline(p, ms) {
|
|
46135
|
+
let timer;
|
|
46136
|
+
const deadline = new Promise((_, reject) => {
|
|
46137
|
+
timer = setTimeout(
|
|
46138
|
+
() => reject(
|
|
46139
|
+
new Error(
|
|
46140
|
+
`The judge did not give a decision within ${Math.round(ms / 1e3)} s, so the action was not approved. Check the network, or raise decisionTimeoutMs.`
|
|
46141
|
+
)
|
|
46142
|
+
),
|
|
46143
|
+
ms
|
|
46144
|
+
);
|
|
46145
|
+
});
|
|
46146
|
+
p.catch(() => void 0);
|
|
46147
|
+
try {
|
|
46148
|
+
return await Promise.race([p, deadline]);
|
|
46149
|
+
} finally {
|
|
46150
|
+
clearTimeout(timer);
|
|
46151
|
+
}
|
|
46152
|
+
}
|
|
46153
|
+
function verifyResponseSignature(bodyBytes, resp, verifyPubKey) {
|
|
46154
|
+
const sig = resp.headers.get("X-Atbash-Signature");
|
|
46155
|
+
if (!sig) {
|
|
46156
|
+
throw new SignatureVerificationError("missing X-Atbash-Signature header");
|
|
46157
|
+
}
|
|
46158
|
+
let ok;
|
|
46159
|
+
try {
|
|
46160
|
+
ok = native.verifySignature(bodyBytes, sig, verifyPubKey);
|
|
46161
|
+
} catch (err) {
|
|
46162
|
+
throw new SignatureVerificationError(
|
|
46163
|
+
`signature verification threw: ${errorMessage(err)}`
|
|
46164
|
+
);
|
|
46165
|
+
}
|
|
46166
|
+
if (!ok) {
|
|
46167
|
+
throw new SignatureVerificationError(
|
|
46168
|
+
"signature does not verify against configured verifyPubKey"
|
|
46169
|
+
);
|
|
46170
|
+
}
|
|
46171
|
+
}
|
|
45511
46172
|
function baseToolCall(raw2) {
|
|
45512
46173
|
return {
|
|
45513
46174
|
toolCallId: String(raw2.tool_call_id ?? ""),
|
|
@@ -45574,15 +46235,17 @@ function coerceOrgSubscription(raw2, orgName) {
|
|
|
45574
46235
|
is_active: Boolean(raw2.is_active)
|
|
45575
46236
|
};
|
|
45576
46237
|
}
|
|
45577
|
-
function
|
|
46238
|
+
function isRecord2(v) {
|
|
45578
46239
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
45579
46240
|
}
|
|
45580
46241
|
function optString(v) {
|
|
45581
46242
|
if (v === null || v === void 0) return void 0;
|
|
46243
|
+
if (typeof v === "object" || typeof v === "function") return void 0;
|
|
45582
46244
|
return typeof v === "string" ? v : String(v);
|
|
45583
46245
|
}
|
|
45584
46246
|
function optNumber(v) {
|
|
45585
46247
|
if (v === null || v === void 0) return void 0;
|
|
46248
|
+
if (typeof v === "object" || typeof v === "function") return void 0;
|
|
45586
46249
|
const n = Number(v);
|
|
45587
46250
|
return Number.isFinite(n) ? n : void 0;
|
|
45588
46251
|
}
|
|
@@ -45597,9 +46260,13 @@ function tryParseJson(text) {
|
|
|
45597
46260
|
return void 0;
|
|
45598
46261
|
}
|
|
45599
46262
|
}
|
|
45600
|
-
function
|
|
45601
|
-
|
|
45602
|
-
|
|
46263
|
+
function requestPath(url) {
|
|
46264
|
+
if (!url) return void 0;
|
|
46265
|
+
try {
|
|
46266
|
+
return new URL(url).pathname || void 0;
|
|
46267
|
+
} catch {
|
|
46268
|
+
return void 0;
|
|
46269
|
+
}
|
|
45603
46270
|
}
|
|
45604
46271
|
async function safeText(resp) {
|
|
45605
46272
|
try {
|
|
@@ -45630,31 +46297,20 @@ function truncate(text, limit = MAX_ACTION_LEN) {
|
|
|
45630
46297
|
return text.slice(0, limit) + "\u2026";
|
|
45631
46298
|
}
|
|
45632
46299
|
|
|
45633
|
-
// src-ts/key-path.ts
|
|
45634
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46300
|
+
// src-ts/browser/key-path.ts
|
|
45635
46301
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45636
|
-
import { homedir } from "os";
|
|
45637
|
-
import { join as join2 } from "path";
|
|
45638
|
-
var KEY_DIR_REL = ".config/atbash";
|
|
45639
46302
|
var KEY_FILENAMES = ["guard-client-key", "atbash-client-key"];
|
|
45640
|
-
|
|
45641
|
-
|
|
45642
|
-
}
|
|
45643
|
-
function expandHome(p) {
|
|
45644
|
-
if (!p.startsWith("~/")) return p;
|
|
45645
|
-
return join2(home(), p.slice(2));
|
|
45646
|
-
}
|
|
46303
|
+
var unavailable = (name2) => {
|
|
46304
|
+
throw new Error(`${name2} is not available in the browser bundle`);
|
|
46305
|
+
};
|
|
45647
46306
|
function keyPathCandidates() {
|
|
45648
|
-
return
|
|
46307
|
+
return unavailable("keyPathCandidates");
|
|
45649
46308
|
}
|
|
45650
|
-
function chooseKeyPath(
|
|
45651
|
-
|
|
45652
|
-
const candidates = keyPathCandidates();
|
|
45653
|
-
return candidates.find(exists) ?? candidates[0];
|
|
46309
|
+
function chooseKeyPath(_input, _exists) {
|
|
46310
|
+
return unavailable("chooseKeyPath");
|
|
45654
46311
|
}
|
|
45655
46312
|
|
|
45656
46313
|
// src-ts/redact.ts
|
|
45657
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45658
46314
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45659
46315
|
function redactJsonStrings(value) {
|
|
45660
46316
|
if (typeof value === "string") {
|
|
@@ -45674,7 +46330,6 @@ function redactJsonStrings(value) {
|
|
|
45674
46330
|
}
|
|
45675
46331
|
|
|
45676
46332
|
// src-ts/signature.ts
|
|
45677
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45678
46333
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45679
46334
|
function verifyJudgeResponseSignature(bodyBytes, signatureHex, pubKeyHex) {
|
|
45680
46335
|
if (!signatureHex) {
|
|
@@ -45698,7 +46353,6 @@ function verifyJudgeResponseSignature(bodyBytes, signatureHex, pubKeyHex) {
|
|
|
45698
46353
|
}
|
|
45699
46354
|
|
|
45700
46355
|
// src-ts/memory/boot-sync-message.ts
|
|
45701
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45702
46356
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45703
46357
|
var BOOT_SYNC_HINT = "check the chain endpoint and orgName if the cause above does not explain it";
|
|
45704
46358
|
function bootSyncFailureLine(cause) {
|
|
@@ -45711,11 +46365,9 @@ function bootSyncFailureLine(cause) {
|
|
|
45711
46365
|
}
|
|
45712
46366
|
|
|
45713
46367
|
// src-ts/memory/index.ts
|
|
45714
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45715
46368
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45716
46369
|
|
|
45717
46370
|
// src-ts/browser/memory-crypto.ts
|
|
45718
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45719
46371
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45720
46372
|
var { Buffer: Buffer4 } = index;
|
|
45721
46373
|
var HKDF_INFO = new TextEncoder().encode("atbash:memory-encryption");
|
|
@@ -45791,7 +46443,6 @@ async function decryptMemoryContent2(ciphertext, nonce, key3) {
|
|
|
45791
46443
|
}
|
|
45792
46444
|
|
|
45793
46445
|
// src-ts/browser/memory-scan.ts
|
|
45794
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45795
46446
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45796
46447
|
var STUB_MSG2 = "not available in @atbash/sdk browser bundle \u2014 scan memory server-side";
|
|
45797
46448
|
async function scanMemory(_entry, _auth, _opts) {
|
|
@@ -45802,7 +46453,6 @@ async function scanMemoryBatch(_entries, _auth, _opts) {
|
|
|
45802
46453
|
}
|
|
45803
46454
|
|
|
45804
46455
|
// src-ts/browser/memory-chain.ts
|
|
45805
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45806
46456
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45807
46457
|
var STUB_MSG3 = "not available in @atbash/sdk browser bundle \u2014 commit/rollback memory server-side";
|
|
45808
46458
|
async function commitMemoryVersion(_plaintext, _auth, _opts) {
|
|
@@ -45811,13 +46461,13 @@ async function commitMemoryVersion(_plaintext, _auth, _opts) {
|
|
|
45811
46461
|
async function getActiveMemoryId(_auth, _chainOpts) {
|
|
45812
46462
|
throw new Error(`getActiveMemoryId ${STUB_MSG3}`);
|
|
45813
46463
|
}
|
|
45814
|
-
async function
|
|
45815
|
-
throw new Error(`
|
|
46464
|
+
async function getRecentAgentMemory(_auth, _chainOpts) {
|
|
46465
|
+
throw new Error(`getRecentAgentMemory ${STUB_MSG3}`);
|
|
45816
46466
|
}
|
|
45817
|
-
async function
|
|
45818
|
-
throw new Error(`
|
|
46467
|
+
async function getActiveAgentMemory(_auth, _chainOpts) {
|
|
46468
|
+
throw new Error(`getActiveAgentMemory ${STUB_MSG3}`);
|
|
45819
46469
|
}
|
|
45820
|
-
async function getMemoryHistory(_auth, _chainOpts) {
|
|
46470
|
+
async function getMemoryHistory(_auth, _chainOpts, _filePath, _page) {
|
|
45821
46471
|
throw new Error(`getMemoryHistory ${STUB_MSG3}`);
|
|
45822
46472
|
}
|
|
45823
46473
|
async function getMemoryById(_id, _auth, _chainOpts) {
|
|
@@ -45831,7 +46481,6 @@ async function rollbackMemory(_toId, _reason, _auth, _opts) {
|
|
|
45831
46481
|
}
|
|
45832
46482
|
|
|
45833
46483
|
// src-ts/browser/memory-classifier.ts
|
|
45834
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45835
46484
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45836
46485
|
var STUB_MSG4 = "not available in @atbash/sdk browser bundle \u2014 classify memory writes server-side";
|
|
45837
46486
|
var DEFAULT_MEMORY_WRITE_TOOL_NAMES = [
|
|
@@ -45854,119 +46503,23 @@ function classifyMemoryWrite(_event, _ctx, _opts = {}) {
|
|
|
45854
46503
|
throw new Error(`classifyMemoryWrite ${STUB_MSG4}`);
|
|
45855
46504
|
}
|
|
45856
46505
|
|
|
45857
|
-
// src-ts/memory
|
|
45858
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46506
|
+
// src-ts/browser/memory-guard.ts
|
|
45859
46507
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45860
|
-
|
|
45861
|
-
function
|
|
45862
|
-
|
|
45863
|
-
const ev = event ?? {};
|
|
45864
|
-
const c = ctx ?? {};
|
|
45865
|
-
const argsCandidate = ev.params ?? c.params ?? ev.args ?? c.args ?? ev.arguments ?? c.arguments;
|
|
45866
|
-
const argsObj = argsCandidate && typeof argsCandidate === "object" ? argsCandidate : {};
|
|
45867
|
-
const argsKeys = Object.keys(argsObj).slice(0, 20);
|
|
45868
|
-
const pickedPath = typeof argsObj.file_path === "string" && argsObj.file_path || typeof argsObj.path === "string" && argsObj.path || typeof argsObj.filename === "string" && argsObj.filename || null;
|
|
45869
|
-
const editsArr = Array.isArray(argsObj.edits) ? argsObj.edits : null;
|
|
45870
|
-
const firstEditKeys = editsArr && editsArr[0] && typeof editsArr[0] === "object" ? Object.keys(editsArr[0]).slice(0, 10) : null;
|
|
45871
|
-
const tool = ev.toolName ?? c.tool?.name ?? c.toolName ?? c.name ?? "(none)";
|
|
45872
|
-
logger2.info("[atbash][probe] before_tool_call", {
|
|
45873
|
-
toolName: tool,
|
|
45874
|
-
eventKeys: Object.keys(ev).slice(0, 20),
|
|
45875
|
-
ctxKeys: Object.keys(c).slice(0, 20),
|
|
45876
|
-
argsKeys,
|
|
45877
|
-
pickedPath,
|
|
45878
|
-
firstEditKeys,
|
|
45879
|
-
editsCount: editsArr?.length,
|
|
45880
|
-
memoryWrite: !!memEntry,
|
|
45881
|
-
memoryPath: memEntry?.key
|
|
45882
|
-
});
|
|
46508
|
+
var STUB_MSG5 = "not available in @atbash/sdk browser bundle \u2014 guard memory writes agent-side";
|
|
46509
|
+
async function guardMemoryWrite(_input) {
|
|
46510
|
+
throw new Error(`guardMemoryWrite ${STUB_MSG5}`);
|
|
45883
46511
|
}
|
|
45884
|
-
|
|
45885
|
-
|
|
45886
|
-
|
|
45887
|
-
|
|
45888
|
-
|
|
45889
|
-
|
|
45890
|
-
|
|
45891
|
-
|
|
45892
|
-
threshold,
|
|
45893
|
-
patterns,
|
|
45894
|
-
toolNames,
|
|
45895
|
-
enforce = true,
|
|
45896
|
-
debug: debug2 = false,
|
|
45897
|
-
logger: logger2,
|
|
45898
|
-
memoryFilePath
|
|
45899
|
-
} = input;
|
|
45900
|
-
const memEntry = classifyMemoryWrite(event, ctx, { patterns, toolNames });
|
|
45901
|
-
if (debug2) emitDebugProbe(event, ctx, memEntry, logger2);
|
|
45902
|
-
if (!memEntry) return { handled: false };
|
|
45903
|
-
let scanResult;
|
|
45904
|
-
try {
|
|
45905
|
-
scanResult = await scanMemory(memEntry, auth, {
|
|
45906
|
-
endpoint,
|
|
45907
|
-
verifyPubKey,
|
|
45908
|
-
orgName,
|
|
45909
|
-
threshold
|
|
45910
|
-
});
|
|
45911
|
-
} catch (err) {
|
|
45912
|
-
const reason = err instanceof Error ? err.message : String(err);
|
|
45913
|
-
logger2?.warn?.("[atbash] memory scan failed", {
|
|
45914
|
-
path: memEntry.key,
|
|
45915
|
-
reason
|
|
45916
|
-
});
|
|
45917
|
-
return {
|
|
45918
|
-
handled: true,
|
|
45919
|
-
decision: enforce ? { allow: false, block: true, reason } : { allow: true }
|
|
45920
|
-
};
|
|
45921
|
-
}
|
|
45922
|
-
if (scanResult.verdict === "red") {
|
|
45923
|
-
logger2?.warn?.("[atbash] memory BLOCK", {
|
|
45924
|
-
path: memEntry.key,
|
|
45925
|
-
reason: scanResult.reason
|
|
45926
|
-
});
|
|
45927
|
-
return {
|
|
45928
|
-
handled: true,
|
|
45929
|
-
decision: enforce ? { allow: false, block: true, reason: scanResult.reason } : { allow: true },
|
|
45930
|
-
scanResult,
|
|
45931
|
-
committed: false
|
|
45932
|
-
};
|
|
45933
|
-
}
|
|
45934
|
-
const isManagedMemoryFile = memoryFilePath !== void 0 && path3.resolve(memEntry.key) === path3.resolve(memoryFilePath);
|
|
45935
|
-
if (isManagedMemoryFile) {
|
|
45936
|
-
commitMemoryVersion(memEntry.value, auth, {
|
|
45937
|
-
score: scanResult.score,
|
|
45938
|
-
orgName,
|
|
45939
|
-
endpoint
|
|
45940
|
-
}).catch((err) => {
|
|
45941
|
-
const reason = err instanceof Error ? err.message : String(err);
|
|
45942
|
-
logger2?.warn?.("[atbash] memory commit to chain failed", {
|
|
45943
|
-
path: memEntry.key,
|
|
45944
|
-
reason
|
|
45945
|
-
});
|
|
45946
|
-
});
|
|
45947
|
-
} else {
|
|
45948
|
-
logger2?.info?.(
|
|
45949
|
-
"[atbash] scanned but not committed \u2014 not the managed memory file",
|
|
45950
|
-
{
|
|
45951
|
-
path: memEntry.key,
|
|
45952
|
-
memoryFilePath: memoryFilePath ?? "(not configured)"
|
|
45953
|
-
}
|
|
45954
|
-
);
|
|
45955
|
-
}
|
|
45956
|
-
logger2?.info?.(
|
|
45957
|
-
scanResult.verdict === "yellow" ? "[atbash] memory HOLD" : "[atbash] memory ALLOW",
|
|
45958
|
-
{ path: memEntry.key, score: scanResult.score, reason: scanResult.reason }
|
|
45959
|
-
);
|
|
45960
|
-
return {
|
|
45961
|
-
handled: true,
|
|
45962
|
-
decision: { allow: true },
|
|
45963
|
-
scanResult,
|
|
45964
|
-
committed: isManagedMemoryFile
|
|
45965
|
-
};
|
|
46512
|
+
|
|
46513
|
+
// src-ts/browser/memory-slot.ts
|
|
46514
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
46515
|
+
var unavailable2 = (name2) => {
|
|
46516
|
+
throw new Error(`${name2} is not available in the browser bundle`);
|
|
46517
|
+
};
|
|
46518
|
+
function memorySlotOf(_target, _home, _root2, _extraHomes, _p) {
|
|
46519
|
+
return unavailable2("memorySlotOf");
|
|
45966
46520
|
}
|
|
45967
46521
|
|
|
45968
46522
|
// src-ts/memory/sync.ts
|
|
45969
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
45970
46523
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
45971
46524
|
var MemoryIntegrityError = class extends Error {
|
|
45972
46525
|
constructor(id, reason) {
|
|
@@ -45984,7 +46537,7 @@ async function syncLocalMemory(auth, pointer, opts = {}) {
|
|
|
45984
46537
|
if (withinTtl) {
|
|
45985
46538
|
return { drifted: false, checked: false, pointer };
|
|
45986
46539
|
}
|
|
45987
|
-
const currentId = await getActiveMemoryId(auth, opts.chainOpts);
|
|
46540
|
+
const currentId = await getActiveMemoryId(auth, opts.chainOpts, opts.filePath);
|
|
45988
46541
|
const nextPointer = { activeId: currentId, checkedAt: now };
|
|
45989
46542
|
if (currentId === pointer.activeId) {
|
|
45990
46543
|
return { drifted: false, checked: true, pointer: nextPointer };
|
|
@@ -46000,9 +46553,8 @@ async function syncLocalMemory(auth, pointer, opts = {}) {
|
|
|
46000
46553
|
}
|
|
46001
46554
|
|
|
46002
46555
|
// src-ts/browser/memory-pointer-store.ts
|
|
46003
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46004
46556
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
46005
|
-
var
|
|
46557
|
+
var unavailable3 = (name2) => {
|
|
46006
46558
|
throw new Error(`${name2} is not available in the browser bundle`);
|
|
46007
46559
|
};
|
|
46008
46560
|
var PointerStore = class {
|
|
@@ -46016,38 +46568,35 @@ var PointerStore = class {
|
|
|
46016
46568
|
}
|
|
46017
46569
|
};
|
|
46018
46570
|
function defaultPointerPath(_workspaceDir) {
|
|
46019
|
-
return
|
|
46571
|
+
return unavailable3("defaultPointerPath");
|
|
46020
46572
|
}
|
|
46021
46573
|
|
|
46022
46574
|
// src-ts/browser/memory-file-logger.ts
|
|
46023
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46024
46575
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
46025
|
-
var
|
|
46576
|
+
var unavailable4 = (name2) => {
|
|
46026
46577
|
throw new Error(`${name2} is not available in the browser bundle`);
|
|
46027
46578
|
};
|
|
46028
46579
|
function createFileLogger(_logFilePath, _hostLogger) {
|
|
46029
|
-
return
|
|
46580
|
+
return unavailable4("createFileLogger");
|
|
46030
46581
|
}
|
|
46031
46582
|
function defaultPluginLogPath(_workspaceDir) {
|
|
46032
|
-
return
|
|
46583
|
+
return unavailable4("defaultPluginLogPath");
|
|
46033
46584
|
}
|
|
46034
46585
|
|
|
46035
46586
|
// src-ts/browser/memory-read-classifier.ts
|
|
46036
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46037
46587
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
46038
|
-
var
|
|
46588
|
+
var STUB_MSG6 = "not available in @atbash/sdk browser bundle \u2014 classify memory reads server-side";
|
|
46039
46589
|
var DEFAULT_MEMORY_READ_TOOL_NAMES = [
|
|
46040
46590
|
"memory_search",
|
|
46041
46591
|
"memory_get"
|
|
46042
46592
|
];
|
|
46043
46593
|
function classifyMemoryRead(_event, _ctx, _opts = {}) {
|
|
46044
|
-
throw new Error(`classifyMemoryRead ${
|
|
46594
|
+
throw new Error(`classifyMemoryRead ${STUB_MSG6}`);
|
|
46045
46595
|
}
|
|
46046
46596
|
|
|
46047
46597
|
// src-ts/browser/memory-guard-manager.ts
|
|
46048
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46049
46598
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
46050
|
-
var
|
|
46599
|
+
var unavailable5 = (name2) => {
|
|
46051
46600
|
throw new Error(`${name2} is not available in the browser bundle`);
|
|
46052
46601
|
};
|
|
46053
46602
|
var MemoryGuardManager = class {
|
|
@@ -46067,7 +46616,7 @@ var MemoryGuardManager = class {
|
|
|
46067
46616
|
}
|
|
46068
46617
|
};
|
|
46069
46618
|
function createMemoryGuardManager(_opts) {
|
|
46070
|
-
return
|
|
46619
|
+
return unavailable5("createMemoryGuardManager");
|
|
46071
46620
|
}
|
|
46072
46621
|
|
|
46073
46622
|
// src-ts/index.ts
|
|
@@ -46129,8 +46678,6 @@ export {
|
|
|
46129
46678
|
Atbash,
|
|
46130
46679
|
AtbashAPIError,
|
|
46131
46680
|
BOOT_SYNC_HINT,
|
|
46132
|
-
DEFAULT_BLOCKCHAIN_RID,
|
|
46133
|
-
DEFAULT_CHROMIA_NODE_URLS,
|
|
46134
46681
|
DEFAULT_ENDPOINT,
|
|
46135
46682
|
DEFAULT_MEMORY_PATH_PATTERNS,
|
|
46136
46683
|
DEFAULT_MEMORY_READ_TOOL_NAMES,
|
|
@@ -46138,19 +46685,25 @@ export {
|
|
|
46138
46685
|
EciesDomain,
|
|
46139
46686
|
HttpClient,
|
|
46140
46687
|
HttpTransportError,
|
|
46688
|
+
JudgeRefusalError,
|
|
46141
46689
|
KEY_FILENAMES,
|
|
46142
46690
|
MemoryGuardManager,
|
|
46143
46691
|
MemoryIntegrityError,
|
|
46692
|
+
PRIVATE_CHAIN,
|
|
46144
46693
|
PointerStore,
|
|
46145
46694
|
SignatureVerificationError,
|
|
46146
46695
|
bootSyncFailureLine,
|
|
46147
46696
|
buildAllowedJudgeHosts,
|
|
46697
|
+
canonicalAllow,
|
|
46698
|
+
chainForNetwork,
|
|
46148
46699
|
chooseKeyPath,
|
|
46149
46700
|
claimHashHex,
|
|
46150
46701
|
classifyMemoryRead,
|
|
46151
46702
|
classifyMemoryWrite,
|
|
46152
46703
|
columnAad,
|
|
46153
46704
|
commitMemoryVersion,
|
|
46705
|
+
configureEvents,
|
|
46706
|
+
configureJailHold,
|
|
46154
46707
|
containsEvasionCharacters2 as containsEvasionCharacters,
|
|
46155
46708
|
containsSecret2 as containsSecret,
|
|
46156
46709
|
createFileLogger,
|
|
@@ -46166,25 +46719,29 @@ export {
|
|
|
46166
46719
|
encryptForOrg,
|
|
46167
46720
|
encryptMemoryContent2 as encryptMemoryContent,
|
|
46168
46721
|
encryptedLength,
|
|
46722
|
+
eventsAreOn,
|
|
46169
46723
|
flushTelemetry,
|
|
46170
46724
|
generateKeypair2 as generateKeypair,
|
|
46171
|
-
|
|
46725
|
+
getActiveAgentMemory,
|
|
46172
46726
|
getActiveMemoryId,
|
|
46173
|
-
getAllAgentMemory,
|
|
46174
46727
|
getConfigDir,
|
|
46175
46728
|
getConfigPath,
|
|
46176
46729
|
getMemoryById,
|
|
46177
46730
|
getMemoryHistory,
|
|
46731
|
+
getRecentAgentMemory,
|
|
46178
46732
|
getRollbackHistory,
|
|
46179
46733
|
guardMemoryWrite,
|
|
46180
46734
|
isEnvelope,
|
|
46735
|
+
isJailHeld,
|
|
46181
46736
|
isValidPrivateKey2 as isValidPrivateKey,
|
|
46182
46737
|
keyFingerprintOf,
|
|
46183
46738
|
keyPathCandidates,
|
|
46184
46739
|
loadAgent2 as loadAgent,
|
|
46185
46740
|
loadAgentFromFile,
|
|
46186
46741
|
loadUserConfig,
|
|
46742
|
+
memorySlotOf,
|
|
46187
46743
|
normalizeActionForHash,
|
|
46744
|
+
normalizeActionType,
|
|
46188
46745
|
normalizeForMatching2 as normalizeForMatching,
|
|
46189
46746
|
normalizeStatus,
|
|
46190
46747
|
normalizeVerdict,
|
|
@@ -46193,8 +46750,10 @@ export {
|
|
|
46193
46750
|
pubkeyToHex,
|
|
46194
46751
|
recordCall,
|
|
46195
46752
|
recordDuration,
|
|
46753
|
+
recordEvent,
|
|
46196
46754
|
redactJsonStrings,
|
|
46197
46755
|
redactSecrets2 as redactSecrets,
|
|
46756
|
+
releaseJailHolds,
|
|
46198
46757
|
resolve,
|
|
46199
46758
|
resolveKeyPath,
|
|
46200
46759
|
rollbackMemory,
|
|
@@ -46233,4 +46792,3 @@ postchain-client/built/esm/index.js:
|
|
|
46233
46792
|
@noble/ciphers/utils.js:
|
|
46234
46793
|
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
46235
46794
|
*/
|
|
46236
|
-
//# sourceMappingURL=browser.mjs.map
|