@secondlayer/stacks 2.9.1 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/shared/{stacks-wyxj879g.cjs → stacks-18jv9aen.js} +83 -4
  2. package/dist/shared/stacks-18jv9aen.js.map +13 -0
  3. package/dist/shared/{stacks-0zysn74p.js → stacks-2mm20wqf.js} +3 -3
  4. package/dist/shared/{stacks-1qmx9kt8.js → stacks-3kmj5yre.js} +4 -4
  5. package/dist/shared/{stacks-ttbq8emk.js → stacks-502j0efj.js} +3 -3
  6. package/dist/shared/{stacks-nqae5amn.cjs → stacks-5nskdw7w.cjs} +19 -2
  7. package/dist/shared/stacks-5nskdw7w.cjs.map +10 -0
  8. package/dist/shared/{stacks-8mj5jw77.js → stacks-63xbc6cj.js} +63 -7
  9. package/dist/shared/stacks-63xbc6cj.js.map +10 -0
  10. package/dist/shared/{stacks-g7ffp8aj.js → stacks-6xt8py97.cjs} +59 -30
  11. package/dist/shared/stacks-6xt8py97.cjs.map +13 -0
  12. package/dist/shared/{stacks-53bjdb6p.js → stacks-7nvbv61d.js} +8 -8
  13. package/dist/shared/stacks-azp00pve.js +70 -0
  14. package/dist/shared/stacks-azp00pve.js.map +11 -0
  15. package/dist/shared/{stacks-vk8fwz0t.cjs → stacks-b9904rc2.cjs} +3 -2
  16. package/dist/shared/{stacks-vk8fwz0t.cjs.map → stacks-b9904rc2.cjs.map} +2 -2
  17. package/dist/shared/{stacks-3y058qda.cjs → stacks-fhzwsn5d.cjs} +16 -2
  18. package/dist/shared/{stacks-3y058qda.cjs.map → stacks-fhzwsn5d.cjs.map} +5 -4
  19. package/dist/shared/{stacks-wqgepfab.js → stacks-g11v9a35.js} +22 -5
  20. package/dist/shared/stacks-g11v9a35.js.map +10 -0
  21. package/dist/shared/{stacks-6xmk24yw.js → stacks-gfm3r397.cjs} +20 -7
  22. package/dist/shared/stacks-gfm3r397.cjs.map +11 -0
  23. package/dist/shared/{stacks-43cxvnr7.js → stacks-jbmcwky5.js} +3 -3
  24. package/dist/shared/{stacks-q1mjkt15.js → stacks-msmgyerb.js} +4 -4
  25. package/dist/shared/{stacks-2h8d2y27.js → stacks-qs5fzts5.js} +17 -3
  26. package/dist/shared/{stacks-2h8d2y27.js.map → stacks-qs5fzts5.js.map} +5 -4
  27. package/dist/shared/{stacks-vdfag81a.cjs → stacks-shn9zw99.cjs} +49 -3
  28. package/dist/shared/stacks-shn9zw99.cjs.map +10 -0
  29. package/dist/shared/{stacks-4trgpb5a.js → stacks-ssndnbbd.js} +48 -13
  30. package/dist/shared/stacks-ssndnbbd.js.map +15 -0
  31. package/dist/shared/{stacks-z1j5d6fd.js → stacks-v150hffx.js} +6 -6
  32. package/dist/shared/{stacks-ertyhttt.cjs → stacks-wamwv8q8.cjs} +41 -4
  33. package/dist/shared/stacks-wamwv8q8.cjs.map +15 -0
  34. package/dist/shared/{stacks-a36n7sjz.js → stacks-x94a1d6s.js} +3 -3
  35. package/dist/src/accounts/index.js +3 -5
  36. package/dist/src/accounts/index.js.map +2 -2
  37. package/dist/src/actions/index.d.cts +91 -10
  38. package/dist/src/actions/index.d.ts +91 -10
  39. package/dist/src/actions/index.js +13 -15
  40. package/dist/src/actions/index.js.map +1 -1
  41. package/dist/src/bitcoin/index.cjs +25 -19
  42. package/dist/src/bitcoin/index.cjs.map +3 -3
  43. package/dist/src/bitcoin/index.js +32 -29
  44. package/dist/src/bitcoin/index.js.map +3 -3
  45. package/dist/src/bns/index.cjs +4 -16
  46. package/dist/src/bns/index.cjs.map +3 -3
  47. package/dist/src/bns/index.js +17 -30
  48. package/dist/src/bns/index.js.map +3 -3
  49. package/dist/src/clarity/index.d.cts +50 -1
  50. package/dist/src/clarity/index.d.ts +50 -1
  51. package/dist/src/clarity/index.js +8 -7
  52. package/dist/src/clarity/index.js.map +1 -1
  53. package/dist/src/index.d.cts +32 -2
  54. package/dist/src/index.d.ts +32 -2
  55. package/dist/src/index.js +12 -15
  56. package/dist/src/index.js.map +2 -2
  57. package/dist/src/postconditions/index.d.cts +14 -2
  58. package/dist/src/postconditions/index.d.ts +14 -2
  59. package/dist/src/postconditions/index.js +3 -3
  60. package/dist/src/pox/index.cjs +2 -6
  61. package/dist/src/pox/index.cjs.map +3 -3
  62. package/dist/src/pox/index.js +14 -19
  63. package/dist/src/pox/index.js.map +3 -3
  64. package/dist/src/sbtc/index.cjs +2 -6
  65. package/dist/src/sbtc/index.cjs.map +3 -3
  66. package/dist/src/sbtc/index.js +13 -18
  67. package/dist/src/sbtc/index.js.map +3 -3
  68. package/dist/src/stackingdao/index.js +11 -13
  69. package/dist/src/stackingdao/index.js.map +2 -2
  70. package/dist/src/tools/index.cjs +199 -57
  71. package/dist/src/tools/index.cjs.map +13 -13
  72. package/dist/src/tools/index.js +199 -57
  73. package/dist/src/tools/index.js.map +13 -13
  74. package/dist/src/transactions/index.cjs +2 -1
  75. package/dist/src/transactions/index.cjs.map +1 -1
  76. package/dist/src/transactions/index.d.cts +35 -3
  77. package/dist/src/transactions/index.d.ts +35 -3
  78. package/dist/src/transactions/index.js +8 -7
  79. package/dist/src/transactions/index.js.map +1 -1
  80. package/dist/src/utils/index.cjs +2 -1
  81. package/dist/src/utils/index.cjs.map +2 -2
  82. package/dist/src/utils/index.d.cts +5 -1
  83. package/dist/src/utils/index.d.ts +5 -1
  84. package/dist/src/utils/index.js +12 -14
  85. package/dist/src/utils/index.js.map +2 -2
  86. package/dist/src/x402/index.d.cts +19 -1
  87. package/dist/src/x402/index.d.ts +19 -1
  88. package/dist/src/x402/index.js +9 -10
  89. package/dist/src/x402/index.js.map +2 -2
  90. package/package.json +4 -2
  91. package/dist/shared/stacks-4trgpb5a.js.map +0 -15
  92. package/dist/shared/stacks-6xmk24yw.js.map +0 -10
  93. package/dist/shared/stacks-8mj5jw77.js.map +0 -10
  94. package/dist/shared/stacks-9g0jhab3.cjs +0 -40
  95. package/dist/shared/stacks-9g0jhab3.cjs.map +0 -10
  96. package/dist/shared/stacks-ertyhttt.cjs.map +0 -15
  97. package/dist/shared/stacks-fcaefc5b.cjs +0 -16
  98. package/dist/shared/stacks-fcaefc5b.cjs.map +0 -10
  99. package/dist/shared/stacks-g7ffp8aj.js.map +0 -13
  100. package/dist/shared/stacks-nqae5amn.cjs.map +0 -10
  101. package/dist/shared/stacks-v9jqcpd4.js +0 -18
  102. package/dist/shared/stacks-v9jqcpd4.js.map +0 -10
  103. package/dist/shared/stacks-vdfag81a.cjs.map +0 -10
  104. package/dist/shared/stacks-wqgepfab.js.map +0 -10
  105. package/dist/shared/stacks-wyxj879g.cjs.map +0 -13
  106. package/dist/shared/stacks-xxn5ma6g.js +0 -22
  107. package/dist/shared/stacks-xxn5ma6g.js.map +0 -10
  108. package/dist/shared/stacks-ya3x01yd.cjs +0 -16
  109. package/dist/shared/stacks-ya3x01yd.cjs.map +0 -10
  110. /package/dist/shared/{stacks-0zysn74p.js.map → stacks-2mm20wqf.js.map} +0 -0
  111. /package/dist/shared/{stacks-1qmx9kt8.js.map → stacks-3kmj5yre.js.map} +0 -0
  112. /package/dist/shared/{stacks-ttbq8emk.js.map → stacks-502j0efj.js.map} +0 -0
  113. /package/dist/shared/{stacks-53bjdb6p.js.map → stacks-7nvbv61d.js.map} +0 -0
  114. /package/dist/shared/{stacks-43cxvnr7.js.map → stacks-jbmcwky5.js.map} +0 -0
  115. /package/dist/shared/{stacks-q1mjkt15.js.map → stacks-msmgyerb.js.map} +0 -0
  116. /package/dist/shared/{stacks-z1j5d6fd.js.map → stacks-v150hffx.js.map} +0 -0
  117. /package/dist/shared/{stacks-a36n7sjz.js.map → stacks-x94a1d6s.js.map} +0 -0
@@ -399,6 +399,11 @@ var NonFungibleConditionCode = {
399
399
  Sends: 16,
400
400
  DoesNotSend: 17
401
401
  };
402
+ var PoxConditionCode = {
403
+ WillNotPerform: 48,
404
+ MayPerform: 49,
405
+ WillPerform: 50
406
+ };
402
407
  var PostConditionPrincipalId = {
403
408
  Origin: 1,
404
409
  Standard: 2,
@@ -407,7 +412,9 @@ var PostConditionPrincipalId = {
407
412
  var AssetType = {
408
413
  STX: 0,
409
414
  Fungible: 1,
410
- NonFungible: 2
415
+ NonFungible: 2,
416
+ Staking: 3,
417
+ Pox: 4
411
418
  };
412
419
  var RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;
413
420
  var MEMO_MAX_LENGTH_BYTES = 34;
@@ -504,6 +511,17 @@ function serializePostCondition(pc) {
504
511
  parts.push(serializeCVBytes(pc.assetId));
505
512
  parts.push(writeUInt8(pc.conditionCode));
506
513
  break;
514
+ case "staking":
515
+ parts.push(writeUInt8(AssetType.Staking));
516
+ parts.push(serializePrincipal(pc.principal));
517
+ parts.push(writeUInt8(pc.conditionCode));
518
+ parts.push(intToBytes(pc.amount, 8));
519
+ break;
520
+ case "pox":
521
+ parts.push(writeUInt8(AssetType.Pox));
522
+ parts.push(serializePrincipal(pc.principal));
523
+ parts.push(writeUInt8(pc.conditionCode));
524
+ break;
507
525
  }
508
526
  return concatBytes(...parts);
509
527
  }
@@ -677,7 +695,37 @@ class BytesReader {
677
695
  }
678
696
  }
679
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
+
680
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
+ }
681
729
  function parseContractId(contractId) {
682
730
  const [address, name] = contractId.split(".");
683
731
  if (!address || !name)
@@ -690,9 +738,9 @@ function isClarityName(name) {
690
738
  }
691
739
 
692
740
  // src/clarity/values.ts
693
- var MAX_U128 = BigInt("0xffffffffffffffffffffffffffffffff");
694
- var MIN_I128 = BigInt("-170141183460469231731687303715884105728");
695
- var MAX_I128 = BigInt("0x7fffffffffffffffffffffffffffffff");
741
+ var MAX_U1282 = BigInt("0xffffffffffffffffffffffffffffffff");
742
+ var MIN_I1282 = BigInt("-170141183460469231731687303715884105728");
743
+ var MAX_I1282 = BigInt("0x7fffffffffffffffffffffffffffffff");
696
744
  function intCV(value) {
697
745
  let v = value;
698
746
  if (typeof v === "string" && v.toLowerCase().startsWith("0x")) {
@@ -701,18 +749,18 @@ function intCV(value) {
701
749
  if (v instanceof Uint8Array)
702
750
  v = bytesToTwosBigInt(v);
703
751
  const n = intToBigInt(v);
704
- if (n > MAX_I128)
705
- throw new RangeError(`Int exceeds max i128: ${MAX_I128}`);
706
- if (n < MIN_I128)
707
- 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}`);
708
756
  return { type: "int", value: n };
709
757
  }
710
758
  function uintCV(value) {
711
759
  const n = intToBigInt(value);
712
760
  if (n < 0n)
713
761
  throw new RangeError("Cannot construct unsigned int from negative value");
714
- if (n > MAX_U128)
715
- throw new RangeError(`UInt exceeds max u128: ${MAX_U128}`);
762
+ if (n > MAX_U1282)
763
+ throw new RangeError(`UInt exceeds max u128: ${MAX_U1282}`);
716
764
  return { type: "uint", value: n };
717
765
  }
718
766
  var trueCV = () => ({ type: "true" });
@@ -725,13 +773,13 @@ function bufferCV(buffer) {
725
773
  return { type: "buffer", value: bytesToHex(buffer) };
726
774
  }
727
775
  function standardPrincipalCV(address) {
728
- const [version, hash160] = c32addressDecode(address);
729
- const normalized = c32address(version, hash160);
776
+ const [version, hash1602] = c32addressDecode(address);
777
+ const normalized = c32address(version, hash1602);
730
778
  return { type: "address", value: normalized };
731
779
  }
732
780
  function contractPrincipalCV(address, contractName) {
733
- const [version, hash160] = c32addressDecode(address);
734
- const normalized = c32address(version, hash160);
781
+ const [version, hash1602] = c32addressDecode(address);
782
+ const normalized = c32address(version, hash1602);
735
783
  if (utf8ToBytes(contractName).byteLength >= 128) {
736
784
  throw new Error("Contract name must be less than 128 bytes");
737
785
  }
@@ -802,8 +850,8 @@ var Cl = {
802
850
  // src/clarity/deserialize.ts
803
851
  function readAddress(reader) {
804
852
  const version = reader.readUInt8();
805
- const hash160 = bytesToHex(reader.readBytes(20));
806
- return c32address(version, hash160);
853
+ const hash1602 = bytesToHex(reader.readBytes(20));
854
+ return c32address(version, hash1602);
807
855
  }
808
856
  function readLPString(reader, prefixBytes = 1) {
809
857
  let length = 0;
@@ -900,11 +948,6 @@ function toCamelCase(str) {
900
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/, "_$&");
901
949
  }
902
950
 
903
- // src/utils/constants.ts
904
- var MAX_U1282 = (1n << 128n) - 1n;
905
- var MAX_I1282 = (1n << 127n) - 1n;
906
- var MIN_I1282 = -(1n << 127n);
907
-
908
951
  // src/clarity/abi/guards.ts
909
952
  function isAbiList(type) {
910
953
  return typeof type === "object" && type !== null && "list" in type;
@@ -929,7 +972,64 @@ function isAbiStringUtf8(type) {
929
972
  }
930
973
 
931
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
+ }
932
1028
  function jsToClarityValue(abiType, value) {
1029
+ if (isAbiBuffer(abiType))
1030
+ return coerceBuffer(value);
1031
+ if (isClarityValue(value))
1032
+ return value;
933
1033
  if (abiType === "uint128")
934
1034
  return uintCV(value);
935
1035
  if (abiType === "int128")
@@ -942,8 +1042,6 @@ function jsToClarityValue(abiType, value) {
942
1042
  return stringAsciiCV(value);
943
1043
  if (isAbiStringUtf8(abiType))
944
1044
  return stringUtf8CV(value);
945
- if (isAbiBuffer(abiType))
946
- return bufferCV(value);
947
1045
  if (isAbiList(abiType)) {
948
1046
  const arr = value;
949
1047
  return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
@@ -1049,37 +1147,10 @@ function clarityValueToJSInner(abiType, cv) {
1049
1147
  throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1050
1148
  }
1051
1149
 
1052
- // src/actions/public/getMapEntry.ts
1053
- async function getMapEntry(client, params) {
1054
- const [address, name] = parseContractId(params.contract);
1055
- const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
1056
- const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
1057
- method: "POST",
1058
- body: serializedKey
1059
- });
1060
- return deserializeCVBytes(data.data);
1061
- }
1062
-
1063
1150
  // src/transactions/authorization.ts
1064
1151
  import { hmac } from "@noble/hashes/hmac.js";
1065
1152
  import { sha256 as sha2563 } from "@noble/hashes/sha2.js";
1066
1153
  import { etc, getPublicKey as nobleGetPublicKey, sign } from "@noble/secp256k1";
1067
-
1068
- // src/utils/hash.ts
1069
- import { ripemd160 } from "@noble/hashes/legacy.js";
1070
- import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
1071
- import { sha512_256 } from "@noble/hashes/sha2.js";
1072
- function hash160(input) {
1073
- return ripemd160(sha2562(input));
1074
- }
1075
- function txidFromBytes(data) {
1076
- return bytesToHex(sha512_256(data));
1077
- }
1078
- function hashP2PKH(input) {
1079
- return bytesToHex(hash160(input));
1080
- }
1081
-
1082
- // src/transactions/authorization.ts
1083
1154
  etc.hmacSha256Sync = (key, ...msgs) => {
1084
1155
  const h = hmac.create(sha2563, key);
1085
1156
  for (const msg of msgs)
@@ -1234,8 +1305,26 @@ function convertPostCondition(pc) {
1234
1305
  assetId: pc.assetId
1235
1306
  };
1236
1307
  }
1308
+ case "staking-postcondition":
1309
+ return {
1310
+ type: "staking",
1311
+ principal: resolvePrincipal(pc.address),
1312
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1313
+ amount: intToBigInt(pc.amount)
1314
+ };
1315
+ case "pox-postcondition":
1316
+ return {
1317
+ type: "pox",
1318
+ principal: resolvePrincipal(pc.address),
1319
+ conditionCode: POX_CODE_MAP[pc.condition]
1320
+ };
1237
1321
  }
1238
1322
  }
1323
+ var POX_CODE_MAP = {
1324
+ "will-not-perform": PoxConditionCode.WillNotPerform,
1325
+ "may-perform": PoxConditionCode.MayPerform,
1326
+ "will-perform": PoxConditionCode.WillPerform
1327
+ };
1239
1328
  function resolveSpendingCondition(opts, nonce, fee) {
1240
1329
  if (opts.publicKeys) {
1241
1330
  return createMultiSigSpendingCondition(opts.publicKeys, opts.signaturesRequired, nonce, fee, opts.hashMode);
@@ -1276,6 +1365,17 @@ function buildContractCall(options) {
1276
1365
  return tx;
1277
1366
  }
1278
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
+
1279
1379
  // src/transactions/signer.ts
1280
1380
  function txid(tx) {
1281
1381
  return txidFromBytes(serializeTransaction(tx));
@@ -1514,6 +1614,46 @@ function getContract(params) {
1514
1614
  };
1515
1615
  }
1516
1616
  });
1617
+ const buildCall = new Proxy({}, {
1618
+ get(_target, prop) {
1619
+ const fnName = camelToKebab.get(prop) ?? prop;
1620
+ const fn = fnByName.get(fnName);
1621
+ if (!fn || fn.access !== "public")
1622
+ return;
1623
+ return async (args, options) => {
1624
+ const publicKey = options?.publicKey ?? client.account?.publicKey;
1625
+ if (!publicKey) {
1626
+ throw new Error("buildCall requires a publicKey (pass options.publicKey or configure a client account)");
1627
+ }
1628
+ const functionArgs = buildFunctionArgs(fn, args);
1629
+ const network = client.chain?.network ?? "mainnet";
1630
+ const nonce = options?.nonce ?? await resolveNonce(client, publicKeyToAddress(publicKey, network));
1631
+ const unsigned = buildContractCall({
1632
+ contractAddress: address,
1633
+ contractName,
1634
+ functionName: fn.name,
1635
+ functionArgs,
1636
+ fee: options?.fee ?? 0n,
1637
+ nonce,
1638
+ publicKey,
1639
+ chain: client.chain,
1640
+ postConditionMode: options?.postConditionMode,
1641
+ postConditions: options?.postConditions,
1642
+ sponsored: options?.sponsored
1643
+ });
1644
+ if (options?.fee === undefined) {
1645
+ const estimates = await estimateFee(client, {
1646
+ transaction: unsigned
1647
+ });
1648
+ const mid = estimates[1] ?? estimates[0];
1649
+ if (mid) {
1650
+ unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
1651
+ }
1652
+ }
1653
+ return unsigned;
1654
+ };
1655
+ }
1656
+ });
1517
1657
  const maps = new Proxy({}, {
1518
1658
  get(_target, prop) {
1519
1659
  const mapName = camelToKebab.get(prop) ?? prop;
@@ -1536,7 +1676,13 @@ function getContract(params) {
1536
1676
  };
1537
1677
  }
1538
1678
  });
1539
- return { read, call, maps };
1679
+ return { read, call, buildCall, maps };
1680
+ }
1681
+ function resolveNetworkContract(client, contracts) {
1682
+ if (!client.chain) {
1683
+ throw new Error("Client must have a chain configured");
1684
+ }
1685
+ return contracts[client.chain.network];
1540
1686
  }
1541
1687
  function buildFunctionArgs(fn, args) {
1542
1688
  return fn.args.map((arg) => {
@@ -2058,11 +2204,7 @@ function validateFQN(fqn) {
2058
2204
 
2059
2205
  // src/bns/actions.ts
2060
2206
  function getBnsContract(client) {
2061
- if (!client.chain) {
2062
- throw new Error("Client must have a chain configured");
2063
- }
2064
- const network = client.chain.network;
2065
- const contract = network === "mainnet" ? BNS_CONTRACTS.mainnet : BNS_CONTRACTS.testnet;
2207
+ const contract = resolveNetworkContract(client, BNS_CONTRACTS);
2066
2208
  return getContract({
2067
2209
  client,
2068
2210
  address: contract.address,
@@ -2719,5 +2861,5 @@ export {
2719
2861
  bnsResolve
2720
2862
  };
2721
2863
 
2722
- //# debugId=0D764C03DAFF717D64756E2164756E21
2864
+ //# debugId=4D62EAB4ED52294064756E2164756E21
2723
2865
  //# sourceMappingURL=index.js.map