@vultisig/cli 4.4.0 → 4.6.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/CHANGELOG.md +54 -0
- package/README.md +1 -0
- package/dist/index.js +2379 -597
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -24,11 +24,11 @@ var __export = (target, all) => {
|
|
|
24
24
|
for (var name in all)
|
|
25
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
26
|
};
|
|
27
|
-
var __copyProps = (to,
|
|
28
|
-
if (
|
|
29
|
-
for (let key of __getOwnPropNames(
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
30
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
-
__defProp(to, key, { get: () =>
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
32
|
}
|
|
33
33
|
return to;
|
|
34
34
|
};
|
|
@@ -2382,69 +2382,9 @@ function format(value, decimals = 0) {
|
|
|
2382
2382
|
fraction = fraction.replace(/(0+)$/, "");
|
|
2383
2383
|
return `${negative ? "-" : ""}${integer || "0"}${fraction ? `.${fraction}` : ""}`;
|
|
2384
2384
|
}
|
|
2385
|
-
|
|
2386
|
-
if (!Number.isInteger(decimals) || decimals < 0)
|
|
2387
|
-
throw new InvalidDecimalsError({ decimals });
|
|
2388
|
-
if (!/^-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)$/.test(value))
|
|
2389
|
-
throw new InvalidDecimalNumberError({ value });
|
|
2390
|
-
let [integer = "", fraction = "0"] = value.split(".");
|
|
2391
|
-
const negative = integer.startsWith("-");
|
|
2392
|
-
if (negative)
|
|
2393
|
-
integer = integer.slice(1);
|
|
2394
|
-
if (integer === "")
|
|
2395
|
-
integer = "0";
|
|
2396
|
-
fraction = fraction.replace(/(0+)$/, "");
|
|
2397
|
-
if (decimals === 0) {
|
|
2398
|
-
if (fraction.length > 0 && Number.parseInt(fraction[0], 10) >= 5)
|
|
2399
|
-
integer = `${BigInt(integer) + 1n}`;
|
|
2400
|
-
fraction = "";
|
|
2401
|
-
} else if (fraction.length > decimals) {
|
|
2402
|
-
const left = fraction.slice(0, decimals);
|
|
2403
|
-
const roundDigit = Number.parseInt(fraction.slice(decimals, decimals + 1), 10);
|
|
2404
|
-
if (roundDigit >= 5) {
|
|
2405
|
-
const carried = carry(left);
|
|
2406
|
-
if (carried.length > decimals) {
|
|
2407
|
-
fraction = carried.slice(1);
|
|
2408
|
-
integer = `${BigInt(integer) + 1n}`;
|
|
2409
|
-
} else {
|
|
2410
|
-
fraction = carried;
|
|
2411
|
-
}
|
|
2412
|
-
} else {
|
|
2413
|
-
fraction = left;
|
|
2414
|
-
}
|
|
2415
|
-
} else {
|
|
2416
|
-
fraction = fraction.padEnd(decimals, "0");
|
|
2417
|
-
}
|
|
2418
|
-
return BigInt(`${negative ? "-" : ""}${integer}${fraction}`);
|
|
2419
|
-
}
|
|
2420
|
-
function carry(digits) {
|
|
2421
|
-
const out = digits.split("");
|
|
2422
|
-
let i = out.length - 1;
|
|
2423
|
-
while (i >= 0) {
|
|
2424
|
-
const d = Number.parseInt(out[i], 10) + 1;
|
|
2425
|
-
if (d < 10) {
|
|
2426
|
-
out[i] = String(d);
|
|
2427
|
-
return out.join("");
|
|
2428
|
-
}
|
|
2429
|
-
out[i] = "0";
|
|
2430
|
-
i--;
|
|
2431
|
-
}
|
|
2432
|
-
return `1${out.join("")}`;
|
|
2433
|
-
}
|
|
2434
|
-
var InvalidDecimalNumberError, InvalidDecimalsError;
|
|
2385
|
+
var InvalidDecimalsError;
|
|
2435
2386
|
var init_Value = __esm({
|
|
2436
2387
|
"../../node_modules/viem/_esm/utils/unit/Value.js"() {
|
|
2437
|
-
InvalidDecimalNumberError = class extends Error {
|
|
2438
|
-
constructor({ value }) {
|
|
2439
|
-
super(`Value \`${value}\` is not a valid decimal number.`);
|
|
2440
|
-
Object.defineProperty(this, "name", {
|
|
2441
|
-
enumerable: true,
|
|
2442
|
-
configurable: true,
|
|
2443
|
-
writable: true,
|
|
2444
|
-
value: "Value.InvalidDecimalNumberError"
|
|
2445
|
-
});
|
|
2446
|
-
}
|
|
2447
|
-
};
|
|
2448
2388
|
InvalidDecimalsError = class extends Error {
|
|
2449
2389
|
constructor({ decimals }) {
|
|
2450
2390
|
super(`\`decimals\` must be a non-negative integer. Got \`${decimals}\`.`);
|
|
@@ -4071,7 +4011,7 @@ function weierstrass(curveDef) {
|
|
|
4071
4011
|
function normalizeS(s) {
|
|
4072
4012
|
return isBiggerThanHalfOrder(s) ? modN2(-s) : s;
|
|
4073
4013
|
}
|
|
4074
|
-
const slcNum = (b,
|
|
4014
|
+
const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
|
|
4075
4015
|
class Signature {
|
|
4076
4016
|
constructor(r, s, recovery) {
|
|
4077
4017
|
aInRange("r", r, _1n5, CURVE_ORDER);
|
|
@@ -4903,57 +4843,1766 @@ var init_secp256k1 = __esm({
|
|
|
4903
4843
|
taggedHash,
|
|
4904
4844
|
mod
|
|
4905
4845
|
}
|
|
4906
|
-
}))();
|
|
4907
|
-
isoMap = /* @__PURE__ */ (() => isogenyMap(Fpk1, [
|
|
4908
|
-
// xNum
|
|
4909
|
-
[
|
|
4910
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
|
|
4911
|
-
"0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
|
|
4912
|
-
"0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
|
|
4913
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
|
|
4914
|
-
],
|
|
4915
|
-
// xDen
|
|
4916
|
-
[
|
|
4917
|
-
"0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
|
|
4918
|
-
"0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
|
|
4919
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
4920
|
-
// LAST 1
|
|
4921
|
-
],
|
|
4922
|
-
// yNum
|
|
4923
|
-
[
|
|
4924
|
-
"0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
|
|
4925
|
-
"0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
|
|
4926
|
-
"0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
|
|
4927
|
-
"0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
|
|
4928
|
-
],
|
|
4929
|
-
// yDen
|
|
4930
|
-
[
|
|
4931
|
-
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
|
|
4932
|
-
"0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
|
|
4933
|
-
"0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
|
|
4934
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
4935
|
-
// LAST 1
|
|
4936
|
-
]
|
|
4937
|
-
].map((i) => i.map((j) => BigInt(j)))))();
|
|
4938
|
-
mapSWU = /* @__PURE__ */ (() => mapToCurveSimpleSWU(Fpk1, {
|
|
4939
|
-
A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
|
|
4940
|
-
B: BigInt("1771"),
|
|
4941
|
-
Z: Fpk1.create(BigInt("-11"))
|
|
4942
|
-
}))();
|
|
4943
|
-
secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.ProjectivePoint, (scalars) => {
|
|
4944
|
-
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
4945
|
-
return isoMap(x, y);
|
|
4946
|
-
}, {
|
|
4947
|
-
DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
|
|
4948
|
-
encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
|
|
4949
|
-
p: Fpk1.ORDER,
|
|
4950
|
-
m: 1,
|
|
4951
|
-
k: 128,
|
|
4952
|
-
expand: "xmd",
|
|
4953
|
-
hash: sha256
|
|
4954
|
-
}))();
|
|
4955
|
-
hashToCurve = /* @__PURE__ */ (() => secp256k1_hasher.hashToCurve)();
|
|
4956
|
-
encodeToCurve = /* @__PURE__ */ (() => secp256k1_hasher.encodeToCurve)();
|
|
4846
|
+
}))();
|
|
4847
|
+
isoMap = /* @__PURE__ */ (() => isogenyMap(Fpk1, [
|
|
4848
|
+
// xNum
|
|
4849
|
+
[
|
|
4850
|
+
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
|
|
4851
|
+
"0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
|
|
4852
|
+
"0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
|
|
4853
|
+
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
|
|
4854
|
+
],
|
|
4855
|
+
// xDen
|
|
4856
|
+
[
|
|
4857
|
+
"0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
|
|
4858
|
+
"0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
|
|
4859
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
4860
|
+
// LAST 1
|
|
4861
|
+
],
|
|
4862
|
+
// yNum
|
|
4863
|
+
[
|
|
4864
|
+
"0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
|
|
4865
|
+
"0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
|
|
4866
|
+
"0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
|
|
4867
|
+
"0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
|
|
4868
|
+
],
|
|
4869
|
+
// yDen
|
|
4870
|
+
[
|
|
4871
|
+
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
|
|
4872
|
+
"0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
|
|
4873
|
+
"0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
|
|
4874
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
4875
|
+
// LAST 1
|
|
4876
|
+
]
|
|
4877
|
+
].map((i) => i.map((j) => BigInt(j)))))();
|
|
4878
|
+
mapSWU = /* @__PURE__ */ (() => mapToCurveSimpleSWU(Fpk1, {
|
|
4879
|
+
A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
|
|
4880
|
+
B: BigInt("1771"),
|
|
4881
|
+
Z: Fpk1.create(BigInt("-11"))
|
|
4882
|
+
}))();
|
|
4883
|
+
secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.ProjectivePoint, (scalars) => {
|
|
4884
|
+
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
4885
|
+
return isoMap(x, y);
|
|
4886
|
+
}, {
|
|
4887
|
+
DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
|
|
4888
|
+
encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
|
|
4889
|
+
p: Fpk1.ORDER,
|
|
4890
|
+
m: 1,
|
|
4891
|
+
k: 128,
|
|
4892
|
+
expand: "xmd",
|
|
4893
|
+
hash: sha256
|
|
4894
|
+
}))();
|
|
4895
|
+
hashToCurve = /* @__PURE__ */ (() => secp256k1_hasher.hashToCurve)();
|
|
4896
|
+
encodeToCurve = /* @__PURE__ */ (() => secp256k1_hasher.encodeToCurve)();
|
|
4897
|
+
}
|
|
4898
|
+
});
|
|
4899
|
+
|
|
4900
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/utils/utf8.cjs
|
|
4901
|
+
var require_utf8 = __commonJS({
|
|
4902
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/utils/utf8.cjs"(exports) {
|
|
4903
|
+
"use strict";
|
|
4904
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4905
|
+
exports.utf8Count = utf8Count;
|
|
4906
|
+
exports.utf8EncodeJs = utf8EncodeJs;
|
|
4907
|
+
exports.utf8EncodeTE = utf8EncodeTE;
|
|
4908
|
+
exports.utf8Encode = utf8Encode;
|
|
4909
|
+
exports.utf8DecodeJs = utf8DecodeJs;
|
|
4910
|
+
exports.utf8DecodeTD = utf8DecodeTD;
|
|
4911
|
+
exports.utf8Decode = utf8Decode;
|
|
4912
|
+
function utf8Count(str2) {
|
|
4913
|
+
const strLength = str2.length;
|
|
4914
|
+
let byteLength = 0;
|
|
4915
|
+
let pos = 0;
|
|
4916
|
+
while (pos < strLength) {
|
|
4917
|
+
let value = str2.charCodeAt(pos++);
|
|
4918
|
+
if ((value & 4294967168) === 0) {
|
|
4919
|
+
byteLength++;
|
|
4920
|
+
continue;
|
|
4921
|
+
} else if ((value & 4294965248) === 0) {
|
|
4922
|
+
byteLength += 2;
|
|
4923
|
+
} else {
|
|
4924
|
+
if (value >= 55296 && value <= 56319) {
|
|
4925
|
+
if (pos < strLength) {
|
|
4926
|
+
const extra = str2.charCodeAt(pos);
|
|
4927
|
+
if ((extra & 64512) === 56320) {
|
|
4928
|
+
++pos;
|
|
4929
|
+
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
4930
|
+
}
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
if ((value & 4294901760) === 0) {
|
|
4934
|
+
byteLength += 3;
|
|
4935
|
+
} else {
|
|
4936
|
+
byteLength += 4;
|
|
4937
|
+
}
|
|
4938
|
+
}
|
|
4939
|
+
}
|
|
4940
|
+
return byteLength;
|
|
4941
|
+
}
|
|
4942
|
+
function utf8EncodeJs(str2, output, outputOffset) {
|
|
4943
|
+
const strLength = str2.length;
|
|
4944
|
+
let offset = outputOffset;
|
|
4945
|
+
let pos = 0;
|
|
4946
|
+
while (pos < strLength) {
|
|
4947
|
+
let value = str2.charCodeAt(pos++);
|
|
4948
|
+
if ((value & 4294967168) === 0) {
|
|
4949
|
+
output[offset++] = value;
|
|
4950
|
+
continue;
|
|
4951
|
+
} else if ((value & 4294965248) === 0) {
|
|
4952
|
+
output[offset++] = value >> 6 & 31 | 192;
|
|
4953
|
+
} else {
|
|
4954
|
+
if (value >= 55296 && value <= 56319) {
|
|
4955
|
+
if (pos < strLength) {
|
|
4956
|
+
const extra = str2.charCodeAt(pos);
|
|
4957
|
+
if ((extra & 64512) === 56320) {
|
|
4958
|
+
++pos;
|
|
4959
|
+
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
4960
|
+
}
|
|
4961
|
+
}
|
|
4962
|
+
}
|
|
4963
|
+
if ((value & 4294901760) === 0) {
|
|
4964
|
+
output[offset++] = value >> 12 & 15 | 224;
|
|
4965
|
+
output[offset++] = value >> 6 & 63 | 128;
|
|
4966
|
+
} else {
|
|
4967
|
+
output[offset++] = value >> 18 & 7 | 240;
|
|
4968
|
+
output[offset++] = value >> 12 & 63 | 128;
|
|
4969
|
+
output[offset++] = value >> 6 & 63 | 128;
|
|
4970
|
+
}
|
|
4971
|
+
}
|
|
4972
|
+
output[offset++] = value & 63 | 128;
|
|
4973
|
+
}
|
|
4974
|
+
}
|
|
4975
|
+
var sharedTextEncoder = new TextEncoder();
|
|
4976
|
+
var TEXT_ENCODER_THRESHOLD = 50;
|
|
4977
|
+
function utf8EncodeTE(str2, output, outputOffset) {
|
|
4978
|
+
sharedTextEncoder.encodeInto(str2, output.subarray(outputOffset));
|
|
4979
|
+
}
|
|
4980
|
+
function utf8Encode(str2, output, outputOffset) {
|
|
4981
|
+
if (str2.length > TEXT_ENCODER_THRESHOLD) {
|
|
4982
|
+
utf8EncodeTE(str2, output, outputOffset);
|
|
4983
|
+
} else {
|
|
4984
|
+
utf8EncodeJs(str2, output, outputOffset);
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
var CHUNK_SIZE = 4096;
|
|
4988
|
+
function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
4989
|
+
let offset = inputOffset;
|
|
4990
|
+
const end = offset + byteLength;
|
|
4991
|
+
const units = [];
|
|
4992
|
+
let result = "";
|
|
4993
|
+
while (offset < end) {
|
|
4994
|
+
const byte1 = bytes[offset++];
|
|
4995
|
+
if ((byte1 & 128) === 0) {
|
|
4996
|
+
units.push(byte1);
|
|
4997
|
+
} else if ((byte1 & 224) === 192) {
|
|
4998
|
+
const byte2 = bytes[offset++] & 63;
|
|
4999
|
+
units.push((byte1 & 31) << 6 | byte2);
|
|
5000
|
+
} else if ((byte1 & 240) === 224) {
|
|
5001
|
+
const byte2 = bytes[offset++] & 63;
|
|
5002
|
+
const byte3 = bytes[offset++] & 63;
|
|
5003
|
+
units.push((byte1 & 31) << 12 | byte2 << 6 | byte3);
|
|
5004
|
+
} else if ((byte1 & 248) === 240) {
|
|
5005
|
+
const byte2 = bytes[offset++] & 63;
|
|
5006
|
+
const byte3 = bytes[offset++] & 63;
|
|
5007
|
+
const byte4 = bytes[offset++] & 63;
|
|
5008
|
+
let unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
|
|
5009
|
+
if (unit > 65535) {
|
|
5010
|
+
unit -= 65536;
|
|
5011
|
+
units.push(unit >>> 10 & 1023 | 55296);
|
|
5012
|
+
unit = 56320 | unit & 1023;
|
|
5013
|
+
}
|
|
5014
|
+
units.push(unit);
|
|
5015
|
+
} else {
|
|
5016
|
+
units.push(byte1);
|
|
5017
|
+
}
|
|
5018
|
+
if (units.length >= CHUNK_SIZE) {
|
|
5019
|
+
result += String.fromCharCode(...units);
|
|
5020
|
+
units.length = 0;
|
|
5021
|
+
}
|
|
5022
|
+
}
|
|
5023
|
+
if (units.length > 0) {
|
|
5024
|
+
result += String.fromCharCode(...units);
|
|
5025
|
+
}
|
|
5026
|
+
return result;
|
|
5027
|
+
}
|
|
5028
|
+
var sharedTextDecoder = new TextDecoder();
|
|
5029
|
+
var TEXT_DECODER_THRESHOLD = 200;
|
|
5030
|
+
function utf8DecodeTD(bytes, inputOffset, byteLength) {
|
|
5031
|
+
const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
|
|
5032
|
+
return sharedTextDecoder.decode(stringBytes);
|
|
5033
|
+
}
|
|
5034
|
+
function utf8Decode(bytes, inputOffset, byteLength) {
|
|
5035
|
+
if (byteLength > TEXT_DECODER_THRESHOLD) {
|
|
5036
|
+
return utf8DecodeTD(bytes, inputOffset, byteLength);
|
|
5037
|
+
} else {
|
|
5038
|
+
return utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
5039
|
+
}
|
|
5040
|
+
}
|
|
5041
|
+
}
|
|
5042
|
+
});
|
|
5043
|
+
|
|
5044
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/ExtData.cjs
|
|
5045
|
+
var require_ExtData = __commonJS({
|
|
5046
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/ExtData.cjs"(exports) {
|
|
5047
|
+
"use strict";
|
|
5048
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5049
|
+
exports.ExtData = void 0;
|
|
5050
|
+
var ExtData = class {
|
|
5051
|
+
type;
|
|
5052
|
+
data;
|
|
5053
|
+
constructor(type, data) {
|
|
5054
|
+
this.type = type;
|
|
5055
|
+
this.data = data;
|
|
5056
|
+
}
|
|
5057
|
+
};
|
|
5058
|
+
exports.ExtData = ExtData;
|
|
5059
|
+
}
|
|
5060
|
+
});
|
|
5061
|
+
|
|
5062
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/DecodeError.cjs
|
|
5063
|
+
var require_DecodeError = __commonJS({
|
|
5064
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/DecodeError.cjs"(exports) {
|
|
5065
|
+
"use strict";
|
|
5066
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5067
|
+
exports.DecodeError = void 0;
|
|
5068
|
+
var DecodeError = class _DecodeError extends Error {
|
|
5069
|
+
constructor(message) {
|
|
5070
|
+
super(message);
|
|
5071
|
+
const proto = Object.create(_DecodeError.prototype);
|
|
5072
|
+
Object.setPrototypeOf(this, proto);
|
|
5073
|
+
Object.defineProperty(this, "name", {
|
|
5074
|
+
configurable: true,
|
|
5075
|
+
enumerable: false,
|
|
5076
|
+
value: _DecodeError.name
|
|
5077
|
+
});
|
|
5078
|
+
}
|
|
5079
|
+
};
|
|
5080
|
+
exports.DecodeError = DecodeError;
|
|
5081
|
+
}
|
|
5082
|
+
});
|
|
5083
|
+
|
|
5084
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/utils/int.cjs
|
|
5085
|
+
var require_int = __commonJS({
|
|
5086
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/utils/int.cjs"(exports) {
|
|
5087
|
+
"use strict";
|
|
5088
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5089
|
+
exports.UINT32_MAX = void 0;
|
|
5090
|
+
exports.setUint64 = setUint64;
|
|
5091
|
+
exports.setInt64 = setInt64;
|
|
5092
|
+
exports.getInt64 = getInt64;
|
|
5093
|
+
exports.getUint64 = getUint64;
|
|
5094
|
+
exports.UINT32_MAX = 4294967295;
|
|
5095
|
+
function setUint64(view, offset, value) {
|
|
5096
|
+
const high = value / 4294967296;
|
|
5097
|
+
const low = value;
|
|
5098
|
+
view.setUint32(offset, high);
|
|
5099
|
+
view.setUint32(offset + 4, low);
|
|
5100
|
+
}
|
|
5101
|
+
function setInt64(view, offset, value) {
|
|
5102
|
+
const high = Math.floor(value / 4294967296);
|
|
5103
|
+
const low = value;
|
|
5104
|
+
view.setUint32(offset, high);
|
|
5105
|
+
view.setUint32(offset + 4, low);
|
|
5106
|
+
}
|
|
5107
|
+
function getInt64(view, offset) {
|
|
5108
|
+
const high = view.getInt32(offset);
|
|
5109
|
+
const low = view.getUint32(offset + 4);
|
|
5110
|
+
return high * 4294967296 + low;
|
|
5111
|
+
}
|
|
5112
|
+
function getUint64(view, offset) {
|
|
5113
|
+
const high = view.getUint32(offset);
|
|
5114
|
+
const low = view.getUint32(offset + 4);
|
|
5115
|
+
return high * 4294967296 + low;
|
|
5116
|
+
}
|
|
5117
|
+
}
|
|
5118
|
+
});
|
|
5119
|
+
|
|
5120
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/timestamp.cjs
|
|
5121
|
+
var require_timestamp = __commonJS({
|
|
5122
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/timestamp.cjs"(exports) {
|
|
5123
|
+
"use strict";
|
|
5124
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5125
|
+
exports.timestampExtension = exports.EXT_TIMESTAMP = void 0;
|
|
5126
|
+
exports.encodeTimeSpecToTimestamp = encodeTimeSpecToTimestamp;
|
|
5127
|
+
exports.encodeDateToTimeSpec = encodeDateToTimeSpec;
|
|
5128
|
+
exports.encodeTimestampExtension = encodeTimestampExtension;
|
|
5129
|
+
exports.decodeTimestampToTimeSpec = decodeTimestampToTimeSpec;
|
|
5130
|
+
exports.decodeTimestampExtension = decodeTimestampExtension;
|
|
5131
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
5132
|
+
var int_ts_1 = require_int();
|
|
5133
|
+
exports.EXT_TIMESTAMP = -1;
|
|
5134
|
+
var TIMESTAMP32_MAX_SEC = 4294967296 - 1;
|
|
5135
|
+
var TIMESTAMP64_MAX_SEC = 17179869184 - 1;
|
|
5136
|
+
function encodeTimeSpecToTimestamp({ sec, nsec }) {
|
|
5137
|
+
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
|
|
5138
|
+
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
|
|
5139
|
+
const rv = new Uint8Array(4);
|
|
5140
|
+
const view = new DataView(rv.buffer);
|
|
5141
|
+
view.setUint32(0, sec);
|
|
5142
|
+
return rv;
|
|
5143
|
+
} else {
|
|
5144
|
+
const secHigh = sec / 4294967296;
|
|
5145
|
+
const secLow = sec & 4294967295;
|
|
5146
|
+
const rv = new Uint8Array(8);
|
|
5147
|
+
const view = new DataView(rv.buffer);
|
|
5148
|
+
view.setUint32(0, nsec << 2 | secHigh & 3);
|
|
5149
|
+
view.setUint32(4, secLow);
|
|
5150
|
+
return rv;
|
|
5151
|
+
}
|
|
5152
|
+
} else {
|
|
5153
|
+
const rv = new Uint8Array(12);
|
|
5154
|
+
const view = new DataView(rv.buffer);
|
|
5155
|
+
view.setUint32(0, nsec);
|
|
5156
|
+
(0, int_ts_1.setInt64)(view, 4, sec);
|
|
5157
|
+
return rv;
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5160
|
+
function encodeDateToTimeSpec(date) {
|
|
5161
|
+
const msec = date.getTime();
|
|
5162
|
+
const sec = Math.floor(msec / 1e3);
|
|
5163
|
+
const nsec = (msec - sec * 1e3) * 1e6;
|
|
5164
|
+
const nsecInSec = Math.floor(nsec / 1e9);
|
|
5165
|
+
return {
|
|
5166
|
+
sec: sec + nsecInSec,
|
|
5167
|
+
nsec: nsec - nsecInSec * 1e9
|
|
5168
|
+
};
|
|
5169
|
+
}
|
|
5170
|
+
function encodeTimestampExtension(object) {
|
|
5171
|
+
if (object instanceof Date) {
|
|
5172
|
+
const timeSpec = encodeDateToTimeSpec(object);
|
|
5173
|
+
return encodeTimeSpecToTimestamp(timeSpec);
|
|
5174
|
+
} else {
|
|
5175
|
+
return null;
|
|
5176
|
+
}
|
|
5177
|
+
}
|
|
5178
|
+
function decodeTimestampToTimeSpec(data) {
|
|
5179
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
5180
|
+
switch (data.byteLength) {
|
|
5181
|
+
case 4: {
|
|
5182
|
+
const sec = view.getUint32(0);
|
|
5183
|
+
const nsec = 0;
|
|
5184
|
+
return { sec, nsec };
|
|
5185
|
+
}
|
|
5186
|
+
case 8: {
|
|
5187
|
+
const nsec30AndSecHigh2 = view.getUint32(0);
|
|
5188
|
+
const secLow32 = view.getUint32(4);
|
|
5189
|
+
const sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32;
|
|
5190
|
+
const nsec = nsec30AndSecHigh2 >>> 2;
|
|
5191
|
+
return { sec, nsec };
|
|
5192
|
+
}
|
|
5193
|
+
case 12: {
|
|
5194
|
+
const sec = (0, int_ts_1.getInt64)(view, 4);
|
|
5195
|
+
const nsec = view.getUint32(0);
|
|
5196
|
+
return { sec, nsec };
|
|
5197
|
+
}
|
|
5198
|
+
default:
|
|
5199
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`);
|
|
5200
|
+
}
|
|
5201
|
+
}
|
|
5202
|
+
function decodeTimestampExtension(data) {
|
|
5203
|
+
const timeSpec = decodeTimestampToTimeSpec(data);
|
|
5204
|
+
return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
|
|
5205
|
+
}
|
|
5206
|
+
exports.timestampExtension = {
|
|
5207
|
+
type: exports.EXT_TIMESTAMP,
|
|
5208
|
+
encode: encodeTimestampExtension,
|
|
5209
|
+
decode: decodeTimestampExtension
|
|
5210
|
+
};
|
|
5211
|
+
}
|
|
5212
|
+
});
|
|
5213
|
+
|
|
5214
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/ExtensionCodec.cjs
|
|
5215
|
+
var require_ExtensionCodec = __commonJS({
|
|
5216
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/ExtensionCodec.cjs"(exports) {
|
|
5217
|
+
"use strict";
|
|
5218
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5219
|
+
exports.ExtensionCodec = void 0;
|
|
5220
|
+
var ExtData_ts_1 = require_ExtData();
|
|
5221
|
+
var timestamp_ts_1 = require_timestamp();
|
|
5222
|
+
var ExtensionCodec = class _ExtensionCodec {
|
|
5223
|
+
static defaultCodec = new _ExtensionCodec();
|
|
5224
|
+
// ensures ExtensionCodecType<X> matches ExtensionCodec<X>
|
|
5225
|
+
// this will make type errors a lot more clear
|
|
5226
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5227
|
+
__brand;
|
|
5228
|
+
// built-in extensions
|
|
5229
|
+
builtInEncoders = [];
|
|
5230
|
+
builtInDecoders = [];
|
|
5231
|
+
// custom extensions
|
|
5232
|
+
encoders = [];
|
|
5233
|
+
decoders = [];
|
|
5234
|
+
constructor() {
|
|
5235
|
+
this.register(timestamp_ts_1.timestampExtension);
|
|
5236
|
+
}
|
|
5237
|
+
register({ type, encode, decode }) {
|
|
5238
|
+
if (type >= 0) {
|
|
5239
|
+
this.encoders[type] = encode;
|
|
5240
|
+
this.decoders[type] = decode;
|
|
5241
|
+
} else {
|
|
5242
|
+
const index = -1 - type;
|
|
5243
|
+
this.builtInEncoders[index] = encode;
|
|
5244
|
+
this.builtInDecoders[index] = decode;
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5247
|
+
tryToEncode(object, context) {
|
|
5248
|
+
for (let i = 0; i < this.builtInEncoders.length; i++) {
|
|
5249
|
+
const encodeExt = this.builtInEncoders[i];
|
|
5250
|
+
if (encodeExt != null) {
|
|
5251
|
+
const data = encodeExt(object, context);
|
|
5252
|
+
if (data != null) {
|
|
5253
|
+
const type = -1 - i;
|
|
5254
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
5255
|
+
}
|
|
5256
|
+
}
|
|
5257
|
+
}
|
|
5258
|
+
for (let i = 0; i < this.encoders.length; i++) {
|
|
5259
|
+
const encodeExt = this.encoders[i];
|
|
5260
|
+
if (encodeExt != null) {
|
|
5261
|
+
const data = encodeExt(object, context);
|
|
5262
|
+
if (data != null) {
|
|
5263
|
+
const type = i;
|
|
5264
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5267
|
+
}
|
|
5268
|
+
if (object instanceof ExtData_ts_1.ExtData) {
|
|
5269
|
+
return object;
|
|
5270
|
+
}
|
|
5271
|
+
return null;
|
|
5272
|
+
}
|
|
5273
|
+
decode(data, type, context) {
|
|
5274
|
+
const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
|
|
5275
|
+
if (decodeExt) {
|
|
5276
|
+
return decodeExt(data, type, context);
|
|
5277
|
+
} else {
|
|
5278
|
+
return new ExtData_ts_1.ExtData(type, data);
|
|
5279
|
+
}
|
|
5280
|
+
}
|
|
5281
|
+
};
|
|
5282
|
+
exports.ExtensionCodec = ExtensionCodec;
|
|
5283
|
+
}
|
|
5284
|
+
});
|
|
5285
|
+
|
|
5286
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/utils/typedArrays.cjs
|
|
5287
|
+
var require_typedArrays = __commonJS({
|
|
5288
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/utils/typedArrays.cjs"(exports) {
|
|
5289
|
+
"use strict";
|
|
5290
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5291
|
+
exports.ensureUint8Array = ensureUint8Array;
|
|
5292
|
+
function isArrayBufferLike(buffer) {
|
|
5293
|
+
return buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer;
|
|
5294
|
+
}
|
|
5295
|
+
function ensureUint8Array(buffer) {
|
|
5296
|
+
if (buffer instanceof Uint8Array) {
|
|
5297
|
+
return buffer;
|
|
5298
|
+
} else if (ArrayBuffer.isView(buffer)) {
|
|
5299
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5300
|
+
} else if (isArrayBufferLike(buffer)) {
|
|
5301
|
+
return new Uint8Array(buffer);
|
|
5302
|
+
} else {
|
|
5303
|
+
return Uint8Array.from(buffer);
|
|
5304
|
+
}
|
|
5305
|
+
}
|
|
5306
|
+
}
|
|
5307
|
+
});
|
|
5308
|
+
|
|
5309
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/Encoder.cjs
|
|
5310
|
+
var require_Encoder = __commonJS({
|
|
5311
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/Encoder.cjs"(exports) {
|
|
5312
|
+
"use strict";
|
|
5313
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5314
|
+
exports.Encoder = exports.DEFAULT_INITIAL_BUFFER_SIZE = exports.DEFAULT_MAX_DEPTH = void 0;
|
|
5315
|
+
var utf8_ts_1 = require_utf8();
|
|
5316
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
5317
|
+
var int_ts_1 = require_int();
|
|
5318
|
+
var typedArrays_ts_1 = require_typedArrays();
|
|
5319
|
+
exports.DEFAULT_MAX_DEPTH = 100;
|
|
5320
|
+
exports.DEFAULT_INITIAL_BUFFER_SIZE = 2048;
|
|
5321
|
+
var Encoder = class _Encoder {
|
|
5322
|
+
extensionCodec;
|
|
5323
|
+
context;
|
|
5324
|
+
useBigInt64;
|
|
5325
|
+
maxDepth;
|
|
5326
|
+
initialBufferSize;
|
|
5327
|
+
sortKeys;
|
|
5328
|
+
forceFloat32;
|
|
5329
|
+
ignoreUndefined;
|
|
5330
|
+
forceIntegerToFloat;
|
|
5331
|
+
pos;
|
|
5332
|
+
view;
|
|
5333
|
+
bytes;
|
|
5334
|
+
entered = false;
|
|
5335
|
+
constructor(options) {
|
|
5336
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec;
|
|
5337
|
+
this.context = options?.context;
|
|
5338
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
5339
|
+
this.maxDepth = options?.maxDepth ?? exports.DEFAULT_MAX_DEPTH;
|
|
5340
|
+
this.initialBufferSize = options?.initialBufferSize ?? exports.DEFAULT_INITIAL_BUFFER_SIZE;
|
|
5341
|
+
this.sortKeys = options?.sortKeys ?? false;
|
|
5342
|
+
this.forceFloat32 = options?.forceFloat32 ?? false;
|
|
5343
|
+
this.ignoreUndefined = options?.ignoreUndefined ?? false;
|
|
5344
|
+
this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false;
|
|
5345
|
+
this.pos = 0;
|
|
5346
|
+
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
|
|
5347
|
+
this.bytes = new Uint8Array(this.view.buffer);
|
|
5348
|
+
}
|
|
5349
|
+
clone() {
|
|
5350
|
+
return new _Encoder({
|
|
5351
|
+
extensionCodec: this.extensionCodec,
|
|
5352
|
+
context: this.context,
|
|
5353
|
+
useBigInt64: this.useBigInt64,
|
|
5354
|
+
maxDepth: this.maxDepth,
|
|
5355
|
+
initialBufferSize: this.initialBufferSize,
|
|
5356
|
+
sortKeys: this.sortKeys,
|
|
5357
|
+
forceFloat32: this.forceFloat32,
|
|
5358
|
+
ignoreUndefined: this.ignoreUndefined,
|
|
5359
|
+
forceIntegerToFloat: this.forceIntegerToFloat
|
|
5360
|
+
});
|
|
5361
|
+
}
|
|
5362
|
+
reinitializeState() {
|
|
5363
|
+
this.pos = 0;
|
|
5364
|
+
}
|
|
5365
|
+
/**
|
|
5366
|
+
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
|
|
5367
|
+
*
|
|
5368
|
+
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
|
|
5369
|
+
*/
|
|
5370
|
+
encodeSharedRef(object) {
|
|
5371
|
+
if (this.entered) {
|
|
5372
|
+
const instance = this.clone();
|
|
5373
|
+
return instance.encodeSharedRef(object);
|
|
5374
|
+
}
|
|
5375
|
+
try {
|
|
5376
|
+
this.entered = true;
|
|
5377
|
+
this.reinitializeState();
|
|
5378
|
+
this.doEncode(object, 1);
|
|
5379
|
+
return this.bytes.subarray(0, this.pos);
|
|
5380
|
+
} finally {
|
|
5381
|
+
this.entered = false;
|
|
5382
|
+
}
|
|
5383
|
+
}
|
|
5384
|
+
/**
|
|
5385
|
+
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
|
|
5386
|
+
*/
|
|
5387
|
+
encode(object) {
|
|
5388
|
+
if (this.entered) {
|
|
5389
|
+
const instance = this.clone();
|
|
5390
|
+
return instance.encode(object);
|
|
5391
|
+
}
|
|
5392
|
+
try {
|
|
5393
|
+
this.entered = true;
|
|
5394
|
+
this.reinitializeState();
|
|
5395
|
+
this.doEncode(object, 1);
|
|
5396
|
+
return this.bytes.slice(0, this.pos);
|
|
5397
|
+
} finally {
|
|
5398
|
+
this.entered = false;
|
|
5399
|
+
}
|
|
5400
|
+
}
|
|
5401
|
+
doEncode(object, depth) {
|
|
5402
|
+
if (depth > this.maxDepth) {
|
|
5403
|
+
throw new Error(`Too deep objects in depth ${depth}`);
|
|
5404
|
+
}
|
|
5405
|
+
if (object == null) {
|
|
5406
|
+
this.encodeNil();
|
|
5407
|
+
} else if (typeof object === "boolean") {
|
|
5408
|
+
this.encodeBoolean(object);
|
|
5409
|
+
} else if (typeof object === "number") {
|
|
5410
|
+
if (!this.forceIntegerToFloat) {
|
|
5411
|
+
this.encodeNumber(object);
|
|
5412
|
+
} else {
|
|
5413
|
+
this.encodeNumberAsFloat(object);
|
|
5414
|
+
}
|
|
5415
|
+
} else if (typeof object === "string") {
|
|
5416
|
+
this.encodeString(object);
|
|
5417
|
+
} else if (this.useBigInt64 && typeof object === "bigint") {
|
|
5418
|
+
this.encodeBigInt64(object);
|
|
5419
|
+
} else {
|
|
5420
|
+
this.encodeObject(object, depth);
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
ensureBufferSizeToWrite(sizeToWrite) {
|
|
5424
|
+
const requiredSize = this.pos + sizeToWrite;
|
|
5425
|
+
if (this.view.byteLength < requiredSize) {
|
|
5426
|
+
this.resizeBuffer(requiredSize * 2);
|
|
5427
|
+
}
|
|
5428
|
+
}
|
|
5429
|
+
resizeBuffer(newSize) {
|
|
5430
|
+
const newBuffer = new ArrayBuffer(newSize);
|
|
5431
|
+
const newBytes = new Uint8Array(newBuffer);
|
|
5432
|
+
const newView = new DataView(newBuffer);
|
|
5433
|
+
newBytes.set(this.bytes);
|
|
5434
|
+
this.view = newView;
|
|
5435
|
+
this.bytes = newBytes;
|
|
5436
|
+
}
|
|
5437
|
+
encodeNil() {
|
|
5438
|
+
this.writeU8(192);
|
|
5439
|
+
}
|
|
5440
|
+
encodeBoolean(object) {
|
|
5441
|
+
if (object === false) {
|
|
5442
|
+
this.writeU8(194);
|
|
5443
|
+
} else {
|
|
5444
|
+
this.writeU8(195);
|
|
5445
|
+
}
|
|
5446
|
+
}
|
|
5447
|
+
encodeNumber(object) {
|
|
5448
|
+
if (!this.forceIntegerToFloat && Number.isSafeInteger(object)) {
|
|
5449
|
+
if (object >= 0) {
|
|
5450
|
+
if (object < 128) {
|
|
5451
|
+
this.writeU8(object);
|
|
5452
|
+
} else if (object < 256) {
|
|
5453
|
+
this.writeU8(204);
|
|
5454
|
+
this.writeU8(object);
|
|
5455
|
+
} else if (object < 65536) {
|
|
5456
|
+
this.writeU8(205);
|
|
5457
|
+
this.writeU16(object);
|
|
5458
|
+
} else if (object < 4294967296) {
|
|
5459
|
+
this.writeU8(206);
|
|
5460
|
+
this.writeU32(object);
|
|
5461
|
+
} else if (!this.useBigInt64) {
|
|
5462
|
+
this.writeU8(207);
|
|
5463
|
+
this.writeU64(object);
|
|
5464
|
+
} else {
|
|
5465
|
+
this.encodeNumberAsFloat(object);
|
|
5466
|
+
}
|
|
5467
|
+
} else {
|
|
5468
|
+
if (object >= -32) {
|
|
5469
|
+
this.writeU8(224 | object + 32);
|
|
5470
|
+
} else if (object >= -128) {
|
|
5471
|
+
this.writeU8(208);
|
|
5472
|
+
this.writeI8(object);
|
|
5473
|
+
} else if (object >= -32768) {
|
|
5474
|
+
this.writeU8(209);
|
|
5475
|
+
this.writeI16(object);
|
|
5476
|
+
} else if (object >= -2147483648) {
|
|
5477
|
+
this.writeU8(210);
|
|
5478
|
+
this.writeI32(object);
|
|
5479
|
+
} else if (!this.useBigInt64) {
|
|
5480
|
+
this.writeU8(211);
|
|
5481
|
+
this.writeI64(object);
|
|
5482
|
+
} else {
|
|
5483
|
+
this.encodeNumberAsFloat(object);
|
|
5484
|
+
}
|
|
5485
|
+
}
|
|
5486
|
+
} else {
|
|
5487
|
+
this.encodeNumberAsFloat(object);
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
encodeNumberAsFloat(object) {
|
|
5491
|
+
if (this.forceFloat32) {
|
|
5492
|
+
this.writeU8(202);
|
|
5493
|
+
this.writeF32(object);
|
|
5494
|
+
} else {
|
|
5495
|
+
this.writeU8(203);
|
|
5496
|
+
this.writeF64(object);
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5499
|
+
encodeBigInt64(object) {
|
|
5500
|
+
if (object >= BigInt(0)) {
|
|
5501
|
+
this.writeU8(207);
|
|
5502
|
+
this.writeBigUint64(object);
|
|
5503
|
+
} else {
|
|
5504
|
+
this.writeU8(211);
|
|
5505
|
+
this.writeBigInt64(object);
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
writeStringHeader(byteLength) {
|
|
5509
|
+
if (byteLength < 32) {
|
|
5510
|
+
this.writeU8(160 + byteLength);
|
|
5511
|
+
} else if (byteLength < 256) {
|
|
5512
|
+
this.writeU8(217);
|
|
5513
|
+
this.writeU8(byteLength);
|
|
5514
|
+
} else if (byteLength < 65536) {
|
|
5515
|
+
this.writeU8(218);
|
|
5516
|
+
this.writeU16(byteLength);
|
|
5517
|
+
} else if (byteLength < 4294967296) {
|
|
5518
|
+
this.writeU8(219);
|
|
5519
|
+
this.writeU32(byteLength);
|
|
5520
|
+
} else {
|
|
5521
|
+
throw new Error(`Too long string: ${byteLength} bytes in UTF-8`);
|
|
5522
|
+
}
|
|
5523
|
+
}
|
|
5524
|
+
encodeString(object) {
|
|
5525
|
+
const maxHeaderSize = 1 + 4;
|
|
5526
|
+
const byteLength = (0, utf8_ts_1.utf8Count)(object);
|
|
5527
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
5528
|
+
this.writeStringHeader(byteLength);
|
|
5529
|
+
(0, utf8_ts_1.utf8Encode)(object, this.bytes, this.pos);
|
|
5530
|
+
this.pos += byteLength;
|
|
5531
|
+
}
|
|
5532
|
+
encodeObject(object, depth) {
|
|
5533
|
+
const ext = this.extensionCodec.tryToEncode(object, this.context);
|
|
5534
|
+
if (ext != null) {
|
|
5535
|
+
this.encodeExtension(ext);
|
|
5536
|
+
} else if (Array.isArray(object)) {
|
|
5537
|
+
this.encodeArray(object, depth);
|
|
5538
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
5539
|
+
this.encodeBinary(object);
|
|
5540
|
+
} else if (typeof object === "object") {
|
|
5541
|
+
this.encodeMap(object, depth);
|
|
5542
|
+
} else {
|
|
5543
|
+
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`);
|
|
5544
|
+
}
|
|
5545
|
+
}
|
|
5546
|
+
encodeBinary(object) {
|
|
5547
|
+
const size2 = object.byteLength;
|
|
5548
|
+
if (size2 < 256) {
|
|
5549
|
+
this.writeU8(196);
|
|
5550
|
+
this.writeU8(size2);
|
|
5551
|
+
} else if (size2 < 65536) {
|
|
5552
|
+
this.writeU8(197);
|
|
5553
|
+
this.writeU16(size2);
|
|
5554
|
+
} else if (size2 < 4294967296) {
|
|
5555
|
+
this.writeU8(198);
|
|
5556
|
+
this.writeU32(size2);
|
|
5557
|
+
} else {
|
|
5558
|
+
throw new Error(`Too large binary: ${size2}`);
|
|
5559
|
+
}
|
|
5560
|
+
const bytes = (0, typedArrays_ts_1.ensureUint8Array)(object);
|
|
5561
|
+
this.writeU8a(bytes);
|
|
5562
|
+
}
|
|
5563
|
+
encodeArray(object, depth) {
|
|
5564
|
+
const size2 = object.length;
|
|
5565
|
+
if (size2 < 16) {
|
|
5566
|
+
this.writeU8(144 + size2);
|
|
5567
|
+
} else if (size2 < 65536) {
|
|
5568
|
+
this.writeU8(220);
|
|
5569
|
+
this.writeU16(size2);
|
|
5570
|
+
} else if (size2 < 4294967296) {
|
|
5571
|
+
this.writeU8(221);
|
|
5572
|
+
this.writeU32(size2);
|
|
5573
|
+
} else {
|
|
5574
|
+
throw new Error(`Too large array: ${size2}`);
|
|
5575
|
+
}
|
|
5576
|
+
for (const item of object) {
|
|
5577
|
+
this.doEncode(item, depth + 1);
|
|
5578
|
+
}
|
|
5579
|
+
}
|
|
5580
|
+
countWithoutUndefined(object, keys) {
|
|
5581
|
+
let count = 0;
|
|
5582
|
+
for (const key of keys) {
|
|
5583
|
+
if (object[key] !== void 0) {
|
|
5584
|
+
count++;
|
|
5585
|
+
}
|
|
5586
|
+
}
|
|
5587
|
+
return count;
|
|
5588
|
+
}
|
|
5589
|
+
encodeMap(object, depth) {
|
|
5590
|
+
const keys = Object.keys(object);
|
|
5591
|
+
if (this.sortKeys) {
|
|
5592
|
+
keys.sort();
|
|
5593
|
+
}
|
|
5594
|
+
const size2 = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
|
|
5595
|
+
if (size2 < 16) {
|
|
5596
|
+
this.writeU8(128 + size2);
|
|
5597
|
+
} else if (size2 < 65536) {
|
|
5598
|
+
this.writeU8(222);
|
|
5599
|
+
this.writeU16(size2);
|
|
5600
|
+
} else if (size2 < 4294967296) {
|
|
5601
|
+
this.writeU8(223);
|
|
5602
|
+
this.writeU32(size2);
|
|
5603
|
+
} else {
|
|
5604
|
+
throw new Error(`Too large map object: ${size2}`);
|
|
5605
|
+
}
|
|
5606
|
+
for (const key of keys) {
|
|
5607
|
+
const value = object[key];
|
|
5608
|
+
if (!(this.ignoreUndefined && value === void 0)) {
|
|
5609
|
+
this.encodeString(key);
|
|
5610
|
+
this.doEncode(value, depth + 1);
|
|
5611
|
+
}
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5614
|
+
encodeExtension(ext) {
|
|
5615
|
+
if (typeof ext.data === "function") {
|
|
5616
|
+
const data = ext.data(this.pos + 6);
|
|
5617
|
+
const size3 = data.length;
|
|
5618
|
+
if (size3 >= 4294967296) {
|
|
5619
|
+
throw new Error(`Too large extension object: ${size3}`);
|
|
5620
|
+
}
|
|
5621
|
+
this.writeU8(201);
|
|
5622
|
+
this.writeU32(size3);
|
|
5623
|
+
this.writeI8(ext.type);
|
|
5624
|
+
this.writeU8a(data);
|
|
5625
|
+
return;
|
|
5626
|
+
}
|
|
5627
|
+
const size2 = ext.data.length;
|
|
5628
|
+
if (size2 === 1) {
|
|
5629
|
+
this.writeU8(212);
|
|
5630
|
+
} else if (size2 === 2) {
|
|
5631
|
+
this.writeU8(213);
|
|
5632
|
+
} else if (size2 === 4) {
|
|
5633
|
+
this.writeU8(214);
|
|
5634
|
+
} else if (size2 === 8) {
|
|
5635
|
+
this.writeU8(215);
|
|
5636
|
+
} else if (size2 === 16) {
|
|
5637
|
+
this.writeU8(216);
|
|
5638
|
+
} else if (size2 < 256) {
|
|
5639
|
+
this.writeU8(199);
|
|
5640
|
+
this.writeU8(size2);
|
|
5641
|
+
} else if (size2 < 65536) {
|
|
5642
|
+
this.writeU8(200);
|
|
5643
|
+
this.writeU16(size2);
|
|
5644
|
+
} else if (size2 < 4294967296) {
|
|
5645
|
+
this.writeU8(201);
|
|
5646
|
+
this.writeU32(size2);
|
|
5647
|
+
} else {
|
|
5648
|
+
throw new Error(`Too large extension object: ${size2}`);
|
|
5649
|
+
}
|
|
5650
|
+
this.writeI8(ext.type);
|
|
5651
|
+
this.writeU8a(ext.data);
|
|
5652
|
+
}
|
|
5653
|
+
writeU8(value) {
|
|
5654
|
+
this.ensureBufferSizeToWrite(1);
|
|
5655
|
+
this.view.setUint8(this.pos, value);
|
|
5656
|
+
this.pos++;
|
|
5657
|
+
}
|
|
5658
|
+
writeU8a(values) {
|
|
5659
|
+
const size2 = values.length;
|
|
5660
|
+
this.ensureBufferSizeToWrite(size2);
|
|
5661
|
+
this.bytes.set(values, this.pos);
|
|
5662
|
+
this.pos += size2;
|
|
5663
|
+
}
|
|
5664
|
+
writeI8(value) {
|
|
5665
|
+
this.ensureBufferSizeToWrite(1);
|
|
5666
|
+
this.view.setInt8(this.pos, value);
|
|
5667
|
+
this.pos++;
|
|
5668
|
+
}
|
|
5669
|
+
writeU16(value) {
|
|
5670
|
+
this.ensureBufferSizeToWrite(2);
|
|
5671
|
+
this.view.setUint16(this.pos, value);
|
|
5672
|
+
this.pos += 2;
|
|
5673
|
+
}
|
|
5674
|
+
writeI16(value) {
|
|
5675
|
+
this.ensureBufferSizeToWrite(2);
|
|
5676
|
+
this.view.setInt16(this.pos, value);
|
|
5677
|
+
this.pos += 2;
|
|
5678
|
+
}
|
|
5679
|
+
writeU32(value) {
|
|
5680
|
+
this.ensureBufferSizeToWrite(4);
|
|
5681
|
+
this.view.setUint32(this.pos, value);
|
|
5682
|
+
this.pos += 4;
|
|
5683
|
+
}
|
|
5684
|
+
writeI32(value) {
|
|
5685
|
+
this.ensureBufferSizeToWrite(4);
|
|
5686
|
+
this.view.setInt32(this.pos, value);
|
|
5687
|
+
this.pos += 4;
|
|
5688
|
+
}
|
|
5689
|
+
writeF32(value) {
|
|
5690
|
+
this.ensureBufferSizeToWrite(4);
|
|
5691
|
+
this.view.setFloat32(this.pos, value);
|
|
5692
|
+
this.pos += 4;
|
|
5693
|
+
}
|
|
5694
|
+
writeF64(value) {
|
|
5695
|
+
this.ensureBufferSizeToWrite(8);
|
|
5696
|
+
this.view.setFloat64(this.pos, value);
|
|
5697
|
+
this.pos += 8;
|
|
5698
|
+
}
|
|
5699
|
+
writeU64(value) {
|
|
5700
|
+
this.ensureBufferSizeToWrite(8);
|
|
5701
|
+
(0, int_ts_1.setUint64)(this.view, this.pos, value);
|
|
5702
|
+
this.pos += 8;
|
|
5703
|
+
}
|
|
5704
|
+
writeI64(value) {
|
|
5705
|
+
this.ensureBufferSizeToWrite(8);
|
|
5706
|
+
(0, int_ts_1.setInt64)(this.view, this.pos, value);
|
|
5707
|
+
this.pos += 8;
|
|
5708
|
+
}
|
|
5709
|
+
writeBigUint64(value) {
|
|
5710
|
+
this.ensureBufferSizeToWrite(8);
|
|
5711
|
+
this.view.setBigUint64(this.pos, value);
|
|
5712
|
+
this.pos += 8;
|
|
5713
|
+
}
|
|
5714
|
+
writeBigInt64(value) {
|
|
5715
|
+
this.ensureBufferSizeToWrite(8);
|
|
5716
|
+
this.view.setBigInt64(this.pos, value);
|
|
5717
|
+
this.pos += 8;
|
|
5718
|
+
}
|
|
5719
|
+
};
|
|
5720
|
+
exports.Encoder = Encoder;
|
|
5721
|
+
}
|
|
5722
|
+
});
|
|
5723
|
+
|
|
5724
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/encode.cjs
|
|
5725
|
+
var require_encode = __commonJS({
|
|
5726
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/encode.cjs"(exports) {
|
|
5727
|
+
"use strict";
|
|
5728
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5729
|
+
exports.encode = encode;
|
|
5730
|
+
var Encoder_ts_1 = require_Encoder();
|
|
5731
|
+
function encode(value, options) {
|
|
5732
|
+
const encoder3 = new Encoder_ts_1.Encoder(options);
|
|
5733
|
+
return encoder3.encodeSharedRef(value);
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5736
|
+
});
|
|
5737
|
+
|
|
5738
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/utils/prettyByte.cjs
|
|
5739
|
+
var require_prettyByte = __commonJS({
|
|
5740
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/utils/prettyByte.cjs"(exports) {
|
|
5741
|
+
"use strict";
|
|
5742
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5743
|
+
exports.prettyByte = prettyByte;
|
|
5744
|
+
function prettyByte(byte) {
|
|
5745
|
+
return `${byte < 0 ? "-" : ""}0x${Math.abs(byte).toString(16).padStart(2, "0")}`;
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5748
|
+
});
|
|
5749
|
+
|
|
5750
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/CachedKeyDecoder.cjs
|
|
5751
|
+
var require_CachedKeyDecoder = __commonJS({
|
|
5752
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/CachedKeyDecoder.cjs"(exports) {
|
|
5753
|
+
"use strict";
|
|
5754
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5755
|
+
exports.CachedKeyDecoder = void 0;
|
|
5756
|
+
var utf8_ts_1 = require_utf8();
|
|
5757
|
+
var DEFAULT_MAX_KEY_LENGTH = 16;
|
|
5758
|
+
var DEFAULT_MAX_LENGTH_PER_KEY = 16;
|
|
5759
|
+
var CachedKeyDecoder = class {
|
|
5760
|
+
hit = 0;
|
|
5761
|
+
miss = 0;
|
|
5762
|
+
caches;
|
|
5763
|
+
maxKeyLength;
|
|
5764
|
+
maxLengthPerKey;
|
|
5765
|
+
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
|
|
5766
|
+
this.maxKeyLength = maxKeyLength;
|
|
5767
|
+
this.maxLengthPerKey = maxLengthPerKey;
|
|
5768
|
+
this.caches = [];
|
|
5769
|
+
for (let i = 0; i < this.maxKeyLength; i++) {
|
|
5770
|
+
this.caches.push([]);
|
|
5771
|
+
}
|
|
5772
|
+
}
|
|
5773
|
+
canBeCached(byteLength) {
|
|
5774
|
+
return byteLength > 0 && byteLength <= this.maxKeyLength;
|
|
5775
|
+
}
|
|
5776
|
+
find(bytes, inputOffset, byteLength) {
|
|
5777
|
+
const records = this.caches[byteLength - 1];
|
|
5778
|
+
FIND_CHUNK: for (const record of records) {
|
|
5779
|
+
const recordBytes = record.bytes;
|
|
5780
|
+
for (let j = 0; j < byteLength; j++) {
|
|
5781
|
+
if (recordBytes[j] !== bytes[inputOffset + j]) {
|
|
5782
|
+
continue FIND_CHUNK;
|
|
5783
|
+
}
|
|
5784
|
+
}
|
|
5785
|
+
return record.str;
|
|
5786
|
+
}
|
|
5787
|
+
return null;
|
|
5788
|
+
}
|
|
5789
|
+
store(bytes, value) {
|
|
5790
|
+
const records = this.caches[bytes.length - 1];
|
|
5791
|
+
const record = { bytes, str: value };
|
|
5792
|
+
if (records.length >= this.maxLengthPerKey) {
|
|
5793
|
+
records[Math.random() * records.length | 0] = record;
|
|
5794
|
+
} else {
|
|
5795
|
+
records.push(record);
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
decode(bytes, inputOffset, byteLength) {
|
|
5799
|
+
const cachedValue = this.find(bytes, inputOffset, byteLength);
|
|
5800
|
+
if (cachedValue != null) {
|
|
5801
|
+
this.hit++;
|
|
5802
|
+
return cachedValue;
|
|
5803
|
+
}
|
|
5804
|
+
this.miss++;
|
|
5805
|
+
const str2 = (0, utf8_ts_1.utf8DecodeJs)(bytes, inputOffset, byteLength);
|
|
5806
|
+
const slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
|
|
5807
|
+
this.store(slicedCopyOfBytes, str2);
|
|
5808
|
+
return str2;
|
|
5809
|
+
}
|
|
5810
|
+
};
|
|
5811
|
+
exports.CachedKeyDecoder = CachedKeyDecoder;
|
|
5812
|
+
}
|
|
5813
|
+
});
|
|
5814
|
+
|
|
5815
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/Decoder.cjs
|
|
5816
|
+
var require_Decoder = __commonJS({
|
|
5817
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/Decoder.cjs"(exports) {
|
|
5818
|
+
"use strict";
|
|
5819
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5820
|
+
exports.Decoder = void 0;
|
|
5821
|
+
var prettyByte_ts_1 = require_prettyByte();
|
|
5822
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
5823
|
+
var int_ts_1 = require_int();
|
|
5824
|
+
var utf8_ts_1 = require_utf8();
|
|
5825
|
+
var typedArrays_ts_1 = require_typedArrays();
|
|
5826
|
+
var CachedKeyDecoder_ts_1 = require_CachedKeyDecoder();
|
|
5827
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
5828
|
+
var STATE_ARRAY = "array";
|
|
5829
|
+
var STATE_MAP_KEY = "map_key";
|
|
5830
|
+
var STATE_MAP_VALUE = "map_value";
|
|
5831
|
+
var mapKeyConverter = (key) => {
|
|
5832
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
5833
|
+
return key;
|
|
5834
|
+
}
|
|
5835
|
+
throw new DecodeError_ts_1.DecodeError("The type of key must be string or number but " + typeof key);
|
|
5836
|
+
};
|
|
5837
|
+
var StackPool = class {
|
|
5838
|
+
stack = [];
|
|
5839
|
+
stackHeadPosition = -1;
|
|
5840
|
+
get length() {
|
|
5841
|
+
return this.stackHeadPosition + 1;
|
|
5842
|
+
}
|
|
5843
|
+
top() {
|
|
5844
|
+
return this.stack[this.stackHeadPosition];
|
|
5845
|
+
}
|
|
5846
|
+
pushArrayState(size2) {
|
|
5847
|
+
const state = this.getUninitializedStateFromPool();
|
|
5848
|
+
state.type = STATE_ARRAY;
|
|
5849
|
+
state.position = 0;
|
|
5850
|
+
state.size = size2;
|
|
5851
|
+
state.array = new Array(size2);
|
|
5852
|
+
}
|
|
5853
|
+
pushMapState(size2) {
|
|
5854
|
+
const state = this.getUninitializedStateFromPool();
|
|
5855
|
+
state.type = STATE_MAP_KEY;
|
|
5856
|
+
state.readCount = 0;
|
|
5857
|
+
state.size = size2;
|
|
5858
|
+
state.map = {};
|
|
5859
|
+
}
|
|
5860
|
+
getUninitializedStateFromPool() {
|
|
5861
|
+
this.stackHeadPosition++;
|
|
5862
|
+
if (this.stackHeadPosition === this.stack.length) {
|
|
5863
|
+
const partialState = {
|
|
5864
|
+
type: void 0,
|
|
5865
|
+
size: 0,
|
|
5866
|
+
array: void 0,
|
|
5867
|
+
position: 0,
|
|
5868
|
+
readCount: 0,
|
|
5869
|
+
map: void 0,
|
|
5870
|
+
key: null
|
|
5871
|
+
};
|
|
5872
|
+
this.stack.push(partialState);
|
|
5873
|
+
}
|
|
5874
|
+
return this.stack[this.stackHeadPosition];
|
|
5875
|
+
}
|
|
5876
|
+
release(state) {
|
|
5877
|
+
const topStackState = this.stack[this.stackHeadPosition];
|
|
5878
|
+
if (topStackState !== state) {
|
|
5879
|
+
throw new Error("Invalid stack state. Released state is not on top of the stack.");
|
|
5880
|
+
}
|
|
5881
|
+
if (state.type === STATE_ARRAY) {
|
|
5882
|
+
const partialState = state;
|
|
5883
|
+
partialState.size = 0;
|
|
5884
|
+
partialState.array = void 0;
|
|
5885
|
+
partialState.position = 0;
|
|
5886
|
+
partialState.type = void 0;
|
|
5887
|
+
}
|
|
5888
|
+
if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) {
|
|
5889
|
+
const partialState = state;
|
|
5890
|
+
partialState.size = 0;
|
|
5891
|
+
partialState.map = void 0;
|
|
5892
|
+
partialState.readCount = 0;
|
|
5893
|
+
partialState.type = void 0;
|
|
5894
|
+
}
|
|
5895
|
+
this.stackHeadPosition--;
|
|
5896
|
+
}
|
|
5897
|
+
reset() {
|
|
5898
|
+
this.stack.length = 0;
|
|
5899
|
+
this.stackHeadPosition = -1;
|
|
5900
|
+
}
|
|
5901
|
+
};
|
|
5902
|
+
var HEAD_BYTE_REQUIRED = -1;
|
|
5903
|
+
var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
5904
|
+
var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
|
|
5905
|
+
try {
|
|
5906
|
+
EMPTY_VIEW.getInt8(0);
|
|
5907
|
+
} catch (e) {
|
|
5908
|
+
if (!(e instanceof RangeError)) {
|
|
5909
|
+
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
5910
|
+
}
|
|
5911
|
+
}
|
|
5912
|
+
var MORE_DATA = new RangeError("Insufficient data");
|
|
5913
|
+
var sharedCachedKeyDecoder = new CachedKeyDecoder_ts_1.CachedKeyDecoder();
|
|
5914
|
+
var Decoder = class _Decoder {
|
|
5915
|
+
extensionCodec;
|
|
5916
|
+
context;
|
|
5917
|
+
useBigInt64;
|
|
5918
|
+
rawStrings;
|
|
5919
|
+
maxStrLength;
|
|
5920
|
+
maxBinLength;
|
|
5921
|
+
maxArrayLength;
|
|
5922
|
+
maxMapLength;
|
|
5923
|
+
maxExtLength;
|
|
5924
|
+
keyDecoder;
|
|
5925
|
+
mapKeyConverter;
|
|
5926
|
+
totalPos = 0;
|
|
5927
|
+
pos = 0;
|
|
5928
|
+
view = EMPTY_VIEW;
|
|
5929
|
+
bytes = EMPTY_BYTES;
|
|
5930
|
+
headByte = HEAD_BYTE_REQUIRED;
|
|
5931
|
+
stack = new StackPool();
|
|
5932
|
+
entered = false;
|
|
5933
|
+
constructor(options) {
|
|
5934
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec_ts_1.ExtensionCodec.defaultCodec;
|
|
5935
|
+
this.context = options?.context;
|
|
5936
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
5937
|
+
this.rawStrings = options?.rawStrings ?? false;
|
|
5938
|
+
this.maxStrLength = options?.maxStrLength ?? int_ts_1.UINT32_MAX;
|
|
5939
|
+
this.maxBinLength = options?.maxBinLength ?? int_ts_1.UINT32_MAX;
|
|
5940
|
+
this.maxArrayLength = options?.maxArrayLength ?? int_ts_1.UINT32_MAX;
|
|
5941
|
+
this.maxMapLength = options?.maxMapLength ?? int_ts_1.UINT32_MAX;
|
|
5942
|
+
this.maxExtLength = options?.maxExtLength ?? int_ts_1.UINT32_MAX;
|
|
5943
|
+
this.keyDecoder = options?.keyDecoder !== void 0 ? options.keyDecoder : sharedCachedKeyDecoder;
|
|
5944
|
+
this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter;
|
|
5945
|
+
}
|
|
5946
|
+
clone() {
|
|
5947
|
+
return new _Decoder({
|
|
5948
|
+
extensionCodec: this.extensionCodec,
|
|
5949
|
+
context: this.context,
|
|
5950
|
+
useBigInt64: this.useBigInt64,
|
|
5951
|
+
rawStrings: this.rawStrings,
|
|
5952
|
+
maxStrLength: this.maxStrLength,
|
|
5953
|
+
maxBinLength: this.maxBinLength,
|
|
5954
|
+
maxArrayLength: this.maxArrayLength,
|
|
5955
|
+
maxMapLength: this.maxMapLength,
|
|
5956
|
+
maxExtLength: this.maxExtLength,
|
|
5957
|
+
keyDecoder: this.keyDecoder
|
|
5958
|
+
});
|
|
5959
|
+
}
|
|
5960
|
+
reinitializeState() {
|
|
5961
|
+
this.totalPos = 0;
|
|
5962
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
5963
|
+
this.stack.reset();
|
|
5964
|
+
}
|
|
5965
|
+
setBuffer(buffer) {
|
|
5966
|
+
const bytes = (0, typedArrays_ts_1.ensureUint8Array)(buffer);
|
|
5967
|
+
this.bytes = bytes;
|
|
5968
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
5969
|
+
this.pos = 0;
|
|
5970
|
+
}
|
|
5971
|
+
appendBuffer(buffer) {
|
|
5972
|
+
if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
|
|
5973
|
+
this.setBuffer(buffer);
|
|
5974
|
+
} else {
|
|
5975
|
+
const remainingData = this.bytes.subarray(this.pos);
|
|
5976
|
+
const newData = (0, typedArrays_ts_1.ensureUint8Array)(buffer);
|
|
5977
|
+
const newBuffer = new Uint8Array(remainingData.length + newData.length);
|
|
5978
|
+
newBuffer.set(remainingData);
|
|
5979
|
+
newBuffer.set(newData, remainingData.length);
|
|
5980
|
+
this.setBuffer(newBuffer);
|
|
5981
|
+
}
|
|
5982
|
+
}
|
|
5983
|
+
hasRemaining(size2) {
|
|
5984
|
+
return this.view.byteLength - this.pos >= size2;
|
|
5985
|
+
}
|
|
5986
|
+
createExtraByteError(posToShow) {
|
|
5987
|
+
const { view, pos } = this;
|
|
5988
|
+
return new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`);
|
|
5989
|
+
}
|
|
5990
|
+
/**
|
|
5991
|
+
* @throws {@link DecodeError}
|
|
5992
|
+
* @throws {@link RangeError}
|
|
5993
|
+
*/
|
|
5994
|
+
decode(buffer) {
|
|
5995
|
+
if (this.entered) {
|
|
5996
|
+
const instance = this.clone();
|
|
5997
|
+
return instance.decode(buffer);
|
|
5998
|
+
}
|
|
5999
|
+
try {
|
|
6000
|
+
this.entered = true;
|
|
6001
|
+
this.reinitializeState();
|
|
6002
|
+
this.setBuffer(buffer);
|
|
6003
|
+
const object = this.doDecodeSync();
|
|
6004
|
+
if (this.hasRemaining(1)) {
|
|
6005
|
+
throw this.createExtraByteError(this.pos);
|
|
6006
|
+
}
|
|
6007
|
+
return object;
|
|
6008
|
+
} finally {
|
|
6009
|
+
this.entered = false;
|
|
6010
|
+
}
|
|
6011
|
+
}
|
|
6012
|
+
*decodeMulti(buffer) {
|
|
6013
|
+
if (this.entered) {
|
|
6014
|
+
const instance = this.clone();
|
|
6015
|
+
yield* instance.decodeMulti(buffer);
|
|
6016
|
+
return;
|
|
6017
|
+
}
|
|
6018
|
+
try {
|
|
6019
|
+
this.entered = true;
|
|
6020
|
+
this.reinitializeState();
|
|
6021
|
+
this.setBuffer(buffer);
|
|
6022
|
+
while (this.hasRemaining(1)) {
|
|
6023
|
+
yield this.doDecodeSync();
|
|
6024
|
+
}
|
|
6025
|
+
} finally {
|
|
6026
|
+
this.entered = false;
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
6029
|
+
async decodeAsync(stream) {
|
|
6030
|
+
if (this.entered) {
|
|
6031
|
+
const instance = this.clone();
|
|
6032
|
+
return instance.decodeAsync(stream);
|
|
6033
|
+
}
|
|
6034
|
+
try {
|
|
6035
|
+
this.entered = true;
|
|
6036
|
+
let decoded = false;
|
|
6037
|
+
let object;
|
|
6038
|
+
for await (const buffer of stream) {
|
|
6039
|
+
if (decoded) {
|
|
6040
|
+
this.entered = false;
|
|
6041
|
+
throw this.createExtraByteError(this.totalPos);
|
|
6042
|
+
}
|
|
6043
|
+
this.appendBuffer(buffer);
|
|
6044
|
+
try {
|
|
6045
|
+
object = this.doDecodeSync();
|
|
6046
|
+
decoded = true;
|
|
6047
|
+
} catch (e) {
|
|
6048
|
+
if (!(e instanceof RangeError)) {
|
|
6049
|
+
throw e;
|
|
6050
|
+
}
|
|
6051
|
+
}
|
|
6052
|
+
this.totalPos += this.pos;
|
|
6053
|
+
}
|
|
6054
|
+
if (decoded) {
|
|
6055
|
+
if (this.hasRemaining(1)) {
|
|
6056
|
+
throw this.createExtraByteError(this.totalPos);
|
|
6057
|
+
}
|
|
6058
|
+
return object;
|
|
6059
|
+
}
|
|
6060
|
+
const { headByte, pos, totalPos } = this;
|
|
6061
|
+
throw new RangeError(`Insufficient data in parsing ${(0, prettyByte_ts_1.prettyByte)(headByte)} at ${totalPos} (${pos} in the current buffer)`);
|
|
6062
|
+
} finally {
|
|
6063
|
+
this.entered = false;
|
|
6064
|
+
}
|
|
6065
|
+
}
|
|
6066
|
+
decodeArrayStream(stream) {
|
|
6067
|
+
return this.decodeMultiAsync(stream, true);
|
|
6068
|
+
}
|
|
6069
|
+
decodeStream(stream) {
|
|
6070
|
+
return this.decodeMultiAsync(stream, false);
|
|
6071
|
+
}
|
|
6072
|
+
async *decodeMultiAsync(stream, isArray) {
|
|
6073
|
+
if (this.entered) {
|
|
6074
|
+
const instance = this.clone();
|
|
6075
|
+
yield* instance.decodeMultiAsync(stream, isArray);
|
|
6076
|
+
return;
|
|
6077
|
+
}
|
|
6078
|
+
try {
|
|
6079
|
+
this.entered = true;
|
|
6080
|
+
let isArrayHeaderRequired = isArray;
|
|
6081
|
+
let arrayItemsLeft = -1;
|
|
6082
|
+
for await (const buffer of stream) {
|
|
6083
|
+
if (isArray && arrayItemsLeft === 0) {
|
|
6084
|
+
throw this.createExtraByteError(this.totalPos);
|
|
6085
|
+
}
|
|
6086
|
+
this.appendBuffer(buffer);
|
|
6087
|
+
if (isArrayHeaderRequired) {
|
|
6088
|
+
arrayItemsLeft = this.readArraySize();
|
|
6089
|
+
isArrayHeaderRequired = false;
|
|
6090
|
+
this.complete();
|
|
6091
|
+
}
|
|
6092
|
+
try {
|
|
6093
|
+
while (true) {
|
|
6094
|
+
yield this.doDecodeSync();
|
|
6095
|
+
if (--arrayItemsLeft === 0) {
|
|
6096
|
+
break;
|
|
6097
|
+
}
|
|
6098
|
+
}
|
|
6099
|
+
} catch (e) {
|
|
6100
|
+
if (!(e instanceof RangeError)) {
|
|
6101
|
+
throw e;
|
|
6102
|
+
}
|
|
6103
|
+
}
|
|
6104
|
+
this.totalPos += this.pos;
|
|
6105
|
+
}
|
|
6106
|
+
} finally {
|
|
6107
|
+
this.entered = false;
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
6110
|
+
doDecodeSync() {
|
|
6111
|
+
DECODE: while (true) {
|
|
6112
|
+
const headByte = this.readHeadByte();
|
|
6113
|
+
let object;
|
|
6114
|
+
if (headByte >= 224) {
|
|
6115
|
+
object = headByte - 256;
|
|
6116
|
+
} else if (headByte < 192) {
|
|
6117
|
+
if (headByte < 128) {
|
|
6118
|
+
object = headByte;
|
|
6119
|
+
} else if (headByte < 144) {
|
|
6120
|
+
const size2 = headByte - 128;
|
|
6121
|
+
if (size2 !== 0) {
|
|
6122
|
+
this.pushMapState(size2);
|
|
6123
|
+
this.complete();
|
|
6124
|
+
continue DECODE;
|
|
6125
|
+
} else {
|
|
6126
|
+
object = {};
|
|
6127
|
+
}
|
|
6128
|
+
} else if (headByte < 160) {
|
|
6129
|
+
const size2 = headByte - 144;
|
|
6130
|
+
if (size2 !== 0) {
|
|
6131
|
+
this.pushArrayState(size2);
|
|
6132
|
+
this.complete();
|
|
6133
|
+
continue DECODE;
|
|
6134
|
+
} else {
|
|
6135
|
+
object = [];
|
|
6136
|
+
}
|
|
6137
|
+
} else {
|
|
6138
|
+
const byteLength = headByte - 160;
|
|
6139
|
+
object = this.decodeString(byteLength, 0);
|
|
6140
|
+
}
|
|
6141
|
+
} else if (headByte === 192) {
|
|
6142
|
+
object = null;
|
|
6143
|
+
} else if (headByte === 194) {
|
|
6144
|
+
object = false;
|
|
6145
|
+
} else if (headByte === 195) {
|
|
6146
|
+
object = true;
|
|
6147
|
+
} else if (headByte === 202) {
|
|
6148
|
+
object = this.readF32();
|
|
6149
|
+
} else if (headByte === 203) {
|
|
6150
|
+
object = this.readF64();
|
|
6151
|
+
} else if (headByte === 204) {
|
|
6152
|
+
object = this.readU8();
|
|
6153
|
+
} else if (headByte === 205) {
|
|
6154
|
+
object = this.readU16();
|
|
6155
|
+
} else if (headByte === 206) {
|
|
6156
|
+
object = this.readU32();
|
|
6157
|
+
} else if (headByte === 207) {
|
|
6158
|
+
if (this.useBigInt64) {
|
|
6159
|
+
object = this.readU64AsBigInt();
|
|
6160
|
+
} else {
|
|
6161
|
+
object = this.readU64();
|
|
6162
|
+
}
|
|
6163
|
+
} else if (headByte === 208) {
|
|
6164
|
+
object = this.readI8();
|
|
6165
|
+
} else if (headByte === 209) {
|
|
6166
|
+
object = this.readI16();
|
|
6167
|
+
} else if (headByte === 210) {
|
|
6168
|
+
object = this.readI32();
|
|
6169
|
+
} else if (headByte === 211) {
|
|
6170
|
+
if (this.useBigInt64) {
|
|
6171
|
+
object = this.readI64AsBigInt();
|
|
6172
|
+
} else {
|
|
6173
|
+
object = this.readI64();
|
|
6174
|
+
}
|
|
6175
|
+
} else if (headByte === 217) {
|
|
6176
|
+
const byteLength = this.lookU8();
|
|
6177
|
+
object = this.decodeString(byteLength, 1);
|
|
6178
|
+
} else if (headByte === 218) {
|
|
6179
|
+
const byteLength = this.lookU16();
|
|
6180
|
+
object = this.decodeString(byteLength, 2);
|
|
6181
|
+
} else if (headByte === 219) {
|
|
6182
|
+
const byteLength = this.lookU32();
|
|
6183
|
+
object = this.decodeString(byteLength, 4);
|
|
6184
|
+
} else if (headByte === 220) {
|
|
6185
|
+
const size2 = this.readU16();
|
|
6186
|
+
if (size2 !== 0) {
|
|
6187
|
+
this.pushArrayState(size2);
|
|
6188
|
+
this.complete();
|
|
6189
|
+
continue DECODE;
|
|
6190
|
+
} else {
|
|
6191
|
+
object = [];
|
|
6192
|
+
}
|
|
6193
|
+
} else if (headByte === 221) {
|
|
6194
|
+
const size2 = this.readU32();
|
|
6195
|
+
if (size2 !== 0) {
|
|
6196
|
+
this.pushArrayState(size2);
|
|
6197
|
+
this.complete();
|
|
6198
|
+
continue DECODE;
|
|
6199
|
+
} else {
|
|
6200
|
+
object = [];
|
|
6201
|
+
}
|
|
6202
|
+
} else if (headByte === 222) {
|
|
6203
|
+
const size2 = this.readU16();
|
|
6204
|
+
if (size2 !== 0) {
|
|
6205
|
+
this.pushMapState(size2);
|
|
6206
|
+
this.complete();
|
|
6207
|
+
continue DECODE;
|
|
6208
|
+
} else {
|
|
6209
|
+
object = {};
|
|
6210
|
+
}
|
|
6211
|
+
} else if (headByte === 223) {
|
|
6212
|
+
const size2 = this.readU32();
|
|
6213
|
+
if (size2 !== 0) {
|
|
6214
|
+
this.pushMapState(size2);
|
|
6215
|
+
this.complete();
|
|
6216
|
+
continue DECODE;
|
|
6217
|
+
} else {
|
|
6218
|
+
object = {};
|
|
6219
|
+
}
|
|
6220
|
+
} else if (headByte === 196) {
|
|
6221
|
+
const size2 = this.lookU8();
|
|
6222
|
+
object = this.decodeBinary(size2, 1);
|
|
6223
|
+
} else if (headByte === 197) {
|
|
6224
|
+
const size2 = this.lookU16();
|
|
6225
|
+
object = this.decodeBinary(size2, 2);
|
|
6226
|
+
} else if (headByte === 198) {
|
|
6227
|
+
const size2 = this.lookU32();
|
|
6228
|
+
object = this.decodeBinary(size2, 4);
|
|
6229
|
+
} else if (headByte === 212) {
|
|
6230
|
+
object = this.decodeExtension(1, 0);
|
|
6231
|
+
} else if (headByte === 213) {
|
|
6232
|
+
object = this.decodeExtension(2, 0);
|
|
6233
|
+
} else if (headByte === 214) {
|
|
6234
|
+
object = this.decodeExtension(4, 0);
|
|
6235
|
+
} else if (headByte === 215) {
|
|
6236
|
+
object = this.decodeExtension(8, 0);
|
|
6237
|
+
} else if (headByte === 216) {
|
|
6238
|
+
object = this.decodeExtension(16, 0);
|
|
6239
|
+
} else if (headByte === 199) {
|
|
6240
|
+
const size2 = this.lookU8();
|
|
6241
|
+
object = this.decodeExtension(size2, 1);
|
|
6242
|
+
} else if (headByte === 200) {
|
|
6243
|
+
const size2 = this.lookU16();
|
|
6244
|
+
object = this.decodeExtension(size2, 2);
|
|
6245
|
+
} else if (headByte === 201) {
|
|
6246
|
+
const size2 = this.lookU32();
|
|
6247
|
+
object = this.decodeExtension(size2, 4);
|
|
6248
|
+
} else {
|
|
6249
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`);
|
|
6250
|
+
}
|
|
6251
|
+
this.complete();
|
|
6252
|
+
const stack = this.stack;
|
|
6253
|
+
while (stack.length > 0) {
|
|
6254
|
+
const state = stack.top();
|
|
6255
|
+
if (state.type === STATE_ARRAY) {
|
|
6256
|
+
state.array[state.position] = object;
|
|
6257
|
+
state.position++;
|
|
6258
|
+
if (state.position === state.size) {
|
|
6259
|
+
object = state.array;
|
|
6260
|
+
stack.release(state);
|
|
6261
|
+
} else {
|
|
6262
|
+
continue DECODE;
|
|
6263
|
+
}
|
|
6264
|
+
} else if (state.type === STATE_MAP_KEY) {
|
|
6265
|
+
if (object === "__proto__") {
|
|
6266
|
+
throw new DecodeError_ts_1.DecodeError("The key __proto__ is not allowed");
|
|
6267
|
+
}
|
|
6268
|
+
state.key = this.mapKeyConverter(object);
|
|
6269
|
+
state.type = STATE_MAP_VALUE;
|
|
6270
|
+
continue DECODE;
|
|
6271
|
+
} else {
|
|
6272
|
+
state.map[state.key] = object;
|
|
6273
|
+
state.readCount++;
|
|
6274
|
+
if (state.readCount === state.size) {
|
|
6275
|
+
object = state.map;
|
|
6276
|
+
stack.release(state);
|
|
6277
|
+
} else {
|
|
6278
|
+
state.key = null;
|
|
6279
|
+
state.type = STATE_MAP_KEY;
|
|
6280
|
+
continue DECODE;
|
|
6281
|
+
}
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
return object;
|
|
6285
|
+
}
|
|
6286
|
+
}
|
|
6287
|
+
readHeadByte() {
|
|
6288
|
+
if (this.headByte === HEAD_BYTE_REQUIRED) {
|
|
6289
|
+
this.headByte = this.readU8();
|
|
6290
|
+
}
|
|
6291
|
+
return this.headByte;
|
|
6292
|
+
}
|
|
6293
|
+
complete() {
|
|
6294
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
6295
|
+
}
|
|
6296
|
+
readArraySize() {
|
|
6297
|
+
const headByte = this.readHeadByte();
|
|
6298
|
+
switch (headByte) {
|
|
6299
|
+
case 220:
|
|
6300
|
+
return this.readU16();
|
|
6301
|
+
case 221:
|
|
6302
|
+
return this.readU32();
|
|
6303
|
+
default: {
|
|
6304
|
+
if (headByte < 160) {
|
|
6305
|
+
return headByte - 144;
|
|
6306
|
+
} else {
|
|
6307
|
+
throw new DecodeError_ts_1.DecodeError(`Unrecognized array type byte: ${(0, prettyByte_ts_1.prettyByte)(headByte)}`);
|
|
6308
|
+
}
|
|
6309
|
+
}
|
|
6310
|
+
}
|
|
6311
|
+
}
|
|
6312
|
+
pushMapState(size2) {
|
|
6313
|
+
if (size2 > this.maxMapLength) {
|
|
6314
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: map length (${size2}) > maxMapLengthLength (${this.maxMapLength})`);
|
|
6315
|
+
}
|
|
6316
|
+
this.stack.pushMapState(size2);
|
|
6317
|
+
}
|
|
6318
|
+
pushArrayState(size2) {
|
|
6319
|
+
if (size2 > this.maxArrayLength) {
|
|
6320
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: array length (${size2}) > maxArrayLength (${this.maxArrayLength})`);
|
|
6321
|
+
}
|
|
6322
|
+
this.stack.pushArrayState(size2);
|
|
6323
|
+
}
|
|
6324
|
+
decodeString(byteLength, headerOffset) {
|
|
6325
|
+
if (!this.rawStrings || this.stateIsMapKey()) {
|
|
6326
|
+
return this.decodeUtf8String(byteLength, headerOffset);
|
|
6327
|
+
}
|
|
6328
|
+
return this.decodeBinary(byteLength, headerOffset);
|
|
6329
|
+
}
|
|
6330
|
+
/**
|
|
6331
|
+
* @throws {@link RangeError}
|
|
6332
|
+
*/
|
|
6333
|
+
decodeUtf8String(byteLength, headerOffset) {
|
|
6334
|
+
if (byteLength > this.maxStrLength) {
|
|
6335
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: UTF-8 byte length (${byteLength}) > maxStrLength (${this.maxStrLength})`);
|
|
6336
|
+
}
|
|
6337
|
+
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
|
|
6338
|
+
throw MORE_DATA;
|
|
6339
|
+
}
|
|
6340
|
+
const offset = this.pos + headerOffset;
|
|
6341
|
+
let object;
|
|
6342
|
+
if (this.stateIsMapKey() && this.keyDecoder?.canBeCached(byteLength)) {
|
|
6343
|
+
object = this.keyDecoder.decode(this.bytes, offset, byteLength);
|
|
6344
|
+
} else {
|
|
6345
|
+
object = (0, utf8_ts_1.utf8Decode)(this.bytes, offset, byteLength);
|
|
6346
|
+
}
|
|
6347
|
+
this.pos += headerOffset + byteLength;
|
|
6348
|
+
return object;
|
|
6349
|
+
}
|
|
6350
|
+
stateIsMapKey() {
|
|
6351
|
+
if (this.stack.length > 0) {
|
|
6352
|
+
const state = this.stack.top();
|
|
6353
|
+
return state.type === STATE_MAP_KEY;
|
|
6354
|
+
}
|
|
6355
|
+
return false;
|
|
6356
|
+
}
|
|
6357
|
+
/**
|
|
6358
|
+
* @throws {@link RangeError}
|
|
6359
|
+
*/
|
|
6360
|
+
decodeBinary(byteLength, headOffset) {
|
|
6361
|
+
if (byteLength > this.maxBinLength) {
|
|
6362
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);
|
|
6363
|
+
}
|
|
6364
|
+
if (!this.hasRemaining(byteLength + headOffset)) {
|
|
6365
|
+
throw MORE_DATA;
|
|
6366
|
+
}
|
|
6367
|
+
const offset = this.pos + headOffset;
|
|
6368
|
+
const object = this.bytes.subarray(offset, offset + byteLength);
|
|
6369
|
+
this.pos += headOffset + byteLength;
|
|
6370
|
+
return object;
|
|
6371
|
+
}
|
|
6372
|
+
decodeExtension(size2, headOffset) {
|
|
6373
|
+
if (size2 > this.maxExtLength) {
|
|
6374
|
+
throw new DecodeError_ts_1.DecodeError(`Max length exceeded: ext length (${size2}) > maxExtLength (${this.maxExtLength})`);
|
|
6375
|
+
}
|
|
6376
|
+
const extType = this.view.getInt8(this.pos + headOffset);
|
|
6377
|
+
const data = this.decodeBinary(
|
|
6378
|
+
size2,
|
|
6379
|
+
headOffset + 1
|
|
6380
|
+
/* extType */
|
|
6381
|
+
);
|
|
6382
|
+
return this.extensionCodec.decode(data, extType, this.context);
|
|
6383
|
+
}
|
|
6384
|
+
lookU8() {
|
|
6385
|
+
return this.view.getUint8(this.pos);
|
|
6386
|
+
}
|
|
6387
|
+
lookU16() {
|
|
6388
|
+
return this.view.getUint16(this.pos);
|
|
6389
|
+
}
|
|
6390
|
+
lookU32() {
|
|
6391
|
+
return this.view.getUint32(this.pos);
|
|
6392
|
+
}
|
|
6393
|
+
readU8() {
|
|
6394
|
+
const value = this.view.getUint8(this.pos);
|
|
6395
|
+
this.pos++;
|
|
6396
|
+
return value;
|
|
6397
|
+
}
|
|
6398
|
+
readI8() {
|
|
6399
|
+
const value = this.view.getInt8(this.pos);
|
|
6400
|
+
this.pos++;
|
|
6401
|
+
return value;
|
|
6402
|
+
}
|
|
6403
|
+
readU16() {
|
|
6404
|
+
const value = this.view.getUint16(this.pos);
|
|
6405
|
+
this.pos += 2;
|
|
6406
|
+
return value;
|
|
6407
|
+
}
|
|
6408
|
+
readI16() {
|
|
6409
|
+
const value = this.view.getInt16(this.pos);
|
|
6410
|
+
this.pos += 2;
|
|
6411
|
+
return value;
|
|
6412
|
+
}
|
|
6413
|
+
readU32() {
|
|
6414
|
+
const value = this.view.getUint32(this.pos);
|
|
6415
|
+
this.pos += 4;
|
|
6416
|
+
return value;
|
|
6417
|
+
}
|
|
6418
|
+
readI32() {
|
|
6419
|
+
const value = this.view.getInt32(this.pos);
|
|
6420
|
+
this.pos += 4;
|
|
6421
|
+
return value;
|
|
6422
|
+
}
|
|
6423
|
+
readU64() {
|
|
6424
|
+
const value = (0, int_ts_1.getUint64)(this.view, this.pos);
|
|
6425
|
+
this.pos += 8;
|
|
6426
|
+
return value;
|
|
6427
|
+
}
|
|
6428
|
+
readI64() {
|
|
6429
|
+
const value = (0, int_ts_1.getInt64)(this.view, this.pos);
|
|
6430
|
+
this.pos += 8;
|
|
6431
|
+
return value;
|
|
6432
|
+
}
|
|
6433
|
+
readU64AsBigInt() {
|
|
6434
|
+
const value = this.view.getBigUint64(this.pos);
|
|
6435
|
+
this.pos += 8;
|
|
6436
|
+
return value;
|
|
6437
|
+
}
|
|
6438
|
+
readI64AsBigInt() {
|
|
6439
|
+
const value = this.view.getBigInt64(this.pos);
|
|
6440
|
+
this.pos += 8;
|
|
6441
|
+
return value;
|
|
6442
|
+
}
|
|
6443
|
+
readF32() {
|
|
6444
|
+
const value = this.view.getFloat32(this.pos);
|
|
6445
|
+
this.pos += 4;
|
|
6446
|
+
return value;
|
|
6447
|
+
}
|
|
6448
|
+
readF64() {
|
|
6449
|
+
const value = this.view.getFloat64(this.pos);
|
|
6450
|
+
this.pos += 8;
|
|
6451
|
+
return value;
|
|
6452
|
+
}
|
|
6453
|
+
};
|
|
6454
|
+
exports.Decoder = Decoder;
|
|
6455
|
+
}
|
|
6456
|
+
});
|
|
6457
|
+
|
|
6458
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/decode.cjs
|
|
6459
|
+
var require_decode = __commonJS({
|
|
6460
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/decode.cjs"(exports) {
|
|
6461
|
+
"use strict";
|
|
6462
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6463
|
+
exports.decode = decode;
|
|
6464
|
+
exports.decodeMulti = decodeMulti;
|
|
6465
|
+
var Decoder_ts_1 = require_Decoder();
|
|
6466
|
+
function decode(buffer, options) {
|
|
6467
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
6468
|
+
return decoder.decode(buffer);
|
|
6469
|
+
}
|
|
6470
|
+
function decodeMulti(buffer, options) {
|
|
6471
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
6472
|
+
return decoder.decodeMulti(buffer);
|
|
6473
|
+
}
|
|
6474
|
+
}
|
|
6475
|
+
});
|
|
6476
|
+
|
|
6477
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/utils/stream.cjs
|
|
6478
|
+
var require_stream = __commonJS({
|
|
6479
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/utils/stream.cjs"(exports) {
|
|
6480
|
+
"use strict";
|
|
6481
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6482
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
6483
|
+
exports.asyncIterableFromStream = asyncIterableFromStream;
|
|
6484
|
+
exports.ensureAsyncIterable = ensureAsyncIterable;
|
|
6485
|
+
function isAsyncIterable(object) {
|
|
6486
|
+
return object[Symbol.asyncIterator] != null;
|
|
6487
|
+
}
|
|
6488
|
+
async function* asyncIterableFromStream(stream) {
|
|
6489
|
+
const reader = stream.getReader();
|
|
6490
|
+
try {
|
|
6491
|
+
while (true) {
|
|
6492
|
+
const { done, value } = await reader.read();
|
|
6493
|
+
if (done) {
|
|
6494
|
+
return;
|
|
6495
|
+
}
|
|
6496
|
+
yield value;
|
|
6497
|
+
}
|
|
6498
|
+
} finally {
|
|
6499
|
+
reader.releaseLock();
|
|
6500
|
+
}
|
|
6501
|
+
}
|
|
6502
|
+
function ensureAsyncIterable(streamLike) {
|
|
6503
|
+
if (isAsyncIterable(streamLike)) {
|
|
6504
|
+
return streamLike;
|
|
6505
|
+
} else {
|
|
6506
|
+
return asyncIterableFromStream(streamLike);
|
|
6507
|
+
}
|
|
6508
|
+
}
|
|
6509
|
+
}
|
|
6510
|
+
});
|
|
6511
|
+
|
|
6512
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/decodeAsync.cjs
|
|
6513
|
+
var require_decodeAsync = __commonJS({
|
|
6514
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/decodeAsync.cjs"(exports) {
|
|
6515
|
+
"use strict";
|
|
6516
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6517
|
+
exports.decodeAsync = decodeAsync;
|
|
6518
|
+
exports.decodeArrayStream = decodeArrayStream;
|
|
6519
|
+
exports.decodeMultiStream = decodeMultiStream;
|
|
6520
|
+
var Decoder_ts_1 = require_Decoder();
|
|
6521
|
+
var stream_ts_1 = require_stream();
|
|
6522
|
+
async function decodeAsync(streamLike, options) {
|
|
6523
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
6524
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
6525
|
+
return decoder.decodeAsync(stream);
|
|
6526
|
+
}
|
|
6527
|
+
function decodeArrayStream(streamLike, options) {
|
|
6528
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
6529
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
6530
|
+
return decoder.decodeArrayStream(stream);
|
|
6531
|
+
}
|
|
6532
|
+
function decodeMultiStream(streamLike, options) {
|
|
6533
|
+
const stream = (0, stream_ts_1.ensureAsyncIterable)(streamLike);
|
|
6534
|
+
const decoder = new Decoder_ts_1.Decoder(options);
|
|
6535
|
+
return decoder.decodeStream(stream);
|
|
6536
|
+
}
|
|
6537
|
+
}
|
|
6538
|
+
});
|
|
6539
|
+
|
|
6540
|
+
// ../../node_modules/@msgpack/msgpack/dist.cjs/index.cjs
|
|
6541
|
+
var require_dist = __commonJS({
|
|
6542
|
+
"../../node_modules/@msgpack/msgpack/dist.cjs/index.cjs"(exports) {
|
|
6543
|
+
"use strict";
|
|
6544
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6545
|
+
exports.decodeTimestampExtension = exports.encodeTimestampExtension = exports.decodeTimestampToTimeSpec = exports.encodeTimeSpecToTimestamp = exports.encodeDateToTimeSpec = exports.EXT_TIMESTAMP = exports.ExtData = exports.ExtensionCodec = exports.Encoder = exports.DecodeError = exports.Decoder = exports.decodeMultiStream = exports.decodeArrayStream = exports.decodeAsync = exports.decodeMulti = exports.decode = exports.encode = void 0;
|
|
6546
|
+
var encode_ts_1 = require_encode();
|
|
6547
|
+
Object.defineProperty(exports, "encode", { enumerable: true, get: function() {
|
|
6548
|
+
return encode_ts_1.encode;
|
|
6549
|
+
} });
|
|
6550
|
+
var decode_ts_1 = require_decode();
|
|
6551
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function() {
|
|
6552
|
+
return decode_ts_1.decode;
|
|
6553
|
+
} });
|
|
6554
|
+
Object.defineProperty(exports, "decodeMulti", { enumerable: true, get: function() {
|
|
6555
|
+
return decode_ts_1.decodeMulti;
|
|
6556
|
+
} });
|
|
6557
|
+
var decodeAsync_ts_1 = require_decodeAsync();
|
|
6558
|
+
Object.defineProperty(exports, "decodeAsync", { enumerable: true, get: function() {
|
|
6559
|
+
return decodeAsync_ts_1.decodeAsync;
|
|
6560
|
+
} });
|
|
6561
|
+
Object.defineProperty(exports, "decodeArrayStream", { enumerable: true, get: function() {
|
|
6562
|
+
return decodeAsync_ts_1.decodeArrayStream;
|
|
6563
|
+
} });
|
|
6564
|
+
Object.defineProperty(exports, "decodeMultiStream", { enumerable: true, get: function() {
|
|
6565
|
+
return decodeAsync_ts_1.decodeMultiStream;
|
|
6566
|
+
} });
|
|
6567
|
+
var Decoder_ts_1 = require_Decoder();
|
|
6568
|
+
Object.defineProperty(exports, "Decoder", { enumerable: true, get: function() {
|
|
6569
|
+
return Decoder_ts_1.Decoder;
|
|
6570
|
+
} });
|
|
6571
|
+
var DecodeError_ts_1 = require_DecodeError();
|
|
6572
|
+
Object.defineProperty(exports, "DecodeError", { enumerable: true, get: function() {
|
|
6573
|
+
return DecodeError_ts_1.DecodeError;
|
|
6574
|
+
} });
|
|
6575
|
+
var Encoder_ts_1 = require_Encoder();
|
|
6576
|
+
Object.defineProperty(exports, "Encoder", { enumerable: true, get: function() {
|
|
6577
|
+
return Encoder_ts_1.Encoder;
|
|
6578
|
+
} });
|
|
6579
|
+
var ExtensionCodec_ts_1 = require_ExtensionCodec();
|
|
6580
|
+
Object.defineProperty(exports, "ExtensionCodec", { enumerable: true, get: function() {
|
|
6581
|
+
return ExtensionCodec_ts_1.ExtensionCodec;
|
|
6582
|
+
} });
|
|
6583
|
+
var ExtData_ts_1 = require_ExtData();
|
|
6584
|
+
Object.defineProperty(exports, "ExtData", { enumerable: true, get: function() {
|
|
6585
|
+
return ExtData_ts_1.ExtData;
|
|
6586
|
+
} });
|
|
6587
|
+
var timestamp_ts_1 = require_timestamp();
|
|
6588
|
+
Object.defineProperty(exports, "EXT_TIMESTAMP", { enumerable: true, get: function() {
|
|
6589
|
+
return timestamp_ts_1.EXT_TIMESTAMP;
|
|
6590
|
+
} });
|
|
6591
|
+
Object.defineProperty(exports, "encodeDateToTimeSpec", { enumerable: true, get: function() {
|
|
6592
|
+
return timestamp_ts_1.encodeDateToTimeSpec;
|
|
6593
|
+
} });
|
|
6594
|
+
Object.defineProperty(exports, "encodeTimeSpecToTimestamp", { enumerable: true, get: function() {
|
|
6595
|
+
return timestamp_ts_1.encodeTimeSpecToTimestamp;
|
|
6596
|
+
} });
|
|
6597
|
+
Object.defineProperty(exports, "decodeTimestampToTimeSpec", { enumerable: true, get: function() {
|
|
6598
|
+
return timestamp_ts_1.decodeTimestampToTimeSpec;
|
|
6599
|
+
} });
|
|
6600
|
+
Object.defineProperty(exports, "encodeTimestampExtension", { enumerable: true, get: function() {
|
|
6601
|
+
return timestamp_ts_1.encodeTimestampExtension;
|
|
6602
|
+
} });
|
|
6603
|
+
Object.defineProperty(exports, "decodeTimestampExtension", { enumerable: true, get: function() {
|
|
6604
|
+
return timestamp_ts_1.decodeTimestampExtension;
|
|
6605
|
+
} });
|
|
4957
6606
|
}
|
|
4958
6607
|
});
|
|
4959
6608
|
|
|
@@ -4961,7 +6610,7 @@ var init_secp256k1 = __esm({
|
|
|
4961
6610
|
import "dotenv/config";
|
|
4962
6611
|
import { promises as fs4 } from "node:fs";
|
|
4963
6612
|
import { descriptions } from "@vultisig/client-shared";
|
|
4964
|
-
import { Chain as
|
|
6613
|
+
import { Chain as Chain14, parseKeygenQR, Vultisig as Vultisig6 } from "@vultisig/sdk";
|
|
4965
6614
|
import chalk16 from "chalk";
|
|
4966
6615
|
import { InvalidArgumentError, program as program2 } from "commander";
|
|
4967
6616
|
|
|
@@ -6016,7 +7665,7 @@ function displayVaultInfo(vault) {
|
|
|
6016
7665
|
printResult(` Chain Code: ${vault.hexChainCode.substring(0, 20)}...
|
|
6017
7666
|
`);
|
|
6018
7667
|
}
|
|
6019
|
-
function displayTransactionPreview(fromAddress, toAddress, amount, symbol, chain, memo, destinationTag, gas) {
|
|
7668
|
+
function displayTransactionPreview(fromAddress, toAddress, amount, symbol, chain, memo, destinationTag, gas, contractAddress) {
|
|
6020
7669
|
if (gas) {
|
|
6021
7670
|
const bigIntReplacer2 = (_k, v) => typeof v === "bigint" ? v.toString() : v;
|
|
6022
7671
|
info(chalk2.blue(`
|
|
@@ -6025,7 +7674,7 @@ Estimated gas: ${JSON.stringify(gas, bigIntReplacer2, 2)}`));
|
|
|
6025
7674
|
printResult(chalk2.cyan("\nTransaction Preview:"));
|
|
6026
7675
|
printResult(` From: ${fromAddress}`);
|
|
6027
7676
|
printResult(` To: ${toAddress}`);
|
|
6028
|
-
printResult(` Amount: ${amount} ${symbol}`);
|
|
7677
|
+
printResult(` Amount: ${amount} ${symbol}${contractAddress ? ` (${escapeTerminalControls(contractAddress)})` : ""}`);
|
|
6029
7678
|
printResult(` Chain: ${chain}`);
|
|
6030
7679
|
if (memo) {
|
|
6031
7680
|
printResult(` Memo: ${escapeTerminalControls(memo)}`);
|
|
@@ -6332,123 +7981,8 @@ function shouldAutoSelectActiveVault(hasActiveVault, corruptPointer, vaultCount)
|
|
|
6332
7981
|
return !hasActiveVault && !corruptPointer && vaultCount > 0;
|
|
6333
7982
|
}
|
|
6334
7983
|
|
|
6335
|
-
//
|
|
6336
|
-
|
|
6337
|
-
Arbitrum: "Arbitrum",
|
|
6338
|
-
Base: "Base",
|
|
6339
|
-
Blast: "Blast",
|
|
6340
|
-
Optimism: "Optimism",
|
|
6341
|
-
Zksync: "Zksync",
|
|
6342
|
-
Mantle: "Mantle",
|
|
6343
|
-
Robinhood: "Robinhood"
|
|
6344
|
-
};
|
|
6345
|
-
var EvmChain = {
|
|
6346
|
-
...EthereumL2Chain,
|
|
6347
|
-
Avalanche: "Avalanche",
|
|
6348
|
-
CronosChain: "CronosChain",
|
|
6349
|
-
BSC: "BSC",
|
|
6350
|
-
Ethereum: "Ethereum",
|
|
6351
|
-
Polygon: "Polygon",
|
|
6352
|
-
Hyperliquid: "Hyperliquid",
|
|
6353
|
-
Sei: "Sei"
|
|
6354
|
-
};
|
|
6355
|
-
var UtxoChain;
|
|
6356
|
-
(function(UtxoChain2) {
|
|
6357
|
-
UtxoChain2["Bitcoin"] = "Bitcoin";
|
|
6358
|
-
UtxoChain2["BitcoinCash"] = "Bitcoin-Cash";
|
|
6359
|
-
UtxoChain2["Litecoin"] = "Litecoin";
|
|
6360
|
-
UtxoChain2["Dogecoin"] = "Dogecoin";
|
|
6361
|
-
UtxoChain2["Dash"] = "Dash";
|
|
6362
|
-
UtxoChain2["Zcash"] = "Zcash";
|
|
6363
|
-
})(UtxoChain || (UtxoChain = {}));
|
|
6364
|
-
var cosmosChainsByKind = {
|
|
6365
|
-
ibcEnabled: {
|
|
6366
|
-
Cosmos: "Cosmos",
|
|
6367
|
-
Osmosis: "Osmosis",
|
|
6368
|
-
Dydx: "Dydx",
|
|
6369
|
-
Kujira: "Kujira",
|
|
6370
|
-
Terra: "Terra",
|
|
6371
|
-
TerraClassic: "TerraClassic",
|
|
6372
|
-
Noble: "Noble",
|
|
6373
|
-
Akash: "Akash"
|
|
6374
|
-
},
|
|
6375
|
-
vaultBased: {
|
|
6376
|
-
THORChain: "THORChain",
|
|
6377
|
-
MayaChain: "MayaChain"
|
|
6378
|
-
}
|
|
6379
|
-
};
|
|
6380
|
-
var IbcEnabledCosmosChain = cosmosChainsByKind.ibcEnabled;
|
|
6381
|
-
var VaultBasedCosmosChain = cosmosChainsByKind.vaultBased;
|
|
6382
|
-
var CosmosChain = {
|
|
6383
|
-
...IbcEnabledCosmosChain,
|
|
6384
|
-
...VaultBasedCosmosChain
|
|
6385
|
-
};
|
|
6386
|
-
var OtherChain;
|
|
6387
|
-
(function(OtherChain2) {
|
|
6388
|
-
OtherChain2["Sui"] = "Sui";
|
|
6389
|
-
OtherChain2["Solana"] = "Solana";
|
|
6390
|
-
OtherChain2["Polkadot"] = "Polkadot";
|
|
6391
|
-
OtherChain2["Bittensor"] = "Bittensor";
|
|
6392
|
-
OtherChain2["Ton"] = "Ton";
|
|
6393
|
-
OtherChain2["Ripple"] = "Ripple";
|
|
6394
|
-
OtherChain2["Tron"] = "Tron";
|
|
6395
|
-
OtherChain2["Cardano"] = "Cardano";
|
|
6396
|
-
OtherChain2["QBTC"] = "QBTC";
|
|
6397
|
-
})(OtherChain || (OtherChain = {}));
|
|
6398
|
-
var Chain2 = {
|
|
6399
|
-
...EvmChain,
|
|
6400
|
-
...UtxoChain,
|
|
6401
|
-
...CosmosChain,
|
|
6402
|
-
...OtherChain
|
|
6403
|
-
};
|
|
6404
|
-
var UtxoBasedChain = [...Object.values(UtxoChain), OtherChain.Cardano];
|
|
6405
|
-
var defaultChains = [Chain2.Bitcoin, Chain2.Ethereum, Chain2.THORChain, Chain2.Solana, Chain2.BSC];
|
|
6406
|
-
|
|
6407
|
-
// ../../packages/core/chain/dist/ChainKind.js
|
|
6408
|
-
var chainKindRecord = {
|
|
6409
|
-
[EvmChain.Arbitrum]: "evm",
|
|
6410
|
-
[EvmChain.Avalanche]: "evm",
|
|
6411
|
-
[EvmChain.Base]: "evm",
|
|
6412
|
-
[EvmChain.CronosChain]: "evm",
|
|
6413
|
-
[EvmChain.BSC]: "evm",
|
|
6414
|
-
[EvmChain.Blast]: "evm",
|
|
6415
|
-
[EvmChain.Ethereum]: "evm",
|
|
6416
|
-
[EvmChain.Optimism]: "evm",
|
|
6417
|
-
[EvmChain.Polygon]: "evm",
|
|
6418
|
-
[EvmChain.Zksync]: "evm",
|
|
6419
|
-
[EvmChain.Mantle]: "evm",
|
|
6420
|
-
[EvmChain.Hyperliquid]: "evm",
|
|
6421
|
-
[EvmChain.Sei]: "evm",
|
|
6422
|
-
[EvmChain.Robinhood]: "evm",
|
|
6423
|
-
[UtxoChain.Bitcoin]: "utxo",
|
|
6424
|
-
[UtxoChain.BitcoinCash]: "utxo",
|
|
6425
|
-
[UtxoChain.Litecoin]: "utxo",
|
|
6426
|
-
[UtxoChain.Dogecoin]: "utxo",
|
|
6427
|
-
[UtxoChain.Dash]: "utxo",
|
|
6428
|
-
[UtxoChain.Zcash]: "utxo",
|
|
6429
|
-
[CosmosChain.THORChain]: "cosmos",
|
|
6430
|
-
[CosmosChain.Cosmos]: "cosmos",
|
|
6431
|
-
[CosmosChain.Osmosis]: "cosmos",
|
|
6432
|
-
[CosmosChain.MayaChain]: "cosmos",
|
|
6433
|
-
[CosmosChain.Dydx]: "cosmos",
|
|
6434
|
-
[CosmosChain.Kujira]: "cosmos",
|
|
6435
|
-
[CosmosChain.Terra]: "cosmos",
|
|
6436
|
-
[CosmosChain.TerraClassic]: "cosmos",
|
|
6437
|
-
[CosmosChain.Noble]: "cosmos",
|
|
6438
|
-
[CosmosChain.Akash]: "cosmos",
|
|
6439
|
-
[OtherChain.Sui]: "sui",
|
|
6440
|
-
[OtherChain.Solana]: "solana",
|
|
6441
|
-
[OtherChain.Polkadot]: "polkadot",
|
|
6442
|
-
[OtherChain.Bittensor]: "bittensor",
|
|
6443
|
-
[OtherChain.Ton]: "ton",
|
|
6444
|
-
[OtherChain.Ripple]: "ripple",
|
|
6445
|
-
[OtherChain.Tron]: "tron",
|
|
6446
|
-
[OtherChain.Cardano]: "cardano",
|
|
6447
|
-
[OtherChain.QBTC]: "qbtc"
|
|
6448
|
-
};
|
|
6449
|
-
function getChainKind2(chain) {
|
|
6450
|
-
return chainKindRecord[chain];
|
|
6451
|
-
}
|
|
7984
|
+
// src/core/broadcastGuard.ts
|
|
7985
|
+
import { getChainKind as getChainKind2 } from "@vultisig/sdk";
|
|
6452
7986
|
|
|
6453
7987
|
// src/agent/broadcastJournal.ts
|
|
6454
7988
|
import { createHash } from "node:crypto";
|
|
@@ -7068,7 +8602,7 @@ async function guardedBroadcast(intent, force, broadcast) {
|
|
|
7068
8602
|
}
|
|
7069
8603
|
|
|
7070
8604
|
// src/interactive/completer.ts
|
|
7071
|
-
import { Chain as
|
|
8605
|
+
import { Chain as Chain2 } from "@vultisig/sdk";
|
|
7072
8606
|
import fs from "fs";
|
|
7073
8607
|
import path from "path";
|
|
7074
8608
|
var COMMANDS = [
|
|
@@ -7212,7 +8746,7 @@ function completeVaultName(ctx2, partial) {
|
|
|
7212
8746
|
return [show, partial];
|
|
7213
8747
|
}
|
|
7214
8748
|
function completeChainName(partial) {
|
|
7215
|
-
const allChains = Object.values(
|
|
8749
|
+
const allChains = Object.values(Chain2);
|
|
7216
8750
|
const partialLower = partial.toLowerCase();
|
|
7217
8751
|
const matches = allChains.filter((chain) => chain.toLowerCase().startsWith(partialLower));
|
|
7218
8752
|
matches.sort();
|
|
@@ -7220,7 +8754,7 @@ function completeChainName(partial) {
|
|
|
7220
8754
|
return [show, partial];
|
|
7221
8755
|
}
|
|
7222
8756
|
function findChainByName(name) {
|
|
7223
|
-
const allChains = Object.values(
|
|
8757
|
+
const allChains = Object.values(Chain2);
|
|
7224
8758
|
const nameLower = name.toLowerCase();
|
|
7225
8759
|
const found = allChains.find((chain) => chain.toLowerCase() === nameLower);
|
|
7226
8760
|
return found ? found : null;
|
|
@@ -7239,6 +8773,10 @@ function resolveChainOrThrow(input, label = "chain") {
|
|
|
7239
8773
|
}
|
|
7240
8774
|
return chain;
|
|
7241
8775
|
}
|
|
8776
|
+
function resolveOptionalChainOrThrow(input, label = "chain") {
|
|
8777
|
+
if (input === void 0 || input === null) return void 0;
|
|
8778
|
+
return resolveChainOrThrow(input, label);
|
|
8779
|
+
}
|
|
7242
8780
|
|
|
7243
8781
|
// src/core/config-store.ts
|
|
7244
8782
|
import { getConfigPath, loadConfig, saveConfig } from "@vultisig/client-shared";
|
|
@@ -7542,10 +9080,10 @@ var resolveDestinationTag = ({ destinationTag, memo }) => {
|
|
|
7542
9080
|
};
|
|
7543
9081
|
|
|
7544
9082
|
// src/commands/transaction.ts
|
|
7545
|
-
import { Chain as
|
|
9083
|
+
import { Chain as Chain3, Vultisig as Vultisig2 } from "@vultisig/sdk";
|
|
7546
9084
|
var getSendPreviewDetails = (chain, keysignPayload) => {
|
|
7547
9085
|
let memo = keysignPayload.memo || void 0;
|
|
7548
|
-
if (chain !==
|
|
9086
|
+
if (chain !== Chain3.Ripple) {
|
|
7549
9087
|
return { memo, destinationTag: void 0 };
|
|
7550
9088
|
}
|
|
7551
9089
|
const rippleSpecific = keysignPayload.blockchainSpecific;
|
|
@@ -7564,7 +9102,7 @@ var getSendPreviewDetails = (chain, keysignPayload) => {
|
|
|
7564
9102
|
};
|
|
7565
9103
|
async function executeSend(ctx2, params) {
|
|
7566
9104
|
const vault = await ctx2.ensureActiveVault();
|
|
7567
|
-
if (!Object.values(
|
|
9105
|
+
if (!Object.values(Chain3).includes(params.chain)) {
|
|
7568
9106
|
throw new Error(`Invalid chain: ${params.chain}`);
|
|
7569
9107
|
}
|
|
7570
9108
|
const isMax = params.amount === "max";
|
|
@@ -7581,12 +9119,13 @@ async function previewDryRun(vault, params, dryResult, to) {
|
|
|
7581
9119
|
dryResult.keysignPayload
|
|
7582
9120
|
);
|
|
7583
9121
|
const isTokenSend = balance.tokenId !== void 0;
|
|
7584
|
-
const
|
|
9122
|
+
const shouldCheckNativeFeeBalance = isTokenSend && params.amount !== "max";
|
|
9123
|
+
const feeBalance = shouldCheckNativeFeeBalance ? await vault.balance(params.chain).catch(() => void 0) : void 0;
|
|
7585
9124
|
const warnings = [];
|
|
7586
9125
|
if (hasInsufficientBalance) {
|
|
7587
9126
|
warnings.push(`Insufficient balance: you have ${balance.formattedAmount} ${balance.symbol}`);
|
|
7588
9127
|
}
|
|
7589
|
-
if (
|
|
9128
|
+
if (shouldCheckNativeFeeBalance && feeBalance === void 0) {
|
|
7590
9129
|
warnings.push(`Could not check your ${dryResult.feeSymbol} balance for the network fee`);
|
|
7591
9130
|
} else if (feeBalance && parseFloat(dryResult.fee) > parseFloat(feeBalance.formattedAmount)) {
|
|
7592
9131
|
warnings.push(
|
|
@@ -7599,6 +9138,7 @@ async function previewDryRun(vault, params, dryResult, to) {
|
|
|
7599
9138
|
to,
|
|
7600
9139
|
amount: params.amount,
|
|
7601
9140
|
symbol: balance.symbol,
|
|
9141
|
+
...dryResult.contractAddress ? { contractAddress: dryResult.contractAddress } : {},
|
|
7602
9142
|
fee: dryResult.fee,
|
|
7603
9143
|
feeSymbol: dryResult.feeSymbol,
|
|
7604
9144
|
total: dryResult.total,
|
|
@@ -7608,14 +9148,27 @@ async function previewDryRun(vault, params, dryResult, to) {
|
|
|
7608
9148
|
...warnings.length > 0 ? { warning: warnings.join(". ") } : {}
|
|
7609
9149
|
};
|
|
7610
9150
|
if (isJsonOutput()) {
|
|
7611
|
-
|
|
7612
|
-
|
|
9151
|
+
if (params.amount !== "max") {
|
|
9152
|
+
outputJson(result);
|
|
9153
|
+
return result;
|
|
9154
|
+
}
|
|
9155
|
+
const decimals = dryResult.keysignPayload.coin?.decimals;
|
|
9156
|
+
if (decimals === void 0) throw new Error("Prepared transaction is missing coin decimals");
|
|
9157
|
+
const jsonResult = {
|
|
9158
|
+
...result,
|
|
9159
|
+
amount: formatBigintAmount(BigInt(dryResult.keysignPayload.toAmount), decimals),
|
|
9160
|
+
isMax: true
|
|
9161
|
+
};
|
|
9162
|
+
outputJson(jsonResult);
|
|
9163
|
+
return jsonResult;
|
|
7613
9164
|
}
|
|
7614
9165
|
info(`
|
|
7615
9166
|
Dry-run preview:`);
|
|
7616
9167
|
info(` Chain: ${result.chain}`);
|
|
7617
9168
|
info(` To: ${result.to}`);
|
|
7618
|
-
info(
|
|
9169
|
+
info(
|
|
9170
|
+
` Amount: ${result.amount} ${result.symbol}${result.contractAddress ? ` (${escapeTerminalControls(result.contractAddress)})` : ""}`
|
|
9171
|
+
);
|
|
7619
9172
|
if (result.destinationTag !== void 0) info(` Destination tag: ${result.destinationTag}`);
|
|
7620
9173
|
if (result.memo) info(` Memo: ${escapeTerminalControls(result.memo)}`);
|
|
7621
9174
|
info(` Fee: ${result.fee} ${result.feeSymbol}`);
|
|
@@ -7631,7 +9184,7 @@ async function sendTransaction(vault, params) {
|
|
|
7631
9184
|
"Pass --yes to confirm, or --dry-run to preview without signing."
|
|
7632
9185
|
);
|
|
7633
9186
|
}
|
|
7634
|
-
const rippleDestination = params.chain ===
|
|
9187
|
+
const rippleDestination = params.chain === Chain3.Ripple ? normalizeRippleDestination(params.to) : { address: params.to };
|
|
7635
9188
|
const to = rippleDestination.address;
|
|
7636
9189
|
if (params.destinationTag !== void 0 && rippleDestination.destinationTag !== void 0 && params.destinationTag !== rippleDestination.destinationTag) {
|
|
7637
9190
|
throw new Error(
|
|
@@ -7672,7 +9225,8 @@ async function sendTransaction(vault, params) {
|
|
|
7672
9225
|
params.chain,
|
|
7673
9226
|
preview.memo,
|
|
7674
9227
|
preview.destinationTag,
|
|
7675
|
-
gas
|
|
9228
|
+
gas,
|
|
9229
|
+
dryResult.contractAddress
|
|
7676
9230
|
);
|
|
7677
9231
|
}
|
|
7678
9232
|
if (!params.yes) {
|
|
@@ -7727,23 +9281,32 @@ async function sendTransaction(vault, params) {
|
|
|
7727
9281
|
|
|
7728
9282
|
// src/commands/execute.ts
|
|
7729
9283
|
var import_qrcode_terminal = __toESM(require_main(), 1);
|
|
7730
|
-
import {
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
gasLimit: "500000"
|
|
9284
|
+
import {
|
|
9285
|
+
buildCosmosWasmExecuteMsg,
|
|
9286
|
+
Chain as Chain4,
|
|
9287
|
+
chainFeeCoin,
|
|
9288
|
+
cosmosFeeCoinDenom,
|
|
9289
|
+
getCosmosGasLimit,
|
|
9290
|
+
Vultisig as Vultisig3
|
|
9291
|
+
} from "@vultisig/sdk";
|
|
9292
|
+
var SUPPORTED_COSMWASM_CHAINS = [Chain4.THORChain, Chain4.MayaChain];
|
|
9293
|
+
function getCosmosChainConfig(chain) {
|
|
9294
|
+
if (!SUPPORTED_COSMWASM_CHAINS.includes(chain)) {
|
|
9295
|
+
throw new Error(
|
|
9296
|
+
`Chain ${chain} does not support CosmWasm execute. Supported chains: ${SUPPORTED_COSMWASM_CHAINS.join(", ")}`
|
|
9297
|
+
);
|
|
7745
9298
|
}
|
|
7746
|
-
|
|
9299
|
+
const supportedChain = chain;
|
|
9300
|
+
const feeCoin = chainFeeCoin[supportedChain];
|
|
9301
|
+
const denom = cosmosFeeCoinDenom[supportedChain];
|
|
9302
|
+
const gasLimit = getCosmosGasLimit({ chain: supportedChain, id: denom }).toString();
|
|
9303
|
+
return {
|
|
9304
|
+
denom,
|
|
9305
|
+
decimals: feeCoin.decimals,
|
|
9306
|
+
ticker: feeCoin.ticker,
|
|
9307
|
+
gasLimit
|
|
9308
|
+
};
|
|
9309
|
+
}
|
|
7747
9310
|
function parseFunds(fundsStr) {
|
|
7748
9311
|
if (!fundsStr) return [];
|
|
7749
9312
|
return fundsStr.split(",").map((fund) => {
|
|
@@ -7756,14 +9319,7 @@ function parseFunds(fundsStr) {
|
|
|
7756
9319
|
}
|
|
7757
9320
|
async function executeExecute(ctx2, params) {
|
|
7758
9321
|
const vault = await ctx2.ensureActiveVault();
|
|
7759
|
-
const chainConfig =
|
|
7760
|
-
if (!chainConfig) {
|
|
7761
|
-
throw new Error(
|
|
7762
|
-
`Chain ${params.chain} does not support CosmWasm execute. Supported chains: ${Object.keys(
|
|
7763
|
-
COSMOS_CHAIN_CONFIG
|
|
7764
|
-
).join(", ")}`
|
|
7765
|
-
);
|
|
7766
|
-
}
|
|
9322
|
+
const chainConfig = getCosmosChainConfig(params.chain);
|
|
7767
9323
|
let msg;
|
|
7768
9324
|
try {
|
|
7769
9325
|
msg = JSON.parse(params.msg);
|
|
@@ -7937,10 +9493,10 @@ Or use this URL: ${qrPayload}
|
|
|
7937
9493
|
|
|
7938
9494
|
// src/commands/sign.ts
|
|
7939
9495
|
var import_qrcode_terminal2 = __toESM(require_main(), 1);
|
|
7940
|
-
import { Chain as
|
|
9496
|
+
import { Chain as Chain5 } from "@vultisig/sdk";
|
|
7941
9497
|
async function executeSignBytes(ctx2, params) {
|
|
7942
9498
|
const vault = await ctx2.ensureActiveVault();
|
|
7943
|
-
if (!Object.values(
|
|
9499
|
+
if (!Object.values(Chain5).includes(params.chain)) {
|
|
7944
9500
|
throw new Error(`Invalid chain: ${params.chain}`);
|
|
7945
9501
|
}
|
|
7946
9502
|
return signBytes(vault, params);
|
|
@@ -8020,10 +9576,10 @@ Or use this URL: ${qrPayload}
|
|
|
8020
9576
|
}
|
|
8021
9577
|
|
|
8022
9578
|
// src/commands/broadcast.ts
|
|
8023
|
-
import { Chain as
|
|
9579
|
+
import { Chain as Chain6, Vultisig as Vultisig4 } from "@vultisig/sdk";
|
|
8024
9580
|
async function executeBroadcast(ctx2, params) {
|
|
8025
9581
|
const vault = await ctx2.ensureActiveVault();
|
|
8026
|
-
if (!Object.values(
|
|
9582
|
+
if (!Object.values(Chain6).includes(params.chain)) {
|
|
8027
9583
|
throw new Error(`Invalid chain: ${params.chain}`);
|
|
8028
9584
|
}
|
|
8029
9585
|
const broadcastSpinner = createSpinner("Broadcasting transaction...");
|
|
@@ -8052,9 +9608,9 @@ async function executeBroadcast(ctx2, params) {
|
|
|
8052
9608
|
}
|
|
8053
9609
|
|
|
8054
9610
|
// src/commands/tx-status.ts
|
|
8055
|
-
import { Chain as
|
|
9611
|
+
import { Chain as Chain7, isValidTxHash, Vultisig as Vultisig5 } from "@vultisig/sdk";
|
|
8056
9612
|
function resolveTxStatusParams(params) {
|
|
8057
|
-
if (!Object.values(
|
|
9613
|
+
if (!Object.values(Chain7).includes(params.chain)) {
|
|
8058
9614
|
throw new InvalidInputError(`Invalid chain: ${params.chain}`);
|
|
8059
9615
|
}
|
|
8060
9616
|
if (!isValidTxHash(params.chain, params.txHash)) {
|
|
@@ -9107,6 +10663,9 @@ Please specify more characters of the vault ID.`
|
|
|
9107
10663
|
throw new Error(`Vault not found: "${idOrName}"`);
|
|
9108
10664
|
}
|
|
9109
10665
|
|
|
10666
|
+
// src/commands/swap.ts
|
|
10667
|
+
import { toChainAmount } from "@vultisig/sdk";
|
|
10668
|
+
|
|
9110
10669
|
// ../../node_modules/viem/_esm/accounts/utils/publicKeyToAddress.js
|
|
9111
10670
|
init_getAddress();
|
|
9112
10671
|
init_keccak256();
|
|
@@ -9377,110 +10936,10 @@ function formatUnits(value, decimals) {
|
|
|
9377
10936
|
return format(value, decimals);
|
|
9378
10937
|
}
|
|
9379
10938
|
|
|
9380
|
-
// ../../node_modules/viem/_esm/
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
}
|
|
9385
|
-
|
|
9386
|
-
// ../../packages/core/chain/dist/amount/toChainAmount.js
|
|
9387
|
-
var ChainAmountParseError = class extends Error {
|
|
9388
|
-
name = "ChainAmountParseError";
|
|
9389
|
-
constructor(message) {
|
|
9390
|
-
super(message);
|
|
9391
|
-
}
|
|
9392
|
-
};
|
|
9393
|
-
var SCIENTIFIC_DECIMAL = /^([+-]?)(?:(\d+)\.?(\d*)|\.(\d+))[eE]([+-]?\d+)$/i;
|
|
9394
|
-
var MAX_SCALE_ABS = 10000n;
|
|
9395
|
-
var padFractionDigits = (frac, totalLen) => {
|
|
9396
|
-
const need = totalLen - BigInt(frac.length);
|
|
9397
|
-
if (need <= 0n) {
|
|
9398
|
-
return frac;
|
|
9399
|
-
}
|
|
9400
|
-
if (need <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
9401
|
-
return `${"0".repeat(Number(need))}${frac}`;
|
|
9402
|
-
}
|
|
9403
|
-
let out = frac;
|
|
9404
|
-
while (BigInt(out.length) < totalLen) {
|
|
9405
|
-
out = `0${out}`;
|
|
9406
|
-
}
|
|
9407
|
-
return out;
|
|
9408
|
-
};
|
|
9409
|
-
var expandScientificNotationToDecimalString = (s) => {
|
|
9410
|
-
const m = SCIENTIFIC_DECIMAL.exec(s.trim());
|
|
9411
|
-
if (!m) {
|
|
9412
|
-
throw new ChainAmountParseError(`Invalid amount: "${s}"`);
|
|
9413
|
-
}
|
|
9414
|
-
const signNeg = m[1] === "-";
|
|
9415
|
-
let digitStr;
|
|
9416
|
-
let fracLen;
|
|
9417
|
-
if (m[4] !== void 0) {
|
|
9418
|
-
digitStr = m[4];
|
|
9419
|
-
fracLen = digitStr.length;
|
|
9420
|
-
} else {
|
|
9421
|
-
digitStr = `${m[2] ?? ""}${m[3] ?? ""}`;
|
|
9422
|
-
fracLen = (m[3] ?? "").length;
|
|
9423
|
-
}
|
|
9424
|
-
if (!/^\d+$/.test(digitStr)) {
|
|
9425
|
-
throw new ChainAmountParseError(`Invalid amount: "${s}"`);
|
|
9426
|
-
}
|
|
9427
|
-
const expStr = m[5] ?? "";
|
|
9428
|
-
if (expStr === "" || expStr === "+" || expStr === "-") {
|
|
9429
|
-
throw new ChainAmountParseError(`Invalid amount: "${s}"`);
|
|
9430
|
-
}
|
|
9431
|
-
const allDigits = BigInt(digitStr);
|
|
9432
|
-
const exp = BigInt(expStr);
|
|
9433
|
-
const scale = exp - BigInt(fracLen);
|
|
9434
|
-
const scaleAbs = scale < 0n ? -scale : scale;
|
|
9435
|
-
if (scaleAbs > MAX_SCALE_ABS) {
|
|
9436
|
-
throw new ChainAmountParseError(`Amount exponent out of supported range: "${s}"`);
|
|
9437
|
-
}
|
|
9438
|
-
let absResult;
|
|
9439
|
-
if (scale >= 0n) {
|
|
9440
|
-
const mult = 10n ** scale;
|
|
9441
|
-
absResult = (allDigits * mult).toString();
|
|
9442
|
-
} else {
|
|
9443
|
-
const k = -scale;
|
|
9444
|
-
const divisor = 10n ** k;
|
|
9445
|
-
const intPart = allDigits / divisor;
|
|
9446
|
-
const rem = allDigits % divisor;
|
|
9447
|
-
const frac = padFractionDigits(rem.toString(), k);
|
|
9448
|
-
absResult = intPart === 0n ? `0.${frac}` : `${intPart.toString()}.${frac}`;
|
|
9449
|
-
}
|
|
9450
|
-
if (signNeg && allDigits !== 0n) {
|
|
9451
|
-
return `-${absResult}`;
|
|
9452
|
-
}
|
|
9453
|
-
return absResult;
|
|
9454
|
-
};
|
|
9455
|
-
var formatNumberAmount = (amount) => {
|
|
9456
|
-
const str2 = amount.toString();
|
|
9457
|
-
return /[eE]/.test(str2) ? expandScientificNotationToDecimalString(str2) : str2;
|
|
9458
|
-
};
|
|
9459
|
-
var truncateToDecimals = (s, decimals) => {
|
|
9460
|
-
const dotIdx = s.indexOf(".");
|
|
9461
|
-
if (dotIdx === -1)
|
|
9462
|
-
return s;
|
|
9463
|
-
if (decimals === 0)
|
|
9464
|
-
return s.slice(0, dotIdx);
|
|
9465
|
-
const fracPart = s.slice(dotIdx + 1);
|
|
9466
|
-
if (fracPart.length <= decimals)
|
|
9467
|
-
return s;
|
|
9468
|
-
return `${s.slice(0, dotIdx + 1)}${fracPart.slice(0, decimals)}`;
|
|
9469
|
-
};
|
|
9470
|
-
var toChainAmount = (amount, decimals) => {
|
|
9471
|
-
if (typeof amount === "string") {
|
|
9472
|
-
const trimmed = amount.trim();
|
|
9473
|
-
if (!trimmed) {
|
|
9474
|
-
throw new ChainAmountParseError("Amount cannot be empty");
|
|
9475
|
-
}
|
|
9476
|
-
if (/[eE]/.test(trimmed)) {
|
|
9477
|
-
const expanded = expandScientificNotationToDecimalString(trimmed);
|
|
9478
|
-
return parseUnits(truncateToDecimals(expanded, decimals), decimals);
|
|
9479
|
-
}
|
|
9480
|
-
return parseUnits(truncateToDecimals(trimmed, decimals), decimals);
|
|
9481
|
-
}
|
|
9482
|
-
return parseUnits(truncateToDecimals(formatNumberAmount(amount), decimals), decimals);
|
|
9483
|
-
};
|
|
10939
|
+
// ../../node_modules/viem/_esm/index.js
|
|
10940
|
+
init_concat();
|
|
10941
|
+
init_toBytes();
|
|
10942
|
+
init_keccak256();
|
|
9484
10943
|
|
|
9485
10944
|
// src/commands/swap.ts
|
|
9486
10945
|
async function executeSwapChains(ctx2) {
|
|
@@ -9511,8 +10970,8 @@ async function executeSwapQuote(ctx2, options) {
|
|
|
9511
10970
|
if (!result.dryRun) throw new Error("unreachable");
|
|
9512
10971
|
spinner.succeed("Quote received");
|
|
9513
10972
|
const quote = result.quote;
|
|
9514
|
-
const semanticAmount = isMax ?
|
|
9515
|
-
const fromAmountDisplay = isMax ? `${
|
|
10973
|
+
const semanticAmount = isMax ? formatBigintAmount(quote.maxSwapable, quote.fromCoin.decimals) : normalizeSwapAmount(amount, quote.fromCoin.decimals);
|
|
10974
|
+
const fromAmountDisplay = isMax ? `${semanticAmount} (max)` : semanticAmount;
|
|
9516
10975
|
if (isJsonOutput()) {
|
|
9517
10976
|
outputJson({
|
|
9518
10977
|
fromChain: options.fromChain,
|
|
@@ -9676,7 +11135,7 @@ async function executeSwap(ctx2, options) {
|
|
|
9676
11135
|
}
|
|
9677
11136
|
|
|
9678
11137
|
// src/commands/settings.ts
|
|
9679
|
-
import { Chain as
|
|
11138
|
+
import { Chain as Chain8, fiatCurrencies as fiatCurrencies2, fiatCurrencyNameRecord as fiatCurrencyNameRecord3 } from "@vultisig/sdk";
|
|
9680
11139
|
import chalk6 from "chalk";
|
|
9681
11140
|
async function executeCurrency(ctx2, newCurrency) {
|
|
9682
11141
|
const vault = await ctx2.ensureActiveVault();
|
|
@@ -9747,7 +11206,7 @@ async function executeAddressBook(ctx2, options = {}) {
|
|
|
9747
11206
|
type: "select",
|
|
9748
11207
|
name: "chain",
|
|
9749
11208
|
message: "Select chain:",
|
|
9750
|
-
choices: Object.values(
|
|
11209
|
+
choices: Object.values(Chain8)
|
|
9751
11210
|
});
|
|
9752
11211
|
}
|
|
9753
11212
|
if (!address) {
|
|
@@ -10238,6 +11697,14 @@ var AskInterface = class {
|
|
|
10238
11697
|
onBalanceSummary: (card) => {
|
|
10239
11698
|
this.cards.push(card);
|
|
10240
11699
|
},
|
|
11700
|
+
onHlOrderConfirmation: (card) => {
|
|
11701
|
+
this.cards.push(card);
|
|
11702
|
+
this.outcome = {
|
|
11703
|
+
kind: "blocked",
|
|
11704
|
+
code: "CONFIRMATION_REQUIRED" /* CONFIRMATION_REQUIRED */,
|
|
11705
|
+
detail: "Explicit approval is required before signing this Hyperliquid order."
|
|
11706
|
+
};
|
|
11707
|
+
},
|
|
10241
11708
|
onYieldOpportunities: (card) => {
|
|
10242
11709
|
this.yieldCards.push(card);
|
|
10243
11710
|
},
|
|
@@ -10245,6 +11712,9 @@ var AskInterface = class {
|
|
|
10245
11712
|
this.polymarketCards.push(card);
|
|
10246
11713
|
},
|
|
10247
11714
|
onTurnOutcome: (outcome) => {
|
|
11715
|
+
if (this.outcome?.kind === "blocked" && this.outcome.code === "CONFIRMATION_REQUIRED" /* CONFIRMATION_REQUIRED */) {
|
|
11716
|
+
return;
|
|
11717
|
+
}
|
|
10248
11718
|
this.outcome = outcome;
|
|
10249
11719
|
},
|
|
10250
11720
|
onProposedTransaction: (proposed) => {
|
|
@@ -10348,11 +11818,11 @@ var AskInterface = class {
|
|
|
10348
11818
|
|
|
10349
11819
|
// src/agent/auth.ts
|
|
10350
11820
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
10351
|
-
import { Chain as
|
|
11821
|
+
import { Chain as Chain9, computePersonalSignHash, formatEcdsaSignature65 } from "@vultisig/sdk";
|
|
10352
11822
|
async function authenticateVault(client, vault, password, maxAttempts = 3) {
|
|
10353
11823
|
const publicKey = vault.publicKeys.ecdsa;
|
|
10354
11824
|
const chainCode = vault.hexChainCode;
|
|
10355
|
-
const ethAddress = await vault.address(
|
|
11825
|
+
const ethAddress = await vault.address(Chain9.Ethereum);
|
|
10356
11826
|
const nonce = "0x" + randomBytes3(16).toString("hex");
|
|
10357
11827
|
const expiresAt = new Date(Date.now() + 15 * 60 * 1e3).toISOString();
|
|
10358
11828
|
const authMessage = JSON.stringify({
|
|
@@ -10369,7 +11839,7 @@ async function authenticateVault(client, vault, password, maxAttempts = 3) {
|
|
|
10369
11839
|
process.stderr.write(` Retry ${attempt}/${maxAttempts}...
|
|
10370
11840
|
`);
|
|
10371
11841
|
}
|
|
10372
|
-
const signature = await vault.signBytes({ data: Buffer.from(messageHash), chain:
|
|
11842
|
+
const signature = await vault.signBytes({ data: Buffer.from(messageHash), chain: Chain9.Ethereum }, {});
|
|
10373
11843
|
if (signature.recovery === void 0) {
|
|
10374
11844
|
throw new Error("Agent authentication requires an ECDSA recovery id");
|
|
10375
11845
|
}
|
|
@@ -10702,10 +12172,13 @@ import { getChainKind as getChainKind4 } from "@vultisig/sdk";
|
|
|
10702
12172
|
// src/agent/executor.ts
|
|
10703
12173
|
import {
|
|
10704
12174
|
Chain as Chain11,
|
|
10705
|
-
chainFeeCoin,
|
|
12175
|
+
chainFeeCoin as chainFeeCoin2,
|
|
12176
|
+
computeEip712Hash,
|
|
10706
12177
|
getChainKind as getChainKind3,
|
|
12178
|
+
getEvmRpcUrl,
|
|
10707
12179
|
parseThorSwapMemo,
|
|
10708
12180
|
resolveChainReference,
|
|
12181
|
+
toCanonicalEvmSignature,
|
|
10709
12182
|
VaultError as VaultError3,
|
|
10710
12183
|
VaultErrorCode as VaultErrorCode3,
|
|
10711
12184
|
Vultisig as VultisigSdk
|
|
@@ -10866,6 +12339,234 @@ function sleep2(ms) {
|
|
|
10866
12339
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10867
12340
|
}
|
|
10868
12341
|
|
|
12342
|
+
// src/agent/hlOrder.ts
|
|
12343
|
+
var import_msgpack = __toESM(require_dist(), 1);
|
|
12344
|
+
import { Chain as Chain10 } from "@vultisig/sdk";
|
|
12345
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
12346
|
+
var HL_AGENT_TYPES = {
|
|
12347
|
+
Agent: [
|
|
12348
|
+
{ name: "source", type: "string" },
|
|
12349
|
+
{ name: "connectionId", type: "bytes32" }
|
|
12350
|
+
]
|
|
12351
|
+
};
|
|
12352
|
+
function isExactStringMember(value, allowed) {
|
|
12353
|
+
return typeof value === "string" && allowed.includes(value);
|
|
12354
|
+
}
|
|
12355
|
+
function nonceBytes(nonce) {
|
|
12356
|
+
if (!Number.isSafeInteger(nonce) || nonce < 0) throw new Error("HL_INVALID_NONCE");
|
|
12357
|
+
const bytes = new Uint8Array(8);
|
|
12358
|
+
let value = BigInt(nonce);
|
|
12359
|
+
for (let i = 7; i >= 0; i--) {
|
|
12360
|
+
bytes[i] = Number(value & 0xffn);
|
|
12361
|
+
value >>= 8n;
|
|
12362
|
+
}
|
|
12363
|
+
return bytes;
|
|
12364
|
+
}
|
|
12365
|
+
function vaultMarker(vaultAddress) {
|
|
12366
|
+
if (!vaultAddress) return new Uint8Array([0]);
|
|
12367
|
+
if (!/^0x[0-9a-f]{40}$/i.test(vaultAddress)) throw new Error("HL_INVALID_VAULT_ADDRESS");
|
|
12368
|
+
return concat([new Uint8Array([1]), hexToBytes(vaultAddress)]);
|
|
12369
|
+
}
|
|
12370
|
+
function computeHlDigest(step) {
|
|
12371
|
+
const packed = (0, import_msgpack.encode)(step.action, { forceIntegerToFloat: false });
|
|
12372
|
+
const connectionId = keccak256(concat([packed, nonceBytes(step.nonce), vaultMarker(step.vault_address)]));
|
|
12373
|
+
return hashTypedData({
|
|
12374
|
+
domain: {
|
|
12375
|
+
name: "Exchange",
|
|
12376
|
+
version: "1",
|
|
12377
|
+
chainId: 1337,
|
|
12378
|
+
verifyingContract: ZERO_ADDRESS
|
|
12379
|
+
},
|
|
12380
|
+
types: HL_AGENT_TYPES,
|
|
12381
|
+
primaryType: "Agent",
|
|
12382
|
+
message: { source: step.is_mainnet ? "a" : "b", connectionId }
|
|
12383
|
+
});
|
|
12384
|
+
}
|
|
12385
|
+
function hasExactObjectKeys(value, allowed) {
|
|
12386
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
12387
|
+
const prototype = Object.getPrototypeOf(value);
|
|
12388
|
+
if (prototype !== Object.prototype && prototype !== null) return false;
|
|
12389
|
+
const keys = Object.keys(value);
|
|
12390
|
+
return keys.length === allowed.length && keys.every((key) => allowed.includes(key));
|
|
12391
|
+
}
|
|
12392
|
+
function isPlainRecord(value) {
|
|
12393
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
12394
|
+
const prototype = Object.getPrototypeOf(value);
|
|
12395
|
+
return prototype === Object.prototype || prototype === null;
|
|
12396
|
+
}
|
|
12397
|
+
function validateOrderAction(action, summary) {
|
|
12398
|
+
if (!hasExactObjectKeys(action, ["type", "orders", "grouping"])) throw new Error("HL_INVALID_ORDER_ACTION_SCHEMA");
|
|
12399
|
+
if (typeof summary.coin !== "string" || !summary.coin.trim()) throw new Error("HL_INVALID_COIN");
|
|
12400
|
+
if (!Number.isInteger(summary.asset_index)) throw new Error("HL_INVALID_ASSET_INDEX");
|
|
12401
|
+
if (!isExactStringMember(action.type, ["order"]) || !Array.isArray(action.orders) || action.orders.length !== 1) {
|
|
12402
|
+
throw new Error("HL_INVALID_ORDER_ACTION");
|
|
12403
|
+
}
|
|
12404
|
+
if (!isExactStringMember(action.grouping, ["na"])) throw new Error("HL_INVALID_ORDER_GROUPING");
|
|
12405
|
+
const order = action.orders[0];
|
|
12406
|
+
if (!hasExactObjectKeys(order, ["a", "b", "p", "r", "s", "t"])) throw new Error("HL_INVALID_ORDER_SCHEMA");
|
|
12407
|
+
if (!Number.isInteger(order.a) || typeof order.b !== "boolean") throw new Error("HL_INVALID_ORDER_ACTION");
|
|
12408
|
+
if (order.a !== summary.asset_index) throw new Error("HL_ASSET_MISMATCH");
|
|
12409
|
+
if (typeof order.p !== "string" || !Number.isFinite(Number(order.p)) || Number(order.p) <= 0) {
|
|
12410
|
+
throw new Error("HL_INVALID_ORDER_PRICE");
|
|
12411
|
+
}
|
|
12412
|
+
if (typeof order.s !== "string" || !Number.isFinite(Number(order.s)) || Number(order.s) <= 0) {
|
|
12413
|
+
throw new Error("HL_INVALID_ORDER_SIZE");
|
|
12414
|
+
}
|
|
12415
|
+
if (summary.size !== order.s) {
|
|
12416
|
+
throw new Error("HL_ORDER_SIZE_MISMATCH");
|
|
12417
|
+
}
|
|
12418
|
+
if (summary.notional_usd !== multiplyDecimalStrings(order.p, order.s)) {
|
|
12419
|
+
throw new Error("HL_INVALID_ORDER_NOTIONAL");
|
|
12420
|
+
}
|
|
12421
|
+
if (summary.price_cap !== order.p) throw new Error("HL_ORDER_PRICE_CAP_MISMATCH");
|
|
12422
|
+
if (!hasExactObjectKeys(order.t, ["limit"])) throw new Error("HL_INVALID_ORDER_TYPE_SCHEMA");
|
|
12423
|
+
const limit = order.t.limit;
|
|
12424
|
+
if (!hasExactObjectKeys(limit, ["tif"])) throw new Error("HL_INVALID_LIMIT_SCHEMA");
|
|
12425
|
+
const tif = limit.tif;
|
|
12426
|
+
if (!isExactStringMember(tif, ["Ioc", "Gtc", "Alo"]) || tif !== summary.tif) throw new Error("HL_TIF_MISMATCH");
|
|
12427
|
+
const expectedOrderType = tif === "Ioc" ? "market" : "limit";
|
|
12428
|
+
if (summary.order_type !== expectedOrderType) throw new Error("HL_ORDER_TYPE_MISMATCH");
|
|
12429
|
+
if (summary.limit_price !== (expectedOrderType === "limit" ? order.p : null))
|
|
12430
|
+
throw new Error("HL_LIMIT_PRICE_MISMATCH");
|
|
12431
|
+
if (order.r !== summary.reduce_only) throw new Error("HL_REDUCE_ONLY_MISMATCH");
|
|
12432
|
+
if (summary.operation === "close" && order.r !== true) throw new Error("HL_CLOSE_NOT_REDUCE_ONLY");
|
|
12433
|
+
const expectedBuy = summary.operation === "open" ? summary.side === "long" : summary.side === "short";
|
|
12434
|
+
if (order.b !== expectedBuy) throw new Error("HL_ORDER_SIDE_MISMATCH");
|
|
12435
|
+
}
|
|
12436
|
+
function multiplyDecimalStrings(left, right) {
|
|
12437
|
+
const parse = (value) => {
|
|
12438
|
+
if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) throw new Error("HL_INVALID_DECIMAL");
|
|
12439
|
+
const [whole2, fraction2 = ""] = value.split(".");
|
|
12440
|
+
return { digits: BigInt(`${whole2}${fraction2}`), scale: fraction2.length };
|
|
12441
|
+
};
|
|
12442
|
+
const a = parse(left);
|
|
12443
|
+
const b = parse(right);
|
|
12444
|
+
const scale = a.scale + b.scale;
|
|
12445
|
+
const raw = (a.digits * b.digits).toString().padStart(scale + 1, "0");
|
|
12446
|
+
if (scale === 0) return raw;
|
|
12447
|
+
const whole = raw.slice(0, -scale);
|
|
12448
|
+
const fraction = raw.slice(-scale).replace(/0+$/, "");
|
|
12449
|
+
return fraction ? `${whole}.${fraction}` : whole;
|
|
12450
|
+
}
|
|
12451
|
+
function validateLeverageAction(action, summary) {
|
|
12452
|
+
if (!hasExactObjectKeys(action, ["type", "asset", "isCross", "leverage"]))
|
|
12453
|
+
throw new Error("HL_INVALID_LEVERAGE_ACTION_SCHEMA");
|
|
12454
|
+
if (!isExactStringMember(action.type, ["updateLeverage"]) || !Number.isInteger(action.asset) || !Number.isInteger(action.leverage)) {
|
|
12455
|
+
throw new Error("HL_INVALID_LEVERAGE_ACTION");
|
|
12456
|
+
}
|
|
12457
|
+
if (typeof action.isCross !== "boolean" || action.leverage !== summary.leverage) {
|
|
12458
|
+
throw new Error("HL_LEVERAGE_MISMATCH");
|
|
12459
|
+
}
|
|
12460
|
+
if (action.asset !== summary.asset_index) throw new Error("HL_LEVERAGE_ASSET_MISMATCH");
|
|
12461
|
+
if (action.leverage < 1 || action.leverage > 100) {
|
|
12462
|
+
throw new Error("HL_INVALID_LEVERAGE");
|
|
12463
|
+
}
|
|
12464
|
+
const expectedCross = summary.margin_mode !== "isolated";
|
|
12465
|
+
if (action.isCross !== expectedCross) throw new Error("HL_MARGIN_MODE_MISMATCH");
|
|
12466
|
+
}
|
|
12467
|
+
function validatePayloadShape(payload) {
|
|
12468
|
+
if (!isPlainRecord(payload)) throw new Error("HL_INVALID_PAYLOAD");
|
|
12469
|
+
if (!isPlainRecord(payload.summary)) throw new Error("HL_INVALID_SUMMARY");
|
|
12470
|
+
if (!isPlainRecord(payload.asset_binding)) throw new Error("HL_INVALID_ASSET_BINDING");
|
|
12471
|
+
if (!Array.isArray(payload.steps)) throw new Error("HL_INVALID_STEPS");
|
|
12472
|
+
for (const key of ["operation", "side", "margin_mode", "reduce_only", "leverage"]) {
|
|
12473
|
+
if (key in payload) throw new Error("HL_CONFLICTING_TOP_LEVEL_FIELD");
|
|
12474
|
+
}
|
|
12475
|
+
}
|
|
12476
|
+
function validateSummary(summary) {
|
|
12477
|
+
if (!isExactStringMember(summary.operation, ["open", "close"])) throw new Error("HL_INVALID_OPERATION");
|
|
12478
|
+
if (!isExactStringMember(summary.side, ["long", "short"])) throw new Error("HL_INVALID_SIDE");
|
|
12479
|
+
if (!isExactStringMember(summary.order_type, ["market", "limit"])) throw new Error("HL_INVALID_ORDER_TYPE");
|
|
12480
|
+
if (!isExactStringMember(summary.tif, ["Ioc", "Gtc", "Alo"])) throw new Error("HL_INVALID_TIF");
|
|
12481
|
+
if (typeof summary.coin !== "string" || !summary.coin.trim()) throw new Error("HL_INVALID_COIN");
|
|
12482
|
+
if (!Number.isInteger(summary.asset_index)) throw new Error("HL_INVALID_ASSET_INDEX");
|
|
12483
|
+
if (summary.margin_mode !== void 0 && !isExactStringMember(summary.margin_mode, ["cross", "isolated"])) {
|
|
12484
|
+
throw new Error("HL_INVALID_MARGIN_MODE");
|
|
12485
|
+
}
|
|
12486
|
+
if (typeof summary.reduce_only !== "boolean") throw new Error("HL_INVALID_REDUCE_ONLY");
|
|
12487
|
+
}
|
|
12488
|
+
async function validateRequestBinding(payload, expected, vault, now) {
|
|
12489
|
+
if (payload.order_ref !== expected.orderRef || payload.conversation_id !== expected.conversationId) {
|
|
12490
|
+
throw new Error("HL_REFERENCE_MISMATCH");
|
|
12491
|
+
}
|
|
12492
|
+
if (typeof payload.owner_public_key !== "string") throw new Error("HL_INVALID_OWNER_PUBLIC_KEY");
|
|
12493
|
+
if (payload.owner_public_key.toLowerCase() !== expected.publicKey.toLowerCase()) throw new Error("HL_OWNER_MISMATCH");
|
|
12494
|
+
if (typeof payload.vault_address !== "string") throw new Error("HL_INVALID_VAULT_ADDRESS");
|
|
12495
|
+
const localAddress = await vault.address(Chain10.Ethereum);
|
|
12496
|
+
if (payload.vault_address.toLowerCase() !== localAddress.toLowerCase()) throw new Error("HL_VAULT_ADDRESS_MISMATCH");
|
|
12497
|
+
if (typeof payload.expires_at !== "string") throw new Error("HL_INVALID_EXPIRY");
|
|
12498
|
+
const expiry = Date.parse(payload.expires_at);
|
|
12499
|
+
if (!Number.isFinite(expiry) || expiry <= now) throw new Error("HL_ORDER_EXPIRED");
|
|
12500
|
+
if (expiry - now > 10 * 6e4) throw new Error("HL_EXPIRY_OUT_OF_RANGE");
|
|
12501
|
+
}
|
|
12502
|
+
function validateSteps(payload) {
|
|
12503
|
+
if (payload.steps.length < 1 || payload.steps.length > 2) throw new Error("HL_INVALID_STEP_COUNT");
|
|
12504
|
+
if (payload.steps.some((step) => !isPlainRecord(step) || !isPlainRecord(step.action)))
|
|
12505
|
+
throw new Error("HL_INVALID_STEP");
|
|
12506
|
+
if (payload.steps.some((step) => !isExactStringMember(step.kind, ["update_leverage", "order"])))
|
|
12507
|
+
throw new Error("HL_INVALID_STEP_KIND");
|
|
12508
|
+
if (payload.steps.some((step) => typeof step.is_mainnet !== "boolean")) throw new Error("HL_INVALID_NETWORK_FLAG");
|
|
12509
|
+
const isMainnet = payload.steps[0].is_mainnet;
|
|
12510
|
+
if (payload.steps.some((step) => step.is_mainnet !== isMainnet)) throw new Error("HL_NETWORK_MISMATCH");
|
|
12511
|
+
return payload.steps.filter((step) => step.kind === "order");
|
|
12512
|
+
}
|
|
12513
|
+
function validateCeremony(payload, orderSteps) {
|
|
12514
|
+
const leverageSteps = payload.steps.filter((step) => step.kind === "update_leverage");
|
|
12515
|
+
if (payload.summary.operation === "open") {
|
|
12516
|
+
if (payload.steps.length !== 2 || payload.steps[0]?.kind !== "update_leverage" || payload.steps[1]?.kind !== "order" || leverageSteps.length !== 1 || orderSteps.length !== 1 || payload.summary.leverage === void 0 || payload.summary.margin_mode === void 0 || payload.summary.reduce_only !== false)
|
|
12517
|
+
throw new Error("HL_INVALID_OPEN_CEREMONY");
|
|
12518
|
+
return;
|
|
12519
|
+
}
|
|
12520
|
+
if (payload.steps.length !== 1 || payload.steps[0]?.kind !== "order" || orderSteps.length !== 1 || leverageSteps.length !== 0 || payload.summary.leverage !== void 0 || payload.summary.margin_mode !== void 0 || payload.summary.reduce_only !== true)
|
|
12521
|
+
throw new Error("HL_INVALID_CLOSE_CEREMONY");
|
|
12522
|
+
}
|
|
12523
|
+
function validateSignedSteps(payload) {
|
|
12524
|
+
for (const step of payload.steps) {
|
|
12525
|
+
if (typeof step.digest !== "string") throw new Error("HL_INVALID_DIGEST");
|
|
12526
|
+
const computed = computeHlDigest(step);
|
|
12527
|
+
if (computed.toLowerCase() !== step.digest.toLowerCase()) throw new Error("HL_DIGEST_MISMATCH");
|
|
12528
|
+
if (step.kind === "order") validateOrderAction(step.action, payload.summary);
|
|
12529
|
+
else validateLeverageAction(step.action, payload.summary);
|
|
12530
|
+
}
|
|
12531
|
+
}
|
|
12532
|
+
async function validateHlSigningPayload(payload, expected, vault, now = Date.now()) {
|
|
12533
|
+
validatePayloadShape(payload);
|
|
12534
|
+
validateSummary(payload.summary);
|
|
12535
|
+
await validateRequestBinding(payload, expected, vault, now);
|
|
12536
|
+
const orderSteps = validateSteps(payload);
|
|
12537
|
+
validateCeremony(payload, orderSteps);
|
|
12538
|
+
if (payload.asset_binding.coin !== payload.summary.coin || payload.asset_binding.asset_index !== payload.summary.asset_index)
|
|
12539
|
+
throw new Error("HL_ASSET_BINDING_MISMATCH");
|
|
12540
|
+
validateSignedSteps(payload);
|
|
12541
|
+
if (expected.digest && orderSteps[0]?.digest.toLowerCase() !== expected.digest.toLowerCase()) {
|
|
12542
|
+
throw new Error("HL_EXPECTED_DIGEST_MISMATCH");
|
|
12543
|
+
}
|
|
12544
|
+
}
|
|
12545
|
+
function formatHlConfirmation(payload) {
|
|
12546
|
+
const s = payload.summary;
|
|
12547
|
+
const network = payload.steps[0]?.is_mainnet === false ? "Testnet" : "Mainnet";
|
|
12548
|
+
const leverage = s.leverage === void 0 ? "" : ` at ${s.leverage}x ${s.margin_mode ?? "cross"}`;
|
|
12549
|
+
const price = s.limit_price === null ? `market max execution price $${s.price_cap}` : `limit $${s.limit_price}`;
|
|
12550
|
+
return `Hyperliquid ${network} ${s.operation} ${s.side} ${s.size} ${s.coin} (asset #${s.asset_index}, signed notional $${s.notional_usd})${leverage}; ${s.order_type}/${s.tif}, ${price}, reduce-only=${s.reduce_only}. This signs and submits a live leveraged order.`;
|
|
12551
|
+
}
|
|
12552
|
+
async function pollHlOrderStatus(transport, params, initial, options = {}) {
|
|
12553
|
+
if (initial.state !== "accepted" && initial.state !== "submitting") return initial;
|
|
12554
|
+
const attempts = options.attempts ?? 20;
|
|
12555
|
+
const sleep4 = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
12556
|
+
let status = initial;
|
|
12557
|
+
for (let i = 1; i < attempts && (status.state === "accepted" || status.state === "submitting"); i++) {
|
|
12558
|
+
await sleep4(options.intervalMs ?? 1e3);
|
|
12559
|
+
try {
|
|
12560
|
+
status = await transport.getHlOrderStatus(params.orderRef, params.conversationId, params.publicKey);
|
|
12561
|
+
} catch {
|
|
12562
|
+
}
|
|
12563
|
+
}
|
|
12564
|
+
return status;
|
|
12565
|
+
}
|
|
12566
|
+
function isHlOrderFailure(status) {
|
|
12567
|
+
return status.state === "rejected" || status.state === "cancelled";
|
|
12568
|
+
}
|
|
12569
|
+
|
|
10869
12570
|
// src/agent/executor.ts
|
|
10870
12571
|
var EVM_CHAINS = /* @__PURE__ */ new Set([
|
|
10871
12572
|
"Ethereum",
|
|
@@ -10882,21 +12583,7 @@ var EVM_CHAINS = /* @__PURE__ */ new Set([
|
|
|
10882
12583
|
"Hyperliquid",
|
|
10883
12584
|
"Sei"
|
|
10884
12585
|
]);
|
|
10885
|
-
var
|
|
10886
|
-
Ethereum: "https://ethereum-rpc.publicnode.com",
|
|
10887
|
-
BSC: "https://bsc-dataseed.binance.org",
|
|
10888
|
-
Polygon: "https://polygon-bor-rpc.publicnode.com",
|
|
10889
|
-
Avalanche: "https://api.avax.network/ext/bc/C/rpc",
|
|
10890
|
-
Arbitrum: "https://arb1.arbitrum.io/rpc",
|
|
10891
|
-
Optimism: "https://mainnet.optimism.io",
|
|
10892
|
-
Base: "https://mainnet.base.org",
|
|
10893
|
-
Blast: "https://rpc.blast.io",
|
|
10894
|
-
Zksync: "https://mainnet.era.zksync.io",
|
|
10895
|
-
Mantle: "https://rpc.mantle.xyz",
|
|
10896
|
-
CronosChain: "https://cronos-evm-rpc.publicnode.com",
|
|
10897
|
-
Hyperliquid: "https://rpc.hyperliquid.xyz/evm",
|
|
10898
|
-
Sei: "https://evm-rpc.sei-apis.com"
|
|
10899
|
-
};
|
|
12586
|
+
var isEvmChain = (chain) => EVM_CHAINS.has(chain);
|
|
10900
12587
|
var AgentExecutor = class {
|
|
10901
12588
|
vault;
|
|
10902
12589
|
/** Owning SDK (optional); used for address book backed by app storage */
|
|
@@ -10922,6 +12609,7 @@ var AgentExecutor = class {
|
|
|
10922
12609
|
// fingerprints so two different vaults sending an identical tx don't collide
|
|
10923
12610
|
// in the single global journal (see BroadcastIntent.owner).
|
|
10924
12611
|
vaultPublicKey;
|
|
12612
|
+
consumedHlOrderRefs = /* @__PURE__ */ new Set();
|
|
10925
12613
|
constructor(vault, verbose = false, vaultId, vultisig) {
|
|
10926
12614
|
this.vault = vault;
|
|
10927
12615
|
this.verbose = verbose;
|
|
@@ -10931,6 +12619,79 @@ var AgentExecutor = class {
|
|
|
10931
12619
|
this.stateStore = new VaultStateStore(vaultId);
|
|
10932
12620
|
}
|
|
10933
12621
|
}
|
|
12622
|
+
async retrieveHlOrder(transport, input, conversationId) {
|
|
12623
|
+
const orderRef = typeof input.order_ref === "string" ? input.order_ref : "";
|
|
12624
|
+
if (!/^[0-9a-f-]{16,64}$/i.test(orderRef)) throw new Error("HL_INVALID_ORDER_REFERENCE");
|
|
12625
|
+
if (this.consumedHlOrderRefs.has(orderRef)) throw new Error("HL_ORDER_REFERENCE_REPLAYED");
|
|
12626
|
+
const payload = await transport.retrieveHlOrderSigningPayload(orderRef, conversationId, this.vaultPublicKey);
|
|
12627
|
+
this.consumedHlOrderRefs.add(orderRef);
|
|
12628
|
+
await validateHlSigningPayload(
|
|
12629
|
+
payload,
|
|
12630
|
+
{
|
|
12631
|
+
orderRef,
|
|
12632
|
+
conversationId,
|
|
12633
|
+
publicKey: this.vaultPublicKey,
|
|
12634
|
+
digest: typeof input.digest === "string" ? input.digest : void 0
|
|
12635
|
+
},
|
|
12636
|
+
this.vault
|
|
12637
|
+
);
|
|
12638
|
+
return payload;
|
|
12639
|
+
}
|
|
12640
|
+
async signAndSubmitHlOrder(transport, payload) {
|
|
12641
|
+
return this.runTool("hl_order", async () => {
|
|
12642
|
+
if (this.vault.isEncrypted && !this.vault.isUnlocked?.() && this.password) {
|
|
12643
|
+
await this.vault.unlock?.(this.password);
|
|
12644
|
+
}
|
|
12645
|
+
const expectedAddress = await this.vault.address(Chain11.Ethereum);
|
|
12646
|
+
const signatures = [];
|
|
12647
|
+
for (const step of payload.steps) {
|
|
12648
|
+
const signed = await this.vault.signBytes({
|
|
12649
|
+
data: step.digest,
|
|
12650
|
+
chain: Chain11.Ethereum
|
|
12651
|
+
});
|
|
12652
|
+
const canonical = toCanonicalEvmSignature(signed.signature, signed.recovery ?? 0);
|
|
12653
|
+
const v = canonical.recovery + 27;
|
|
12654
|
+
const wireSignature = `0x${canonical.r}${canonical.s}${v.toString(16).padStart(2, "0")}`;
|
|
12655
|
+
const recovered = await recoverAddress({
|
|
12656
|
+
hash: step.digest,
|
|
12657
|
+
signature: wireSignature
|
|
12658
|
+
});
|
|
12659
|
+
if (recovered.toLowerCase() !== expectedAddress.toLowerCase()) {
|
|
12660
|
+
throw new Error("HL_SIGNATURE_RECOVERY_MISMATCH");
|
|
12661
|
+
}
|
|
12662
|
+
signatures.push({
|
|
12663
|
+
kind: step.kind,
|
|
12664
|
+
digest: step.digest,
|
|
12665
|
+
r: `0x${canonical.r}`,
|
|
12666
|
+
s: `0x${canonical.s}`,
|
|
12667
|
+
v
|
|
12668
|
+
});
|
|
12669
|
+
}
|
|
12670
|
+
const params = {
|
|
12671
|
+
orderRef: payload.order_ref,
|
|
12672
|
+
conversationId: payload.conversation_id,
|
|
12673
|
+
publicKey: this.vaultPublicKey
|
|
12674
|
+
};
|
|
12675
|
+
const submitted = await transport.submitHlOrder(
|
|
12676
|
+
params.orderRef,
|
|
12677
|
+
params.conversationId,
|
|
12678
|
+
params.publicKey,
|
|
12679
|
+
signatures
|
|
12680
|
+
);
|
|
12681
|
+
const status = await pollHlOrderStatus(transport, params, submitted);
|
|
12682
|
+
if (isHlOrderFailure(status)) {
|
|
12683
|
+
throw new Error(`HL_ORDER_${status.state.toUpperCase()}: ${status.reason ?? "venue did not accept the order"}`);
|
|
12684
|
+
}
|
|
12685
|
+
return {
|
|
12686
|
+
order_ref: payload.order_ref,
|
|
12687
|
+
state: status.state,
|
|
12688
|
+
order_id: status.order_id,
|
|
12689
|
+
filled_size: status.filled_size,
|
|
12690
|
+
average_price: status.average_price,
|
|
12691
|
+
reason: status.reason
|
|
12692
|
+
};
|
|
12693
|
+
});
|
|
12694
|
+
}
|
|
10934
12695
|
setPassword(password) {
|
|
10935
12696
|
this.password = password;
|
|
10936
12697
|
}
|
|
@@ -11023,7 +12784,7 @@ var AgentExecutor = class {
|
|
|
11023
12784
|
return false;
|
|
11024
12785
|
}
|
|
11025
12786
|
const chain2 = approvalChain;
|
|
11026
|
-
if (!
|
|
12787
|
+
if (!isEvmChain(chain2)) {
|
|
11027
12788
|
if (this.verbose)
|
|
11028
12789
|
process.stderr.write(
|
|
11029
12790
|
`[executor] rejecting multi-leg envelope on non-EVM chain ${chain2}: signMultiLeg is EVM-only
|
|
@@ -11380,7 +13141,9 @@ var AgentExecutor = class {
|
|
|
11380
13141
|
}
|
|
11381
13142
|
const isMultiLeg = !!payload.__multiLeg;
|
|
11382
13143
|
const primaryIntent = isMultiLeg ? this.buildBroadcastIntent(payload, chain, { txArgs: payload.txArgs }) : this.buildBroadcastIntent(payload, chain);
|
|
11383
|
-
const approveIntent = isMultiLeg ? this.buildBroadcastIntent(payload, chain, {
|
|
13144
|
+
const approveIntent = isMultiLeg ? this.buildBroadcastIntent(payload, chain, {
|
|
13145
|
+
txArgs: payload.approvalTxArgs
|
|
13146
|
+
}) : void 0;
|
|
11384
13147
|
const primaryFp = computeFingerprint(primaryIntent);
|
|
11385
13148
|
const approveFp = approveIntent ? computeFingerprint(approveIntent) : void 0;
|
|
11386
13149
|
assertNoRecentDuplicate(primaryIntent, { force: this.forceBroadcast });
|
|
@@ -11926,7 +13689,7 @@ var AgentExecutor = class {
|
|
|
11926
13689
|
* Releases any previously held lock first (e.g. from an abandoned build).
|
|
11927
13690
|
*/
|
|
11928
13691
|
async acquireEvmLockIfNeeded(chain) {
|
|
11929
|
-
if (!this.stateStore || !
|
|
13692
|
+
if (!this.stateStore || !isEvmChain(chain)) return;
|
|
11930
13693
|
await this.releaseEvmLock(chain);
|
|
11931
13694
|
const release = await this.stateStore.acquireChainLock(chain);
|
|
11932
13695
|
this.chainLockReleases.set(chain, release);
|
|
@@ -11955,7 +13718,7 @@ var AgentExecutor = class {
|
|
|
11955
13718
|
* dropped and local state is stale.
|
|
11956
13719
|
*/
|
|
11957
13720
|
async patchEvmNonce(chain, payload) {
|
|
11958
|
-
if (!this.stateStore || !
|
|
13721
|
+
if (!this.stateStore || !isEvmChain(chain)) return;
|
|
11959
13722
|
const bs = payload.blockchainSpecific;
|
|
11960
13723
|
if (!bs || bs.case !== "ethereumSpecific") return;
|
|
11961
13724
|
const rpcNonce = bs.value.nonce;
|
|
@@ -12007,11 +13770,10 @@ var AgentExecutor = class {
|
|
|
12007
13770
|
* Compensates for gas price drift between build time and sign time.
|
|
12008
13771
|
*/
|
|
12009
13772
|
async patchEvmGas(chain, payload) {
|
|
12010
|
-
if (!
|
|
13773
|
+
if (!isEvmChain(chain)) return;
|
|
12011
13774
|
const bs = payload.blockchainSpecific;
|
|
12012
13775
|
if (!bs || bs.case !== "ethereumSpecific") return;
|
|
12013
|
-
const rpcUrl =
|
|
12014
|
-
if (!rpcUrl) return;
|
|
13776
|
+
const rpcUrl = getEvmRpcUrl(chain);
|
|
12015
13777
|
try {
|
|
12016
13778
|
const res = await fetch(rpcUrl, {
|
|
12017
13779
|
method: "POST",
|
|
@@ -12053,8 +13815,8 @@ var AgentExecutor = class {
|
|
|
12053
13815
|
* Returns null if the RPC call fails (non-fatal).
|
|
12054
13816
|
*/
|
|
12055
13817
|
async fetchEvmPendingNonce(chain) {
|
|
12056
|
-
|
|
12057
|
-
|
|
13818
|
+
if (!isEvmChain(chain)) return null;
|
|
13819
|
+
const rpcUrl = getEvmRpcUrl(chain);
|
|
12058
13820
|
try {
|
|
12059
13821
|
const address = await this.vault.address(chain);
|
|
12060
13822
|
const res = await fetch(rpcUrl, {
|
|
@@ -12082,7 +13844,7 @@ var AgentExecutor = class {
|
|
|
12082
13844
|
* For approve+swap flows with N message hashes, the highest nonce used is base + N - 1.
|
|
12083
13845
|
*/
|
|
12084
13846
|
recordEvmNonceFromPayload(chain, payload, numTxs) {
|
|
12085
|
-
if (!this.stateStore || !
|
|
13847
|
+
if (!this.stateStore || !isEvmChain(chain)) return;
|
|
12086
13848
|
const bs = payload.blockchainSpecific;
|
|
12087
13849
|
if (!bs || bs.case !== "ethereumSpecific") return;
|
|
12088
13850
|
const baseNonce = bs.value.nonce;
|
|
@@ -12158,7 +13920,7 @@ var AgentExecutor = class {
|
|
|
12158
13920
|
}
|
|
12159
13921
|
if (this.verbose) process.stderr.write(`[sign_typed_data] primaryType=${primaryType} domain.name=${domain.name}
|
|
12160
13922
|
`);
|
|
12161
|
-
const eip712Hash =
|
|
13923
|
+
const eip712Hash = computeEip712Hash(domain, types, primaryType, message);
|
|
12162
13924
|
if (this.verbose) process.stderr.write(`[sign_typed_data] hash=${eip712Hash}
|
|
12163
13925
|
`);
|
|
12164
13926
|
const chainName = params.chain;
|
|
@@ -12322,7 +14084,7 @@ function convertBaseUnitsToDecimal(chain, amountRaw, context) {
|
|
|
12322
14084
|
`${context}: amount '${amountRaw}' for ${chain} exceeds ${MAX_AMOUNT_DIGITS}-digit safety bound. Likely a quote-side bug. Refusing to sign.`
|
|
12323
14085
|
);
|
|
12324
14086
|
}
|
|
12325
|
-
const decimals =
|
|
14087
|
+
const decimals = chainFeeCoin2[chain]?.decimals;
|
|
12326
14088
|
if (decimals === void 0) {
|
|
12327
14089
|
throw new VaultError3(VaultErrorCode3.UnsupportedChain, `${context}: no native decimals registered for ${chain}`);
|
|
12328
14090
|
}
|
|
@@ -12351,7 +14113,7 @@ function parseNonEvmEnvelope(serverTxData, chain) {
|
|
|
12351
14113
|
const amountDecimal = convertBaseUnitsToDecimal(chain, amountRaw, "parseNonEvmEnvelope");
|
|
12352
14114
|
let symbol;
|
|
12353
14115
|
const tokenResolved = serverTxData?.resolved?.labels?.token_resolved;
|
|
12354
|
-
const nativeTicker =
|
|
14116
|
+
const nativeTicker = chainFeeCoin2[chain]?.ticker;
|
|
12355
14117
|
if (typeof tokenResolved === "string" && tokenResolved !== nativeTicker) {
|
|
12356
14118
|
symbol = tokenResolved;
|
|
12357
14119
|
}
|
|
@@ -12361,74 +14123,6 @@ function parseNonEvmEnvelope(serverTxData, chain) {
|
|
|
12361
14123
|
function resolveChainId(chainId) {
|
|
12362
14124
|
return resolveChainReference(chainId) ?? null;
|
|
12363
14125
|
}
|
|
12364
|
-
function computeEIP712Hash(domain, types, primaryType, message) {
|
|
12365
|
-
const messageTypes = { ...types };
|
|
12366
|
-
delete messageTypes.EIP712Domain;
|
|
12367
|
-
const normalizedDomain = domain.chainId !== void 0 ? { ...domain, chainId: coerceChainId(domain.chainId) } : domain;
|
|
12368
|
-
return hashTypedData({
|
|
12369
|
-
domain: normalizedDomain,
|
|
12370
|
-
types: messageTypes,
|
|
12371
|
-
primaryType,
|
|
12372
|
-
message
|
|
12373
|
-
});
|
|
12374
|
-
}
|
|
12375
|
-
function coerceChainId(raw) {
|
|
12376
|
-
if (typeof raw === "number" || typeof raw === "bigint") return raw;
|
|
12377
|
-
const s = String(raw).trim();
|
|
12378
|
-
if (s === "") {
|
|
12379
|
-
throw new Error("EIP-712 domain.chainId is empty");
|
|
12380
|
-
}
|
|
12381
|
-
if (/^[0-9]+$/.test(s) || /^0x[0-9a-fA-F]+$/.test(s)) {
|
|
12382
|
-
const big = BigInt(s);
|
|
12383
|
-
return big <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(big) : big;
|
|
12384
|
-
}
|
|
12385
|
-
throw new Error(`EIP-712 domain.chainId not parseable: ${String(raw)}`);
|
|
12386
|
-
}
|
|
12387
|
-
var SECP256K1_N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;
|
|
12388
|
-
function toCanonicalEvmSignature(sigHex, recovery) {
|
|
12389
|
-
const { r, s } = parseDERSignature(sigHex);
|
|
12390
|
-
const sBig = BigInt("0x" + s);
|
|
12391
|
-
if (sBig > SECP256K1_N >> 1n) {
|
|
12392
|
-
const folded = SECP256K1_N - sBig;
|
|
12393
|
-
return { r, s: folded.toString(16).padStart(64, "0"), recovery: recovery ^ 1 };
|
|
12394
|
-
}
|
|
12395
|
-
return { r, s, recovery };
|
|
12396
|
-
}
|
|
12397
|
-
function parseDERSignature(sigHex) {
|
|
12398
|
-
const raw = sigHex.startsWith("0x") ? sigHex.slice(2) : sigHex;
|
|
12399
|
-
if (raw.length === 128) {
|
|
12400
|
-
return { r: raw.slice(0, 64), s: raw.slice(64) };
|
|
12401
|
-
}
|
|
12402
|
-
let offset = 0;
|
|
12403
|
-
if (raw.slice(offset, offset + 2) !== "30") {
|
|
12404
|
-
return {
|
|
12405
|
-
r: raw.slice(0, 64).padStart(64, "0"),
|
|
12406
|
-
s: raw.slice(64).padStart(64, "0")
|
|
12407
|
-
};
|
|
12408
|
-
}
|
|
12409
|
-
offset += 2;
|
|
12410
|
-
offset += 2;
|
|
12411
|
-
if (raw.slice(offset, offset + 2) !== "02") throw new Error("Invalid DER: expected 02 for R");
|
|
12412
|
-
offset += 2;
|
|
12413
|
-
const rLen = parseInt(raw.slice(offset, offset + 2), 16);
|
|
12414
|
-
offset += 2;
|
|
12415
|
-
let rHex = raw.slice(offset, offset + rLen * 2);
|
|
12416
|
-
offset += rLen * 2;
|
|
12417
|
-
if (rHex.length > 64 && rHex.startsWith("00")) {
|
|
12418
|
-
rHex = rHex.slice(rHex.length - 64);
|
|
12419
|
-
}
|
|
12420
|
-
rHex = rHex.padStart(64, "0");
|
|
12421
|
-
if (raw.slice(offset, offset + 2) !== "02") throw new Error("Invalid DER: expected 02 for S");
|
|
12422
|
-
offset += 2;
|
|
12423
|
-
const sLen = parseInt(raw.slice(offset, offset + 2), 16);
|
|
12424
|
-
offset += 2;
|
|
12425
|
-
let sHex = raw.slice(offset, offset + sLen * 2);
|
|
12426
|
-
if (sHex.length > 64 && sHex.startsWith("00")) {
|
|
12427
|
-
sHex = sHex.slice(sHex.length - 64);
|
|
12428
|
-
}
|
|
12429
|
-
sHex = sHex.padStart(64, "0");
|
|
12430
|
-
return { r: rHex, s: sHex };
|
|
12431
|
-
}
|
|
12432
14126
|
|
|
12433
14127
|
// src/agent/toolOutputSigning.ts
|
|
12434
14128
|
var POLYMARKET_DEPOSIT_TOOL = "polymarket_deposit";
|
|
@@ -12670,6 +14364,26 @@ var AgentStreamIdleTimeoutError = class extends Error {
|
|
|
12670
14364
|
timeoutMs;
|
|
12671
14365
|
code = "TIMEOUT" /* TIMEOUT */;
|
|
12672
14366
|
};
|
|
14367
|
+
var HL_ORDER_BUILD_TOOLS = /* @__PURE__ */ new Set(["build_hyperliquid_open_position", "build_hyperliquid_close_position"]);
|
|
14368
|
+
function deriveHlOrderClientAction(toolName, output) {
|
|
14369
|
+
if (!HL_ORDER_BUILD_TOOLS.has(toolName)) return null;
|
|
14370
|
+
let value = output;
|
|
14371
|
+
if (typeof value === "string") {
|
|
14372
|
+
try {
|
|
14373
|
+
value = JSON.parse(value);
|
|
14374
|
+
} catch {
|
|
14375
|
+
return null;
|
|
14376
|
+
}
|
|
14377
|
+
}
|
|
14378
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
14379
|
+
const result = value;
|
|
14380
|
+
const expectedAction = toolName === "build_hyperliquid_open_position" ? "open" : "close";
|
|
14381
|
+
const expectedReduceOnly = expectedAction === "close";
|
|
14382
|
+
if (result.surface !== "hyperliquid_order" || result.status !== "ready_to_sign" || result.action !== expectedAction || typeof result.order_ref !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(result.order_ref) || typeof result.coin !== "string" || !Number.isInteger(result.asset_index) || typeof result.wire_size !== "string" || typeof result.price_cap !== "string" || typeof result.wire_notional_usd !== "string" || !["Ioc", "Gtc", "Alo"].includes(String(result.tif)) || result.reduce_only !== expectedReduceOnly) {
|
|
14383
|
+
return null;
|
|
14384
|
+
}
|
|
14385
|
+
return { order_ref: result.order_ref };
|
|
14386
|
+
}
|
|
12673
14387
|
function v1StatusFromType(type) {
|
|
12674
14388
|
switch (type) {
|
|
12675
14389
|
case "tool-input-start":
|
|
@@ -12832,7 +14546,10 @@ var AgentClient = class {
|
|
|
12832
14546
|
try {
|
|
12833
14547
|
res = await fetch(`${this.baseUrl}/auth/token`, {
|
|
12834
14548
|
method: "POST",
|
|
12835
|
-
headers: {
|
|
14549
|
+
headers: {
|
|
14550
|
+
"Content-Type": "application/json",
|
|
14551
|
+
...this.profileHeader()
|
|
14552
|
+
},
|
|
12836
14553
|
body: JSON.stringify(req),
|
|
12837
14554
|
signal: this.timeoutSignal()
|
|
12838
14555
|
});
|
|
@@ -12852,7 +14569,9 @@ var AgentClient = class {
|
|
|
12852
14569
|
// ============================================================================
|
|
12853
14570
|
async healthCheck() {
|
|
12854
14571
|
try {
|
|
12855
|
-
const res = await fetch(`${this.baseUrl}/healthz`, {
|
|
14572
|
+
const res = await fetch(`${this.baseUrl}/healthz`, {
|
|
14573
|
+
signal: this.timeoutSignal()
|
|
14574
|
+
});
|
|
12856
14575
|
return res.ok;
|
|
12857
14576
|
} catch {
|
|
12858
14577
|
return false;
|
|
@@ -12878,6 +14597,28 @@ var AgentClient = class {
|
|
|
12878
14597
|
public_key: publicKey
|
|
12879
14598
|
});
|
|
12880
14599
|
}
|
|
14600
|
+
async retrieveHlOrderSigningPayload(orderRef, conversationId, publicKey) {
|
|
14601
|
+
return this.post(
|
|
14602
|
+
`/agent/hyperliquid/orders/${encodeURIComponent(orderRef)}/signing-payload`,
|
|
14603
|
+
{
|
|
14604
|
+
conversation_id: conversationId,
|
|
14605
|
+
public_key: publicKey
|
|
14606
|
+
}
|
|
14607
|
+
);
|
|
14608
|
+
}
|
|
14609
|
+
async submitHlOrder(orderRef, conversationId, publicKey, signatures) {
|
|
14610
|
+
return this.post(`/agent/hyperliquid/orders/${encodeURIComponent(orderRef)}/submit`, {
|
|
14611
|
+
conversation_id: conversationId,
|
|
14612
|
+
public_key: publicKey,
|
|
14613
|
+
signatures
|
|
14614
|
+
});
|
|
14615
|
+
}
|
|
14616
|
+
async getHlOrderStatus(orderRef, conversationId, publicKey) {
|
|
14617
|
+
return this.post(`/agent/hyperliquid/orders/${encodeURIComponent(orderRef)}/status`, {
|
|
14618
|
+
conversation_id: conversationId,
|
|
14619
|
+
public_key: publicKey
|
|
14620
|
+
});
|
|
14621
|
+
}
|
|
12881
14622
|
// ============================================================================
|
|
12882
14623
|
// Messages - JSON mode
|
|
12883
14624
|
// ============================================================================
|
|
@@ -13139,7 +14880,12 @@ var AgentClient = class {
|
|
|
13139
14880
|
`);
|
|
13140
14881
|
let warning = result.protocolWarnings[0];
|
|
13141
14882
|
if (!warning) {
|
|
13142
|
-
warning = {
|
|
14883
|
+
warning = {
|
|
14884
|
+
code: "PROTOCOL_DRIFT",
|
|
14885
|
+
message: "",
|
|
14886
|
+
count: 0,
|
|
14887
|
+
eventTypes: []
|
|
14888
|
+
};
|
|
13143
14889
|
result.protocolWarnings.push(warning);
|
|
13144
14890
|
}
|
|
13145
14891
|
warning.count += 1;
|
|
@@ -13201,8 +14947,20 @@ var AgentClient = class {
|
|
|
13201
14947
|
const toolName = inlineName ?? (callId ? toolNameByCallId.get(callId) : void 0);
|
|
13202
14948
|
const label = typeof parsed.label === "string" ? parsed.label : void 0;
|
|
13203
14949
|
this.maybeEmitClientSideToolCall(parsed, callbacks, v1Type, callId, toolName);
|
|
13204
|
-
const
|
|
14950
|
+
const hlOrderAction = status === "done" && toolName && HL_ORDER_BUILD_TOOLS.has(toolName) ? deriveHlOrderClientAction(toolName, parsed.output) : void 0;
|
|
14951
|
+
const derivedOk = deriveToolDoneOk(status, parsed.output, v1Type);
|
|
14952
|
+
const ok = hlOrderAction === null ? false : derivedOk;
|
|
13205
14953
|
if (status && toolName) callbacks.onToolProgress?.(toolName, status, label, ok);
|
|
14954
|
+
if (status === "done" && toolName && HL_ORDER_BUILD_TOOLS.has(toolName)) {
|
|
14955
|
+
if (hlOrderAction && callId && callbacks.onClientSideToolCall) {
|
|
14956
|
+
callbacks.onClientSideToolCall(`${callId}:hl_order`, "hl_order", hlOrderAction);
|
|
14957
|
+
} else {
|
|
14958
|
+
callbacks.onError?.(
|
|
14959
|
+
"Hyperliquid preview was not delivered as a complete ready-to-sign action.",
|
|
14960
|
+
"INVALID_INPUT" /* INVALID_INPUT */
|
|
14961
|
+
);
|
|
14962
|
+
}
|
|
14963
|
+
}
|
|
13206
14964
|
this.maybeSignToolOutput(status, toolName, parsed.output, callbacks, v1Type);
|
|
13207
14965
|
if (status === "done" && callId) toolNameByCallId.delete(callId);
|
|
13208
14966
|
}
|
|
@@ -13421,7 +15179,7 @@ var AgentClient = class {
|
|
|
13421
15179
|
};
|
|
13422
15180
|
|
|
13423
15181
|
// src/agent/context.ts
|
|
13424
|
-
import {
|
|
15182
|
+
import { chainFeeCoin as chainFeeCoin3 } from "@vultisig/sdk";
|
|
13425
15183
|
function applyChainPublicKeys(vault, context) {
|
|
13426
15184
|
const raw = vault.data.chainPublicKeys;
|
|
13427
15185
|
if (!raw) return;
|
|
@@ -13482,11 +15240,12 @@ async function buildMessageContext(vault) {
|
|
|
13482
15240
|
const coins = [];
|
|
13483
15241
|
const chains = vault.chains;
|
|
13484
15242
|
for (const chain of chains) {
|
|
15243
|
+
const nativeCoin = chainFeeCoin3[chain];
|
|
13485
15244
|
coins.push({
|
|
13486
15245
|
chain: chain.toString(),
|
|
13487
|
-
ticker:
|
|
15246
|
+
ticker: nativeCoin?.ticker ?? chain.toString(),
|
|
13488
15247
|
is_native_token: true,
|
|
13489
|
-
decimals:
|
|
15248
|
+
decimals: nativeCoin?.decimals ?? 18
|
|
13490
15249
|
});
|
|
13491
15250
|
const tokens = vault.tokens[chain] || [];
|
|
13492
15251
|
for (const token of tokens) {
|
|
@@ -13532,62 +15291,6 @@ async function buildMinimalContext(vault) {
|
|
|
13532
15291
|
}
|
|
13533
15292
|
return context;
|
|
13534
15293
|
}
|
|
13535
|
-
function getNativeTokenTicker(chain) {
|
|
13536
|
-
const tickers = {
|
|
13537
|
-
[Chain13.Ethereum]: "ETH",
|
|
13538
|
-
[Chain13.Bitcoin]: "BTC",
|
|
13539
|
-
[Chain13.Solana]: "SOL",
|
|
13540
|
-
[Chain13.THORChain]: "RUNE",
|
|
13541
|
-
[Chain13.Cosmos]: "ATOM",
|
|
13542
|
-
[Chain13.Avalanche]: "AVAX",
|
|
13543
|
-
[Chain13.BSC]: "BNB",
|
|
13544
|
-
[Chain13.Polygon]: "MATIC",
|
|
13545
|
-
[Chain13.Arbitrum]: "ETH",
|
|
13546
|
-
[Chain13.Optimism]: "ETH",
|
|
13547
|
-
[Chain13.Base]: "ETH",
|
|
13548
|
-
[Chain13.Blast]: "ETH",
|
|
13549
|
-
[Chain13.Litecoin]: "LTC",
|
|
13550
|
-
[Chain13.Dogecoin]: "DOGE",
|
|
13551
|
-
[Chain13.Dash]: "DASH",
|
|
13552
|
-
[Chain13.MayaChain]: "CACAO",
|
|
13553
|
-
[Chain13.Polkadot]: "DOT",
|
|
13554
|
-
[Chain13.Sui]: "SUI",
|
|
13555
|
-
[Chain13.Ton]: "TON",
|
|
13556
|
-
[Chain13.Tron]: "TRX",
|
|
13557
|
-
[Chain13.Ripple]: "XRP",
|
|
13558
|
-
[Chain13.Dydx]: "DYDX",
|
|
13559
|
-
[Chain13.Osmosis]: "OSMO",
|
|
13560
|
-
[Chain13.Terra]: "LUNA",
|
|
13561
|
-
[Chain13.Noble]: "USDC",
|
|
13562
|
-
[Chain13.Kujira]: "KUJI",
|
|
13563
|
-
[Chain13.Zksync]: "ETH",
|
|
13564
|
-
[Chain13.CronosChain]: "CRO"
|
|
13565
|
-
};
|
|
13566
|
-
return tickers[chain] || chain.toString();
|
|
13567
|
-
}
|
|
13568
|
-
function getNativeTokenDecimals(chain) {
|
|
13569
|
-
const decimals = {
|
|
13570
|
-
[Chain13.Bitcoin]: 8,
|
|
13571
|
-
[Chain13.Litecoin]: 8,
|
|
13572
|
-
[Chain13.Dogecoin]: 8,
|
|
13573
|
-
[Chain13.Dash]: 8,
|
|
13574
|
-
[Chain13.Solana]: 9,
|
|
13575
|
-
[Chain13.Sui]: 9,
|
|
13576
|
-
[Chain13.Ton]: 9,
|
|
13577
|
-
[Chain13.Polkadot]: 10,
|
|
13578
|
-
[Chain13.Cosmos]: 6,
|
|
13579
|
-
[Chain13.THORChain]: 8,
|
|
13580
|
-
[Chain13.MayaChain]: 10,
|
|
13581
|
-
[Chain13.Osmosis]: 6,
|
|
13582
|
-
[Chain13.Dydx]: 18,
|
|
13583
|
-
[Chain13.Tron]: 6,
|
|
13584
|
-
[Chain13.Ripple]: 6,
|
|
13585
|
-
[Chain13.Noble]: 6,
|
|
13586
|
-
[Chain13.Kujira]: 6,
|
|
13587
|
-
[Chain13.Terra]: 6
|
|
13588
|
-
};
|
|
13589
|
-
return decimals[chain] || 18;
|
|
13590
|
-
}
|
|
13591
15294
|
|
|
13592
15295
|
// src/agent/pipe.ts
|
|
13593
15296
|
import * as readline from "node:readline";
|
|
@@ -13817,14 +15520,13 @@ import {
|
|
|
13817
15520
|
statSync as statSync3,
|
|
13818
15521
|
writeFileSync as writeFileSync3
|
|
13819
15522
|
} from "node:fs";
|
|
13820
|
-
import { homedir } from "node:os";
|
|
13821
15523
|
import { dirname as dirname2, join as join3 } from "node:path";
|
|
15524
|
+
import { getVultisigConfigDir as getVultisigConfigDir3 } from "@vultisig/client-shared";
|
|
13822
15525
|
var LOCK_RETRY_MS = 25;
|
|
13823
15526
|
var LOCK_MAX_WAIT_MS2 = 5e3;
|
|
13824
15527
|
var LOCK_STALE_MS2 = 3e4;
|
|
13825
15528
|
function getTokenCachePath() {
|
|
13826
|
-
|
|
13827
|
-
return join3(dir, "agent-tokens.json");
|
|
15529
|
+
return join3(getVultisigConfigDir3(), "agent-tokens.json");
|
|
13828
15530
|
}
|
|
13829
15531
|
function tokenCacheKey(scope) {
|
|
13830
15532
|
return JSON.stringify([scope.publicKey, scope.backendUrl.replace(/\/+$/, ""), scope.profile ?? ""]);
|
|
@@ -13960,7 +15662,7 @@ async function clearCachedToken(scope) {
|
|
|
13960
15662
|
}
|
|
13961
15663
|
|
|
13962
15664
|
// src/agent/session.ts
|
|
13963
|
-
var PASSWORD_REQUIRED_TOOLS = /* @__PURE__ */ new Set(["sign_typed_data", "sign_tx"]);
|
|
15665
|
+
var PASSWORD_REQUIRED_TOOLS = /* @__PURE__ */ new Set(["sign_typed_data", "sign_tx", "hl_order"]);
|
|
13964
15666
|
var AUTO_SUBMIT_MARKERS = /* @__PURE__ */ new Set([
|
|
13965
15667
|
"__pm_auto_submit",
|
|
13966
15668
|
"__pm_auto_submit_batch",
|
|
@@ -13982,7 +15684,8 @@ var BACKEND_CLIENT_SIDE_TOOL_NAMES = [
|
|
|
13982
15684
|
"delete_policy",
|
|
13983
15685
|
"sign_typed_data",
|
|
13984
15686
|
"polymarket_sign_bet",
|
|
13985
|
-
"polymarket_sign_batch"
|
|
15687
|
+
"polymarket_sign_batch",
|
|
15688
|
+
"hl_order"
|
|
13986
15689
|
];
|
|
13987
15690
|
var CLIENT_SIDE_DISPATCH_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
13988
15691
|
...BACKEND_CLIENT_SIDE_TOOL_NAMES,
|
|
@@ -13993,6 +15696,11 @@ var PROPOSED_SUMMARY_MAX_CHARS = 500;
|
|
|
13993
15696
|
function capSigningSummary(summary) {
|
|
13994
15697
|
return summary.length > PROPOSED_SUMMARY_MAX_CHARS ? `${summary.slice(0, PROPOSED_SUMMARY_MAX_CHARS)}\u2026` : summary;
|
|
13995
15698
|
}
|
|
15699
|
+
function applyAgentMode(request, config) {
|
|
15700
|
+
if (config.viaAgent || config.askMode) {
|
|
15701
|
+
request.via_agent = true;
|
|
15702
|
+
}
|
|
15703
|
+
}
|
|
13996
15704
|
var RECOVERY_POLL_INTERVAL_MS = 2e3;
|
|
13997
15705
|
var RECOVERY_MAX_POLLS = 90;
|
|
13998
15706
|
var TX_CONFIRM_POLL_INTERVAL_MS = 3e3;
|
|
@@ -14066,6 +15774,9 @@ var AgentSession = class {
|
|
|
14066
15774
|
pushService = null;
|
|
14067
15775
|
// Flushed into context.recent_actions on the next outbound request.
|
|
14068
15776
|
pendingToolResults = [];
|
|
15777
|
+
terminalHlConfirmation = false;
|
|
15778
|
+
firstHlOrderRef = null;
|
|
15779
|
+
seenHlOrderRefs = /* @__PURE__ */ new Set();
|
|
14069
15780
|
// Snapshot, taken the instant sendMessage's catch fires (BEFORE it clears the
|
|
14070
15781
|
// queue), of whether an already-broadcast tx result was still UNDELIVERED to
|
|
14071
15782
|
// the backend. This is the true "ack failed" signal: a successful broadcast
|
|
@@ -14200,7 +15911,9 @@ var AgentSession = class {
|
|
|
14200
15911
|
new Error(
|
|
14201
15912
|
`Session ${this.config.sessionId} could not be resumed (${err?.message ?? "unknown error"}); refusing to execute the request without its conversation context`
|
|
14202
15913
|
),
|
|
14203
|
-
{
|
|
15914
|
+
{
|
|
15915
|
+
code: isAuthError(err) ? "AUTH_FAILED" /* AUTH_FAILED */ : "SESSION_NOT_FOUND" /* SESSION_NOT_FOUND */
|
|
15916
|
+
}
|
|
14204
15917
|
);
|
|
14205
15918
|
}
|
|
14206
15919
|
this.conversationId = null;
|
|
@@ -14322,6 +16035,9 @@ var AgentSession = class {
|
|
|
14322
16035
|
throw new Error("Session not initialized");
|
|
14323
16036
|
}
|
|
14324
16037
|
this.abortController = new AbortController();
|
|
16038
|
+
this.terminalHlConfirmation = false;
|
|
16039
|
+
this.firstHlOrderRef = null;
|
|
16040
|
+
this.seenHlOrderRefs = /* @__PURE__ */ new Set();
|
|
14325
16041
|
this.unacknowledgedBroadcastAtError = false;
|
|
14326
16042
|
try {
|
|
14327
16043
|
this.cachedContext = this.config.viaAgent || this.config.askMode ? await buildMinimalContext(this.vault) : await buildMessageContext(this.vault);
|
|
@@ -14366,9 +16082,7 @@ var AgentSession = class {
|
|
|
14366
16082
|
// narrates. See cards.ts / backend types.go SupportedSurfaces.
|
|
14367
16083
|
supported_surfaces: [...CLI_SUPPORTED_SURFACES]
|
|
14368
16084
|
};
|
|
14369
|
-
|
|
14370
|
-
request.via_agent = true;
|
|
14371
|
-
}
|
|
16085
|
+
applyAgentMode(request, this.config);
|
|
14372
16086
|
if (content) {
|
|
14373
16087
|
request.content = content;
|
|
14374
16088
|
}
|
|
@@ -14398,6 +16112,14 @@ var AgentSession = class {
|
|
|
14398
16112
|
}
|
|
14399
16113
|
},
|
|
14400
16114
|
onClientSideToolCall: (toolCallId, toolName, input) => {
|
|
16115
|
+
if (toolName === "hl_order") {
|
|
16116
|
+
const orderRef = typeof input.order_ref === "string" ? input.order_ref : "";
|
|
16117
|
+
if (this.firstHlOrderRef === null || this.firstHlOrderRef === void 0) {
|
|
16118
|
+
this.firstHlOrderRef = orderRef;
|
|
16119
|
+
} else if (this.firstHlOrderRef !== orderRef) {
|
|
16120
|
+
return;
|
|
16121
|
+
}
|
|
16122
|
+
}
|
|
14401
16123
|
const dispatch = dispatchChain.then(() => this.dispatchClientSideTool(toolCallId, toolName, input, ui));
|
|
14402
16124
|
dispatchChain = dispatch.catch(() => {
|
|
14403
16125
|
});
|
|
@@ -14469,6 +16191,11 @@ var AgentSession = class {
|
|
|
14469
16191
|
if (pendingDispatches.length > 0) {
|
|
14470
16192
|
await Promise.all(pendingDispatches);
|
|
14471
16193
|
}
|
|
16194
|
+
if (this.terminalHlConfirmation) {
|
|
16195
|
+
this.pendingToolResults = this.pendingToolResults.filter((result) => result.tool !== "hl_order");
|
|
16196
|
+
ui.onDone();
|
|
16197
|
+
return;
|
|
16198
|
+
}
|
|
14472
16199
|
if (streamResult.disconnected && !streamResult.message) {
|
|
14473
16200
|
ui.onReconnecting?.();
|
|
14474
16201
|
await this.recoverDisconnectedTurn(streamResult, callbacks.onBalanceSummary);
|
|
@@ -14787,10 +16514,10 @@ var AgentSession = class {
|
|
|
14787
16514
|
* by the executor (or a synthetic failure `RecentAction` if the password
|
|
14788
16515
|
* prompt was declined).
|
|
14789
16516
|
*/
|
|
14790
|
-
async runPasswordGatedTool(toolName, toolCallId, ui, body, input) {
|
|
16517
|
+
async runPasswordGatedTool(toolName, toolCallId, ui, body, input, confirmationSummary) {
|
|
14791
16518
|
let signingRecord;
|
|
14792
16519
|
if (PASSWORD_REQUIRED_TOOLS.has(toolName)) {
|
|
14793
|
-
const summary = (toolName === "sign_tx" ? this.executor.getPendingSummary() : null) ?? `${toolName}${input ? ` ${JSON.stringify(input)}` : ""}`;
|
|
16520
|
+
const summary = confirmationSummary ?? (toolName === "sign_tx" ? this.executor.getPendingSummary() : null) ?? `${toolName}${input ? ` ${JSON.stringify(input)}` : ""}`;
|
|
14794
16521
|
const approved = await ui.requestConfirmation(summary);
|
|
14795
16522
|
if (!approved) {
|
|
14796
16523
|
return reportDeclinedSigning(this.executor, toolName, toolCallId, summary, input, ui);
|
|
@@ -14854,6 +16581,51 @@ var AgentSession = class {
|
|
|
14854
16581
|
// entries surface as a visible `[cli] unimplemented` warning + failure
|
|
14855
16582
|
// RecentAction (never silent).
|
|
14856
16583
|
async dispatchClientSideTool(toolCallId, toolName, input, ui) {
|
|
16584
|
+
if (toolName === "hl_order") {
|
|
16585
|
+
let recent2;
|
|
16586
|
+
try {
|
|
16587
|
+
const conversationId = this.conversationId;
|
|
16588
|
+
if (!conversationId) throw new Error("HL_CONVERSATION_REQUIRED");
|
|
16589
|
+
const orderRef = typeof input.order_ref === "string" ? input.order_ref : "";
|
|
16590
|
+
if (this.firstHlOrderRef === null || this.firstHlOrderRef === void 0) {
|
|
16591
|
+
this.firstHlOrderRef = orderRef;
|
|
16592
|
+
} else if (this.firstHlOrderRef !== orderRef) {
|
|
16593
|
+
return;
|
|
16594
|
+
}
|
|
16595
|
+
const seenRefs = this.seenHlOrderRefs ?? (this.seenHlOrderRefs = /* @__PURE__ */ new Set());
|
|
16596
|
+
if (seenRefs.has(orderRef)) return;
|
|
16597
|
+
seenRefs.add(orderRef);
|
|
16598
|
+
const payload = await this.executor.retrieveHlOrder(this.client, input, conversationId);
|
|
16599
|
+
recent2 = await this.runPasswordGatedTool(
|
|
16600
|
+
toolName,
|
|
16601
|
+
toolCallId,
|
|
16602
|
+
ui,
|
|
16603
|
+
() => this.executor.signAndSubmitHlOrder(this.client, payload),
|
|
16604
|
+
input,
|
|
16605
|
+
formatHlConfirmation(payload)
|
|
16606
|
+
);
|
|
16607
|
+
if (recent2.data?.code === "CONFIRMATION_REQUIRED" /* CONFIRMATION_REQUIRED */) {
|
|
16608
|
+
const proposed = String(recent2.data.proposed ?? formatHlConfirmation(payload));
|
|
16609
|
+
const card = {
|
|
16610
|
+
surface: "hyperliquid_order_confirmation",
|
|
16611
|
+
status: "confirmation_required",
|
|
16612
|
+
order_ref: payload.order_ref,
|
|
16613
|
+
...payload.summary,
|
|
16614
|
+
proposed
|
|
16615
|
+
};
|
|
16616
|
+
recent2.data.confirmation_card = card;
|
|
16617
|
+
this.terminalHlConfirmation = true;
|
|
16618
|
+
ui.onHlOrderConfirmation?.(card);
|
|
16619
|
+
}
|
|
16620
|
+
} catch (err) {
|
|
16621
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
16622
|
+
recent2 = { tool: toolName, success: false, data: { error: message } };
|
|
16623
|
+
ui.onToolCall(toolCallId, toolName, input);
|
|
16624
|
+
ui.onToolResult(toolCallId, toolName, false, recent2.data, message);
|
|
16625
|
+
}
|
|
16626
|
+
if (!this.terminalHlConfirmation) this.pendingToolResults.push(recent2);
|
|
16627
|
+
return;
|
|
16628
|
+
}
|
|
14857
16629
|
const handler = CLIENT_SIDE_TOOL_DISPATCH[toolName];
|
|
14858
16630
|
if (!handler) {
|
|
14859
16631
|
process.stderr.write(`[cli] unimplemented client-side tool: ${toolName}
|
|
@@ -14861,7 +16633,10 @@ var AgentSession = class {
|
|
|
14861
16633
|
this.pendingToolResults.push({
|
|
14862
16634
|
tool: toolName,
|
|
14863
16635
|
success: false,
|
|
14864
|
-
data: {
|
|
16636
|
+
data: {
|
|
16637
|
+
code: "TOOL_UNSUPPORTED" /* TOOL_UNSUPPORTED */,
|
|
16638
|
+
error: `unimplemented in CLI: ${toolName}`
|
|
16639
|
+
}
|
|
14865
16640
|
});
|
|
14866
16641
|
return;
|
|
14867
16642
|
}
|
|
@@ -15077,7 +16852,7 @@ var ChatTUI = class {
|
|
|
15077
16852
|
},
|
|
15078
16853
|
onAssistantMessage: (content) => {
|
|
15079
16854
|
if (this.isStreaming) {
|
|
15080
|
-
process.stdout.write(renderMarkdown(this.currentStreamText) + "\n");
|
|
16855
|
+
process.stdout.write(renderMarkdown(content || this.currentStreamText) + "\n");
|
|
15081
16856
|
this.isStreaming = false;
|
|
15082
16857
|
} else if (content && content !== this.currentStreamText) {
|
|
15083
16858
|
const ts = this.timestamp();
|
|
@@ -15396,6 +17171,7 @@ function outputAskError(wantsJson, message, code, conversationId, result) {
|
|
|
15396
17171
|
if (result?.toolCalls.length) data.tool_calls = result.toolCalls;
|
|
15397
17172
|
if (result?.response) data.response = result.response;
|
|
15398
17173
|
if (result?.warnings.length) data.warnings = result.warnings;
|
|
17174
|
+
if (result?.cards.length) data.cards = result.cards;
|
|
15399
17175
|
if (result?.outcome) data.outcome = result.outcome;
|
|
15400
17176
|
if (result?.proposedTransaction) {
|
|
15401
17177
|
data.confirmation_required = true;
|
|
@@ -15435,7 +17211,7 @@ var ACK_FAILED_MESSAGE = "A transaction was broadcast, but its post-broadcast re
|
|
|
15435
17211
|
function hasCommittedBroadcast(result) {
|
|
15436
17212
|
return !!result?.transactions.some((tx) => tx.hash.trim().length > 0 && tx.status !== "failed");
|
|
15437
17213
|
}
|
|
15438
|
-
var SIGNING_TOOLS = /* @__PURE__ */ new Set(["sign_tx", "sign_typed_data"]);
|
|
17214
|
+
var SIGNING_TOOLS = /* @__PURE__ */ new Set(["sign_tx", "sign_typed_data", "hl_order"]);
|
|
15439
17215
|
var CONFIRMATION_REQUIRED_MESSAGE = "The transaction was built but signing was not authorized, so nothing was signed or broadcast. Re-run with --yes to authorize signing.";
|
|
15440
17216
|
function failedSigningError(result) {
|
|
15441
17217
|
const failed = [...result.toolCalls].reverse().find((call) => SIGNING_TOOLS.has(call.action));
|
|
@@ -15513,9 +17289,15 @@ function outputAskHuman(result, confirmationRequired, proposed) {
|
|
|
15513
17289
|
}
|
|
15514
17290
|
writeSigningRecordLines(result.signingRecords, (line) => process.stdout.write(line));
|
|
15515
17291
|
for (const card of result.cards) {
|
|
15516
|
-
|
|
17292
|
+
if (card.surface === "balance_summary") {
|
|
17293
|
+
process.stdout.write(`
|
|
15517
17294
|
${renderBalanceSummaryCard(card)}
|
|
15518
17295
|
`);
|
|
17296
|
+
} else {
|
|
17297
|
+
process.stdout.write(`
|
|
17298
|
+
confirmation:${card.proposed}
|
|
17299
|
+
`);
|
|
17300
|
+
}
|
|
15519
17301
|
}
|
|
15520
17302
|
for (const card of result.yieldCards) {
|
|
15521
17303
|
process.stdout.write(`
|
|
@@ -15757,7 +17539,7 @@ function formatDate(iso) {
|
|
|
15757
17539
|
}
|
|
15758
17540
|
|
|
15759
17541
|
// src/lib/version.ts
|
|
15760
|
-
import { getVultisigConfigDir as
|
|
17542
|
+
import { getVultisigConfigDir as getVultisigConfigDir4 } from "@vultisig/client-shared";
|
|
15761
17543
|
import chalk11 from "chalk";
|
|
15762
17544
|
import { existsSync as existsSync2, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
15763
17545
|
import { join as join4 } from "path";
|
|
@@ -15765,7 +17547,7 @@ var cachedVersion = null;
|
|
|
15765
17547
|
function getVersion() {
|
|
15766
17548
|
if (cachedVersion) return cachedVersion;
|
|
15767
17549
|
if (true) {
|
|
15768
|
-
cachedVersion = "4.
|
|
17550
|
+
cachedVersion = "4.6.0";
|
|
15769
17551
|
return cachedVersion;
|
|
15770
17552
|
}
|
|
15771
17553
|
try {
|
|
@@ -15778,7 +17560,7 @@ function getVersion() {
|
|
|
15778
17560
|
return cachedVersion;
|
|
15779
17561
|
}
|
|
15780
17562
|
}
|
|
15781
|
-
var CACHE_DIR = join4(
|
|
17563
|
+
var CACHE_DIR = join4(getVultisigConfigDir4(), "cache");
|
|
15782
17564
|
var VERSION_CACHE_FILE = join4(CACHE_DIR, "version-check.json");
|
|
15783
17565
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
15784
17566
|
function readVersionCache() {
|
|
@@ -15862,7 +17644,7 @@ function formatVersionShort() {
|
|
|
15862
17644
|
}
|
|
15863
17645
|
function formatVersionDetailed() {
|
|
15864
17646
|
const lines = [];
|
|
15865
|
-
const configDir =
|
|
17647
|
+
const configDir = getVultisigConfigDir4();
|
|
15866
17648
|
lines.push(chalk11.bold(`Vultisig CLI v${getVersion()}`));
|
|
15867
17649
|
lines.push("");
|
|
15868
17650
|
lines.push(` Node.js: ${process.version}`);
|
|
@@ -16225,7 +18007,7 @@ var EventBuffer = class {
|
|
|
16225
18007
|
};
|
|
16226
18008
|
|
|
16227
18009
|
// src/interactive/session.ts
|
|
16228
|
-
import { Chain as
|
|
18010
|
+
import { Chain as Chain13, fiatCurrencies as fiatCurrencies3 } from "@vultisig/sdk";
|
|
16229
18011
|
import chalk14 from "chalk";
|
|
16230
18012
|
import ora3 from "ora";
|
|
16231
18013
|
import * as readline3 from "readline";
|
|
@@ -17027,7 +18809,7 @@ Error: ${error2.message}`));
|
|
|
17027
18809
|
const raw = args.includes("--raw");
|
|
17028
18810
|
await this.withCancellation(
|
|
17029
18811
|
() => executeBalance(this.ctx, {
|
|
17030
|
-
chain:
|
|
18812
|
+
chain: resolveOptionalChainOrThrow(chainStr),
|
|
17031
18813
|
includeTokens,
|
|
17032
18814
|
raw
|
|
17033
18815
|
})
|
|
@@ -17057,7 +18839,7 @@ Error: ${error2.message}`));
|
|
|
17057
18839
|
return;
|
|
17058
18840
|
}
|
|
17059
18841
|
const [chainStr, to, amount, ...rest] = args;
|
|
17060
|
-
const chain =
|
|
18842
|
+
const chain = resolveChainOrThrow(chainStr);
|
|
17061
18843
|
let tokenId;
|
|
17062
18844
|
let memo;
|
|
17063
18845
|
let destinationTag;
|
|
@@ -17074,7 +18856,7 @@ Error: ${error2.message}`));
|
|
|
17074
18856
|
} else if (rest[i] === "--destination-tag") {
|
|
17075
18857
|
const tag = rest[i + 1];
|
|
17076
18858
|
const parsedTag = Number(tag);
|
|
17077
|
-
if (chain !==
|
|
18859
|
+
if (chain !== Chain13.Ripple || !/^(0|[1-9]\d*)$/.test(tag ?? "") || !Number.isSafeInteger(parsedTag) || parsedTag > 4294967295) {
|
|
17078
18860
|
throw new Error("Invalid XRP DestinationTag: expected an integer from 0 to 4294967295");
|
|
17079
18861
|
}
|
|
17080
18862
|
destinationTag = parsedTag;
|
|
@@ -17099,7 +18881,7 @@ Error: ${error2.message}`));
|
|
|
17099
18881
|
return;
|
|
17100
18882
|
}
|
|
17101
18883
|
const [chainStr, txHash, ...rest] = args;
|
|
17102
|
-
const chain =
|
|
18884
|
+
const chain = resolveChainOrThrow(chainStr);
|
|
17103
18885
|
const noWait = rest.includes("--no-wait");
|
|
17104
18886
|
await this.withCancellation(() => executeTxStatus(this.ctx, { chain, txHash, noWait }));
|
|
17105
18887
|
}
|
|
@@ -17138,7 +18920,7 @@ Error: ${error2.message}`));
|
|
|
17138
18920
|
return;
|
|
17139
18921
|
}
|
|
17140
18922
|
const chainStr = args[0];
|
|
17141
|
-
const chain =
|
|
18923
|
+
const chain = resolveChainOrThrow(chainStr);
|
|
17142
18924
|
let add;
|
|
17143
18925
|
let remove;
|
|
17144
18926
|
for (let i = 1; i < args.length; i++) {
|
|
@@ -17160,8 +18942,8 @@ Error: ${error2.message}`));
|
|
|
17160
18942
|
return;
|
|
17161
18943
|
}
|
|
17162
18944
|
const [fromChainStr, toChainStr, amountStr, ...rest] = args;
|
|
17163
|
-
const fromChain =
|
|
17164
|
-
const toChain =
|
|
18945
|
+
const fromChain = resolveChainOrThrow(fromChainStr, "source chain");
|
|
18946
|
+
const toChain = resolveChainOrThrow(toChainStr, "destination chain");
|
|
17165
18947
|
const amount = amountStr;
|
|
17166
18948
|
let fromToken;
|
|
17167
18949
|
let toToken;
|
|
@@ -17186,8 +18968,8 @@ Error: ${error2.message}`));
|
|
|
17186
18968
|
return;
|
|
17187
18969
|
}
|
|
17188
18970
|
const [fromChainStr, toChainStr, amountStr, ...rest] = args;
|
|
17189
|
-
const fromChain =
|
|
17190
|
-
const toChain =
|
|
18971
|
+
const fromChain = resolveChainOrThrow(fromChainStr, "source chain");
|
|
18972
|
+
const toChain = resolveChainOrThrow(toChainStr, "destination chain");
|
|
17191
18973
|
const amount = amountStr;
|
|
17192
18974
|
let fromToken;
|
|
17193
18975
|
let toToken;
|
|
@@ -17227,7 +19009,7 @@ Error: ${error2.message}`));
|
|
|
17227
19009
|
remove = args[i + 1];
|
|
17228
19010
|
i++;
|
|
17229
19011
|
} else if (args[i] === "--chain" && i + 1 < args.length) {
|
|
17230
|
-
chain =
|
|
19012
|
+
chain = resolveChainOrThrow(args[i + 1], "chain");
|
|
17231
19013
|
i++;
|
|
17232
19014
|
}
|
|
17233
19015
|
}
|
|
@@ -17302,7 +19084,7 @@ Error: ${error2.message}`));
|
|
|
17302
19084
|
};
|
|
17303
19085
|
|
|
17304
19086
|
// src/lib/completion.ts
|
|
17305
|
-
import { getVultisigConfigDir as
|
|
19087
|
+
import { getVultisigConfigDir as getVultisigConfigDir5 } from "@vultisig/client-shared";
|
|
17306
19088
|
import { SUPPORTED_CHAINS as SUPPORTED_CHAINS2 } from "@vultisig/sdk";
|
|
17307
19089
|
import { program } from "commander";
|
|
17308
19090
|
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync5 } from "fs";
|
|
@@ -17329,7 +19111,7 @@ function getChains() {
|
|
|
17329
19111
|
}
|
|
17330
19112
|
function getVaultNames() {
|
|
17331
19113
|
try {
|
|
17332
|
-
const vaultDir =
|
|
19114
|
+
const vaultDir = getVultisigConfigDir5();
|
|
17333
19115
|
if (!existsSync3(vaultDir)) return [];
|
|
17334
19116
|
const files = readdirSync(vaultDir);
|
|
17335
19117
|
const names = [];
|
|
@@ -17582,10 +19364,10 @@ complete -c vsig -n "__fish_seen_subcommand_from import export" -a "(__fish_comp
|
|
|
17582
19364
|
}
|
|
17583
19365
|
|
|
17584
19366
|
// src/lib/config.ts
|
|
17585
|
-
import { getVultisigConfigDir as
|
|
19367
|
+
import { getVultisigConfigDir as getVultisigConfigDir6 } from "@vultisig/client-shared";
|
|
17586
19368
|
import { FileStorage } from "@vultisig/sdk/node";
|
|
17587
19369
|
function getConfigDir() {
|
|
17588
|
-
return
|
|
19370
|
+
return getVultisigConfigDir6();
|
|
17589
19371
|
}
|
|
17590
19372
|
function createVaultStorage() {
|
|
17591
19373
|
return new FileStorage({ basePath: getConfigDir() });
|
|
@@ -17896,7 +19678,7 @@ Examples:
|
|
|
17896
19678
|
withExit(async (chainStr, options) => {
|
|
17897
19679
|
const context = await init(program2.opts().vault);
|
|
17898
19680
|
await executeBalance(context, {
|
|
17899
|
-
chain:
|
|
19681
|
+
chain: resolveOptionalChainOrThrow(chainStr),
|
|
17900
19682
|
includeTokens: options.tokens,
|
|
17901
19683
|
raw: options.raw
|
|
17902
19684
|
});
|
|
@@ -17920,8 +19702,8 @@ See also: balance, tx-status`
|
|
|
17920
19702
|
async (chainStr, to, amount, options) => {
|
|
17921
19703
|
if (!amount && !options.max) throw new Error("Provide an amount or use --max");
|
|
17922
19704
|
if (amount && options.max) throw new Error("Cannot specify both amount and --max");
|
|
17923
|
-
const chain =
|
|
17924
|
-
if (options.destinationTag !== void 0 && chain !==
|
|
19705
|
+
const chain = resolveChainOrThrow(chainStr);
|
|
19706
|
+
if (options.destinationTag !== void 0 && chain !== Chain14.Ripple) {
|
|
17925
19707
|
throw new Error("--destination-tag is only supported for XRP");
|
|
17926
19708
|
}
|
|
17927
19709
|
const destinationTag = options.destinationTag === void 0 ? void 0 : Number(options.destinationTag);
|
|
@@ -17955,7 +19737,7 @@ Examples:
|
|
|
17955
19737
|
async (chainStr, contract, msg, options) => {
|
|
17956
19738
|
const context = await init(program2.opts().vault, options.password);
|
|
17957
19739
|
await executeExecute(context, {
|
|
17958
|
-
chain:
|
|
19740
|
+
chain: resolveChainOrThrow(chainStr),
|
|
17959
19741
|
contract,
|
|
17960
19742
|
msg,
|
|
17961
19743
|
funds: options.funds,
|
|
@@ -17971,7 +19753,7 @@ program2.command("sign").description("Sign pre-hashed bytes (for externally cons
|
|
|
17971
19753
|
withExit(async (options) => {
|
|
17972
19754
|
const context = await init(program2.opts().vault, options.password);
|
|
17973
19755
|
await executeSignBytes(context, {
|
|
17974
|
-
chain:
|
|
19756
|
+
chain: resolveChainOrThrow(options.chain),
|
|
17975
19757
|
bytes: options.bytes,
|
|
17976
19758
|
password: options.password
|
|
17977
19759
|
});
|
|
@@ -17981,7 +19763,7 @@ program2.command("broadcast").description("Broadcast a pre-signed raw transactio
|
|
|
17981
19763
|
withExit(async (options) => {
|
|
17982
19764
|
const context = await init(program2.opts().vault);
|
|
17983
19765
|
await executeBroadcast(context, {
|
|
17984
|
-
chain:
|
|
19766
|
+
chain: resolveChainOrThrow(options.chain),
|
|
17985
19767
|
rawTx: options.rawTx
|
|
17986
19768
|
});
|
|
17987
19769
|
})
|
|
@@ -18005,7 +19787,7 @@ Examples:
|
|
|
18005
19787
|
);
|
|
18006
19788
|
}
|
|
18007
19789
|
const params = resolveTxStatusParams({
|
|
18008
|
-
chain:
|
|
19790
|
+
chain: resolveChainOrThrow(options.chain),
|
|
18009
19791
|
txHash: options.txHash,
|
|
18010
19792
|
noWait: !options.wait,
|
|
18011
19793
|
timeoutSec
|
|
@@ -18081,7 +19863,7 @@ program2.command("address-book").description("Manage address book entries").opti
|
|
|
18081
19863
|
await executeAddressBook(context, {
|
|
18082
19864
|
add: options.add,
|
|
18083
19865
|
remove: options.remove,
|
|
18084
|
-
chain:
|
|
19866
|
+
chain: resolveOptionalChainOrThrow(options.chain),
|
|
18085
19867
|
address: options.address,
|
|
18086
19868
|
name: options.name
|
|
18087
19869
|
});
|
|
@@ -18098,9 +19880,9 @@ Examples:
|
|
|
18098
19880
|
withExit(async (options) => {
|
|
18099
19881
|
const context = await init(program2.opts().vault);
|
|
18100
19882
|
await executeChains(context, {
|
|
18101
|
-
add: options.add
|
|
19883
|
+
add: resolveOptionalChainOrThrow(options.add, "chain"),
|
|
18102
19884
|
addAll: options.addAll,
|
|
18103
|
-
remove: options.remove
|
|
19885
|
+
remove: resolveOptionalChainOrThrow(options.remove, "chain")
|
|
18104
19886
|
});
|
|
18105
19887
|
})
|
|
18106
19888
|
);
|
|
@@ -18217,8 +19999,8 @@ See also: swap-quote, swap-chains, balance`
|
|
|
18217
19999
|
if (amountStr && options.max) throw new Error("Cannot specify both amount and --max");
|
|
18218
20000
|
const context = await init(program2.opts().vault);
|
|
18219
20001
|
await executeSwap(context, {
|
|
18220
|
-
fromChain:
|
|
18221
|
-
toChain:
|
|
20002
|
+
fromChain: resolveChainOrThrow(fromChainStr, "source chain"),
|
|
20003
|
+
toChain: resolveChainOrThrow(toChainStr, "destination chain"),
|
|
18222
20004
|
amount: options.max ? "max" : amountStr,
|
|
18223
20005
|
fromToken: options.fromToken,
|
|
18224
20006
|
toToken: options.toToken,
|