@secondlayer/stacks 2.10.0 → 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 (91) 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-0ek3cyt8.js → stacks-3kmj5yre.js} +4 -4
  5. package/dist/shared/{stacks-9t68zmpn.js → stacks-502j0efj.js} +3 -3
  6. package/dist/shared/{stacks-99ghanwx.js → stacks-63xbc6cj.js} +56 -6
  7. package/dist/shared/stacks-63xbc6cj.js.map +10 -0
  8. package/dist/shared/{stacks-g7ffp8aj.js → stacks-6xt8py97.cjs} +59 -30
  9. package/dist/shared/stacks-6xt8py97.cjs.map +13 -0
  10. package/dist/shared/{stacks-2dhf79w5.js → stacks-7nvbv61d.js} +8 -8
  11. package/dist/shared/stacks-azp00pve.js +70 -0
  12. package/dist/shared/stacks-azp00pve.js.map +11 -0
  13. package/dist/shared/{stacks-vk8fwz0t.cjs → stacks-b9904rc2.cjs} +3 -2
  14. package/dist/shared/{stacks-vk8fwz0t.cjs.map → stacks-b9904rc2.cjs.map} +2 -2
  15. package/dist/shared/{stacks-3y058qda.cjs → stacks-fhzwsn5d.cjs} +16 -2
  16. package/dist/shared/{stacks-3y058qda.cjs.map → stacks-fhzwsn5d.cjs.map} +5 -4
  17. package/dist/shared/{stacks-e60vrr34.js → stacks-g11v9a35.js} +4 -4
  18. package/dist/shared/{stacks-6xmk24yw.js → stacks-gfm3r397.cjs} +20 -7
  19. package/dist/shared/stacks-gfm3r397.cjs.map +11 -0
  20. package/dist/shared/{stacks-43cxvnr7.js → stacks-jbmcwky5.js} +3 -3
  21. package/dist/shared/{stacks-q1mjkt15.js → stacks-msmgyerb.js} +4 -4
  22. package/dist/shared/{stacks-2h8d2y27.js → stacks-qs5fzts5.js} +17 -3
  23. package/dist/shared/{stacks-2h8d2y27.js.map → stacks-qs5fzts5.js.map} +5 -4
  24. package/dist/shared/{stacks-xw0j252s.cjs → stacks-shn9zw99.cjs} +43 -3
  25. package/dist/shared/stacks-shn9zw99.cjs.map +10 -0
  26. package/dist/shared/{stacks-vf0ekgwb.js → stacks-ssndnbbd.js} +8 -10
  27. package/dist/shared/{stacks-vf0ekgwb.js.map → stacks-ssndnbbd.js.map} +2 -2
  28. package/dist/shared/{stacks-4t2vmp4y.js → stacks-v150hffx.js} +6 -6
  29. package/dist/shared/{stacks-a36n7sjz.js → stacks-x94a1d6s.js} +3 -3
  30. package/dist/src/accounts/index.js +3 -5
  31. package/dist/src/accounts/index.js.map +2 -2
  32. package/dist/src/actions/index.d.cts +59 -8
  33. package/dist/src/actions/index.d.ts +59 -8
  34. package/dist/src/actions/index.js +13 -15
  35. package/dist/src/actions/index.js.map +1 -1
  36. package/dist/src/bitcoin/index.js +8 -11
  37. package/dist/src/bitcoin/index.js.map +2 -2
  38. package/dist/src/bns/index.js +12 -14
  39. package/dist/src/bns/index.js.map +2 -2
  40. package/dist/src/clarity/index.d.cts +50 -1
  41. package/dist/src/clarity/index.d.ts +50 -1
  42. package/dist/src/clarity/index.js +8 -7
  43. package/dist/src/clarity/index.js.map +1 -1
  44. package/dist/src/index.js +12 -15
  45. package/dist/src/index.js.map +2 -2
  46. package/dist/src/postconditions/index.js +3 -3
  47. package/dist/src/pox/index.js +11 -13
  48. package/dist/src/pox/index.js.map +2 -2
  49. package/dist/src/sbtc/index.js +10 -12
  50. package/dist/src/sbtc/index.js.map +2 -2
  51. package/dist/src/stackingdao/index.js +11 -13
  52. package/dist/src/stackingdao/index.js.map +2 -2
  53. package/dist/src/tools/index.cjs +155 -51
  54. package/dist/src/tools/index.cjs.map +9 -9
  55. package/dist/src/tools/index.js +155 -51
  56. package/dist/src/tools/index.js.map +9 -9
  57. package/dist/src/transactions/index.js +6 -7
  58. package/dist/src/transactions/index.js.map +1 -1
  59. package/dist/src/utils/index.cjs +2 -1
  60. package/dist/src/utils/index.cjs.map +2 -2
  61. package/dist/src/utils/index.d.cts +5 -1
  62. package/dist/src/utils/index.d.ts +5 -1
  63. package/dist/src/utils/index.js +12 -14
  64. package/dist/src/utils/index.js.map +2 -2
  65. package/dist/src/x402/index.js +9 -10
  66. package/dist/src/x402/index.js.map +2 -2
  67. package/package.json +1 -1
  68. package/dist/shared/stacks-6xmk24yw.js.map +0 -10
  69. package/dist/shared/stacks-99ghanwx.js.map +0 -10
  70. package/dist/shared/stacks-9g0jhab3.cjs +0 -40
  71. package/dist/shared/stacks-9g0jhab3.cjs.map +0 -10
  72. package/dist/shared/stacks-fcaefc5b.cjs +0 -16
  73. package/dist/shared/stacks-fcaefc5b.cjs.map +0 -10
  74. package/dist/shared/stacks-g7ffp8aj.js.map +0 -13
  75. package/dist/shared/stacks-v9jqcpd4.js +0 -18
  76. package/dist/shared/stacks-v9jqcpd4.js.map +0 -10
  77. package/dist/shared/stacks-wyxj879g.cjs.map +0 -13
  78. package/dist/shared/stacks-xw0j252s.cjs.map +0 -10
  79. package/dist/shared/stacks-xxn5ma6g.js +0 -22
  80. package/dist/shared/stacks-xxn5ma6g.js.map +0 -10
  81. package/dist/shared/stacks-ya3x01yd.cjs +0 -16
  82. package/dist/shared/stacks-ya3x01yd.cjs.map +0 -10
  83. /package/dist/shared/{stacks-0zysn74p.js.map → stacks-2mm20wqf.js.map} +0 -0
  84. /package/dist/shared/{stacks-0ek3cyt8.js.map → stacks-3kmj5yre.js.map} +0 -0
  85. /package/dist/shared/{stacks-9t68zmpn.js.map → stacks-502j0efj.js.map} +0 -0
  86. /package/dist/shared/{stacks-2dhf79w5.js.map → stacks-7nvbv61d.js.map} +0 -0
  87. /package/dist/shared/{stacks-e60vrr34.js.map → stacks-g11v9a35.js.map} +0 -0
  88. /package/dist/shared/{stacks-43cxvnr7.js.map → stacks-jbmcwky5.js.map} +0 -0
  89. /package/dist/shared/{stacks-q1mjkt15.js.map → stacks-msmgyerb.js.map} +0 -0
  90. /package/dist/shared/{stacks-4t2vmp4y.js.map → stacks-v150hffx.js.map} +0 -0
  91. /package/dist/shared/{stacks-a36n7sjz.js.map → stacks-x94a1d6s.js.map} +0 -0
@@ -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 MAX_U128 = BigInt("0xffffffffffffffffffffffffffffffff");
765
- var MIN_I128 = BigInt("-170141183460469231731687303715884105728");
766
- var MAX_I128 = BigInt("0x7fffffffffffffffffffffffffffffff");
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 > MAX_I128)
776
- throw new RangeError(`Int exceeds max i128: ${MAX_I128}`);
777
- if (n < MIN_I128)
778
- throw new RangeError(`Int below min i128: ${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 > MAX_U128)
786
- throw new RangeError(`UInt exceeds max u128: ${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, hash160] = c32addressDecode(address);
800
- const normalized = c32address(version, hash160);
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, hash160] = c32addressDecode(address);
805
- const normalized = c32address(version, hash160);
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 hash160 = bytesToHex(reader.readBytes(20));
877
- return c32address(version, hash160);
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));
@@ -1600,6 +1664,46 @@ function getContract(params) {
1600
1664
  };
1601
1665
  }
1602
1666
  });
1667
+ const buildCall = new Proxy({}, {
1668
+ get(_target, prop) {
1669
+ const fnName = camelToKebab.get(prop) ?? prop;
1670
+ const fn = fnByName.get(fnName);
1671
+ if (!fn || fn.access !== "public")
1672
+ return;
1673
+ return async (args, options) => {
1674
+ const publicKey = options?.publicKey ?? client.account?.publicKey;
1675
+ if (!publicKey) {
1676
+ throw new Error("buildCall requires a publicKey (pass options.publicKey or configure a client account)");
1677
+ }
1678
+ const functionArgs = buildFunctionArgs(fn, args);
1679
+ const network = client.chain?.network ?? "mainnet";
1680
+ const nonce = options?.nonce ?? await resolveNonce(client, publicKeyToAddress(publicKey, network));
1681
+ const unsigned = buildContractCall({
1682
+ contractAddress: address,
1683
+ contractName,
1684
+ functionName: fn.name,
1685
+ functionArgs,
1686
+ fee: options?.fee ?? 0n,
1687
+ nonce,
1688
+ publicKey,
1689
+ chain: client.chain,
1690
+ postConditionMode: options?.postConditionMode,
1691
+ postConditions: options?.postConditions,
1692
+ sponsored: options?.sponsored
1693
+ });
1694
+ if (options?.fee === undefined) {
1695
+ const estimates = await estimateFee(client, {
1696
+ transaction: unsigned
1697
+ });
1698
+ const mid = estimates[1] ?? estimates[0];
1699
+ if (mid) {
1700
+ unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
1701
+ }
1702
+ }
1703
+ return unsigned;
1704
+ };
1705
+ }
1706
+ });
1603
1707
  const maps = new Proxy({}, {
1604
1708
  get(_target, prop) {
1605
1709
  const mapName = camelToKebab.get(prop) ?? prop;
@@ -1622,7 +1726,7 @@ function getContract(params) {
1622
1726
  };
1623
1727
  }
1624
1728
  });
1625
- return { read, call, maps };
1729
+ return { read, call, buildCall, maps };
1626
1730
  }
1627
1731
  function resolveNetworkContract(client, contracts) {
1628
1732
  if (!client.chain) {
@@ -2792,5 +2896,5 @@ var getNftHoldings = import_ai.tool({
2792
2896
  execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
2793
2897
  });
2794
2898
 
2795
- //# debugId=F40D5D6D3BD59C9E64756E2164756E21
2899
+ //# debugId=47021AD178AA414364756E2164756E21
2796
2900
  //# sourceMappingURL=index.cjs.map