@secondlayer/stacks 2.10.0 → 2.12.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/README.md +24 -0
- package/dist/shared/{stacks-4t2vmp4y.js → stacks-01pbr7gf.js} +17 -16
- package/dist/shared/stacks-01pbr7gf.js.map +11 -0
- package/dist/shared/{stacks-wyxj879g.cjs → stacks-18jv9aen.js} +83 -4
- package/dist/shared/stacks-18jv9aen.js.map +13 -0
- package/dist/shared/{stacks-0zysn74p.js → stacks-2mm20wqf.js} +3 -3
- package/dist/shared/{stacks-hxm7r5ay.cjs → stacks-44y18a8e.cjs} +3 -10
- package/dist/shared/stacks-44y18a8e.cjs.map +10 -0
- package/dist/shared/{stacks-2dhf79w5.js → stacks-59xy6t1p.js} +33 -31
- package/dist/shared/{stacks-2dhf79w5.js.map → stacks-59xy6t1p.js.map} +6 -6
- package/dist/shared/{stacks-99ghanwx.js → stacks-6n2m9hyk.js} +56 -6
- package/dist/shared/stacks-6n2m9hyk.js.map +10 -0
- package/dist/shared/{stacks-g7ffp8aj.js → stacks-6xt8py97.cjs} +59 -30
- package/dist/shared/stacks-6xt8py97.cjs.map +13 -0
- package/dist/shared/stacks-azp00pve.js +70 -0
- package/dist/shared/stacks-azp00pve.js.map +11 -0
- package/dist/shared/{stacks-vk8fwz0t.cjs → stacks-b9904rc2.cjs} +3 -2
- package/dist/shared/{stacks-vk8fwz0t.cjs.map → stacks-b9904rc2.cjs.map} +2 -2
- package/dist/shared/stacks-esn3wcw5.cjs +416 -0
- package/dist/shared/stacks-esn3wcw5.cjs.map +18 -0
- package/dist/shared/{stacks-3y058qda.cjs → stacks-fhzwsn5d.cjs} +16 -2
- package/dist/shared/{stacks-3y058qda.cjs.map → stacks-fhzwsn5d.cjs.map} +5 -4
- package/dist/shared/{stacks-e60vrr34.js → stacks-g11v9a35.js} +4 -4
- package/dist/shared/{stacks-0ek3cyt8.js → stacks-g67f4w1d.js} +7 -14
- package/dist/shared/stacks-g67f4w1d.js.map +10 -0
- package/dist/shared/{stacks-6xmk24yw.js → stacks-gfm3r397.cjs} +20 -7
- package/dist/shared/stacks-gfm3r397.cjs.map +11 -0
- package/dist/shared/{stacks-43cxvnr7.js → stacks-jbmcwky5.js} +3 -3
- package/dist/shared/stacks-kjg7fw4y.js +434 -0
- package/dist/shared/stacks-kjg7fw4y.js.map +18 -0
- package/dist/shared/{stacks-q1mjkt15.js → stacks-msmgyerb.js} +4 -4
- package/dist/shared/{stacks-2h8d2y27.js → stacks-qs5fzts5.js} +17 -3
- package/dist/shared/{stacks-2h8d2y27.js.map → stacks-qs5fzts5.js.map} +5 -4
- package/dist/shared/{stacks-xw0j252s.cjs → stacks-shn9zw99.cjs} +43 -3
- package/dist/shared/stacks-shn9zw99.cjs.map +10 -0
- package/dist/shared/{stacks-vf0ekgwb.js → stacks-ssndnbbd.js} +8 -10
- package/dist/shared/{stacks-vf0ekgwb.js.map → stacks-ssndnbbd.js.map} +2 -2
- package/dist/shared/{stacks-maamjqma.cjs → stacks-tbv5p6pn.cjs} +7 -9
- package/dist/shared/stacks-tbv5p6pn.cjs.map +11 -0
- package/dist/shared/{stacks-a36n7sjz.js → stacks-x94a1d6s.js} +3 -3
- package/dist/shared/{stacks-k5an9zcw.cjs → stacks-y5epf0sb.cjs} +19 -22
- package/dist/shared/{stacks-k5an9zcw.cjs.map → stacks-y5epf0sb.cjs.map} +6 -6
- package/dist/src/accounts/index.js +3 -5
- package/dist/src/accounts/index.js.map +2 -2
- package/dist/src/actions/index.cjs +8 -1
- package/dist/src/actions/index.cjs.map +1 -1
- package/dist/src/actions/index.d.cts +198 -13
- package/dist/src/actions/index.d.ts +198 -13
- package/dist/src/actions/index.js +29 -17
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.js +8 -11
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.js +12 -14
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/clarity/index.d.cts +50 -1
- package/dist/src/clarity/index.d.ts +50 -1
- package/dist/src/clarity/index.js +8 -7
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/index.cjs +10 -1
- package/dist/src/index.cjs.map +3 -3
- package/dist/src/index.d.cts +167 -9
- package/dist/src/index.d.ts +167 -9
- package/dist/src/index.js +30 -17
- package/dist/src/index.js.map +3 -3
- package/dist/src/postconditions/index.js +3 -3
- package/dist/src/pox/index.js +11 -13
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/sbtc/index.js +10 -12
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +11 -13
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/tools/index.cjs +348 -63
- package/dist/src/tools/index.cjs.map +18 -15
- package/dist/src/tools/index.js +348 -63
- package/dist/src/tools/index.js.map +18 -15
- package/dist/src/transactions/index.js +6 -7
- package/dist/src/transactions/index.js.map +1 -1
- package/dist/src/utils/index.cjs +2 -1
- package/dist/src/utils/index.cjs.map +2 -2
- package/dist/src/utils/index.d.cts +5 -1
- package/dist/src/utils/index.d.ts +5 -1
- package/dist/src/utils/index.js +12 -14
- package/dist/src/utils/index.js.map +2 -2
- package/dist/src/x402/index.cjs +5 -2
- package/dist/src/x402/index.cjs.map +3 -3
- package/dist/src/x402/index.d.cts +36 -0
- package/dist/src/x402/index.d.ts +36 -0
- package/dist/src/x402/index.js +13 -11
- package/dist/src/x402/index.js.map +3 -3
- package/package.json +1 -1
- package/dist/shared/stacks-0ek3cyt8.js.map +0 -10
- package/dist/shared/stacks-4t2vmp4y.js.map +0 -11
- package/dist/shared/stacks-6xmk24yw.js.map +0 -10
- package/dist/shared/stacks-99ghanwx.js.map +0 -10
- package/dist/shared/stacks-9g0jhab3.cjs +0 -40
- package/dist/shared/stacks-9g0jhab3.cjs.map +0 -10
- package/dist/shared/stacks-9t68zmpn.js +0 -210
- package/dist/shared/stacks-9t68zmpn.js.map +0 -15
- package/dist/shared/stacks-fcaefc5b.cjs +0 -16
- package/dist/shared/stacks-fcaefc5b.cjs.map +0 -10
- package/dist/shared/stacks-g7ffp8aj.js.map +0 -13
- package/dist/shared/stacks-hxm7r5ay.cjs.map +0 -10
- package/dist/shared/stacks-maamjqma.cjs.map +0 -11
- package/dist/shared/stacks-v9jqcpd4.js +0 -18
- package/dist/shared/stacks-v9jqcpd4.js.map +0 -10
- package/dist/shared/stacks-wyxj879g.cjs.map +0 -13
- package/dist/shared/stacks-xmsms921.cjs +0 -196
- package/dist/shared/stacks-xmsms921.cjs.map +0 -15
- package/dist/shared/stacks-xw0j252s.cjs.map +0 -10
- package/dist/shared/stacks-xxn5ma6g.js +0 -22
- package/dist/shared/stacks-xxn5ma6g.js.map +0 -10
- package/dist/shared/stacks-ya3x01yd.cjs +0 -16
- package/dist/shared/stacks-ya3x01yd.cjs.map +0 -10
- /package/dist/shared/{stacks-0zysn74p.js.map → stacks-2mm20wqf.js.map} +0 -0
- /package/dist/shared/{stacks-e60vrr34.js.map → stacks-g11v9a35.js.map} +0 -0
- /package/dist/shared/{stacks-43cxvnr7.js.map → stacks-jbmcwky5.js.map} +0 -0
- /package/dist/shared/{stacks-q1mjkt15.js.map → stacks-msmgyerb.js.map} +0 -0
- /package/dist/shared/{stacks-a36n7sjz.js.map → stacks-x94a1d6s.js.map} +0 -0
package/dist/src/tools/index.cjs
CHANGED
|
@@ -41,7 +41,7 @@ var __export = (target, all) => {
|
|
|
41
41
|
var exports_tools = {};
|
|
42
42
|
__export(exports_tools, {
|
|
43
43
|
readContract: () => readContract2,
|
|
44
|
-
getTransaction: () =>
|
|
44
|
+
getTransaction: () => getTransaction2,
|
|
45
45
|
getStxBalance: () => getStxBalance,
|
|
46
46
|
getNftHoldings: () => getNftHoldings,
|
|
47
47
|
getMempoolStats: () => getMempoolStats,
|
|
@@ -748,7 +748,37 @@ class BytesReader {
|
|
|
748
748
|
}
|
|
749
749
|
}
|
|
750
750
|
|
|
751
|
+
// src/utils/constants.ts
|
|
752
|
+
var MAX_U128 = (1n << 128n) - 1n;
|
|
753
|
+
var MAX_I128 = (1n << 127n) - 1n;
|
|
754
|
+
var MIN_I128 = -(1n << 127n);
|
|
755
|
+
var AddressVersion = {
|
|
756
|
+
MainnetSingleSig: 22,
|
|
757
|
+
MainnetMultiSig: 20,
|
|
758
|
+
TestnetSingleSig: 26,
|
|
759
|
+
TestnetMultiSig: 21
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// src/utils/hash.ts
|
|
763
|
+
var import_legacy = require("@noble/hashes/legacy.js");
|
|
764
|
+
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
765
|
+
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
766
|
+
function hash160(input) {
|
|
767
|
+
return import_legacy.ripemd160(import_sha22.sha256(input));
|
|
768
|
+
}
|
|
769
|
+
function txidFromBytes(data) {
|
|
770
|
+
return bytesToHex(import_sha23.sha512_256(data));
|
|
771
|
+
}
|
|
772
|
+
function hashP2PKH(input) {
|
|
773
|
+
return bytesToHex(hash160(input));
|
|
774
|
+
}
|
|
775
|
+
|
|
751
776
|
// src/utils/address.ts
|
|
777
|
+
function publicKeyToAddress(publicKey, network = "mainnet") {
|
|
778
|
+
const bytes = typeof publicKey === "string" ? hexToBytes(without0x(publicKey)) : publicKey;
|
|
779
|
+
const version = network === "mainnet" ? AddressVersion.MainnetSingleSig : AddressVersion.TestnetSingleSig;
|
|
780
|
+
return c32address(version, bytesToHex(hash160(bytes)));
|
|
781
|
+
}
|
|
752
782
|
function parseContractId(contractId) {
|
|
753
783
|
const [address, name] = contractId.split(".");
|
|
754
784
|
if (!address || !name)
|
|
@@ -761,9 +791,9 @@ function isClarityName(name) {
|
|
|
761
791
|
}
|
|
762
792
|
|
|
763
793
|
// src/clarity/values.ts
|
|
764
|
-
var
|
|
765
|
-
var
|
|
766
|
-
var
|
|
794
|
+
var MAX_U1282 = BigInt("0xffffffffffffffffffffffffffffffff");
|
|
795
|
+
var MIN_I1282 = BigInt("-170141183460469231731687303715884105728");
|
|
796
|
+
var MAX_I1282 = BigInt("0x7fffffffffffffffffffffffffffffff");
|
|
767
797
|
function intCV(value) {
|
|
768
798
|
let v = value;
|
|
769
799
|
if (typeof v === "string" && v.toLowerCase().startsWith("0x")) {
|
|
@@ -772,18 +802,18 @@ function intCV(value) {
|
|
|
772
802
|
if (v instanceof Uint8Array)
|
|
773
803
|
v = bytesToTwosBigInt(v);
|
|
774
804
|
const n = intToBigInt(v);
|
|
775
|
-
if (n >
|
|
776
|
-
throw new RangeError(`Int exceeds max i128: ${
|
|
777
|
-
if (n <
|
|
778
|
-
throw new RangeError(`Int below min i128: ${
|
|
805
|
+
if (n > MAX_I1282)
|
|
806
|
+
throw new RangeError(`Int exceeds max i128: ${MAX_I1282}`);
|
|
807
|
+
if (n < MIN_I1282)
|
|
808
|
+
throw new RangeError(`Int below min i128: ${MIN_I1282}`);
|
|
779
809
|
return { type: "int", value: n };
|
|
780
810
|
}
|
|
781
811
|
function uintCV(value) {
|
|
782
812
|
const n = intToBigInt(value);
|
|
783
813
|
if (n < 0n)
|
|
784
814
|
throw new RangeError("Cannot construct unsigned int from negative value");
|
|
785
|
-
if (n >
|
|
786
|
-
throw new RangeError(`UInt exceeds max u128: ${
|
|
815
|
+
if (n > MAX_U1282)
|
|
816
|
+
throw new RangeError(`UInt exceeds max u128: ${MAX_U1282}`);
|
|
787
817
|
return { type: "uint", value: n };
|
|
788
818
|
}
|
|
789
819
|
var trueCV = () => ({ type: "true" });
|
|
@@ -796,13 +826,13 @@ function bufferCV(buffer) {
|
|
|
796
826
|
return { type: "buffer", value: bytesToHex(buffer) };
|
|
797
827
|
}
|
|
798
828
|
function standardPrincipalCV(address) {
|
|
799
|
-
const [version,
|
|
800
|
-
const normalized = c32address(version,
|
|
829
|
+
const [version, hash1602] = c32addressDecode(address);
|
|
830
|
+
const normalized = c32address(version, hash1602);
|
|
801
831
|
return { type: "address", value: normalized };
|
|
802
832
|
}
|
|
803
833
|
function contractPrincipalCV(address, contractName) {
|
|
804
|
-
const [version,
|
|
805
|
-
const normalized = c32address(version,
|
|
834
|
+
const [version, hash1602] = c32addressDecode(address);
|
|
835
|
+
const normalized = c32address(version, hash1602);
|
|
806
836
|
if (utf8ToBytes(contractName).byteLength >= 128) {
|
|
807
837
|
throw new Error("Contract name must be less than 128 bytes");
|
|
808
838
|
}
|
|
@@ -873,8 +903,8 @@ var Cl = {
|
|
|
873
903
|
// src/clarity/deserialize.ts
|
|
874
904
|
function readAddress(reader) {
|
|
875
905
|
const version = reader.readUInt8();
|
|
876
|
-
const
|
|
877
|
-
return c32address(version,
|
|
906
|
+
const hash1602 = bytesToHex(reader.readBytes(20));
|
|
907
|
+
return c32address(version, hash1602);
|
|
878
908
|
}
|
|
879
909
|
function readLPString(reader, prefixBytes = 1) {
|
|
880
910
|
let length = 0;
|
|
@@ -971,11 +1001,6 @@ function toCamelCase(str) {
|
|
|
971
1001
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/-([A-Z])/g, (_, letter) => letter).replace(/-(\d)/g, (_, digit) => digit).replace(/-/g, "").replace(/^\d/, "_$&");
|
|
972
1002
|
}
|
|
973
1003
|
|
|
974
|
-
// src/utils/constants.ts
|
|
975
|
-
var MAX_U1282 = (1n << 128n) - 1n;
|
|
976
|
-
var MAX_I1282 = (1n << 127n) - 1n;
|
|
977
|
-
var MIN_I1282 = -(1n << 127n);
|
|
978
|
-
|
|
979
1004
|
// src/clarity/abi/guards.ts
|
|
980
1005
|
function isAbiList(type) {
|
|
981
1006
|
return typeof type === "object" && type !== null && "list" in type;
|
|
@@ -1000,7 +1025,64 @@ function isAbiStringUtf8(type) {
|
|
|
1000
1025
|
}
|
|
1001
1026
|
|
|
1002
1027
|
// src/clarity/bridge.ts
|
|
1028
|
+
var CV_TYPE_TAGS = new Set([
|
|
1029
|
+
"int",
|
|
1030
|
+
"uint",
|
|
1031
|
+
"true",
|
|
1032
|
+
"false",
|
|
1033
|
+
"address",
|
|
1034
|
+
"contract",
|
|
1035
|
+
"ascii",
|
|
1036
|
+
"utf8",
|
|
1037
|
+
"buffer",
|
|
1038
|
+
"list",
|
|
1039
|
+
"tuple",
|
|
1040
|
+
"none",
|
|
1041
|
+
"some",
|
|
1042
|
+
"ok",
|
|
1043
|
+
"err"
|
|
1044
|
+
]);
|
|
1045
|
+
function isClarityValue(value) {
|
|
1046
|
+
if (typeof value !== "object" || value === null)
|
|
1047
|
+
return false;
|
|
1048
|
+
const type = value.type;
|
|
1049
|
+
if (typeof type !== "string" || !CV_TYPE_TAGS.has(type))
|
|
1050
|
+
return false;
|
|
1051
|
+
if (type === "true" || type === "false" || type === "none")
|
|
1052
|
+
return true;
|
|
1053
|
+
return "value" in value;
|
|
1054
|
+
}
|
|
1055
|
+
var HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;
|
|
1056
|
+
function coerceBuffer(value) {
|
|
1057
|
+
if (value instanceof Uint8Array)
|
|
1058
|
+
return bufferCV(value);
|
|
1059
|
+
if (typeof value === "object" && value !== null && "type" in value) {
|
|
1060
|
+
const tagged = value;
|
|
1061
|
+
if (tagged.type === "buffer" && isClarityValue(value))
|
|
1062
|
+
return value;
|
|
1063
|
+
if (typeof tagged.value === "string") {
|
|
1064
|
+
if (tagged.type === "ascii")
|
|
1065
|
+
return Cl.bufferFromAscii(tagged.value);
|
|
1066
|
+
if (tagged.type === "utf8")
|
|
1067
|
+
return Cl.bufferFromUtf8(tagged.value);
|
|
1068
|
+
if (tagged.type === "hex")
|
|
1069
|
+
return Cl.bufferFromHex(tagged.value);
|
|
1070
|
+
}
|
|
1071
|
+
throw new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);
|
|
1072
|
+
}
|
|
1073
|
+
if (typeof value === "string") {
|
|
1074
|
+
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
1075
|
+
if (HEX_PAIRS_REGEX.test(hex))
|
|
1076
|
+
return Cl.bufferFromHex(hex);
|
|
1077
|
+
return Cl.bufferFromUtf8(value);
|
|
1078
|
+
}
|
|
1079
|
+
throw new Error("buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV");
|
|
1080
|
+
}
|
|
1003
1081
|
function jsToClarityValue(abiType, value) {
|
|
1082
|
+
if (isAbiBuffer(abiType))
|
|
1083
|
+
return coerceBuffer(value);
|
|
1084
|
+
if (isClarityValue(value))
|
|
1085
|
+
return value;
|
|
1004
1086
|
if (abiType === "uint128")
|
|
1005
1087
|
return uintCV(value);
|
|
1006
1088
|
if (abiType === "int128")
|
|
@@ -1013,8 +1095,6 @@ function jsToClarityValue(abiType, value) {
|
|
|
1013
1095
|
return stringAsciiCV(value);
|
|
1014
1096
|
if (isAbiStringUtf8(abiType))
|
|
1015
1097
|
return stringUtf8CV(value);
|
|
1016
|
-
if (isAbiBuffer(abiType))
|
|
1017
|
-
return bufferCV(value);
|
|
1018
1098
|
if (isAbiList(abiType)) {
|
|
1019
1099
|
const arr = value;
|
|
1020
1100
|
return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
|
|
@@ -1120,37 +1200,10 @@ function clarityValueToJSInner(abiType, cv) {
|
|
|
1120
1200
|
throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
|
|
1121
1201
|
}
|
|
1122
1202
|
|
|
1123
|
-
// src/actions/public/getMapEntry.ts
|
|
1124
|
-
async function getMapEntry(client, params) {
|
|
1125
|
-
const [address, name] = parseContractId(params.contract);
|
|
1126
|
-
const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
|
|
1127
|
-
const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
|
|
1128
|
-
method: "POST",
|
|
1129
|
-
body: serializedKey
|
|
1130
|
-
});
|
|
1131
|
-
return deserializeCVBytes(data.data);
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
1203
|
// src/transactions/authorization.ts
|
|
1135
1204
|
var import_hmac = require("@noble/hashes/hmac.js");
|
|
1136
1205
|
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
1137
1206
|
var import_secp256k1 = require("@noble/secp256k1");
|
|
1138
|
-
|
|
1139
|
-
// src/utils/hash.ts
|
|
1140
|
-
var import_legacy = require("@noble/hashes/legacy.js");
|
|
1141
|
-
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
1142
|
-
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
1143
|
-
function hash160(input) {
|
|
1144
|
-
return import_legacy.ripemd160(import_sha22.sha256(input));
|
|
1145
|
-
}
|
|
1146
|
-
function txidFromBytes(data) {
|
|
1147
|
-
return bytesToHex(import_sha23.sha512_256(data));
|
|
1148
|
-
}
|
|
1149
|
-
function hashP2PKH(input) {
|
|
1150
|
-
return bytesToHex(hash160(input));
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
// src/transactions/authorization.ts
|
|
1154
1207
|
import_secp256k1.etc.hmacSha256Sync = (key, ...msgs) => {
|
|
1155
1208
|
const h = import_hmac.hmac.create(import_sha24.sha256, key);
|
|
1156
1209
|
for (const msg of msgs)
|
|
@@ -1362,6 +1415,17 @@ function buildContractCall(options) {
|
|
|
1362
1415
|
return tx;
|
|
1363
1416
|
}
|
|
1364
1417
|
|
|
1418
|
+
// src/actions/public/getMapEntry.ts
|
|
1419
|
+
async function getMapEntry(client, params) {
|
|
1420
|
+
const [address, name] = parseContractId(params.contract);
|
|
1421
|
+
const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
|
|
1422
|
+
const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
|
|
1423
|
+
method: "POST",
|
|
1424
|
+
body: serializedKey
|
|
1425
|
+
});
|
|
1426
|
+
return deserializeCVBytes(data.data);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1365
1429
|
// src/transactions/signer.ts
|
|
1366
1430
|
function txid(tx) {
|
|
1367
1431
|
return txidFromBytes(serializeTransaction(tx));
|
|
@@ -1425,10 +1489,39 @@ class BroadcastError extends BaseError {
|
|
|
1425
1489
|
name = "BroadcastError";
|
|
1426
1490
|
txid;
|
|
1427
1491
|
reason;
|
|
1492
|
+
reasonData;
|
|
1428
1493
|
constructor(message, options) {
|
|
1429
1494
|
super(message, options);
|
|
1430
1495
|
this.txid = options?.txid;
|
|
1431
1496
|
this.reason = options?.reason;
|
|
1497
|
+
this.reasonData = options?.reasonData;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
class TransactionAbortedError extends BaseError {
|
|
1502
|
+
name = "TransactionAbortedError";
|
|
1503
|
+
receipt;
|
|
1504
|
+
constructor(message, options) {
|
|
1505
|
+
super(message, options);
|
|
1506
|
+
this.receipt = options.receipt;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
class TransactionDroppedError extends BaseError {
|
|
1511
|
+
name = "TransactionDroppedError";
|
|
1512
|
+
txid;
|
|
1513
|
+
constructor(message, options) {
|
|
1514
|
+
super(message, options);
|
|
1515
|
+
this.txid = options.txid;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
class WaitForTransactionTimeoutError extends BaseError {
|
|
1520
|
+
name = "WaitForTransactionTimeoutError";
|
|
1521
|
+
txid;
|
|
1522
|
+
constructor(message, options) {
|
|
1523
|
+
super(message, options);
|
|
1524
|
+
this.txid = options.txid;
|
|
1432
1525
|
}
|
|
1433
1526
|
}
|
|
1434
1527
|
|
|
@@ -1444,6 +1537,107 @@ async function getNonce(client, params) {
|
|
|
1444
1537
|
return BigInt(nonce);
|
|
1445
1538
|
}
|
|
1446
1539
|
|
|
1540
|
+
// src/actions/public/txSources.ts
|
|
1541
|
+
function normalizeTxid(txid2) {
|
|
1542
|
+
return txid2.startsWith("0x") ? txid2 : `0x${txid2}`;
|
|
1543
|
+
}
|
|
1544
|
+
function decodeResultHex(hex) {
|
|
1545
|
+
if (!hex)
|
|
1546
|
+
return {};
|
|
1547
|
+
try {
|
|
1548
|
+
return { result: deserializeCVBytes(hex), resultHex: hex };
|
|
1549
|
+
} catch {
|
|
1550
|
+
return { resultHex: hex };
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
function normalizeStatus(txStatus) {
|
|
1554
|
+
switch (txStatus) {
|
|
1555
|
+
case "pending":
|
|
1556
|
+
case "success":
|
|
1557
|
+
case "abort_by_response":
|
|
1558
|
+
case "abort_by_post_condition":
|
|
1559
|
+
return txStatus;
|
|
1560
|
+
default:
|
|
1561
|
+
return txStatus.startsWith("dropped") ? "dropped" : undefined;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
function extendedApiSource() {
|
|
1565
|
+
return {
|
|
1566
|
+
async get({ client, txid: txid2 }) {
|
|
1567
|
+
const data = await client.request(`/extended/v1/tx/${normalizeTxid(txid2)}`, { method: "GET" });
|
|
1568
|
+
const txStatus = typeof data?.tx_status === "string" ? data.tx_status : undefined;
|
|
1569
|
+
if (!txStatus)
|
|
1570
|
+
return { receipt: null };
|
|
1571
|
+
const status = normalizeStatus(txStatus);
|
|
1572
|
+
if (!status)
|
|
1573
|
+
return { receipt: null };
|
|
1574
|
+
return {
|
|
1575
|
+
receipt: {
|
|
1576
|
+
txid: normalizeTxid(txid2),
|
|
1577
|
+
status,
|
|
1578
|
+
blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
|
|
1579
|
+
blockHash: data.block_hash ?? undefined,
|
|
1580
|
+
...decodeResultHex(data.tx_result?.hex),
|
|
1581
|
+
events: Array.isArray(data.events) ? data.events : [],
|
|
1582
|
+
raw: data
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// src/actions/public/waitForTransactionReceipt.ts
|
|
1590
|
+
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1591
|
+
async function waitForTransactionReceipt(client, params) {
|
|
1592
|
+
const {
|
|
1593
|
+
txid: txid2,
|
|
1594
|
+
confirmations = 1,
|
|
1595
|
+
timeout = 180000,
|
|
1596
|
+
pollingInterval = 3000,
|
|
1597
|
+
droppedGracePeriod = 30000
|
|
1598
|
+
} = params;
|
|
1599
|
+
const source = params.source ?? extendedApiSource();
|
|
1600
|
+
const startedAt = Date.now();
|
|
1601
|
+
let unknownSince = null;
|
|
1602
|
+
let everPending = false;
|
|
1603
|
+
while (true) {
|
|
1604
|
+
const snapshot = await source.get({ client, txid: txid2 });
|
|
1605
|
+
const receipt = snapshot.receipt;
|
|
1606
|
+
if (receipt === null) {
|
|
1607
|
+
unknownSince ??= Date.now();
|
|
1608
|
+
if (Date.now() - unknownSince >= droppedGracePeriod) {
|
|
1609
|
+
throw new TransactionDroppedError(everPending ? `Transaction ${txid2} left the mempool without being mined` : `Transaction ${txid2} was never observed by the status source`, { txid: txid2 });
|
|
1610
|
+
}
|
|
1611
|
+
} else {
|
|
1612
|
+
unknownSince = null;
|
|
1613
|
+
switch (receipt.status) {
|
|
1614
|
+
case "dropped":
|
|
1615
|
+
throw new TransactionDroppedError(`Transaction ${txid2} was dropped from the mempool`, { txid: txid2 });
|
|
1616
|
+
case "abort_by_response":
|
|
1617
|
+
case "abort_by_post_condition":
|
|
1618
|
+
throw new TransactionAbortedError(`Transaction ${txid2} aborted (${receipt.status})`, { receipt });
|
|
1619
|
+
case "pending":
|
|
1620
|
+
everPending = true;
|
|
1621
|
+
break;
|
|
1622
|
+
case "success": {
|
|
1623
|
+
if (confirmations <= 1)
|
|
1624
|
+
return receipt;
|
|
1625
|
+
if (receipt.blockHeight !== undefined) {
|
|
1626
|
+
const tip = snapshot.tip ?? await getBlockHeight(client);
|
|
1627
|
+
if (tip - receipt.blockHeight + 1 >= confirmations)
|
|
1628
|
+
return receipt;
|
|
1629
|
+
}
|
|
1630
|
+
break;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (Date.now() - startedAt >= timeout) {
|
|
1635
|
+
throw new WaitForTransactionTimeoutError(`Timed out after ${timeout}ms waiting for transaction ${txid2}`, { txid: txid2 });
|
|
1636
|
+
}
|
|
1637
|
+
await sleep(pollingInterval);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1447
1641
|
// src/actions/wallet/sendTransaction.ts
|
|
1448
1642
|
async function sendTransaction(client, params) {
|
|
1449
1643
|
const hex = bytesToHex(serializeTransaction(params.transaction));
|
|
@@ -1457,10 +1651,20 @@ async function sendTransaction(client, params) {
|
|
|
1457
1651
|
});
|
|
1458
1652
|
if (data.error) {
|
|
1459
1653
|
throw new BroadcastError(data.reason ?? data.error, {
|
|
1460
|
-
reason: data.reason
|
|
1654
|
+
reason: data.reason,
|
|
1655
|
+
reasonData: data.reason_data,
|
|
1656
|
+
txid: data.txid ?? getTransactionId(params.transaction)
|
|
1461
1657
|
});
|
|
1462
1658
|
}
|
|
1463
1659
|
const txid2 = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
|
|
1660
|
+
if (params.wait) {
|
|
1661
|
+
const confirmations = params.wait === true ? 1 : params.wait;
|
|
1662
|
+
const receipt = await waitForTransactionReceipt(client, {
|
|
1663
|
+
txid: txid2,
|
|
1664
|
+
confirmations
|
|
1665
|
+
});
|
|
1666
|
+
return { txid: txid2, receipt };
|
|
1667
|
+
}
|
|
1464
1668
|
return { txid: txid2 };
|
|
1465
1669
|
}
|
|
1466
1670
|
|
|
@@ -1473,8 +1677,12 @@ async function resolveNonce(client, address) {
|
|
|
1473
1677
|
function isNonceConflictError(error) {
|
|
1474
1678
|
if (!(error instanceof BroadcastError))
|
|
1475
1679
|
return false;
|
|
1476
|
-
|
|
1477
|
-
|
|
1680
|
+
if (error.reason === "ConflictingNonceInMempool" || error.reason === "BadNonce") {
|
|
1681
|
+
return true;
|
|
1682
|
+
}
|
|
1683
|
+
if (error.reason !== undefined)
|
|
1684
|
+
return false;
|
|
1685
|
+
return error.message.toLowerCase().includes("nonce");
|
|
1478
1686
|
}
|
|
1479
1687
|
async function broadcastWithNonceReset(client, params) {
|
|
1480
1688
|
try {
|
|
@@ -1494,6 +1702,36 @@ async function broadcastWithNonceReset(client, params) {
|
|
|
1494
1702
|
function isProviderAccount(account) {
|
|
1495
1703
|
return account.type === "provider";
|
|
1496
1704
|
}
|
|
1705
|
+
var FEE_TIERS = ["min", "low", "mid", "high"];
|
|
1706
|
+
var TIER_INDEX = { low: 0, mid: 1, high: 2 };
|
|
1707
|
+
function isFeeTier(fee) {
|
|
1708
|
+
return typeof fee === "string" && FEE_TIERS.includes(fee);
|
|
1709
|
+
}
|
|
1710
|
+
function minimumFee(transaction) {
|
|
1711
|
+
return BigInt(serializeTransaction(transaction).length);
|
|
1712
|
+
}
|
|
1713
|
+
async function resolveFee(client, transaction, fee) {
|
|
1714
|
+
if (fee !== undefined && !isFeeTier(fee))
|
|
1715
|
+
return intToBigInt(fee);
|
|
1716
|
+
const tier = fee ?? "mid";
|
|
1717
|
+
if (tier === "min")
|
|
1718
|
+
return minimumFee(transaction);
|
|
1719
|
+
try {
|
|
1720
|
+
const estimates = await estimateFee(client, { transaction });
|
|
1721
|
+
const pick = estimates[TIER_INDEX[tier]] ?? estimates[estimates.length - 1];
|
|
1722
|
+
if (pick)
|
|
1723
|
+
return BigInt(pick.fee);
|
|
1724
|
+
} catch {}
|
|
1725
|
+
return minimumFee(transaction);
|
|
1726
|
+
}
|
|
1727
|
+
function setUnsignedFee(transaction, fee) {
|
|
1728
|
+
transaction.auth.spendingCondition.fee = fee;
|
|
1729
|
+
}
|
|
1730
|
+
function assertNoFeeTierForProvider(fee) {
|
|
1731
|
+
if (isFeeTier(fee)) {
|
|
1732
|
+
throw new Error(`Fee tier '${fee}' requires local signing; provider (wallet) accounts set their own fee`);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1497
1735
|
|
|
1498
1736
|
// src/actions/wallet/callContract.ts
|
|
1499
1737
|
async function callContract(client, params) {
|
|
@@ -1502,6 +1740,7 @@ async function callContract(client, params) {
|
|
|
1502
1740
|
throw new Error("Account required");
|
|
1503
1741
|
const [contractAddress, contractName] = parseContractId(params.contract);
|
|
1504
1742
|
if (isProviderAccount(account)) {
|
|
1743
|
+
assertNoFeeTierForProvider(params.fee);
|
|
1505
1744
|
const result = await account.provider.request("stx_callContract", {
|
|
1506
1745
|
contract: params.contract,
|
|
1507
1746
|
functionName: params.functionName,
|
|
@@ -1510,24 +1749,21 @@ async function callContract(client, params) {
|
|
|
1510
1749
|
return result.txid;
|
|
1511
1750
|
}
|
|
1512
1751
|
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
1752
|
+
const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
|
|
1513
1753
|
const unsigned = buildContractCall({
|
|
1514
1754
|
contractAddress,
|
|
1515
1755
|
contractName,
|
|
1516
1756
|
functionName: params.functionName,
|
|
1517
1757
|
functionArgs: params.functionArgs ?? [],
|
|
1518
|
-
fee: params.fee
|
|
1758
|
+
fee: needsFeeResolution ? 0n : params.fee,
|
|
1519
1759
|
nonce,
|
|
1520
1760
|
publicKey: account.publicKey,
|
|
1521
1761
|
chain: client.chain,
|
|
1522
1762
|
postConditionMode: params.postConditionMode,
|
|
1523
1763
|
postConditions: params.postConditions
|
|
1524
1764
|
});
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1527
|
-
const mid = estimates[1] ?? estimates[0];
|
|
1528
|
-
if (mid) {
|
|
1529
|
-
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
1530
|
-
}
|
|
1765
|
+
if (needsFeeResolution) {
|
|
1766
|
+
setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
|
|
1531
1767
|
}
|
|
1532
1768
|
const signed = await signTransactionWithAccount(unsigned, account);
|
|
1533
1769
|
return broadcastWithNonceReset(client, {
|
|
@@ -1600,6 +1836,46 @@ function getContract(params) {
|
|
|
1600
1836
|
};
|
|
1601
1837
|
}
|
|
1602
1838
|
});
|
|
1839
|
+
const buildCall = new Proxy({}, {
|
|
1840
|
+
get(_target, prop) {
|
|
1841
|
+
const fnName = camelToKebab.get(prop) ?? prop;
|
|
1842
|
+
const fn = fnByName.get(fnName);
|
|
1843
|
+
if (!fn || fn.access !== "public")
|
|
1844
|
+
return;
|
|
1845
|
+
return async (args, options) => {
|
|
1846
|
+
const publicKey = options?.publicKey ?? client.account?.publicKey;
|
|
1847
|
+
if (!publicKey) {
|
|
1848
|
+
throw new Error("buildCall requires a publicKey (pass options.publicKey or configure a client account)");
|
|
1849
|
+
}
|
|
1850
|
+
const functionArgs = buildFunctionArgs(fn, args);
|
|
1851
|
+
const network = client.chain?.network ?? "mainnet";
|
|
1852
|
+
const nonce = options?.nonce ?? await resolveNonce(client, publicKeyToAddress(publicKey, network));
|
|
1853
|
+
const unsigned = buildContractCall({
|
|
1854
|
+
contractAddress: address,
|
|
1855
|
+
contractName,
|
|
1856
|
+
functionName: fn.name,
|
|
1857
|
+
functionArgs,
|
|
1858
|
+
fee: options?.fee ?? 0n,
|
|
1859
|
+
nonce,
|
|
1860
|
+
publicKey,
|
|
1861
|
+
chain: client.chain,
|
|
1862
|
+
postConditionMode: options?.postConditionMode,
|
|
1863
|
+
postConditions: options?.postConditions,
|
|
1864
|
+
sponsored: options?.sponsored
|
|
1865
|
+
});
|
|
1866
|
+
if (options?.fee === undefined) {
|
|
1867
|
+
const estimates = await estimateFee(client, {
|
|
1868
|
+
transaction: unsigned
|
|
1869
|
+
});
|
|
1870
|
+
const mid = estimates[1] ?? estimates[0];
|
|
1871
|
+
if (mid) {
|
|
1872
|
+
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
return unsigned;
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
});
|
|
1603
1879
|
const maps = new Proxy({}, {
|
|
1604
1880
|
get(_target, prop) {
|
|
1605
1881
|
const mapName = camelToKebab.get(prop) ?? prop;
|
|
@@ -1622,7 +1898,7 @@ function getContract(params) {
|
|
|
1622
1898
|
};
|
|
1623
1899
|
}
|
|
1624
1900
|
});
|
|
1625
|
-
return { read, call, maps };
|
|
1901
|
+
return { read, call, buildCall, maps };
|
|
1626
1902
|
}
|
|
1627
1903
|
function resolveNetworkContract(client, contracts) {
|
|
1628
1904
|
if (!client.chain) {
|
|
@@ -2307,6 +2583,13 @@ async function getContractAbi(client, params) {
|
|
|
2307
2583
|
});
|
|
2308
2584
|
}
|
|
2309
2585
|
|
|
2586
|
+
// src/actions/public/getTransaction.ts
|
|
2587
|
+
async function getTransaction(client, params) {
|
|
2588
|
+
const source = params.source ?? extendedApiSource();
|
|
2589
|
+
const { receipt } = await source.get({ client, txid: params.txid });
|
|
2590
|
+
return receipt;
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2310
2593
|
// src/actions/public/multicall.ts
|
|
2311
2594
|
async function multicall(client, params) {
|
|
2312
2595
|
const { calls, allowFailure = true } = params;
|
|
@@ -2457,6 +2740,8 @@ function publicActions(client) {
|
|
|
2457
2740
|
multicall: (params) => multicall(client, params),
|
|
2458
2741
|
simulateCall: (params) => simulateCall(client, params),
|
|
2459
2742
|
simulateTransaction: (params) => simulateTransaction(client, params),
|
|
2743
|
+
getTransaction: (params) => getTransaction(client, params),
|
|
2744
|
+
waitForTransactionReceipt: (params) => waitForTransactionReceipt(client, params),
|
|
2460
2745
|
watchBlocks: (params) => watchBlocks(client, params),
|
|
2461
2746
|
watchMempool: (params) => watchMempool(client, params),
|
|
2462
2747
|
watchTransaction: (params) => watchTransaction(client, params),
|
|
@@ -2765,7 +3050,7 @@ var bnsReverse = import_ai.tool({
|
|
|
2765
3050
|
inputSchema: import_zod.z.object({ principal: PRINCIPAL }),
|
|
2766
3051
|
execute: ({ principal }) => bnsReverseImpl(getDefaultPublicClient(), principal)
|
|
2767
3052
|
});
|
|
2768
|
-
var
|
|
3053
|
+
var getTransaction2 = import_ai.tool({
|
|
2769
3054
|
description: "Fetch a confirmed Stacks transaction by txId (Hiro extended API).",
|
|
2770
3055
|
inputSchema: import_zod.z.object({ txId: import_zod.z.string() }),
|
|
2771
3056
|
execute: ({ txId }) => transactionByTxId(getDefaultPublicClient(), txId)
|
|
@@ -2792,5 +3077,5 @@ var getNftHoldings = import_ai.tool({
|
|
|
2792
3077
|
execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
|
|
2793
3078
|
});
|
|
2794
3079
|
|
|
2795
|
-
//# debugId=
|
|
3080
|
+
//# debugId=E0CFA9E2C0C074CF64756E2164756E21
|
|
2796
3081
|
//# sourceMappingURL=index.cjs.map
|