@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.
Files changed (118) hide show
  1. package/README.md +24 -0
  2. package/dist/shared/{stacks-4t2vmp4y.js → stacks-01pbr7gf.js} +17 -16
  3. package/dist/shared/stacks-01pbr7gf.js.map +11 -0
  4. package/dist/shared/{stacks-wyxj879g.cjs → stacks-18jv9aen.js} +83 -4
  5. package/dist/shared/stacks-18jv9aen.js.map +13 -0
  6. package/dist/shared/{stacks-0zysn74p.js → stacks-2mm20wqf.js} +3 -3
  7. package/dist/shared/{stacks-hxm7r5ay.cjs → stacks-44y18a8e.cjs} +3 -10
  8. package/dist/shared/stacks-44y18a8e.cjs.map +10 -0
  9. package/dist/shared/{stacks-2dhf79w5.js → stacks-59xy6t1p.js} +33 -31
  10. package/dist/shared/{stacks-2dhf79w5.js.map → stacks-59xy6t1p.js.map} +6 -6
  11. package/dist/shared/{stacks-99ghanwx.js → stacks-6n2m9hyk.js} +56 -6
  12. package/dist/shared/stacks-6n2m9hyk.js.map +10 -0
  13. package/dist/shared/{stacks-g7ffp8aj.js → stacks-6xt8py97.cjs} +59 -30
  14. package/dist/shared/stacks-6xt8py97.cjs.map +13 -0
  15. package/dist/shared/stacks-azp00pve.js +70 -0
  16. package/dist/shared/stacks-azp00pve.js.map +11 -0
  17. package/dist/shared/{stacks-vk8fwz0t.cjs → stacks-b9904rc2.cjs} +3 -2
  18. package/dist/shared/{stacks-vk8fwz0t.cjs.map → stacks-b9904rc2.cjs.map} +2 -2
  19. package/dist/shared/stacks-esn3wcw5.cjs +416 -0
  20. package/dist/shared/stacks-esn3wcw5.cjs.map +18 -0
  21. package/dist/shared/{stacks-3y058qda.cjs → stacks-fhzwsn5d.cjs} +16 -2
  22. package/dist/shared/{stacks-3y058qda.cjs.map → stacks-fhzwsn5d.cjs.map} +5 -4
  23. package/dist/shared/{stacks-e60vrr34.js → stacks-g11v9a35.js} +4 -4
  24. package/dist/shared/{stacks-0ek3cyt8.js → stacks-g67f4w1d.js} +7 -14
  25. package/dist/shared/stacks-g67f4w1d.js.map +10 -0
  26. package/dist/shared/{stacks-6xmk24yw.js → stacks-gfm3r397.cjs} +20 -7
  27. package/dist/shared/stacks-gfm3r397.cjs.map +11 -0
  28. package/dist/shared/{stacks-43cxvnr7.js → stacks-jbmcwky5.js} +3 -3
  29. package/dist/shared/stacks-kjg7fw4y.js +434 -0
  30. package/dist/shared/stacks-kjg7fw4y.js.map +18 -0
  31. package/dist/shared/{stacks-q1mjkt15.js → stacks-msmgyerb.js} +4 -4
  32. package/dist/shared/{stacks-2h8d2y27.js → stacks-qs5fzts5.js} +17 -3
  33. package/dist/shared/{stacks-2h8d2y27.js.map → stacks-qs5fzts5.js.map} +5 -4
  34. package/dist/shared/{stacks-xw0j252s.cjs → stacks-shn9zw99.cjs} +43 -3
  35. package/dist/shared/stacks-shn9zw99.cjs.map +10 -0
  36. package/dist/shared/{stacks-vf0ekgwb.js → stacks-ssndnbbd.js} +8 -10
  37. package/dist/shared/{stacks-vf0ekgwb.js.map → stacks-ssndnbbd.js.map} +2 -2
  38. package/dist/shared/{stacks-maamjqma.cjs → stacks-tbv5p6pn.cjs} +7 -9
  39. package/dist/shared/stacks-tbv5p6pn.cjs.map +11 -0
  40. package/dist/shared/{stacks-a36n7sjz.js → stacks-x94a1d6s.js} +3 -3
  41. package/dist/shared/{stacks-k5an9zcw.cjs → stacks-y5epf0sb.cjs} +19 -22
  42. package/dist/shared/{stacks-k5an9zcw.cjs.map → stacks-y5epf0sb.cjs.map} +6 -6
  43. package/dist/src/accounts/index.js +3 -5
  44. package/dist/src/accounts/index.js.map +2 -2
  45. package/dist/src/actions/index.cjs +8 -1
  46. package/dist/src/actions/index.cjs.map +1 -1
  47. package/dist/src/actions/index.d.cts +198 -13
  48. package/dist/src/actions/index.d.ts +198 -13
  49. package/dist/src/actions/index.js +29 -17
  50. package/dist/src/actions/index.js.map +1 -1
  51. package/dist/src/bitcoin/index.js +8 -11
  52. package/dist/src/bitcoin/index.js.map +2 -2
  53. package/dist/src/bns/index.js +12 -14
  54. package/dist/src/bns/index.js.map +2 -2
  55. package/dist/src/clarity/index.d.cts +50 -1
  56. package/dist/src/clarity/index.d.ts +50 -1
  57. package/dist/src/clarity/index.js +8 -7
  58. package/dist/src/clarity/index.js.map +1 -1
  59. package/dist/src/index.cjs +10 -1
  60. package/dist/src/index.cjs.map +3 -3
  61. package/dist/src/index.d.cts +167 -9
  62. package/dist/src/index.d.ts +167 -9
  63. package/dist/src/index.js +30 -17
  64. package/dist/src/index.js.map +3 -3
  65. package/dist/src/postconditions/index.js +3 -3
  66. package/dist/src/pox/index.js +11 -13
  67. package/dist/src/pox/index.js.map +2 -2
  68. package/dist/src/sbtc/index.js +10 -12
  69. package/dist/src/sbtc/index.js.map +2 -2
  70. package/dist/src/stackingdao/index.js +11 -13
  71. package/dist/src/stackingdao/index.js.map +2 -2
  72. package/dist/src/tools/index.cjs +348 -63
  73. package/dist/src/tools/index.cjs.map +18 -15
  74. package/dist/src/tools/index.js +348 -63
  75. package/dist/src/tools/index.js.map +18 -15
  76. package/dist/src/transactions/index.js +6 -7
  77. package/dist/src/transactions/index.js.map +1 -1
  78. package/dist/src/utils/index.cjs +2 -1
  79. package/dist/src/utils/index.cjs.map +2 -2
  80. package/dist/src/utils/index.d.cts +5 -1
  81. package/dist/src/utils/index.d.ts +5 -1
  82. package/dist/src/utils/index.js +12 -14
  83. package/dist/src/utils/index.js.map +2 -2
  84. package/dist/src/x402/index.cjs +5 -2
  85. package/dist/src/x402/index.cjs.map +3 -3
  86. package/dist/src/x402/index.d.cts +36 -0
  87. package/dist/src/x402/index.d.ts +36 -0
  88. package/dist/src/x402/index.js +13 -11
  89. package/dist/src/x402/index.js.map +3 -3
  90. package/package.json +1 -1
  91. package/dist/shared/stacks-0ek3cyt8.js.map +0 -10
  92. package/dist/shared/stacks-4t2vmp4y.js.map +0 -11
  93. package/dist/shared/stacks-6xmk24yw.js.map +0 -10
  94. package/dist/shared/stacks-99ghanwx.js.map +0 -10
  95. package/dist/shared/stacks-9g0jhab3.cjs +0 -40
  96. package/dist/shared/stacks-9g0jhab3.cjs.map +0 -10
  97. package/dist/shared/stacks-9t68zmpn.js +0 -210
  98. package/dist/shared/stacks-9t68zmpn.js.map +0 -15
  99. package/dist/shared/stacks-fcaefc5b.cjs +0 -16
  100. package/dist/shared/stacks-fcaefc5b.cjs.map +0 -10
  101. package/dist/shared/stacks-g7ffp8aj.js.map +0 -13
  102. package/dist/shared/stacks-hxm7r5ay.cjs.map +0 -10
  103. package/dist/shared/stacks-maamjqma.cjs.map +0 -11
  104. package/dist/shared/stacks-v9jqcpd4.js +0 -18
  105. package/dist/shared/stacks-v9jqcpd4.js.map +0 -10
  106. package/dist/shared/stacks-wyxj879g.cjs.map +0 -13
  107. package/dist/shared/stacks-xmsms921.cjs +0 -196
  108. package/dist/shared/stacks-xmsms921.cjs.map +0 -15
  109. package/dist/shared/stacks-xw0j252s.cjs.map +0 -10
  110. package/dist/shared/stacks-xxn5ma6g.js +0 -22
  111. package/dist/shared/stacks-xxn5ma6g.js.map +0 -10
  112. package/dist/shared/stacks-ya3x01yd.cjs +0 -16
  113. package/dist/shared/stacks-ya3x01yd.cjs.map +0 -10
  114. /package/dist/shared/{stacks-0zysn74p.js.map → stacks-2mm20wqf.js.map} +0 -0
  115. /package/dist/shared/{stacks-e60vrr34.js.map → stacks-g11v9a35.js.map} +0 -0
  116. /package/dist/shared/{stacks-43cxvnr7.js.map → stacks-jbmcwky5.js.map} +0 -0
  117. /package/dist/shared/{stacks-q1mjkt15.js.map → stacks-msmgyerb.js.map} +0 -0
  118. /package/dist/shared/{stacks-a36n7sjz.js.map → stacks-x94a1d6s.js.map} +0 -0
@@ -695,7 +695,37 @@ class BytesReader {
695
695
  }
696
696
  }
697
697
 
698
+ // src/utils/constants.ts
699
+ var MAX_U128 = (1n << 128n) - 1n;
700
+ var MAX_I128 = (1n << 127n) - 1n;
701
+ var MIN_I128 = -(1n << 127n);
702
+ var AddressVersion = {
703
+ MainnetSingleSig: 22,
704
+ MainnetMultiSig: 20,
705
+ TestnetSingleSig: 26,
706
+ TestnetMultiSig: 21
707
+ };
708
+
709
+ // src/utils/hash.ts
710
+ import { ripemd160 } from "@noble/hashes/legacy.js";
711
+ import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
712
+ import { sha512_256 } from "@noble/hashes/sha2.js";
713
+ function hash160(input) {
714
+ return ripemd160(sha2562(input));
715
+ }
716
+ function txidFromBytes(data) {
717
+ return bytesToHex(sha512_256(data));
718
+ }
719
+ function hashP2PKH(input) {
720
+ return bytesToHex(hash160(input));
721
+ }
722
+
698
723
  // src/utils/address.ts
724
+ function publicKeyToAddress(publicKey, network = "mainnet") {
725
+ const bytes = typeof publicKey === "string" ? hexToBytes(without0x(publicKey)) : publicKey;
726
+ const version = network === "mainnet" ? AddressVersion.MainnetSingleSig : AddressVersion.TestnetSingleSig;
727
+ return c32address(version, bytesToHex(hash160(bytes)));
728
+ }
699
729
  function parseContractId(contractId) {
700
730
  const [address, name] = contractId.split(".");
701
731
  if (!address || !name)
@@ -708,9 +738,9 @@ function isClarityName(name) {
708
738
  }
709
739
 
710
740
  // src/clarity/values.ts
711
- var MAX_U128 = BigInt("0xffffffffffffffffffffffffffffffff");
712
- var MIN_I128 = BigInt("-170141183460469231731687303715884105728");
713
- var MAX_I128 = BigInt("0x7fffffffffffffffffffffffffffffff");
741
+ var MAX_U1282 = BigInt("0xffffffffffffffffffffffffffffffff");
742
+ var MIN_I1282 = BigInt("-170141183460469231731687303715884105728");
743
+ var MAX_I1282 = BigInt("0x7fffffffffffffffffffffffffffffff");
714
744
  function intCV(value) {
715
745
  let v = value;
716
746
  if (typeof v === "string" && v.toLowerCase().startsWith("0x")) {
@@ -719,18 +749,18 @@ function intCV(value) {
719
749
  if (v instanceof Uint8Array)
720
750
  v = bytesToTwosBigInt(v);
721
751
  const n = intToBigInt(v);
722
- if (n > MAX_I128)
723
- throw new RangeError(`Int exceeds max i128: ${MAX_I128}`);
724
- if (n < MIN_I128)
725
- throw new RangeError(`Int below min i128: ${MIN_I128}`);
752
+ if (n > MAX_I1282)
753
+ throw new RangeError(`Int exceeds max i128: ${MAX_I1282}`);
754
+ if (n < MIN_I1282)
755
+ throw new RangeError(`Int below min i128: ${MIN_I1282}`);
726
756
  return { type: "int", value: n };
727
757
  }
728
758
  function uintCV(value) {
729
759
  const n = intToBigInt(value);
730
760
  if (n < 0n)
731
761
  throw new RangeError("Cannot construct unsigned int from negative value");
732
- if (n > MAX_U128)
733
- throw new RangeError(`UInt exceeds max u128: ${MAX_U128}`);
762
+ if (n > MAX_U1282)
763
+ throw new RangeError(`UInt exceeds max u128: ${MAX_U1282}`);
734
764
  return { type: "uint", value: n };
735
765
  }
736
766
  var trueCV = () => ({ type: "true" });
@@ -743,13 +773,13 @@ function bufferCV(buffer) {
743
773
  return { type: "buffer", value: bytesToHex(buffer) };
744
774
  }
745
775
  function standardPrincipalCV(address) {
746
- const [version, hash160] = c32addressDecode(address);
747
- const normalized = c32address(version, hash160);
776
+ const [version, hash1602] = c32addressDecode(address);
777
+ const normalized = c32address(version, hash1602);
748
778
  return { type: "address", value: normalized };
749
779
  }
750
780
  function contractPrincipalCV(address, contractName) {
751
- const [version, hash160] = c32addressDecode(address);
752
- const normalized = c32address(version, hash160);
781
+ const [version, hash1602] = c32addressDecode(address);
782
+ const normalized = c32address(version, hash1602);
753
783
  if (utf8ToBytes(contractName).byteLength >= 128) {
754
784
  throw new Error("Contract name must be less than 128 bytes");
755
785
  }
@@ -820,8 +850,8 @@ var Cl = {
820
850
  // src/clarity/deserialize.ts
821
851
  function readAddress(reader) {
822
852
  const version = reader.readUInt8();
823
- const hash160 = bytesToHex(reader.readBytes(20));
824
- return c32address(version, hash160);
853
+ const hash1602 = bytesToHex(reader.readBytes(20));
854
+ return c32address(version, hash1602);
825
855
  }
826
856
  function readLPString(reader, prefixBytes = 1) {
827
857
  let length = 0;
@@ -918,11 +948,6 @@ function toCamelCase(str) {
918
948
  return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/-([A-Z])/g, (_, letter) => letter).replace(/-(\d)/g, (_, digit) => digit).replace(/-/g, "").replace(/^\d/, "_$&");
919
949
  }
920
950
 
921
- // src/utils/constants.ts
922
- var MAX_U1282 = (1n << 128n) - 1n;
923
- var MAX_I1282 = (1n << 127n) - 1n;
924
- var MIN_I1282 = -(1n << 127n);
925
-
926
951
  // src/clarity/abi/guards.ts
927
952
  function isAbiList(type) {
928
953
  return typeof type === "object" && type !== null && "list" in type;
@@ -947,7 +972,64 @@ function isAbiStringUtf8(type) {
947
972
  }
948
973
 
949
974
  // src/clarity/bridge.ts
975
+ var CV_TYPE_TAGS = new Set([
976
+ "int",
977
+ "uint",
978
+ "true",
979
+ "false",
980
+ "address",
981
+ "contract",
982
+ "ascii",
983
+ "utf8",
984
+ "buffer",
985
+ "list",
986
+ "tuple",
987
+ "none",
988
+ "some",
989
+ "ok",
990
+ "err"
991
+ ]);
992
+ function isClarityValue(value) {
993
+ if (typeof value !== "object" || value === null)
994
+ return false;
995
+ const type = value.type;
996
+ if (typeof type !== "string" || !CV_TYPE_TAGS.has(type))
997
+ return false;
998
+ if (type === "true" || type === "false" || type === "none")
999
+ return true;
1000
+ return "value" in value;
1001
+ }
1002
+ var HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;
1003
+ function coerceBuffer(value) {
1004
+ if (value instanceof Uint8Array)
1005
+ return bufferCV(value);
1006
+ if (typeof value === "object" && value !== null && "type" in value) {
1007
+ const tagged = value;
1008
+ if (tagged.type === "buffer" && isClarityValue(value))
1009
+ return value;
1010
+ if (typeof tagged.value === "string") {
1011
+ if (tagged.type === "ascii")
1012
+ return Cl.bufferFromAscii(tagged.value);
1013
+ if (tagged.type === "utf8")
1014
+ return Cl.bufferFromUtf8(tagged.value);
1015
+ if (tagged.type === "hex")
1016
+ return Cl.bufferFromHex(tagged.value);
1017
+ }
1018
+ throw new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);
1019
+ }
1020
+ if (typeof value === "string") {
1021
+ const hex = value.startsWith("0x") ? value.slice(2) : value;
1022
+ if (HEX_PAIRS_REGEX.test(hex))
1023
+ return Cl.bufferFromHex(hex);
1024
+ return Cl.bufferFromUtf8(value);
1025
+ }
1026
+ throw new Error("buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV");
1027
+ }
950
1028
  function jsToClarityValue(abiType, value) {
1029
+ if (isAbiBuffer(abiType))
1030
+ return coerceBuffer(value);
1031
+ if (isClarityValue(value))
1032
+ return value;
951
1033
  if (abiType === "uint128")
952
1034
  return uintCV(value);
953
1035
  if (abiType === "int128")
@@ -960,8 +1042,6 @@ function jsToClarityValue(abiType, value) {
960
1042
  return stringAsciiCV(value);
961
1043
  if (isAbiStringUtf8(abiType))
962
1044
  return stringUtf8CV(value);
963
- if (isAbiBuffer(abiType))
964
- return bufferCV(value);
965
1045
  if (isAbiList(abiType)) {
966
1046
  const arr = value;
967
1047
  return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
@@ -1067,37 +1147,10 @@ function clarityValueToJSInner(abiType, cv) {
1067
1147
  throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1068
1148
  }
1069
1149
 
1070
- // src/actions/public/getMapEntry.ts
1071
- async function getMapEntry(client, params) {
1072
- const [address, name] = parseContractId(params.contract);
1073
- const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
1074
- const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
1075
- method: "POST",
1076
- body: serializedKey
1077
- });
1078
- return deserializeCVBytes(data.data);
1079
- }
1080
-
1081
1150
  // src/transactions/authorization.ts
1082
1151
  import { hmac } from "@noble/hashes/hmac.js";
1083
1152
  import { sha256 as sha2563 } from "@noble/hashes/sha2.js";
1084
1153
  import { etc, getPublicKey as nobleGetPublicKey, sign } from "@noble/secp256k1";
1085
-
1086
- // src/utils/hash.ts
1087
- import { ripemd160 } from "@noble/hashes/legacy.js";
1088
- import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
1089
- import { sha512_256 } from "@noble/hashes/sha2.js";
1090
- function hash160(input) {
1091
- return ripemd160(sha2562(input));
1092
- }
1093
- function txidFromBytes(data) {
1094
- return bytesToHex(sha512_256(data));
1095
- }
1096
- function hashP2PKH(input) {
1097
- return bytesToHex(hash160(input));
1098
- }
1099
-
1100
- // src/transactions/authorization.ts
1101
1154
  etc.hmacSha256Sync = (key, ...msgs) => {
1102
1155
  const h = hmac.create(sha2563, key);
1103
1156
  for (const msg of msgs)
@@ -1312,6 +1365,17 @@ function buildContractCall(options) {
1312
1365
  return tx;
1313
1366
  }
1314
1367
 
1368
+ // src/actions/public/getMapEntry.ts
1369
+ async function getMapEntry(client, params) {
1370
+ const [address, name] = parseContractId(params.contract);
1371
+ const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
1372
+ const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
1373
+ method: "POST",
1374
+ body: serializedKey
1375
+ });
1376
+ return deserializeCVBytes(data.data);
1377
+ }
1378
+
1315
1379
  // src/transactions/signer.ts
1316
1380
  function txid(tx) {
1317
1381
  return txidFromBytes(serializeTransaction(tx));
@@ -1375,10 +1439,39 @@ class BroadcastError extends BaseError {
1375
1439
  name = "BroadcastError";
1376
1440
  txid;
1377
1441
  reason;
1442
+ reasonData;
1378
1443
  constructor(message, options) {
1379
1444
  super(message, options);
1380
1445
  this.txid = options?.txid;
1381
1446
  this.reason = options?.reason;
1447
+ this.reasonData = options?.reasonData;
1448
+ }
1449
+ }
1450
+
1451
+ class TransactionAbortedError extends BaseError {
1452
+ name = "TransactionAbortedError";
1453
+ receipt;
1454
+ constructor(message, options) {
1455
+ super(message, options);
1456
+ this.receipt = options.receipt;
1457
+ }
1458
+ }
1459
+
1460
+ class TransactionDroppedError extends BaseError {
1461
+ name = "TransactionDroppedError";
1462
+ txid;
1463
+ constructor(message, options) {
1464
+ super(message, options);
1465
+ this.txid = options.txid;
1466
+ }
1467
+ }
1468
+
1469
+ class WaitForTransactionTimeoutError extends BaseError {
1470
+ name = "WaitForTransactionTimeoutError";
1471
+ txid;
1472
+ constructor(message, options) {
1473
+ super(message, options);
1474
+ this.txid = options.txid;
1382
1475
  }
1383
1476
  }
1384
1477
 
@@ -1394,6 +1487,107 @@ async function getNonce(client, params) {
1394
1487
  return BigInt(nonce);
1395
1488
  }
1396
1489
 
1490
+ // src/actions/public/txSources.ts
1491
+ function normalizeTxid(txid2) {
1492
+ return txid2.startsWith("0x") ? txid2 : `0x${txid2}`;
1493
+ }
1494
+ function decodeResultHex(hex) {
1495
+ if (!hex)
1496
+ return {};
1497
+ try {
1498
+ return { result: deserializeCVBytes(hex), resultHex: hex };
1499
+ } catch {
1500
+ return { resultHex: hex };
1501
+ }
1502
+ }
1503
+ function normalizeStatus(txStatus) {
1504
+ switch (txStatus) {
1505
+ case "pending":
1506
+ case "success":
1507
+ case "abort_by_response":
1508
+ case "abort_by_post_condition":
1509
+ return txStatus;
1510
+ default:
1511
+ return txStatus.startsWith("dropped") ? "dropped" : undefined;
1512
+ }
1513
+ }
1514
+ function extendedApiSource() {
1515
+ return {
1516
+ async get({ client, txid: txid2 }) {
1517
+ const data = await client.request(`/extended/v1/tx/${normalizeTxid(txid2)}`, { method: "GET" });
1518
+ const txStatus = typeof data?.tx_status === "string" ? data.tx_status : undefined;
1519
+ if (!txStatus)
1520
+ return { receipt: null };
1521
+ const status = normalizeStatus(txStatus);
1522
+ if (!status)
1523
+ return { receipt: null };
1524
+ return {
1525
+ receipt: {
1526
+ txid: normalizeTxid(txid2),
1527
+ status,
1528
+ blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
1529
+ blockHash: data.block_hash ?? undefined,
1530
+ ...decodeResultHex(data.tx_result?.hex),
1531
+ events: Array.isArray(data.events) ? data.events : [],
1532
+ raw: data
1533
+ }
1534
+ };
1535
+ }
1536
+ };
1537
+ }
1538
+
1539
+ // src/actions/public/waitForTransactionReceipt.ts
1540
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1541
+ async function waitForTransactionReceipt(client, params) {
1542
+ const {
1543
+ txid: txid2,
1544
+ confirmations = 1,
1545
+ timeout = 180000,
1546
+ pollingInterval = 3000,
1547
+ droppedGracePeriod = 30000
1548
+ } = params;
1549
+ const source = params.source ?? extendedApiSource();
1550
+ const startedAt = Date.now();
1551
+ let unknownSince = null;
1552
+ let everPending = false;
1553
+ while (true) {
1554
+ const snapshot = await source.get({ client, txid: txid2 });
1555
+ const receipt = snapshot.receipt;
1556
+ if (receipt === null) {
1557
+ unknownSince ??= Date.now();
1558
+ if (Date.now() - unknownSince >= droppedGracePeriod) {
1559
+ throw new TransactionDroppedError(everPending ? `Transaction ${txid2} left the mempool without being mined` : `Transaction ${txid2} was never observed by the status source`, { txid: txid2 });
1560
+ }
1561
+ } else {
1562
+ unknownSince = null;
1563
+ switch (receipt.status) {
1564
+ case "dropped":
1565
+ throw new TransactionDroppedError(`Transaction ${txid2} was dropped from the mempool`, { txid: txid2 });
1566
+ case "abort_by_response":
1567
+ case "abort_by_post_condition":
1568
+ throw new TransactionAbortedError(`Transaction ${txid2} aborted (${receipt.status})`, { receipt });
1569
+ case "pending":
1570
+ everPending = true;
1571
+ break;
1572
+ case "success": {
1573
+ if (confirmations <= 1)
1574
+ return receipt;
1575
+ if (receipt.blockHeight !== undefined) {
1576
+ const tip = snapshot.tip ?? await getBlockHeight(client);
1577
+ if (tip - receipt.blockHeight + 1 >= confirmations)
1578
+ return receipt;
1579
+ }
1580
+ break;
1581
+ }
1582
+ }
1583
+ }
1584
+ if (Date.now() - startedAt >= timeout) {
1585
+ throw new WaitForTransactionTimeoutError(`Timed out after ${timeout}ms waiting for transaction ${txid2}`, { txid: txid2 });
1586
+ }
1587
+ await sleep(pollingInterval);
1588
+ }
1589
+ }
1590
+
1397
1591
  // src/actions/wallet/sendTransaction.ts
1398
1592
  async function sendTransaction(client, params) {
1399
1593
  const hex = bytesToHex(serializeTransaction(params.transaction));
@@ -1407,10 +1601,20 @@ async function sendTransaction(client, params) {
1407
1601
  });
1408
1602
  if (data.error) {
1409
1603
  throw new BroadcastError(data.reason ?? data.error, {
1410
- reason: data.reason
1604
+ reason: data.reason,
1605
+ reasonData: data.reason_data,
1606
+ txid: data.txid ?? getTransactionId(params.transaction)
1411
1607
  });
1412
1608
  }
1413
1609
  const txid2 = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
1610
+ if (params.wait) {
1611
+ const confirmations = params.wait === true ? 1 : params.wait;
1612
+ const receipt = await waitForTransactionReceipt(client, {
1613
+ txid: txid2,
1614
+ confirmations
1615
+ });
1616
+ return { txid: txid2, receipt };
1617
+ }
1414
1618
  return { txid: txid2 };
1415
1619
  }
1416
1620
 
@@ -1423,8 +1627,12 @@ async function resolveNonce(client, address) {
1423
1627
  function isNonceConflictError(error) {
1424
1628
  if (!(error instanceof BroadcastError))
1425
1629
  return false;
1426
- const haystack = `${error.reason ?? ""} ${error.message}`.toLowerCase();
1427
- return haystack.includes("nonce");
1630
+ if (error.reason === "ConflictingNonceInMempool" || error.reason === "BadNonce") {
1631
+ return true;
1632
+ }
1633
+ if (error.reason !== undefined)
1634
+ return false;
1635
+ return error.message.toLowerCase().includes("nonce");
1428
1636
  }
1429
1637
  async function broadcastWithNonceReset(client, params) {
1430
1638
  try {
@@ -1444,6 +1652,36 @@ async function broadcastWithNonceReset(client, params) {
1444
1652
  function isProviderAccount(account) {
1445
1653
  return account.type === "provider";
1446
1654
  }
1655
+ var FEE_TIERS = ["min", "low", "mid", "high"];
1656
+ var TIER_INDEX = { low: 0, mid: 1, high: 2 };
1657
+ function isFeeTier(fee) {
1658
+ return typeof fee === "string" && FEE_TIERS.includes(fee);
1659
+ }
1660
+ function minimumFee(transaction) {
1661
+ return BigInt(serializeTransaction(transaction).length);
1662
+ }
1663
+ async function resolveFee(client, transaction, fee) {
1664
+ if (fee !== undefined && !isFeeTier(fee))
1665
+ return intToBigInt(fee);
1666
+ const tier = fee ?? "mid";
1667
+ if (tier === "min")
1668
+ return minimumFee(transaction);
1669
+ try {
1670
+ const estimates = await estimateFee(client, { transaction });
1671
+ const pick = estimates[TIER_INDEX[tier]] ?? estimates[estimates.length - 1];
1672
+ if (pick)
1673
+ return BigInt(pick.fee);
1674
+ } catch {}
1675
+ return minimumFee(transaction);
1676
+ }
1677
+ function setUnsignedFee(transaction, fee) {
1678
+ transaction.auth.spendingCondition.fee = fee;
1679
+ }
1680
+ function assertNoFeeTierForProvider(fee) {
1681
+ if (isFeeTier(fee)) {
1682
+ throw new Error(`Fee tier '${fee}' requires local signing; provider (wallet) accounts set their own fee`);
1683
+ }
1684
+ }
1447
1685
 
1448
1686
  // src/actions/wallet/callContract.ts
1449
1687
  async function callContract(client, params) {
@@ -1452,6 +1690,7 @@ async function callContract(client, params) {
1452
1690
  throw new Error("Account required");
1453
1691
  const [contractAddress, contractName] = parseContractId(params.contract);
1454
1692
  if (isProviderAccount(account)) {
1693
+ assertNoFeeTierForProvider(params.fee);
1455
1694
  const result = await account.provider.request("stx_callContract", {
1456
1695
  contract: params.contract,
1457
1696
  functionName: params.functionName,
@@ -1460,24 +1699,21 @@ async function callContract(client, params) {
1460
1699
  return result.txid;
1461
1700
  }
1462
1701
  const nonce = params.nonce ?? await resolveNonce(client, account.address);
1702
+ const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
1463
1703
  const unsigned = buildContractCall({
1464
1704
  contractAddress,
1465
1705
  contractName,
1466
1706
  functionName: params.functionName,
1467
1707
  functionArgs: params.functionArgs ?? [],
1468
- fee: params.fee ?? 0n,
1708
+ fee: needsFeeResolution ? 0n : params.fee,
1469
1709
  nonce,
1470
1710
  publicKey: account.publicKey,
1471
1711
  chain: client.chain,
1472
1712
  postConditionMode: params.postConditionMode,
1473
1713
  postConditions: params.postConditions
1474
1714
  });
1475
- if (params.fee === undefined) {
1476
- const estimates = await estimateFee(client, { transaction: unsigned });
1477
- const mid = estimates[1] ?? estimates[0];
1478
- if (mid) {
1479
- unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
1480
- }
1715
+ if (needsFeeResolution) {
1716
+ setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
1481
1717
  }
1482
1718
  const signed = await signTransactionWithAccount(unsigned, account);
1483
1719
  return broadcastWithNonceReset(client, {
@@ -1550,6 +1786,46 @@ function getContract(params) {
1550
1786
  };
1551
1787
  }
1552
1788
  });
1789
+ const buildCall = new Proxy({}, {
1790
+ get(_target, prop) {
1791
+ const fnName = camelToKebab.get(prop) ?? prop;
1792
+ const fn = fnByName.get(fnName);
1793
+ if (!fn || fn.access !== "public")
1794
+ return;
1795
+ return async (args, options) => {
1796
+ const publicKey = options?.publicKey ?? client.account?.publicKey;
1797
+ if (!publicKey) {
1798
+ throw new Error("buildCall requires a publicKey (pass options.publicKey or configure a client account)");
1799
+ }
1800
+ const functionArgs = buildFunctionArgs(fn, args);
1801
+ const network = client.chain?.network ?? "mainnet";
1802
+ const nonce = options?.nonce ?? await resolveNonce(client, publicKeyToAddress(publicKey, network));
1803
+ const unsigned = buildContractCall({
1804
+ contractAddress: address,
1805
+ contractName,
1806
+ functionName: fn.name,
1807
+ functionArgs,
1808
+ fee: options?.fee ?? 0n,
1809
+ nonce,
1810
+ publicKey,
1811
+ chain: client.chain,
1812
+ postConditionMode: options?.postConditionMode,
1813
+ postConditions: options?.postConditions,
1814
+ sponsored: options?.sponsored
1815
+ });
1816
+ if (options?.fee === undefined) {
1817
+ const estimates = await estimateFee(client, {
1818
+ transaction: unsigned
1819
+ });
1820
+ const mid = estimates[1] ?? estimates[0];
1821
+ if (mid) {
1822
+ unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
1823
+ }
1824
+ }
1825
+ return unsigned;
1826
+ };
1827
+ }
1828
+ });
1553
1829
  const maps = new Proxy({}, {
1554
1830
  get(_target, prop) {
1555
1831
  const mapName = camelToKebab.get(prop) ?? prop;
@@ -1572,7 +1848,7 @@ function getContract(params) {
1572
1848
  };
1573
1849
  }
1574
1850
  });
1575
- return { read, call, maps };
1851
+ return { read, call, buildCall, maps };
1576
1852
  }
1577
1853
  function resolveNetworkContract(client, contracts) {
1578
1854
  if (!client.chain) {
@@ -2257,6 +2533,13 @@ async function getContractAbi(client, params) {
2257
2533
  });
2258
2534
  }
2259
2535
 
2536
+ // src/actions/public/getTransaction.ts
2537
+ async function getTransaction(client, params) {
2538
+ const source = params.source ?? extendedApiSource();
2539
+ const { receipt } = await source.get({ client, txid: params.txid });
2540
+ return receipt;
2541
+ }
2542
+
2260
2543
  // src/actions/public/multicall.ts
2261
2544
  async function multicall(client, params) {
2262
2545
  const { calls, allowFailure = true } = params;
@@ -2407,6 +2690,8 @@ function publicActions(client) {
2407
2690
  multicall: (params) => multicall(client, params),
2408
2691
  simulateCall: (params) => simulateCall(client, params),
2409
2692
  simulateTransaction: (params) => simulateTransaction(client, params),
2693
+ getTransaction: (params) => getTransaction(client, params),
2694
+ waitForTransactionReceipt: (params) => waitForTransactionReceipt(client, params),
2410
2695
  watchBlocks: (params) => watchBlocks(client, params),
2411
2696
  watchMempool: (params) => watchMempool(client, params),
2412
2697
  watchTransaction: (params) => watchTransaction(client, params),
@@ -2715,7 +3000,7 @@ var bnsReverse = tool({
2715
3000
  inputSchema: z.object({ principal: PRINCIPAL }),
2716
3001
  execute: ({ principal }) => bnsReverseImpl(getDefaultPublicClient(), principal)
2717
3002
  });
2718
- var getTransaction = tool({
3003
+ var getTransaction2 = tool({
2719
3004
  description: "Fetch a confirmed Stacks transaction by txId (Hiro extended API).",
2720
3005
  inputSchema: z.object({ txId: z.string() }),
2721
3006
  execute: ({ txId }) => transactionByTxId(getDefaultPublicClient(), txId)
@@ -2743,7 +3028,7 @@ var getNftHoldings = tool({
2743
3028
  });
2744
3029
  export {
2745
3030
  readContract2 as readContract,
2746
- getTransaction,
3031
+ getTransaction2 as getTransaction,
2747
3032
  getStxBalance,
2748
3033
  getNftHoldings,
2749
3034
  getMempoolStats,
@@ -2757,5 +3042,5 @@ export {
2757
3042
  bnsResolve
2758
3043
  };
2759
3044
 
2760
- //# debugId=98CD0F025D02FDCF64756E2164756E21
3045
+ //# debugId=B4C309A1C0AA64D664756E2164756E21
2761
3046
  //# sourceMappingURL=index.js.map