@secondlayer/stacks 6.1.0 → 6.1.2

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 (166) hide show
  1. package/dist/shared/stacks-esm-0pc6tmf0.js +50 -0
  2. package/dist/shared/{stacks-esm-743jfh10.js.map → stacks-esm-0pc6tmf0.js.map} +2 -2
  3. package/dist/shared/{stacks-esm-0rdxcta7.js → stacks-esm-16d82wyc.js} +10 -10
  4. package/dist/shared/{stacks-esm-0rdxcta7.js.map → stacks-esm-16d82wyc.js.map} +2 -2
  5. package/dist/shared/{stacks-esm-cvhazvhd.js → stacks-esm-7a0ehykf.js} +43 -43
  6. package/dist/shared/{stacks-esm-cvhazvhd.js.map → stacks-esm-7a0ehykf.js.map} +2 -2
  7. package/dist/shared/{stacks-esm-1jae0a3r.js → stacks-esm-7v18h5dk.js} +4 -4
  8. package/dist/shared/{stacks-esm-1jae0a3r.js.map → stacks-esm-7v18h5dk.js.map} +2 -2
  9. package/dist/shared/{stacks-esm-9rnx0zxr.js → stacks-esm-8f5catbf.js} +126 -126
  10. package/dist/shared/{stacks-esm-9rnx0zxr.js.map → stacks-esm-8f5catbf.js.map} +2 -2
  11. package/dist/shared/{stacks-esm-7fpqgtyx.js → stacks-esm-8jt6k8p3.js} +13 -13
  12. package/dist/shared/{stacks-esm-7fpqgtyx.js.map → stacks-esm-8jt6k8p3.js.map} +2 -2
  13. package/dist/shared/{stacks-esm-hr7fpxtj.js → stacks-esm-a20wyky3.js} +92 -92
  14. package/dist/shared/{stacks-esm-hr7fpxtj.js.map → stacks-esm-a20wyky3.js.map} +2 -2
  15. package/dist/shared/{stacks-esm-3pv5avgr.js → stacks-esm-b54n1jdx.js} +54 -54
  16. package/dist/shared/{stacks-esm-3pv5avgr.js.map → stacks-esm-b54n1jdx.js.map} +2 -2
  17. package/dist/shared/{stacks-esm-r9q4wnyw.js → stacks-esm-cmtj5vky.js} +162 -162
  18. package/dist/shared/{stacks-esm-r9q4wnyw.js.map → stacks-esm-cmtj5vky.js.map} +2 -2
  19. package/dist/shared/{stacks-esm-wv67m4g6.js → stacks-esm-e2qhfgke.js} +36 -36
  20. package/dist/shared/{stacks-esm-wv67m4g6.js.map → stacks-esm-e2qhfgke.js.map} +2 -2
  21. package/dist/shared/{stacks-esm-qk0p9fr6.js → stacks-esm-ea4m4bk7.js} +117 -117
  22. package/dist/shared/{stacks-esm-qk0p9fr6.js.map → stacks-esm-ea4m4bk7.js.map} +2 -2
  23. package/dist/shared/{stacks-esm-fcfdn2zx.js → stacks-esm-hkw1kvd4.js} +140 -140
  24. package/dist/shared/{stacks-esm-fcfdn2zx.js.map → stacks-esm-hkw1kvd4.js.map} +2 -2
  25. package/dist/shared/{stacks-esm-qkj67g80.js → stacks-esm-k108pemv.js} +4 -4
  26. package/dist/shared/{stacks-esm-qkj67g80.js.map → stacks-esm-k108pemv.js.map} +2 -2
  27. package/dist/shared/stacks-esm-kbz5s6v8.js +84 -0
  28. package/dist/shared/{stacks-esm-2mc7ebrm.js.map → stacks-esm-kbz5s6v8.js.map} +2 -2
  29. package/dist/shared/{stacks-esm-n53kvwmt.js → stacks-esm-mt1thm7k.js} +9 -9
  30. package/dist/shared/{stacks-esm-n53kvwmt.js.map → stacks-esm-mt1thm7k.js.map} +2 -2
  31. package/dist/shared/{stacks-esm-v45990hx.js → stacks-esm-n1mekwnb.js} +9 -9
  32. package/dist/shared/{stacks-esm-v45990hx.js.map → stacks-esm-n1mekwnb.js.map} +2 -2
  33. package/dist/shared/{stacks-esm-r6dejrgr.js → stacks-esm-nt5hf8ht.js} +34 -34
  34. package/dist/shared/{stacks-esm-r6dejrgr.js.map → stacks-esm-nt5hf8ht.js.map} +2 -2
  35. package/dist/shared/{stacks-esm-skmcf5n2.js → stacks-esm-phgy8yqf.js} +210 -210
  36. package/dist/shared/{stacks-esm-skmcf5n2.js.map → stacks-esm-phgy8yqf.js.map} +2 -2
  37. package/dist/shared/{stacks-esm-kds4n82p.js → stacks-esm-pxv6ny92.js} +116 -116
  38. package/dist/shared/{stacks-esm-kds4n82p.js.map → stacks-esm-pxv6ny92.js.map} +2 -2
  39. package/dist/shared/{stacks-esm-3g33bqsm.js → stacks-esm-qfzxhdqz.js} +19 -19
  40. package/dist/shared/{stacks-esm-3g33bqsm.js.map → stacks-esm-qfzxhdqz.js.map} +2 -2
  41. package/dist/shared/{stacks-esm-aw2mj3sj.js → stacks-esm-snj9s2q8.js} +43 -43
  42. package/dist/shared/{stacks-esm-aw2mj3sj.js.map → stacks-esm-snj9s2q8.js.map} +2 -2
  43. package/dist/shared/{stacks-esm-q19a17fd.js → stacks-esm-ss9ap75h.js} +28 -28
  44. package/dist/shared/{stacks-esm-q19a17fd.js.map → stacks-esm-ss9ap75h.js.map} +2 -2
  45. package/dist/shared/{stacks-esm-x1r01353.js → stacks-esm-t88hc019.js} +18 -18
  46. package/dist/shared/{stacks-esm-x1r01353.js.map → stacks-esm-t88hc019.js.map} +2 -2
  47. package/dist/shared/stacks-esm-tdrdye4y.js +48 -0
  48. package/dist/shared/{stacks-esm-pxhfqfff.js.map → stacks-esm-tdrdye4y.js.map} +2 -2
  49. package/dist/src/accounts/index.cjs +15 -13
  50. package/dist/src/accounts/index.cjs.map +2 -2
  51. package/dist/src/accounts/index.d.cts +1 -1
  52. package/dist/src/accounts/index.d.ts +1 -1
  53. package/dist/src/accounts/index.js +26 -26
  54. package/dist/src/accounts/index.js.map +2 -2
  55. package/dist/src/actions/index.cjs +83 -81
  56. package/dist/src/actions/index.cjs.map +2 -2
  57. package/dist/src/actions/index.d.cts +1 -1
  58. package/dist/src/actions/index.d.ts +1 -1
  59. package/dist/src/actions/index.js +102 -103
  60. package/dist/src/actions/index.js.map +1 -1
  61. package/dist/src/bitcoin/index.cjs +2035 -2036
  62. package/dist/src/bitcoin/index.cjs.map +8 -8
  63. package/dist/src/bitcoin/index.d.cts +92 -92
  64. package/dist/src/bitcoin/index.d.ts +92 -92
  65. package/dist/src/bitcoin/index.js +88 -90
  66. package/dist/src/bitcoin/index.js.map +2 -2
  67. package/dist/src/bns/index.cjs +3313 -3310
  68. package/dist/src/bns/index.cjs.map +13 -13
  69. package/dist/src/bns/index.d.cts +1 -1
  70. package/dist/src/bns/index.d.ts +1 -1
  71. package/dist/src/bns/index.js +39 -41
  72. package/dist/src/bns/index.js.map +2 -2
  73. package/dist/src/chains/index.cjs +14 -12
  74. package/dist/src/chains/index.cjs.map +2 -2
  75. package/dist/src/chains/index.d.cts +1 -1
  76. package/dist/src/chains/index.d.ts +1 -1
  77. package/dist/src/chains/index.js +12 -12
  78. package/dist/src/chains/index.js.map +1 -1
  79. package/dist/src/clarity/index.cjs +98 -96
  80. package/dist/src/clarity/index.cjs.map +2 -2
  81. package/dist/src/clarity/index.d.cts +1 -1
  82. package/dist/src/clarity/index.d.ts +1 -1
  83. package/dist/src/clarity/index.js +170 -171
  84. package/dist/src/clarity/index.js.map +1 -1
  85. package/dist/src/connect/index.cjs +27 -20
  86. package/dist/src/connect/index.cjs.map +3 -3
  87. package/dist/src/connect/index.d.cts +1 -1
  88. package/dist/src/connect/index.d.ts +1 -1
  89. package/dist/src/connect/index.js +27 -20
  90. package/dist/src/connect/index.js.map +3 -3
  91. package/dist/src/connect/walletconnect/index.cjs +6 -46
  92. package/dist/src/connect/walletconnect/index.cjs.map +3 -4
  93. package/dist/src/connect/walletconnect/index.d.cts +1 -1
  94. package/dist/src/connect/walletconnect/index.d.ts +1 -1
  95. package/dist/src/connect/walletconnect/index.js +6 -46
  96. package/dist/src/connect/walletconnect/index.js.map +3 -4
  97. package/dist/src/filters/index.cjs +22 -20
  98. package/dist/src/filters/index.cjs.map +2 -2
  99. package/dist/src/filters/index.d.cts +1 -1
  100. package/dist/src/filters/index.d.ts +1 -1
  101. package/dist/src/filters/index.js +30 -30
  102. package/dist/src/filters/index.js.map +1 -1
  103. package/dist/src/index.cjs +1411 -1410
  104. package/dist/src/index.cjs.map +11 -11
  105. package/dist/src/index.d.cts +724 -724
  106. package/dist/src/index.d.ts +724 -724
  107. package/dist/src/index.js +219 -219
  108. package/dist/src/index.js.map +2 -2
  109. package/dist/src/postconditions/index.cjs +26 -24
  110. package/dist/src/postconditions/index.cjs.map +2 -2
  111. package/dist/src/postconditions/index.d.cts +1 -1
  112. package/dist/src/postconditions/index.d.ts +1 -1
  113. package/dist/src/postconditions/index.js +16 -17
  114. package/dist/src/postconditions/index.js.map +1 -1
  115. package/dist/src/pox/index.cjs +722 -721
  116. package/dist/src/pox/index.cjs.map +9 -9
  117. package/dist/src/pox/index.d.cts +1 -1
  118. package/dist/src/pox/index.d.ts +1 -1
  119. package/dist/src/pox/index.js +40 -41
  120. package/dist/src/pox/index.js.map +2 -2
  121. package/dist/src/pox5/index.cjs +141 -137
  122. package/dist/src/pox5/index.cjs.map +3 -3
  123. package/dist/src/pox5/index.d.cts +9 -1
  124. package/dist/src/pox5/index.d.ts +9 -1
  125. package/dist/src/pox5/index.js +210 -209
  126. package/dist/src/pox5/index.js.map +3 -3
  127. package/dist/src/sbtc/index.cjs +71 -69
  128. package/dist/src/sbtc/index.cjs.map +2 -2
  129. package/dist/src/sbtc/index.d.cts +1 -1
  130. package/dist/src/sbtc/index.d.ts +1 -1
  131. package/dist/src/sbtc/index.js +39 -40
  132. package/dist/src/sbtc/index.js.map +2 -2
  133. package/dist/src/simnet/index.cjs +16 -16
  134. package/dist/src/simnet/index.cjs.map +2 -2
  135. package/dist/src/simnet/index.d.cts +1 -1
  136. package/dist/src/simnet/index.d.ts +1 -1
  137. package/dist/src/simnet/index.js +16 -16
  138. package/dist/src/simnet/index.js.map +2 -2
  139. package/dist/src/stackingdao/index.cjs +716 -715
  140. package/dist/src/stackingdao/index.cjs.map +9 -9
  141. package/dist/src/stackingdao/index.d.cts +1 -1
  142. package/dist/src/stackingdao/index.d.ts +1 -1
  143. package/dist/src/stackingdao/index.js +26 -27
  144. package/dist/src/stackingdao/index.js.map +2 -2
  145. package/dist/src/subscriptions/index.cjs +15 -13
  146. package/dist/src/subscriptions/index.cjs.map +2 -2
  147. package/dist/src/subscriptions/index.d.cts +1 -1
  148. package/dist/src/subscriptions/index.d.ts +1 -1
  149. package/dist/src/subscriptions/index.js +14 -15
  150. package/dist/src/subscriptions/index.js.map +1 -1
  151. package/dist/src/transactions/index.cjs +79 -77
  152. package/dist/src/transactions/index.cjs.map +2 -2
  153. package/dist/src/transactions/index.d.cts +1 -1
  154. package/dist/src/transactions/index.d.ts +1 -1
  155. package/dist/src/transactions/index.js +104 -105
  156. package/dist/src/transactions/index.js.map +1 -1
  157. package/dist/src/utils/index.cjs +76 -74
  158. package/dist/src/utils/index.cjs.map +2 -2
  159. package/dist/src/utils/index.d.cts +1 -1
  160. package/dist/src/utils/index.d.ts +1 -1
  161. package/dist/src/utils/index.js +131 -131
  162. package/dist/src/utils/index.js.map +2 -2
  163. package/package.json +1 -1
  164. package/dist/shared/stacks-esm-2mc7ebrm.js +0 -84
  165. package/dist/shared/stacks-esm-743jfh10.js +0 -50
  166. package/dist/shared/stacks-esm-pxhfqfff.js +0 -48
@@ -19,13 +19,15 @@ var __toESM = (mod, isNodeMode, target) => {
19
19
  return cached;
20
20
  }
21
21
  target = mod != null ? __create(__getProtoOf(mod)) : {};
22
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
23
- for (let key of __getOwnPropNames(mod))
24
- if (!__hasOwnProp.call(to, key))
25
- __defProp(to, key, {
26
- get: __accessProp.bind(mod, key),
27
- enumerable: true
28
- });
22
+ const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
23
+ if (mod && typeof mod === "object" || typeof mod === "function") {
24
+ for (let key of __getOwnPropNames(mod))
25
+ if (!__hasOwnProp.call(to, key))
26
+ __defProp(to, key, {
27
+ get: __accessProp.bind(mod, key),
28
+ enumerable: true
29
+ });
30
+ }
29
31
  if (canCache)
30
32
  cache.set(mod, to);
31
33
  return to;
@@ -61,16 +63,26 @@ var __export = (target, all) => {
61
63
  });
62
64
  };
63
65
 
64
- // src/postconditions/index.ts
65
- var exports_postconditions = {};
66
- __export(exports_postconditions, {
67
- wireToPostCondition: () => wireToPostCondition,
68
- postConditionToHex: () => postConditionToHex,
69
- parsePostConditionAmount: () => parsePostConditionAmount,
70
- fromHex: () => fromHex,
71
- Pc: () => Pc
66
+ // src/pox/index.ts
67
+ var exports_pox = {};
68
+ __export(exports_pox, {
69
+ MAX_LOCK_PERIOD: () => MAX_LOCK_PERIOD,
70
+ MIN_LOCK_PERIOD: () => MIN_LOCK_PERIOD,
71
+ POX_ABI: () => POX_ABI,
72
+ POX_ADDRESS_VERSION: () => POX_ADDRESS_VERSION,
73
+ POX_CONTRACTS: () => POX_CONTRACTS,
74
+ burnHeightToRewardCycle: () => burnHeightToRewardCycle,
75
+ parseBtcAddress: () => parseBtcAddress2,
76
+ pox: () => pox,
77
+ rewardCycleToBurnHeight: () => rewardCycleToBurnHeight,
78
+ validateLockPeriod: () => validateLockPeriod
72
79
  });
73
- module.exports = __toCommonJS(exports_postconditions);
80
+ module.exports = __toCommonJS(exports_pox);
81
+
82
+ // src/clarity/abi/utils.ts
83
+ function toCamelCase(str) {
84
+ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/-([A-Z])/g, (_, letter) => letter).replace(/-(\d)/g, (_, digit) => digit).replace(/-/g, "").replace(/^\d/, "_$&");
85
+ }
74
86
 
75
87
  // src/utils/c32.ts
76
88
  var import_sha2 = require("@noble/hashes/sha2.js");
@@ -403,103 +415,86 @@ function getContractAddress(deployer, contractName) {
403
415
  }
404
416
  return `${deployer}.${contractName}`;
405
417
  }
406
-
407
- // src/transactions/types.ts
408
- var AuthType = {
409
- Standard: 4,
410
- Sponsored: 5
411
- };
412
- var PayloadType = {
413
- TokenTransfer: 0,
414
- SmartContract: 1,
415
- ContractCall: 2,
416
- PoisonMicroblock: 3,
417
- Coinbase: 4,
418
- CoinbaseToAltRecipient: 5,
419
- VersionedSmartContract: 6,
420
- TenureChange: 7,
421
- NakamotoCoinbase: 8
422
- };
423
- var ClarityVersion = {
424
- Clarity1: 1,
425
- Clarity2: 2,
426
- Clarity3: 3,
427
- Clarity4: 4,
428
- Clarity5: 5,
429
- Clarity6: 6
430
- };
431
- var AnchorMode = {
432
- OnChainOnly: 1,
433
- OffChainOnly: 2,
434
- Any: 3
435
- };
436
- var PostConditionModeWire = {
437
- Allow: 1,
438
- Deny: 2,
439
- Originator: 3
440
- };
441
- var AddressHashMode = {
442
- P2PKH: 0,
443
- P2SH: 1,
444
- P2WPKH: 2,
445
- P2WSH: 3,
446
- P2SH_NonSequential: 5,
447
- P2WSH_P2SH_NonSequential: 7
448
- };
449
- var PubKeyEncoding = {
450
- Compressed: 0,
451
- Uncompressed: 1
452
- };
453
- var FungibleConditionCode = {
454
- Equal: 1,
455
- Greater: 2,
456
- GreaterEqual: 3,
457
- Less: 4,
458
- LessEqual: 5
459
- };
460
- var NonFungibleConditionCode = {
461
- Sends: 16,
462
- DoesNotSend: 17,
463
- MaybeSent: 18
464
- };
465
- var PoxConditionCode = {
466
- WillNotPerform: 48,
467
- MayPerform: 49,
468
- WillPerform: 50
469
- };
470
- var PostConditionPrincipalId = {
471
- Origin: 1,
472
- Standard: 2,
473
- Contract: 3
474
- };
475
- var AssetType = {
476
- STX: 0,
477
- Fungible: 1,
478
- NonFungible: 2,
479
- Staking: 3,
480
- Pox: 4
481
- };
482
- var AuthFieldType = {
483
- PublicKeyCompressed: 0,
484
- PublicKeyUncompressed: 1,
485
- SignatureCompressed: 2,
486
- SignatureUncompressed: 3
487
- };
488
- var RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;
489
- var MEMO_MAX_LENGTH_BYTES = 34;
490
- var MAX_STRING_LENGTH_BYTES = 128;
491
- var COINBASE_BYTES_LENGTH = 32;
492
- var VRF_PROOF_BYTES_LENGTH = 80;
493
- var MICROBLOCK_HEADER_BYTES_LENGTH = 132;
494
- var TenureChangeCause = {
495
- BlockFound: 0,
496
- Extended: 1,
497
- ExtendedRuntime: 2,
498
- ExtendedReadCount: 3,
499
- ExtendedReadLength: 4,
500
- ExtendedWriteCount: 5,
501
- ExtendedWriteLength: 6
502
- };
418
+ // src/clarity/abi/guards.ts
419
+ function isUint128(value) {
420
+ return typeof value === "bigint" && value >= 0n && value <= MAX_U128;
421
+ }
422
+ function isInt128(value) {
423
+ return typeof value === "bigint" && value >= MIN_I128 && value <= MAX_I128;
424
+ }
425
+ function isBool(value) {
426
+ return typeof value === "boolean";
427
+ }
428
+ function isPrincipal(value) {
429
+ return typeof value === "string" && parsePrincipal(value) !== null;
430
+ }
431
+ function isStandardPrincipal(value) {
432
+ if (typeof value !== "string")
433
+ return false;
434
+ const parsed = parsePrincipal(value);
435
+ return parsed !== null && parsed.contractName === undefined;
436
+ }
437
+ function isContractPrincipal(value) {
438
+ if (typeof value !== "string")
439
+ return false;
440
+ const parsed = parsePrincipal(value);
441
+ return parsed !== null && parsed.contractName !== undefined;
442
+ }
443
+ function isTraitReference(value) {
444
+ return isContractPrincipal(value);
445
+ }
446
+ function isString(value) {
447
+ return typeof value === "string";
448
+ }
449
+ function isUint8Array(value) {
450
+ return value instanceof Uint8Array;
451
+ }
452
+ function isArray(value, itemGuard) {
453
+ return Array.isArray(value) && value.every(itemGuard);
454
+ }
455
+ function isOptional(value, guard) {
456
+ return value === null || guard(value);
457
+ }
458
+ function isOkResponse(response) {
459
+ return "ok" in response && !("err" in response);
460
+ }
461
+ function isErrResponse(response) {
462
+ return "err" in response && !("ok" in response);
463
+ }
464
+ function isResponse(value, okGuard, errGuard) {
465
+ if (typeof value !== "object" || value === null)
466
+ return false;
467
+ const obj = value;
468
+ if ("ok" in value && !("err" in value))
469
+ return okGuard(obj.ok);
470
+ if ("err" in value && !("ok" in value))
471
+ return errGuard(obj.err);
472
+ return false;
473
+ }
474
+ function isAbiList(type) {
475
+ return typeof type === "object" && type !== null && "list" in type;
476
+ }
477
+ function isAbiTuple(type) {
478
+ return typeof type === "object" && type !== null && "tuple" in type;
479
+ }
480
+ function isAbiOptional(type) {
481
+ return typeof type === "object" && type !== null && "optional" in type;
482
+ }
483
+ function isAbiResponse(type) {
484
+ return typeof type === "object" && type !== null && "response" in type;
485
+ }
486
+ function isAbiBuffer(type) {
487
+ return typeof type === "object" && type !== null && "buff" in type;
488
+ }
489
+ function isAbiStringAscii(type) {
490
+ return typeof type === "object" && type !== null && "string-ascii" in type;
491
+ }
492
+ function isAbiStringUtf8(type) {
493
+ return typeof type === "object" && type !== null && "string-utf8" in type;
494
+ }
495
+ function isAbiTraitReference(type) {
496
+ return type === "trait_reference";
497
+ }
503
498
 
504
499
  // src/errors/base.ts
505
500
  function codeFromName(name) {
@@ -663,37 +658,131 @@ function clarityTypeFromByte(byte) {
663
658
  return type;
664
659
  }
665
660
 
666
- // src/clarity/serialize.ts
667
- var CLARITY_INT_SIZE = 128n;
668
- var CLARITY_INT_BYTE_SIZE = 16;
669
- function typeIdByte(type) {
670
- return ClarityWireType[type];
671
- }
672
- function withTypeId(type, bytes) {
673
- return concatBytes(new Uint8Array([typeIdByte(type)]), bytes);
661
+ // src/clarity/deserialize.ts
662
+ function readAddress(reader) {
663
+ const version = reader.readUInt8();
664
+ const hash160 = bytesToHex(reader.readBytes(20));
665
+ return c32address(version, hash160);
674
666
  }
675
- function serializeAddress(c32Address) {
676
- const [version, hash1602] = c32addressDecode(c32Address);
677
- return concatBytes(new Uint8Array([version]), hexToBytes(hash1602));
667
+ function readLPString(reader, prefixBytes = 1) {
668
+ let length = 0;
669
+ for (let i = 0;i < prefixBytes; i++) {
670
+ length = length << 8 | reader.readUInt8();
671
+ }
672
+ return bytesToUtf8(reader.readBytes(length));
678
673
  }
679
- function serializeLPString(str, prefixBytes = 1) {
680
- const content = utf8ToBytes(str);
681
- const lengthPrefix = hexToBytes(intToHex(content.byteLength, prefixBytes));
682
- return concatBytes(lengthPrefix, content);
674
+ var MAX_CV_DEPTH = 64;
675
+ var MIN_LIST_ITEM_BYTES = 1;
676
+ var MIN_TUPLE_ENTRY_BYTES = 2;
677
+ function checkCount(reader, count, minBytes) {
678
+ if (count * minBytes > reader.remaining()) {
679
+ throw new SerializationError(`Clarity value declares ${count} elements but only ${reader.remaining()} bytes remain`);
680
+ }
683
681
  }
684
- function serializeCVBytes(value) {
685
- switch (value.type) {
682
+ function readCV(reader, depth = 0) {
683
+ if (depth > MAX_CV_DEPTH) {
684
+ throw new SerializationError(`Clarity value nests deeper than ${MAX_CV_DEPTH} levels`);
685
+ }
686
+ const typeByte = reader.readUInt8();
687
+ const type = clarityTypeFromByte(typeByte);
688
+ switch (type) {
689
+ case "int":
690
+ return intCV(bytesToTwosBigInt(reader.readBytes(16)));
691
+ case "uint":
692
+ return uintCV(reader.readBytes(16));
686
693
  case "true":
694
+ return trueCV();
687
695
  case "false":
688
- return new Uint8Array([typeIdByte(value.type)]);
689
- case "int": {
690
- const bytes = bigIntToBytes(toTwos(BigInt(value.value), CLARITY_INT_SIZE), CLARITY_INT_BYTE_SIZE);
691
- return withTypeId(value.type, bytes);
692
- }
693
- case "uint": {
694
- const bytes = bigIntToBytes(BigInt(value.value), CLARITY_INT_BYTE_SIZE);
695
- return withTypeId(value.type, bytes);
696
- }
696
+ return falseCV();
697
+ case "buffer": {
698
+ const len = reader.readUInt32BE();
699
+ return bufferCV(reader.readBytes(len));
700
+ }
701
+ case "none":
702
+ return noneCV();
703
+ case "some":
704
+ return someCV(readCV(reader, depth + 1));
705
+ case "ok":
706
+ return responseOkCV(readCV(reader, depth + 1));
707
+ case "err":
708
+ return responseErrorCV(readCV(reader, depth + 1));
709
+ case "address":
710
+ return standardPrincipalCV(readAddress(reader));
711
+ case "contract": {
712
+ const addr = readAddress(reader);
713
+ const name = readLPString(reader);
714
+ return contractPrincipalCV(addr, name);
715
+ }
716
+ case "list": {
717
+ const len = reader.readUInt32BE();
718
+ checkCount(reader, len, MIN_LIST_ITEM_BYTES);
719
+ const items = [];
720
+ for (let i = 0;i < len; i++) {
721
+ items.push(readCV(reader, depth + 1));
722
+ }
723
+ return listCV(items);
724
+ }
725
+ case "tuple": {
726
+ const len = reader.readUInt32BE();
727
+ checkCount(reader, len, MIN_TUPLE_ENTRY_BYTES);
728
+ const data = {};
729
+ for (let i = 0;i < len; i++) {
730
+ const key = readLPString(reader);
731
+ data[key] = readCV(reader, depth + 1);
732
+ }
733
+ return tupleCV(data);
734
+ }
735
+ case "ascii": {
736
+ const len = reader.readUInt32BE();
737
+ return stringAsciiCV(bytesToAscii(reader.readBytes(len)));
738
+ }
739
+ case "utf8": {
740
+ const len = reader.readUInt32BE();
741
+ return stringUtf8CV(bytesToUtf8(reader.readBytes(len)));
742
+ }
743
+ default:
744
+ throw new SerializationError(`Cannot deserialize unknown clarity type: ${type}`);
745
+ }
746
+ }
747
+ function deserializeCVBytes(input) {
748
+ const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
749
+ return readCV(new BytesReader(bytes));
750
+ }
751
+ function deserializeCV(input) {
752
+ return deserializeCVBytes(input);
753
+ }
754
+
755
+ // src/clarity/serialize.ts
756
+ var CLARITY_INT_SIZE = 128n;
757
+ var CLARITY_INT_BYTE_SIZE = 16;
758
+ function typeIdByte(type) {
759
+ return ClarityWireType[type];
760
+ }
761
+ function withTypeId(type, bytes) {
762
+ return concatBytes(new Uint8Array([typeIdByte(type)]), bytes);
763
+ }
764
+ function serializeAddress(c32Address) {
765
+ const [version, hash160] = c32addressDecode(c32Address);
766
+ return concatBytes(new Uint8Array([version]), hexToBytes(hash160));
767
+ }
768
+ function serializeLPString(str, prefixBytes = 1) {
769
+ const content = utf8ToBytes(str);
770
+ const lengthPrefix = hexToBytes(intToHex(content.byteLength, prefixBytes));
771
+ return concatBytes(lengthPrefix, content);
772
+ }
773
+ function serializeCVBytes(value) {
774
+ switch (value.type) {
775
+ case "true":
776
+ case "false":
777
+ return new Uint8Array([typeIdByte(value.type)]);
778
+ case "int": {
779
+ const bytes = bigIntToBytes(toTwos(BigInt(value.value), CLARITY_INT_SIZE), CLARITY_INT_BYTE_SIZE);
780
+ return withTypeId(value.type, bytes);
781
+ }
782
+ case "uint": {
783
+ const bytes = bigIntToBytes(BigInt(value.value), CLARITY_INT_BYTE_SIZE);
784
+ return withTypeId(value.type, bytes);
785
+ }
697
786
  case "buffer": {
698
787
  const bufBytes = hexToBytes(value.value);
699
788
  return withTypeId(value.type, concatBytes(writeUInt32BE(bufBytes.length), bufBytes));
@@ -781,13 +870,13 @@ function bufferCV(buffer) {
781
870
  return { type: "buffer", value: bytesToHex(buffer) };
782
871
  }
783
872
  function standardPrincipalCV(address) {
784
- const [version, hash1602] = c32addressDecode(address);
785
- const normalized = c32address(version, hash1602);
873
+ const [version, hash160] = c32addressDecode(address);
874
+ const normalized = c32address(version, hash160);
786
875
  return { type: "address", value: normalized };
787
876
  }
788
877
  function contractPrincipalCV(address, contractName) {
789
- const [version, hash1602] = c32addressDecode(address);
790
- const normalized = c32address(version, hash1602);
878
+ const [version, hash160] = c32addressDecode(address);
879
+ const normalized = c32address(version, hash160);
791
880
  if (utf8ToBytes(contractName).byteLength >= 128) {
792
881
  throw new Error("Contract name must be less than 128 bytes");
793
882
  }
@@ -855,103 +944,285 @@ var Cl = {
855
944
  deserialize: deserializeCVBytes
856
945
  };
857
946
 
858
- // src/clarity/deserialize.ts
859
- function readAddress(reader) {
860
- const version = reader.readUInt8();
861
- const hash1602 = bytesToHex(reader.readBytes(20));
862
- return c32address(version, hash1602);
947
+ // src/clarity/bridge.ts
948
+ var CV_TYPE_TAGS = new Set([
949
+ "int",
950
+ "uint",
951
+ "true",
952
+ "false",
953
+ "address",
954
+ "contract",
955
+ "ascii",
956
+ "utf8",
957
+ "buffer",
958
+ "list",
959
+ "tuple",
960
+ "none",
961
+ "some",
962
+ "ok",
963
+ "err"
964
+ ]);
965
+ function isClarityValue(value) {
966
+ if (typeof value !== "object" || value === null)
967
+ return false;
968
+ const type = value.type;
969
+ if (typeof type !== "string" || !CV_TYPE_TAGS.has(type))
970
+ return false;
971
+ if (type === "true" || type === "false" || type === "none")
972
+ return true;
973
+ return "value" in value;
863
974
  }
864
- function readLPString(reader, prefixBytes = 1) {
865
- let length = 0;
866
- for (let i = 0;i < prefixBytes; i++) {
867
- length = length << 8 | reader.readUInt8();
975
+ var HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;
976
+ function coerceBuffer(value) {
977
+ if (value instanceof Uint8Array)
978
+ return bufferCV(value);
979
+ if (typeof value === "object" && value !== null && "type" in value) {
980
+ const tagged = value;
981
+ if (tagged.type === "buffer" && isClarityValue(value))
982
+ return value;
983
+ if (typeof tagged.value === "string") {
984
+ if (tagged.type === "ascii")
985
+ return Cl.bufferFromAscii(tagged.value);
986
+ if (tagged.type === "utf8")
987
+ return Cl.bufferFromUtf8(tagged.value);
988
+ if (tagged.type === "hex")
989
+ return Cl.bufferFromHex(tagged.value);
990
+ }
991
+ throw new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);
868
992
  }
869
- return bytesToUtf8(reader.readBytes(length));
870
- }
871
- var MAX_CV_DEPTH = 64;
872
- var MIN_LIST_ITEM_BYTES = 1;
873
- var MIN_TUPLE_ENTRY_BYTES = 2;
874
- function checkCount(reader, count, minBytes) {
875
- if (count * minBytes > reader.remaining()) {
876
- throw new SerializationError(`Clarity value declares ${count} elements but only ${reader.remaining()} bytes remain`);
993
+ if (typeof value === "string") {
994
+ const hex = value.startsWith("0x") ? value.slice(2) : value;
995
+ if (HEX_PAIRS_REGEX.test(hex))
996
+ return Cl.bufferFromHex(hex);
997
+ return Cl.bufferFromUtf8(value);
877
998
  }
999
+ throw new Error("buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV");
878
1000
  }
879
- function readCV(reader, depth = 0) {
880
- if (depth > MAX_CV_DEPTH) {
881
- throw new SerializationError(`Clarity value nests deeper than ${MAX_CV_DEPTH} levels`);
1001
+ function jsToClarityValue(abiType, value) {
1002
+ if (isAbiBuffer(abiType))
1003
+ return coerceBuffer(value);
1004
+ if (isClarityValue(value))
1005
+ return value;
1006
+ if (abiType === "uint128")
1007
+ return uintCV(value);
1008
+ if (abiType === "int128")
1009
+ return intCV(value);
1010
+ if (abiType === "bool")
1011
+ return boolCV(value);
1012
+ if (abiType === "principal" || abiType === "trait_reference")
1013
+ return Cl.principal(value);
1014
+ if (isAbiStringAscii(abiType))
1015
+ return stringAsciiCV(value);
1016
+ if (isAbiStringUtf8(abiType))
1017
+ return stringUtf8CV(value);
1018
+ if (isAbiList(abiType)) {
1019
+ const arr = value;
1020
+ return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
882
1021
  }
883
- const typeByte = reader.readUInt8();
884
- const type = clarityTypeFromByte(typeByte);
885
- switch (type) {
886
- case "int":
887
- return intCV(bytesToTwosBigInt(reader.readBytes(16)));
888
- case "uint":
889
- return uintCV(reader.readBytes(16));
890
- case "true":
891
- return trueCV();
892
- case "false":
893
- return falseCV();
894
- case "buffer": {
895
- const len = reader.readUInt32BE();
896
- return bufferCV(reader.readBytes(len));
897
- }
898
- case "none":
899
- return noneCV();
900
- case "some":
901
- return someCV(readCV(reader, depth + 1));
902
- case "ok":
903
- return responseOkCV(readCV(reader, depth + 1));
904
- case "err":
905
- return responseErrorCV(readCV(reader, depth + 1));
906
- case "address":
907
- return standardPrincipalCV(readAddress(reader));
908
- case "contract": {
909
- const addr = readAddress(reader);
910
- const name = readLPString(reader);
911
- return contractPrincipalCV(addr, name);
912
- }
913
- case "list": {
914
- const len = reader.readUInt32BE();
915
- checkCount(reader, len, MIN_LIST_ITEM_BYTES);
916
- const items = [];
917
- for (let i = 0;i < len; i++) {
918
- items.push(readCV(reader, depth + 1));
919
- }
920
- return listCV(items);
921
- }
922
- case "tuple": {
923
- const len = reader.readUInt32BE();
924
- checkCount(reader, len, MIN_TUPLE_ENTRY_BYTES);
925
- const data = {};
926
- for (let i = 0;i < len; i++) {
927
- const key = readLPString(reader);
928
- data[key] = readCV(reader, depth + 1);
1022
+ if (isAbiTuple(abiType)) {
1023
+ const obj = value;
1024
+ const data = {};
1025
+ for (const field of abiType.tuple) {
1026
+ const camelKey = toCamelCase(field.name);
1027
+ const hasOriginal = field.name in obj;
1028
+ const hasCamel = camelKey in obj;
1029
+ const fieldValue = hasOriginal ? obj[field.name] : hasCamel ? obj[camelKey] : undefined;
1030
+ if (fieldValue === undefined && !isAbiOptional(field.type)) {
1031
+ throw new Error(`Missing tuple field: ${field.name}`);
929
1032
  }
930
- return tupleCV(data);
931
- }
932
- case "ascii": {
933
- const len = reader.readUInt32BE();
934
- return stringAsciiCV(bytesToAscii(reader.readBytes(len)));
935
- }
936
- case "utf8": {
937
- const len = reader.readUInt32BE();
938
- return stringUtf8CV(bytesToUtf8(reader.readBytes(len)));
1033
+ data[field.name] = jsToClarityValue(field.type, fieldValue);
939
1034
  }
940
- default:
941
- throw new SerializationError(`Cannot deserialize unknown clarity type: ${type}`);
1035
+ return tupleCV(data);
942
1036
  }
943
- }
944
- function deserializeCVBytes(input) {
945
- const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
946
- return readCV(new BytesReader(bytes));
947
- }
948
- function deserializeCV(input) {
949
- return deserializeCVBytes(input);
950
- }
951
-
952
- // src/transactions/wire/deserialize.ts
953
- function readSpendingCondition(r) {
954
- const hashMode = r.readUInt8();
1037
+ if (isAbiOptional(abiType)) {
1038
+ if (value === null || value === undefined)
1039
+ return noneCV();
1040
+ return someCV(jsToClarityValue(abiType.optional, value));
1041
+ }
1042
+ if (isAbiResponse(abiType)) {
1043
+ const obj = value;
1044
+ if ("ok" in obj && !("err" in obj))
1045
+ return responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));
1046
+ if ("err" in obj && !("ok" in obj))
1047
+ return responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));
1048
+ throw new Error("Response must have exactly 'ok' or 'err' property");
1049
+ }
1050
+ throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1051
+ }
1052
+ function clarityValueToJS(abiType, cv) {
1053
+ return clarityValueToJSInner(abiType, cv);
1054
+ }
1055
+ function clarityValueToJSUntyped(abiType, cv) {
1056
+ return clarityValueToJSInner(abiType, cv);
1057
+ }
1058
+ function clarityValueToJSInner(abiType, cv) {
1059
+ if (abiType === "uint128" || abiType === "int128") {
1060
+ if (cv.type !== "int" && cv.type !== "uint")
1061
+ throw new Error(`Expected int/uint CV, got ${cv.type}`);
1062
+ return cv.value;
1063
+ }
1064
+ if (abiType === "bool") {
1065
+ if (cv.type === "true")
1066
+ return true;
1067
+ if (cv.type === "false")
1068
+ return false;
1069
+ throw new Error(`Expected bool CV, got ${cv.type}`);
1070
+ }
1071
+ if (abiType === "principal" || abiType === "trait_reference") {
1072
+ if (cv.type !== "address" && cv.type !== "contract")
1073
+ throw new Error(`Expected principal CV, got ${cv.type}`);
1074
+ return cv.value;
1075
+ }
1076
+ if (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {
1077
+ if (cv.type !== "ascii" && cv.type !== "utf8")
1078
+ throw new Error(`Expected string CV, got ${cv.type}`);
1079
+ return cv.value;
1080
+ }
1081
+ if (isAbiBuffer(abiType)) {
1082
+ if (cv.type !== "buffer")
1083
+ throw new Error(`Expected buffer CV, got ${cv.type}`);
1084
+ const hex = cv.value;
1085
+ const bytes = new Uint8Array(hex.length / 2);
1086
+ for (let i = 0;i < bytes.length; i++) {
1087
+ bytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
1088
+ }
1089
+ return bytes;
1090
+ }
1091
+ if (isAbiList(abiType)) {
1092
+ if (cv.type !== "list")
1093
+ throw new Error(`Expected list CV, got ${cv.type}`);
1094
+ return cv.value.map((item) => clarityValueToJSInner(abiType.list.type, item));
1095
+ }
1096
+ if (isAbiTuple(abiType)) {
1097
+ if (cv.type !== "tuple")
1098
+ throw new Error(`Expected tuple CV, got ${cv.type}`);
1099
+ const result = {};
1100
+ for (const field of abiType.tuple) {
1101
+ const fieldCV = cv.value[field.name];
1102
+ if (!fieldCV)
1103
+ throw new Error(`Missing tuple field in CV: ${field.name}`);
1104
+ const camelKey = toCamelCase(field.name);
1105
+ result[camelKey] = clarityValueToJSInner(field.type, fieldCV);
1106
+ }
1107
+ return result;
1108
+ }
1109
+ if (isAbiOptional(abiType)) {
1110
+ if (cv.type === "none")
1111
+ return null;
1112
+ if (cv.type === "some")
1113
+ return clarityValueToJSInner(abiType.optional, cv.value);
1114
+ throw new Error(`Expected optional CV, got ${cv.type}`);
1115
+ }
1116
+ if (isAbiResponse(abiType)) {
1117
+ if (cv.type === "ok")
1118
+ return { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };
1119
+ if (cv.type === "err")
1120
+ return { err: clarityValueToJSInner(abiType.response.error, cv.value) };
1121
+ throw new Error(`Expected response CV, got ${cv.type}`);
1122
+ }
1123
+ throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1124
+ }
1125
+
1126
+ // src/transactions/types.ts
1127
+ var AuthType = {
1128
+ Standard: 4,
1129
+ Sponsored: 5
1130
+ };
1131
+ var PayloadType = {
1132
+ TokenTransfer: 0,
1133
+ SmartContract: 1,
1134
+ ContractCall: 2,
1135
+ PoisonMicroblock: 3,
1136
+ Coinbase: 4,
1137
+ CoinbaseToAltRecipient: 5,
1138
+ VersionedSmartContract: 6,
1139
+ TenureChange: 7,
1140
+ NakamotoCoinbase: 8
1141
+ };
1142
+ var ClarityVersion = {
1143
+ Clarity1: 1,
1144
+ Clarity2: 2,
1145
+ Clarity3: 3,
1146
+ Clarity4: 4,
1147
+ Clarity5: 5,
1148
+ Clarity6: 6
1149
+ };
1150
+ var AnchorMode = {
1151
+ OnChainOnly: 1,
1152
+ OffChainOnly: 2,
1153
+ Any: 3
1154
+ };
1155
+ var PostConditionModeWire = {
1156
+ Allow: 1,
1157
+ Deny: 2,
1158
+ Originator: 3
1159
+ };
1160
+ var AddressHashMode = {
1161
+ P2PKH: 0,
1162
+ P2SH: 1,
1163
+ P2WPKH: 2,
1164
+ P2WSH: 3,
1165
+ P2SH_NonSequential: 5,
1166
+ P2WSH_P2SH_NonSequential: 7
1167
+ };
1168
+ var PubKeyEncoding = {
1169
+ Compressed: 0,
1170
+ Uncompressed: 1
1171
+ };
1172
+ var FungibleConditionCode = {
1173
+ Equal: 1,
1174
+ Greater: 2,
1175
+ GreaterEqual: 3,
1176
+ Less: 4,
1177
+ LessEqual: 5
1178
+ };
1179
+ var NonFungibleConditionCode = {
1180
+ Sends: 16,
1181
+ DoesNotSend: 17,
1182
+ MaybeSent: 18
1183
+ };
1184
+ var PoxConditionCode = {
1185
+ WillNotPerform: 48,
1186
+ MayPerform: 49,
1187
+ WillPerform: 50
1188
+ };
1189
+ var PostConditionPrincipalId = {
1190
+ Origin: 1,
1191
+ Standard: 2,
1192
+ Contract: 3
1193
+ };
1194
+ var AssetType = {
1195
+ STX: 0,
1196
+ Fungible: 1,
1197
+ NonFungible: 2,
1198
+ Staking: 3,
1199
+ Pox: 4
1200
+ };
1201
+ var AuthFieldType = {
1202
+ PublicKeyCompressed: 0,
1203
+ PublicKeyUncompressed: 1,
1204
+ SignatureCompressed: 2,
1205
+ SignatureUncompressed: 3
1206
+ };
1207
+ var RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;
1208
+ var MEMO_MAX_LENGTH_BYTES = 34;
1209
+ var MAX_STRING_LENGTH_BYTES = 128;
1210
+ var COINBASE_BYTES_LENGTH = 32;
1211
+ var VRF_PROOF_BYTES_LENGTH = 80;
1212
+ var MICROBLOCK_HEADER_BYTES_LENGTH = 132;
1213
+ var TenureChangeCause = {
1214
+ BlockFound: 0,
1215
+ Extended: 1,
1216
+ ExtendedRuntime: 2,
1217
+ ExtendedReadCount: 3,
1218
+ ExtendedReadLength: 4,
1219
+ ExtendedWriteCount: 5,
1220
+ ExtendedWriteLength: 6
1221
+ };
1222
+
1223
+ // src/transactions/wire/deserialize.ts
1224
+ function readSpendingCondition(r) {
1225
+ const hashMode = r.readUInt8();
955
1226
  const signer = bytesToHex(r.readBytes(20));
956
1227
  const nonce = r.readBigUInt64BE();
957
1228
  const fee = r.readBigUInt64BE();
@@ -1216,8 +1487,8 @@ function deserializeTransaction(input, meta) {
1216
1487
 
1217
1488
  // src/transactions/wire/serialize.ts
1218
1489
  function serializeAddress2(c32Address) {
1219
- const [version, hash1602] = c32addressDecode(c32Address);
1220
- return concatBytes(new Uint8Array([version]), hexToBytes(hash1602));
1490
+ const [version, hash160] = c32addressDecode(c32Address);
1491
+ return concatBytes(new Uint8Array([version]), hexToBytes(hash160));
1221
1492
  }
1222
1493
  function serializeLPString2(str, prefixBytes = 1) {
1223
1494
  const content = utf8ToBytes(str);
@@ -1256,8 +1527,8 @@ function serializeSpendingCondition(condition) {
1256
1527
  }
1257
1528
  function serializeAuthField(field) {
1258
1529
  if (field.type === "publicKey") {
1259
- const typeId2 = field.pubKeyEncoding === 0 ? 0 : 1;
1260
- return concatBytes(writeUInt8(typeId2), hexToBytes(field.data));
1530
+ const typeId = field.pubKeyEncoding === 0 ? 0 : 1;
1531
+ return concatBytes(writeUInt8(typeId), hexToBytes(field.data));
1261
1532
  }
1262
1533
  const typeId = field.pubKeyEncoding === 0 ? 2 : 3;
1263
1534
  return concatBytes(writeUInt8(typeId), hexToBytes(field.data));
@@ -1544,463 +1815,41 @@ function wireToPostCondition(wire) {
1544
1815
  case "staking":
1545
1816
  return {
1546
1817
  type: "staking-postcondition",
1547
- address: principalToString(wire.principal),
1548
- condition: fungibleName(wire.conditionCode),
1549
- amount: wire.amount.toString()
1550
- };
1551
- case "pox":
1552
- return {
1553
- type: "pox-postcondition",
1554
- address: principalToString(wire.principal),
1555
- condition: poxName(wire.conditionCode)
1556
- };
1557
- }
1558
- }
1559
- function fungibleName(code) {
1560
- const name = FUNGIBLE_CODE_REVERSE[code];
1561
- if (!name)
1562
- throw new Error(`Unknown fungible post-condition code: ${code}`);
1563
- return name;
1564
- }
1565
- function nftName(code) {
1566
- const name = NFT_CODE_REVERSE[code];
1567
- if (!name)
1568
- throw new Error(`Unknown nft post-condition code: ${code}`);
1569
- return name;
1570
- }
1571
- function poxName(code) {
1572
- const name = POX_CODE_REVERSE[code];
1573
- if (!name)
1574
- throw new Error(`Unknown pox post-condition code: ${code}`);
1575
- return name;
1576
- }
1577
- function fromHex(hex) {
1578
- return wireToPostCondition(deserializePostConditionWire(hex));
1579
- }
1580
- function postConditionToHex(pc) {
1581
- return bytesToHex(serializePostConditionWire(convertPostCondition(pc)));
1582
- }
1583
-
1584
- // src/postconditions/builder.ts
1585
- class PartialPcWithPrincipal {
1586
- address;
1587
- constructor(address) {
1588
- this.address = address;
1589
- }
1590
- willSendEq(amount) {
1591
- return new PartialPcFtWithCode(this.address, amount, "eq");
1592
- }
1593
- willSendGte(amount) {
1594
- return new PartialPcFtWithCode(this.address, amount, "gte");
1595
- }
1596
- willSendGt(amount) {
1597
- return new PartialPcFtWithCode(this.address, amount, "gt");
1598
- }
1599
- willSendLte(amount) {
1600
- return new PartialPcFtWithCode(this.address, amount, "lte");
1601
- }
1602
- willSendLt(amount) {
1603
- return new PartialPcFtWithCode(this.address, amount, "lt");
1604
- }
1605
- willSendAsset() {
1606
- return new PartialPcNftWithCode(this.address, "sent");
1607
- }
1608
- willNotSendAsset() {
1609
- return new PartialPcNftWithCode(this.address, "not-sent");
1610
- }
1611
- willMaybeSendAsset() {
1612
- return new PartialPcNftWithCode(this.address, "maybe-sent");
1613
- }
1614
- willPerformPox() {
1615
- return {
1616
- type: "pox-postcondition",
1617
- address: this.address,
1618
- condition: "will-perform"
1619
- };
1620
- }
1621
- willNotPerformPox() {
1622
- return {
1623
- type: "pox-postcondition",
1624
- address: this.address,
1625
- condition: "will-not-perform"
1626
- };
1627
- }
1628
- mayPerformPox() {
1629
- return {
1630
- type: "pox-postcondition",
1631
- address: this.address,
1632
- condition: "may-perform"
1633
- };
1634
- }
1635
- }
1636
-
1637
- class PartialPcFtWithCode {
1638
- address;
1639
- amount;
1640
- code;
1641
- constructor(address, amount, code) {
1642
- this.address = address;
1643
- this.amount = amount;
1644
- this.code = code;
1645
- }
1646
- ustx() {
1647
- return {
1648
- type: "stx-postcondition",
1649
- address: this.address,
1650
- condition: this.code,
1651
- amount: parsePostConditionAmount(this.amount).toString()
1652
- };
1653
- }
1654
- ustxToLock() {
1655
- return {
1656
- type: "staking-postcondition",
1657
- address: this.address,
1658
- condition: this.code,
1659
- amount: parsePostConditionAmount(this.amount).toString()
1660
- };
1661
- }
1662
- ft(contractId, tokenName) {
1663
- const [address, name] = contractId.split(".");
1664
- if (!address || !validateStacksAddress(address) || !name) {
1665
- throw new Error(`Invalid contract id: ${contractId}`);
1666
- }
1667
- return {
1668
- type: "ft-postcondition",
1669
- address: this.address,
1670
- condition: this.code,
1671
- amount: parsePostConditionAmount(this.amount).toString(),
1672
- asset: `${contractId}::${tokenName}`
1673
- };
1674
- }
1675
- }
1676
-
1677
- class PartialPcNftWithCode {
1678
- address;
1679
- code;
1680
- constructor(address, code) {
1681
- this.address = address;
1682
- this.code = code;
1683
- }
1684
- nft(assetOrContractId, tokenNameOrAssetId, assetId) {
1685
- let contractAddress;
1686
- let contractName;
1687
- let tokenName;
1688
- let id;
1689
- if (assetId !== undefined) {
1690
- [contractAddress, contractName] = parseContractId(assetOrContractId);
1691
- tokenName = tokenNameOrAssetId;
1692
- id = assetId;
1693
- } else {
1694
- const [principal, tName] = assetOrContractId.split("::");
1695
- if (!principal || !tName)
1696
- throw new Error(`Invalid asset name: ${assetOrContractId}`);
1697
- [contractAddress, contractName] = parseContractId(principal);
1698
- tokenName = tName;
1699
- id = tokenNameOrAssetId;
1700
- }
1701
- if (!validateStacksAddress(contractAddress)) {
1702
- throw new Error(`Invalid contract address: ${contractAddress}`);
1703
- }
1704
- return {
1705
- type: "nft-postcondition",
1706
- address: this.address,
1707
- condition: this.code,
1708
- asset: `${contractAddress}.${contractName}::${tokenName}`,
1709
- assetId: id
1710
- };
1711
- }
1712
- }
1713
- var Pc = {
1714
- principal(address) {
1715
- const [addr, name] = address.split(".");
1716
- if (!addr || !validateStacksAddress(addr) || typeof name === "string" && !name) {
1717
- throw new Error(`Invalid principal: ${address}`);
1718
- }
1719
- return new PartialPcWithPrincipal(address);
1720
- },
1721
- origin() {
1722
- return new PartialPcWithPrincipal("origin");
1723
- },
1724
- fromHex: (hex) => fromHex(hex)
1725
- };
1726
- // src/pox/index.ts
1727
- var exports_pox = {};
1728
- __export(exports_pox, {
1729
- validateLockPeriod: () => validateLockPeriod,
1730
- rewardCycleToBurnHeight: () => rewardCycleToBurnHeight,
1731
- pox: () => pox,
1732
- parseBtcAddress: () => parseBtcAddress2,
1733
- burnHeightToRewardCycle: () => burnHeightToRewardCycle,
1734
- POX_CONTRACTS: () => POX_CONTRACTS,
1735
- POX_ADDRESS_VERSION: () => POX_ADDRESS_VERSION,
1736
- POX_ABI: () => POX_ABI,
1737
- MIN_LOCK_PERIOD: () => MIN_LOCK_PERIOD,
1738
- MAX_LOCK_PERIOD: () => MAX_LOCK_PERIOD
1739
- });
1740
- module.exports = __toCommonJS(exports_pox);
1741
-
1742
- // src/clarity/abi/utils.ts
1743
- function toCamelCase(str) {
1744
- return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/-([A-Z])/g, (_, letter) => letter).replace(/-(\d)/g, (_, digit) => digit).replace(/-/g, "").replace(/^\d/, "_$&");
1745
- }
1746
- // src/clarity/abi/guards.ts
1747
- function isUint128(value) {
1748
- return typeof value === "bigint" && value >= 0n && value <= MAX_U128;
1749
- }
1750
- function isInt128(value) {
1751
- return typeof value === "bigint" && value >= MIN_I128 && value <= MAX_I128;
1752
- }
1753
- function isBool(value) {
1754
- return typeof value === "boolean";
1755
- }
1756
- function isPrincipal(value) {
1757
- return typeof value === "string" && parsePrincipal(value) !== null;
1758
- }
1759
- function isStandardPrincipal(value) {
1760
- if (typeof value !== "string")
1761
- return false;
1762
- const parsed = parsePrincipal(value);
1763
- return parsed !== null && parsed.contractName === undefined;
1764
- }
1765
- function isContractPrincipal(value) {
1766
- if (typeof value !== "string")
1767
- return false;
1768
- const parsed = parsePrincipal(value);
1769
- return parsed !== null && parsed.contractName !== undefined;
1770
- }
1771
- function isTraitReference(value) {
1772
- return isContractPrincipal(value);
1773
- }
1774
- function isString(value) {
1775
- return typeof value === "string";
1776
- }
1777
- function isUint8Array(value) {
1778
- return value instanceof Uint8Array;
1779
- }
1780
- function isArray(value, itemGuard) {
1781
- return Array.isArray(value) && value.every(itemGuard);
1782
- }
1783
- function isOptional(value, guard) {
1784
- return value === null || guard(value);
1785
- }
1786
- function isOkResponse(response) {
1787
- return "ok" in response && !("err" in response);
1788
- }
1789
- function isErrResponse(response) {
1790
- return "err" in response && !("ok" in response);
1791
- }
1792
- function isResponse(value, okGuard, errGuard) {
1793
- if (typeof value !== "object" || value === null)
1794
- return false;
1795
- const obj = value;
1796
- if ("ok" in value && !("err" in value))
1797
- return okGuard(obj.ok);
1798
- if ("err" in value && !("ok" in value))
1799
- return errGuard(obj.err);
1800
- return false;
1801
- }
1802
- function isAbiList(type) {
1803
- return typeof type === "object" && type !== null && "list" in type;
1804
- }
1805
- function isAbiTuple(type) {
1806
- return typeof type === "object" && type !== null && "tuple" in type;
1807
- }
1808
- function isAbiOptional(type) {
1809
- return typeof type === "object" && type !== null && "optional" in type;
1810
- }
1811
- function isAbiResponse(type) {
1812
- return typeof type === "object" && type !== null && "response" in type;
1813
- }
1814
- function isAbiBuffer(type) {
1815
- return typeof type === "object" && type !== null && "buff" in type;
1816
- }
1817
- function isAbiStringAscii(type) {
1818
- return typeof type === "object" && type !== null && "string-ascii" in type;
1819
- }
1820
- function isAbiStringUtf8(type) {
1821
- return typeof type === "object" && type !== null && "string-utf8" in type;
1822
- }
1823
- function isAbiTraitReference(type) {
1824
- return type === "trait_reference";
1825
- }
1826
-
1827
- // src/clarity/bridge.ts
1828
- var CV_TYPE_TAGS = new Set([
1829
- "int",
1830
- "uint",
1831
- "true",
1832
- "false",
1833
- "address",
1834
- "contract",
1835
- "ascii",
1836
- "utf8",
1837
- "buffer",
1838
- "list",
1839
- "tuple",
1840
- "none",
1841
- "some",
1842
- "ok",
1843
- "err"
1844
- ]);
1845
- function isClarityValue(value) {
1846
- if (typeof value !== "object" || value === null)
1847
- return false;
1848
- const type = value.type;
1849
- if (typeof type !== "string" || !CV_TYPE_TAGS.has(type))
1850
- return false;
1851
- if (type === "true" || type === "false" || type === "none")
1852
- return true;
1853
- return "value" in value;
1854
- }
1855
- var HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;
1856
- function coerceBuffer(value) {
1857
- if (value instanceof Uint8Array)
1858
- return bufferCV(value);
1859
- if (typeof value === "object" && value !== null && "type" in value) {
1860
- const tagged = value;
1861
- if (tagged.type === "buffer" && isClarityValue(value))
1862
- return value;
1863
- if (typeof tagged.value === "string") {
1864
- if (tagged.type === "ascii")
1865
- return Cl.bufferFromAscii(tagged.value);
1866
- if (tagged.type === "utf8")
1867
- return Cl.bufferFromUtf8(tagged.value);
1868
- if (tagged.type === "hex")
1869
- return Cl.bufferFromHex(tagged.value);
1870
- }
1871
- throw new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);
1872
- }
1873
- if (typeof value === "string") {
1874
- const hex = value.startsWith("0x") ? value.slice(2) : value;
1875
- if (HEX_PAIRS_REGEX.test(hex))
1876
- return Cl.bufferFromHex(hex);
1877
- return Cl.bufferFromUtf8(value);
1878
- }
1879
- throw new Error("buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV");
1880
- }
1881
- function jsToClarityValue(abiType, value) {
1882
- if (isAbiBuffer(abiType))
1883
- return coerceBuffer(value);
1884
- if (isClarityValue(value))
1885
- return value;
1886
- if (abiType === "uint128")
1887
- return uintCV(value);
1888
- if (abiType === "int128")
1889
- return intCV(value);
1890
- if (abiType === "bool")
1891
- return boolCV(value);
1892
- if (abiType === "principal" || abiType === "trait_reference")
1893
- return Cl.principal(value);
1894
- if (isAbiStringAscii(abiType))
1895
- return stringAsciiCV(value);
1896
- if (isAbiStringUtf8(abiType))
1897
- return stringUtf8CV(value);
1898
- if (isAbiList(abiType)) {
1899
- const arr = value;
1900
- return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
1901
- }
1902
- if (isAbiTuple(abiType)) {
1903
- const obj = value;
1904
- const data = {};
1905
- for (const field of abiType.tuple) {
1906
- const camelKey = toCamelCase(field.name);
1907
- const hasOriginal = field.name in obj;
1908
- const hasCamel = camelKey in obj;
1909
- const fieldValue = hasOriginal ? obj[field.name] : hasCamel ? obj[camelKey] : undefined;
1910
- if (fieldValue === undefined && !isAbiOptional(field.type)) {
1911
- throw new Error(`Missing tuple field: ${field.name}`);
1912
- }
1913
- data[field.name] = jsToClarityValue(field.type, fieldValue);
1914
- }
1915
- return tupleCV(data);
1916
- }
1917
- if (isAbiOptional(abiType)) {
1918
- if (value === null || value === undefined)
1919
- return noneCV();
1920
- return someCV(jsToClarityValue(abiType.optional, value));
1921
- }
1922
- if (isAbiResponse(abiType)) {
1923
- const obj = value;
1924
- if ("ok" in obj && !("err" in obj))
1925
- return responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));
1926
- if ("err" in obj && !("ok" in obj))
1927
- return responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));
1928
- throw new Error("Response must have exactly 'ok' or 'err' property");
1818
+ address: principalToString(wire.principal),
1819
+ condition: fungibleName(wire.conditionCode),
1820
+ amount: wire.amount.toString()
1821
+ };
1822
+ case "pox":
1823
+ return {
1824
+ type: "pox-postcondition",
1825
+ address: principalToString(wire.principal),
1826
+ condition: poxName(wire.conditionCode)
1827
+ };
1929
1828
  }
1930
- throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1931
1829
  }
1932
- function clarityValueToJS(abiType, cv) {
1933
- return clarityValueToJSInner(abiType, cv);
1830
+ function fungibleName(code) {
1831
+ const name = FUNGIBLE_CODE_REVERSE[code];
1832
+ if (!name)
1833
+ throw new Error(`Unknown fungible post-condition code: ${code}`);
1834
+ return name;
1934
1835
  }
1935
- function clarityValueToJSUntyped(abiType, cv) {
1936
- return clarityValueToJSInner(abiType, cv);
1836
+ function nftName(code) {
1837
+ const name = NFT_CODE_REVERSE[code];
1838
+ if (!name)
1839
+ throw new Error(`Unknown nft post-condition code: ${code}`);
1840
+ return name;
1937
1841
  }
1938
- function clarityValueToJSInner(abiType, cv) {
1939
- if (abiType === "uint128" || abiType === "int128") {
1940
- if (cv.type !== "int" && cv.type !== "uint")
1941
- throw new Error(`Expected int/uint CV, got ${cv.type}`);
1942
- return cv.value;
1943
- }
1944
- if (abiType === "bool") {
1945
- if (cv.type === "true")
1946
- return true;
1947
- if (cv.type === "false")
1948
- return false;
1949
- throw new Error(`Expected bool CV, got ${cv.type}`);
1950
- }
1951
- if (abiType === "principal" || abiType === "trait_reference") {
1952
- if (cv.type !== "address" && cv.type !== "contract")
1953
- throw new Error(`Expected principal CV, got ${cv.type}`);
1954
- return cv.value;
1955
- }
1956
- if (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {
1957
- if (cv.type !== "ascii" && cv.type !== "utf8")
1958
- throw new Error(`Expected string CV, got ${cv.type}`);
1959
- return cv.value;
1960
- }
1961
- if (isAbiBuffer(abiType)) {
1962
- if (cv.type !== "buffer")
1963
- throw new Error(`Expected buffer CV, got ${cv.type}`);
1964
- const hex = cv.value;
1965
- const bytes = new Uint8Array(hex.length / 2);
1966
- for (let i = 0;i < bytes.length; i++) {
1967
- bytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
1968
- }
1969
- return bytes;
1970
- }
1971
- if (isAbiList(abiType)) {
1972
- if (cv.type !== "list")
1973
- throw new Error(`Expected list CV, got ${cv.type}`);
1974
- return cv.value.map((item) => clarityValueToJSInner(abiType.list.type, item));
1975
- }
1976
- if (isAbiTuple(abiType)) {
1977
- if (cv.type !== "tuple")
1978
- throw new Error(`Expected tuple CV, got ${cv.type}`);
1979
- const result = {};
1980
- for (const field of abiType.tuple) {
1981
- const fieldCV = cv.value[field.name];
1982
- if (!fieldCV)
1983
- throw new Error(`Missing tuple field in CV: ${field.name}`);
1984
- const camelKey = toCamelCase(field.name);
1985
- result[camelKey] = clarityValueToJSInner(field.type, fieldCV);
1986
- }
1987
- return result;
1988
- }
1989
- if (isAbiOptional(abiType)) {
1990
- if (cv.type === "none")
1991
- return null;
1992
- if (cv.type === "some")
1993
- return clarityValueToJSInner(abiType.optional, cv.value);
1994
- throw new Error(`Expected optional CV, got ${cv.type}`);
1995
- }
1996
- if (isAbiResponse(abiType)) {
1997
- if (cv.type === "ok")
1998
- return { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };
1999
- if (cv.type === "err")
2000
- return { err: clarityValueToJSInner(abiType.response.error, cv.value) };
2001
- throw new Error(`Expected response CV, got ${cv.type}`);
2002
- }
2003
- throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1842
+ function poxName(code) {
1843
+ const name = POX_CODE_REVERSE[code];
1844
+ if (!name)
1845
+ throw new Error(`Unknown pox post-condition code: ${code}`);
1846
+ return name;
1847
+ }
1848
+ function fromHex(hex) {
1849
+ return wireToPostCondition(deserializePostConditionWire(hex));
1850
+ }
1851
+ function postConditionToHex(pc) {
1852
+ return bytesToHex(serializePostConditionWire(convertPostCondition(pc)));
2004
1853
  }
2005
1854
 
2006
1855
  // src/transactions/authorization.ts
@@ -2149,11 +1998,11 @@ function replayMultiSigSigHash(tx) {
2149
1998
  const condition = tx.auth.spendingCondition;
2150
1999
  if (isNonSequential(condition.hashMode)) {
2151
2000
  const preSign = nonSequentialPreSignHash(tx);
2152
- let curSigHash2 = preSign;
2001
+ let curSigHash = preSign;
2153
2002
  for (const field of condition.fields) {
2154
- curSigHash2 = sigHashPostSign(curSigHash2, field.pubKeyEncoding, field.data);
2003
+ curSigHash = sigHashPostSign(curSigHash, field.pubKeyEncoding, field.data);
2155
2004
  }
2156
- return curSigHash2;
2005
+ return curSigHash;
2157
2006
  }
2158
2007
  let curSigHash = initialSigHash(tx);
2159
2008
  for (const field of condition.fields) {
@@ -2274,8 +2123,8 @@ async function signSequentialWithAccount(tx, condition, account, publicKeys, sig
2274
2123
  const fields = [...condition.fields];
2275
2124
  let curSigHash = initialSigHash(tx);
2276
2125
  for (const field of fields) {
2277
- const preSign2 = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
2278
- curSigHash = sigHashPostSign(preSign2, field.pubKeyEncoding, field.data);
2126
+ const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
2127
+ curSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);
2279
2128
  }
2280
2129
  for (let i = fields.length;i < signerIndex; i++) {
2281
2130
  const pubKeyField = {
@@ -2284,8 +2133,8 @@ async function signSequentialWithAccount(tx, condition, account, publicKeys, sig
2284
2133
  data: publicKeys[i]
2285
2134
  };
2286
2135
  fields.push(pubKeyField);
2287
- const preSign2 = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
2288
- curSigHash = sigHashPostSign(preSign2, pubKeyField.pubKeyEncoding, pubKeyField.data);
2136
+ const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
2137
+ curSigHash = sigHashPostSign(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);
2289
2138
  }
2290
2139
  const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
2291
2140
  const sigBytes = await account.sign(hexToBytes(preSign));
@@ -2579,9 +2428,9 @@ function getOriginSigHash(tx) {
2579
2428
  if ("fields" in condition) {
2580
2429
  return replayMultiSigSigHash(tx);
2581
2430
  }
2582
- const initialSigHash2 = signBegin(tx);
2431
+ const initialSigHash = signBegin(tx);
2583
2432
  const sc = condition;
2584
- const preSign = sigHashPreSign(initialSigHash2, AuthType.Standard, sc.fee, sc.nonce);
2433
+ const preSign = sigHashPreSign(initialSigHash, AuthType.Standard, sc.fee, sc.nonce);
2585
2434
  return sigHashPostSign(preSign, sc.keyEncoding, sc.signature);
2586
2435
  }
2587
2436
  function signSponsor(tx, privateKey) {
@@ -2885,8 +2734,8 @@ function indexNotFound(error, sourceName) {
2885
2734
  }
2886
2735
  return true;
2887
2736
  }
2888
- function normalizeTxid(txid2) {
2889
- return txid2.startsWith("0x") ? txid2 : `0x${txid2}`;
2737
+ function normalizeTxid(txid) {
2738
+ return txid.startsWith("0x") ? txid : `0x${txid}`;
2890
2739
  }
2891
2740
  function decodeResultHex(hex) {
2892
2741
  if (!hex)
@@ -2910,10 +2759,10 @@ function normalizeStatus(txStatus) {
2910
2759
  }
2911
2760
  function extendedApiSource() {
2912
2761
  return {
2913
- async get({ client, txid: txid2 }) {
2762
+ async get({ client, txid }) {
2914
2763
  let data;
2915
2764
  try {
2916
- data = await client.request(`/extended/v1/tx/${encodeURIComponent(normalizeTxid(txid2))}`, { method: "GET" });
2765
+ data = await client.request(`/extended/v1/tx/${encodeURIComponent(normalizeTxid(txid))}`, { method: "GET" });
2917
2766
  } catch (error) {
2918
2767
  if (error instanceof HttpRequestError && error.status === 404) {
2919
2768
  return { receipt: null };
@@ -2928,7 +2777,7 @@ function extendedApiSource() {
2928
2777
  return { receipt: null };
2929
2778
  return {
2930
2779
  receipt: {
2931
- txid: normalizeTxid(txid2),
2780
+ txid: normalizeTxid(txid),
2932
2781
  status,
2933
2782
  blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
2934
2783
  blockHash: data.block_hash ?? undefined,
@@ -2944,11 +2793,11 @@ function indexTxSource(params = {}) {
2944
2793
  const headers = params.apiKey ? { authorization: `Bearer ${params.apiKey}` } : undefined;
2945
2794
  return {
2946
2795
  canonicalOnly: true,
2947
- async get({ client, txid: txid2 }) {
2796
+ async get({ client, txid }) {
2948
2797
  const request = indexRequestFn(client, params.baseUrl, "indexTxSource");
2949
2798
  let data;
2950
2799
  try {
2951
- data = await request(`/v1/index/transactions/${normalizeTxid(txid2)}`, {
2800
+ data = await request(`/v1/index/transactions/${normalizeTxid(txid)}`, {
2952
2801
  method: "GET",
2953
2802
  headers
2954
2803
  });
@@ -2997,7 +2846,7 @@ async function getBlockHeight(client) {
2997
2846
  var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
2998
2847
  async function waitForTransactionReceipt(client, params) {
2999
2848
  const {
3000
- txid: txid2,
2849
+ txid,
3001
2850
  confirmations = 1,
3002
2851
  timeout = 180000,
3003
2852
  pollingInterval = 3000
@@ -3008,21 +2857,21 @@ async function waitForTransactionReceipt(client, params) {
3008
2857
  let unknownSince = null;
3009
2858
  let everPending = false;
3010
2859
  while (true) {
3011
- const snapshot = await source.get({ client, txid: txid2 });
2860
+ const snapshot = await source.get({ client, txid });
3012
2861
  const receipt = snapshot.receipt;
3013
2862
  if (receipt === null) {
3014
2863
  unknownSince ??= Date.now();
3015
2864
  if (Date.now() - unknownSince >= droppedGracePeriod) {
3016
- throw new TransactionDroppedError(everPending ? `Transaction ${txid2} left the mempool without being mined` : `Transaction ${txid2} was never observed by the status source`, { txid: txid2 });
2865
+ throw new TransactionDroppedError(everPending ? `Transaction ${txid} left the mempool without being mined` : `Transaction ${txid} was never observed by the status source`, { txid });
3017
2866
  }
3018
2867
  } else {
3019
2868
  unknownSince = null;
3020
2869
  switch (receipt.status) {
3021
2870
  case "dropped":
3022
- throw new TransactionDroppedError(`Transaction ${txid2} was dropped from the mempool`, { txid: txid2 });
2871
+ throw new TransactionDroppedError(`Transaction ${txid} was dropped from the mempool`, { txid });
3023
2872
  case "abort_by_response":
3024
2873
  case "abort_by_post_condition":
3025
- throw new TransactionAbortedError(`Transaction ${txid2} aborted (${receipt.status})`, { receipt });
2874
+ throw new TransactionAbortedError(`Transaction ${txid} aborted (${receipt.status})`, { receipt });
3026
2875
  case "pending":
3027
2876
  everPending = true;
3028
2877
  break;
@@ -3039,7 +2888,7 @@ async function waitForTransactionReceipt(client, params) {
3039
2888
  }
3040
2889
  }
3041
2890
  if (Date.now() - startedAt >= timeout) {
3042
- throw new WaitForTransactionTimeoutError(`Timed out after ${timeout}ms waiting for transaction ${txid2}`, { txid: txid2 });
2891
+ throw new WaitForTransactionTimeoutError(`Timed out after ${timeout}ms waiting for transaction ${txid}`, { txid });
3043
2892
  }
3044
2893
  await sleep2(pollingInterval);
3045
2894
  }
@@ -3067,11 +2916,11 @@ async function sendTransaction(client, params) {
3067
2916
  throw error;
3068
2917
  }
3069
2918
  } else if (error instanceof TimeoutError) {
3070
- const txid3 = getTransactionId(params.transaction);
3071
- const receipt = await getTransaction(client, { txid: txid3 }).catch(() => null);
2919
+ const txid = getTransactionId(params.transaction);
2920
+ const receipt = await getTransaction(client, { txid }).catch(() => null);
3072
2921
  if (receipt === null)
3073
2922
  throw error;
3074
- data = { txid: txid3 };
2923
+ data = { txid };
3075
2924
  } else {
3076
2925
  throw error;
3077
2926
  }
@@ -3083,16 +2932,16 @@ async function sendTransaction(client, params) {
3083
2932
  txid: data.txid ?? getTransactionId(params.transaction)
3084
2933
  });
3085
2934
  }
3086
- const txid2 = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
2935
+ const txid = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
3087
2936
  if (params.wait) {
3088
2937
  const confirmations = params.wait === true ? 1 : params.wait;
3089
2938
  const receipt = await waitForTransactionReceipt(client, {
3090
- txid: txid2,
2939
+ txid,
3091
2940
  confirmations
3092
2941
  });
3093
- return { txid: txid2, receipt };
2942
+ return { txid, receipt };
3094
2943
  }
3095
- return { txid: txid2 };
2944
+ return { txid };
3096
2945
  }
3097
2946
 
3098
2947
  // src/actions/wallet/nonceManager.ts
@@ -3525,6 +3374,158 @@ class ContractResponseError extends Error {
3525
3374
  }
3526
3375
  }
3527
3376
 
3377
+ // src/postconditions/index.ts
3378
+ var exports_postconditions = {};
3379
+ __export(exports_postconditions, {
3380
+ Pc: () => Pc,
3381
+ fromHex: () => fromHex,
3382
+ parsePostConditionAmount: () => parsePostConditionAmount,
3383
+ postConditionToHex: () => postConditionToHex,
3384
+ wireToPostCondition: () => wireToPostCondition
3385
+ });
3386
+
3387
+ // src/postconditions/builder.ts
3388
+ class PartialPcWithPrincipal {
3389
+ address;
3390
+ constructor(address) {
3391
+ this.address = address;
3392
+ }
3393
+ willSendEq(amount) {
3394
+ return new PartialPcFtWithCode(this.address, amount, "eq");
3395
+ }
3396
+ willSendGte(amount) {
3397
+ return new PartialPcFtWithCode(this.address, amount, "gte");
3398
+ }
3399
+ willSendGt(amount) {
3400
+ return new PartialPcFtWithCode(this.address, amount, "gt");
3401
+ }
3402
+ willSendLte(amount) {
3403
+ return new PartialPcFtWithCode(this.address, amount, "lte");
3404
+ }
3405
+ willSendLt(amount) {
3406
+ return new PartialPcFtWithCode(this.address, amount, "lt");
3407
+ }
3408
+ willSendAsset() {
3409
+ return new PartialPcNftWithCode(this.address, "sent");
3410
+ }
3411
+ willNotSendAsset() {
3412
+ return new PartialPcNftWithCode(this.address, "not-sent");
3413
+ }
3414
+ willMaybeSendAsset() {
3415
+ return new PartialPcNftWithCode(this.address, "maybe-sent");
3416
+ }
3417
+ willPerformPox() {
3418
+ return {
3419
+ type: "pox-postcondition",
3420
+ address: this.address,
3421
+ condition: "will-perform"
3422
+ };
3423
+ }
3424
+ willNotPerformPox() {
3425
+ return {
3426
+ type: "pox-postcondition",
3427
+ address: this.address,
3428
+ condition: "will-not-perform"
3429
+ };
3430
+ }
3431
+ mayPerformPox() {
3432
+ return {
3433
+ type: "pox-postcondition",
3434
+ address: this.address,
3435
+ condition: "may-perform"
3436
+ };
3437
+ }
3438
+ }
3439
+
3440
+ class PartialPcFtWithCode {
3441
+ address;
3442
+ amount;
3443
+ code;
3444
+ constructor(address, amount, code) {
3445
+ this.address = address;
3446
+ this.amount = amount;
3447
+ this.code = code;
3448
+ }
3449
+ ustx() {
3450
+ return {
3451
+ type: "stx-postcondition",
3452
+ address: this.address,
3453
+ condition: this.code,
3454
+ amount: parsePostConditionAmount(this.amount).toString()
3455
+ };
3456
+ }
3457
+ ustxToLock() {
3458
+ return {
3459
+ type: "staking-postcondition",
3460
+ address: this.address,
3461
+ condition: this.code,
3462
+ amount: parsePostConditionAmount(this.amount).toString()
3463
+ };
3464
+ }
3465
+ ft(contractId, tokenName) {
3466
+ const [address, name] = contractId.split(".");
3467
+ if (!address || !validateStacksAddress(address) || !name) {
3468
+ throw new Error(`Invalid contract id: ${contractId}`);
3469
+ }
3470
+ return {
3471
+ type: "ft-postcondition",
3472
+ address: this.address,
3473
+ condition: this.code,
3474
+ amount: parsePostConditionAmount(this.amount).toString(),
3475
+ asset: `${contractId}::${tokenName}`
3476
+ };
3477
+ }
3478
+ }
3479
+
3480
+ class PartialPcNftWithCode {
3481
+ address;
3482
+ code;
3483
+ constructor(address, code) {
3484
+ this.address = address;
3485
+ this.code = code;
3486
+ }
3487
+ nft(assetOrContractId, tokenNameOrAssetId, assetId) {
3488
+ let contractAddress;
3489
+ let contractName;
3490
+ let tokenName;
3491
+ let id;
3492
+ if (assetId !== undefined) {
3493
+ [contractAddress, contractName] = parseContractId(assetOrContractId);
3494
+ tokenName = tokenNameOrAssetId;
3495
+ id = assetId;
3496
+ } else {
3497
+ const [principal, tName] = assetOrContractId.split("::");
3498
+ if (!principal || !tName)
3499
+ throw new Error(`Invalid asset name: ${assetOrContractId}`);
3500
+ [contractAddress, contractName] = parseContractId(principal);
3501
+ tokenName = tName;
3502
+ id = tokenNameOrAssetId;
3503
+ }
3504
+ if (!validateStacksAddress(contractAddress)) {
3505
+ throw new Error(`Invalid contract address: ${contractAddress}`);
3506
+ }
3507
+ return {
3508
+ type: "nft-postcondition",
3509
+ address: this.address,
3510
+ condition: this.code,
3511
+ asset: `${contractAddress}.${contractName}::${tokenName}`,
3512
+ assetId: id
3513
+ };
3514
+ }
3515
+ }
3516
+ var Pc = {
3517
+ principal(address) {
3518
+ const [addr, name] = address.split(".");
3519
+ if (!addr || !validateStacksAddress(addr) || typeof name === "string" && !name) {
3520
+ throw new Error(`Invalid principal: ${address}`);
3521
+ }
3522
+ return new PartialPcWithPrincipal(address);
3523
+ },
3524
+ origin() {
3525
+ return new PartialPcWithPrincipal("origin");
3526
+ },
3527
+ fromHex: (hex) => fromHex(hex)
3528
+ };
3528
3529
  // src/pox/abi.ts
3529
3530
  var POX_ABI = {
3530
3531
  functions: [
@@ -3925,8 +3926,8 @@ function stripWitness(rawTx) {
3925
3926
  return scanTx(rawTx).legacy;
3926
3927
  }
3927
3928
  function bitcoinTxid(rawTx, { display = false } = {}) {
3928
- const txid2 = doubleSha256(scanTx(rawTx).legacy);
3929
- return display ? reverseBytes(txid2) : txid2;
3929
+ const txid = doubleSha256(scanTx(rawTx).legacy);
3930
+ return display ? reverseBytes(txid) : txid;
3930
3931
  }
3931
3932
  function parseBlockHeader(header) {
3932
3933
  if (header.length !== 80) {
@@ -4259,5 +4260,5 @@ function pox() {
4259
4260
  });
4260
4261
  }
4261
4262
 
4262
- //# debugId=E01835A817EE70FD64756E2164756E21
4263
+ //# debugId=674F0BF04FE141AD64756E2164756E21
4263
4264
  //# sourceMappingURL=index.cjs.map