@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
@@ -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));
@@ -1550,6 +1614,46 @@ function getContract(params) {
1550
1614
  };
1551
1615
  }
1552
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
+ });
1553
1657
  const maps = new Proxy({}, {
1554
1658
  get(_target, prop) {
1555
1659
  const mapName = camelToKebab.get(prop) ?? prop;
@@ -1572,7 +1676,7 @@ function getContract(params) {
1572
1676
  };
1573
1677
  }
1574
1678
  });
1575
- return { read, call, maps };
1679
+ return { read, call, buildCall, maps };
1576
1680
  }
1577
1681
  function resolveNetworkContract(client, contracts) {
1578
1682
  if (!client.chain) {
@@ -2757,5 +2861,5 @@ export {
2757
2861
  bnsResolve
2758
2862
  };
2759
2863
 
2760
- //# debugId=98CD0F025D02FDCF64756E2164756E21
2864
+ //# debugId=4D62EAB4ED52294064756E2164756E21
2761
2865
  //# sourceMappingURL=index.js.map