stxer 0.7.0 → 0.8.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.
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var transactions = require('@stacks/transactions');
6
+ var sha2_js = require('@noble/hashes/sha2.js');
6
7
  var tsClarity = require('ts-clarity');
7
8
  var network = require('@stacks/network');
8
9
  var c32check = require('c32check');
@@ -37,6 +38,13 @@ function _asyncToGenerator(n) {
37
38
  });
38
39
  };
39
40
  }
41
+ function _construct(t, e, r) {
42
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
43
+ var o = [null];
44
+ o.push.apply(o, e);
45
+ var p = new (t.bind.apply(t, o))();
46
+ return r && _setPrototypeOf(p, r.prototype), p;
47
+ }
40
48
  function _createForOfIteratorHelperLoose(r, e) {
41
49
  var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
42
50
  if (t) return (t = t.call(r)).next.bind(t);
@@ -63,6 +71,29 @@ function _extends() {
63
71
  return n;
64
72
  }, _extends.apply(null, arguments);
65
73
  }
74
+ function _getPrototypeOf(t) {
75
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
76
+ return t.__proto__ || Object.getPrototypeOf(t);
77
+ }, _getPrototypeOf(t);
78
+ }
79
+ function _inheritsLoose(t, o) {
80
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
81
+ }
82
+ function _isNativeFunction(t) {
83
+ try {
84
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
85
+ } catch (n) {
86
+ return "function" == typeof t;
87
+ }
88
+ }
89
+ function _isNativeReflectConstruct() {
90
+ try {
91
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
92
+ } catch (t) {}
93
+ return (_isNativeReflectConstruct = function () {
94
+ return !!t;
95
+ })();
96
+ }
66
97
  function _regenerator() {
67
98
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
68
99
  var e,
@@ -171,6 +202,11 @@ function _regeneratorDefine(e, r, n, t) {
171
202
  }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
172
203
  }, _regeneratorDefine(e, r, n, t);
173
204
  }
205
+ function _setPrototypeOf(t, e) {
206
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
207
+ return t.__proto__ = e, t;
208
+ }, _setPrototypeOf(t, e);
209
+ }
174
210
  function _unsupportedIterableToArray(r, a) {
175
211
  if (r) {
176
212
  if ("string" == typeof r) return _arrayLikeToArray(r, a);
@@ -178,6 +214,28 @@ function _unsupportedIterableToArray(r, a) {
178
214
  return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
179
215
  }
180
216
  }
217
+ function _wrapNativeSuper(t) {
218
+ var r = "function" == typeof Map ? new Map() : void 0;
219
+ return _wrapNativeSuper = function (t) {
220
+ if (null === t || !_isNativeFunction(t)) return t;
221
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
222
+ if (void 0 !== r) {
223
+ if (r.has(t)) return r.get(t);
224
+ r.set(t, Wrapper);
225
+ }
226
+ function Wrapper() {
227
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
228
+ }
229
+ return Wrapper.prototype = Object.create(t.prototype, {
230
+ constructor: {
231
+ value: Wrapper,
232
+ enumerable: !1,
233
+ writable: !0,
234
+ configurable: !0
235
+ }
236
+ }), _setPrototypeOf(Wrapper, t);
237
+ }, _wrapNativeSuper(t);
238
+ }
181
239
 
182
240
  /**
183
241
  * API endpoint constants
@@ -383,6 +441,273 @@ function _batchRead() {
383
441
  return _batchRead.apply(this, arguments);
384
442
  }
385
443
 
444
+ // ============================================================================
445
+ // Hashing primitives
446
+ // ============================================================================
447
+ /**
448
+ * SHA-256. Pure-JS via `@noble/hashes` so this module works in
449
+ * browsers, Node, and Bun without a polyfill.
450
+ */
451
+ function sha256(data) {
452
+ return sha2_js.sha256(data);
453
+ }
454
+ /** Bitcoin-style double-sha256 used for txids, block hashes, and Merkle nodes. */
455
+ function sha256d(data) {
456
+ return sha256(sha256(data));
457
+ }
458
+ // ============================================================================
459
+ // Hex encoding
460
+ // ============================================================================
461
+ /** Decode a hex string (with or without `0x` prefix). */
462
+ function hexToBytes(s) {
463
+ var t = s.toLowerCase().replace(/^0x/, '');
464
+ if (t.length % 2 !== 0) throw new Error('odd-length hex');
465
+ var out = new Uint8Array(t.length / 2);
466
+ for (var i = 0; i < out.length; i++) {
467
+ out[i] = Number.parseInt(t.slice(i * 2, i * 2 + 2), 16);
468
+ }
469
+ return out;
470
+ }
471
+ /** Lower-case hex (no `0x` prefix). */
472
+ function bytesToHex(b) {
473
+ return Array.from(b).map(function (x) {
474
+ return x.toString(16).padStart(2, '0');
475
+ }).join('');
476
+ }
477
+ // ============================================================================
478
+ // Bitcoin script builders
479
+ // ============================================================================
480
+ /** P2WPKH output script: `OP_0 <20-byte pubkey-hash>`. */
481
+ function p2wpkhScript(pubKeyHash20) {
482
+ if (pubKeyHash20.length !== 20) {
483
+ throw new Error('pubKeyHash must be 20 bytes');
484
+ }
485
+ var out = new Uint8Array(22);
486
+ out[0] = 0x00; // OP_0
487
+ out[1] = 0x14; // pushdata length 20
488
+ out.set(pubKeyHash20, 2);
489
+ return out;
490
+ }
491
+ /** P2PKH output script: `OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG`. */
492
+ function p2pkhScript(pubKeyHash20) {
493
+ if (pubKeyHash20.length !== 20) {
494
+ throw new Error('pubKeyHash must be 20 bytes');
495
+ }
496
+ var out = new Uint8Array(25);
497
+ out[0] = 0x76; // OP_DUP
498
+ out[1] = 0xa9; // OP_HASH160
499
+ out[2] = 0x14; // pushdata 20
500
+ out.set(pubKeyHash20, 3);
501
+ out[23] = 0x88; // OP_EQUALVERIFY
502
+ out[24] = 0xac; // OP_CHECKSIG
503
+ return out;
504
+ }
505
+ /**
506
+ * `OP_RETURN <data>` output. Used to embed peg-in metadata
507
+ * (recipient principal, marker bytes, etc.). Bitcoin's standard relay
508
+ * limit caps `data` at 80 bytes; this helper rejects > 75 to leave
509
+ * room for the prefix bytes.
510
+ */
511
+ function opReturnScript(data) {
512
+ if (data.length > 75) {
513
+ throw new Error("OP_RETURN data too long: " + data.length);
514
+ }
515
+ var out = new Uint8Array(2 + data.length);
516
+ out[0] = 0x6a; // OP_RETURN
517
+ out[1] = data.length; // direct push
518
+ out.set(data, 2);
519
+ return out;
520
+ }
521
+ /**
522
+ * Build a non-witness Bitcoin transaction (legacy serialization). The
523
+ * txid is `sha256d` of the returned `bytes`. Use this form when you
524
+ * only need to assert SPV inclusion; segwit witness data is irrelevant
525
+ * to the txid.
526
+ *
527
+ * Wire format:
528
+ * ```
529
+ * 4 version (LE)
530
+ * varint in-count
531
+ * per-input: 32 prev_txid + 4 prev_vout + varint script-len + script + 4 sequence
532
+ * varint out-count
533
+ * per-output: 8 value (LE) + varint script-len + script
534
+ * 4 locktime (LE)
535
+ * ```
536
+ */
537
+ function forgeBitcoinTx(opts) {
538
+ var _opts$version, _opts$locktime;
539
+ var chunks = [];
540
+ var u32le = function u32le(n) {
541
+ var b = new Uint8Array(4);
542
+ new DataView(b.buffer).setUint32(0, n >>> 0, true);
543
+ return b;
544
+ };
545
+ var u64le = function u64le(n) {
546
+ var b = new Uint8Array(8);
547
+ var view = new DataView(b.buffer);
548
+ view.setUint32(0, Number(n & 0xffffffffn), true);
549
+ view.setUint32(4, Number(n >> 32n & 0xffffffffn), true);
550
+ return b;
551
+ };
552
+ var varint = function varint(n) {
553
+ if (n < 0xfd) return new Uint8Array([n]);
554
+ if (n <= 0xffff) {
555
+ var b = new Uint8Array(3);
556
+ b[0] = 0xfd;
557
+ new DataView(b.buffer).setUint16(1, n, true);
558
+ return b;
559
+ }
560
+ if (n <= 0xffffffff) {
561
+ var _b = new Uint8Array(5);
562
+ _b[0] = 0xfe;
563
+ new DataView(_b.buffer).setUint32(1, n, true);
564
+ return _b;
565
+ }
566
+ throw new Error("varint too large: " + n);
567
+ };
568
+ chunks.push(u32le((_opts$version = opts.version) != null ? _opts$version : 2));
569
+ chunks.push(varint(opts.inputs.length));
570
+ for (var _iterator = _createForOfIteratorHelperLoose(opts.inputs), _step; !(_step = _iterator()).done;) {
571
+ var _i$sequence;
572
+ var i = _step.value;
573
+ if (i.prevTxid.length !== 32) {
574
+ throw new Error('prevTxid must be 32 bytes');
575
+ }
576
+ chunks.push(i.prevTxid);
577
+ chunks.push(u32le(i.prevVout));
578
+ chunks.push(varint(i.scriptSig.length));
579
+ chunks.push(i.scriptSig);
580
+ chunks.push(u32le((_i$sequence = i.sequence) != null ? _i$sequence : 0xfffffffd));
581
+ }
582
+ chunks.push(varint(opts.outputs.length));
583
+ for (var _iterator2 = _createForOfIteratorHelperLoose(opts.outputs), _step2; !(_step2 = _iterator2()).done;) {
584
+ var o = _step2.value;
585
+ chunks.push(u64le(o.value));
586
+ chunks.push(varint(o.scriptPubKey.length));
587
+ chunks.push(o.scriptPubKey);
588
+ }
589
+ chunks.push(u32le((_opts$locktime = opts.locktime) != null ? _opts$locktime : 0));
590
+ var total = chunks.reduce(function (s, c) {
591
+ return s + c.length;
592
+ }, 0);
593
+ var bytes = new Uint8Array(total);
594
+ var off = 0;
595
+ for (var _i = 0, _chunks = chunks; _i < _chunks.length; _i++) {
596
+ var c = _chunks[_i];
597
+ bytes.set(c, off);
598
+ off += c.length;
599
+ }
600
+ var txid = sha256d(bytes);
601
+ var txidDisplay = reverseBytes(txid);
602
+ return {
603
+ bytes: bytes,
604
+ txid: txid,
605
+ txidDisplay: txidDisplay
606
+ };
607
+ }
608
+ /**
609
+ * Build an 80-byte Bitcoin block header. `prevHash` and `merkleRoot`
610
+ * are written in internal byte order (raw `sha256d` output) — matching
611
+ * the on-chain `clarity-bitcoin-v1-07` parser convention.
612
+ */
613
+ function buildBitcoinHeader(h) {
614
+ var _h$version, _h$prevHash, _h$timestamp, _h$bits, _h$nonce;
615
+ var out = new Uint8Array(80);
616
+ var view = new DataView(out.buffer);
617
+ view.setUint32(0, (_h$version = h.version) != null ? _h$version : 0x20000000, true);
618
+ out.set((_h$prevHash = h.prevHash) != null ? _h$prevHash : new Uint8Array(32), 4);
619
+ out.set(h.merkleRoot, 36);
620
+ view.setUint32(68, (_h$timestamp = h.timestamp) != null ? _h$timestamp : Math.floor(Date.now() / 1000), true);
621
+ view.setUint32(72, (_h$bits = h.bits) != null ? _h$bits : 0x1d00ffff, true);
622
+ view.setUint32(76, (_h$nonce = h.nonce) != null ? _h$nonce : 0, true);
623
+ var rawHash = sha256d(out);
624
+ return {
625
+ header: out,
626
+ hash: reverseBytes(rawHash),
627
+ rawHash: rawHash
628
+ };
629
+ }
630
+ // ============================================================================
631
+ // Merkle proofs (Bitcoin convention)
632
+ // ============================================================================
633
+ /**
634
+ * Single-tx Merkle root — the txid itself. Bitcoin's Merkle tree
635
+ * convention does NOT pre-hash the leaves; for a one-tx block the
636
+ * root equals the txid.
637
+ */
638
+ function singleTxMerkleRoot(txid) {
639
+ return new Uint8Array(txid);
640
+ }
641
+ /**
642
+ * Compute a Bitcoin Merkle proof for `txid` at `index` in `txids`
643
+ * (transaction order within the block). Returns the sibling hashes
644
+ * from leaf to root.
645
+ *
646
+ * Bitcoin convention:
647
+ * - Leaves are the txids themselves (no pre-hashing).
648
+ * - Inner nodes are `sha256d(left || right)`.
649
+ * - Odd levels duplicate the last entry to pair.
650
+ */
651
+ function merkleProof(txids, index) {
652
+ if (index < 0 || index >= txids.length) {
653
+ throw new Error("merkleProof: index " + index + " out of range " + txids.length);
654
+ }
655
+ var level = txids.map(function (t) {
656
+ return new Uint8Array(t);
657
+ });
658
+ var proof = [];
659
+ var i = index;
660
+ while (level.length > 1) {
661
+ if (level.length % 2 === 1) level.push(level[level.length - 1]);
662
+ var sibling = level[i ^ 1];
663
+ proof.push(sibling);
664
+ var next = [];
665
+ for (var j = 0; j < level.length; j += 2) {
666
+ next.push(sha256d(concatBytes(level[j], level[j + 1])));
667
+ }
668
+ level = next;
669
+ i = Math.floor(i / 2);
670
+ }
671
+ return {
672
+ proof: proof,
673
+ root: level[0]
674
+ };
675
+ }
676
+ /**
677
+ * Verify a Bitcoin Merkle proof against `root`. Returns `true` iff the
678
+ * proof reconstructs the root from `txid` at `index`. Matches the
679
+ * on-chain `verify-merkle-proof` semantic.
680
+ */
681
+ function verifyMerkleProof(txid, index, proof, root) {
682
+ var h = new Uint8Array(txid);
683
+ var i = index;
684
+ for (var _iterator3 = _createForOfIteratorHelperLoose(proof), _step3; !(_step3 = _iterator3()).done;) {
685
+ var sibling = _step3.value;
686
+ h = (i & 1) === 0 ? sha256d(concatBytes(h, sibling)) : sha256d(concatBytes(sibling, h));
687
+ i = Math.floor(i / 2);
688
+ }
689
+ return bytesEqual(h, root);
690
+ }
691
+ // ============================================================================
692
+ // Internal byte helpers
693
+ // ============================================================================
694
+ function reverseBytes(a) {
695
+ var out = new Uint8Array(a.length);
696
+ for (var i = 0; i < a.length; i++) out[i] = a[a.length - 1 - i];
697
+ return out;
698
+ }
699
+ function concatBytes(a, b) {
700
+ var out = new Uint8Array(a.length + b.length);
701
+ out.set(a, 0);
702
+ out.set(b, a.length);
703
+ return out;
704
+ }
705
+ function bytesEqual(a, b) {
706
+ if (a.length !== b.length) return false;
707
+ for (var i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
708
+ return true;
709
+ }
710
+
386
711
  var BatchProcessor = /*#__PURE__*/function () {
387
712
  function BatchProcessor(options) {
388
713
  var _options$stxerAPIEndp;
@@ -696,6 +1021,43 @@ function _readVariable() {
696
1021
  return _readVariable.apply(this, arguments);
697
1022
  }
698
1023
 
1024
+ /**
1025
+ * Thrown by the simulation-api fetch wrappers when the API responds
1026
+ * with a non-2xx status. `status` carries the wire HTTP code so
1027
+ * callers can branch on 409 (busy) / 410 (outdated) without parsing
1028
+ * the message string. `marker` is the server-side classification
1029
+ * extracted from the body prefix (`simulation_busy:` /
1030
+ * `simulation_outdated:`).
1031
+ *
1032
+ * Pre-0.8.0 SDKs threw a plain `Error` whose message embedded the body
1033
+ * text; that lossy form is still used for the message field here so
1034
+ * existing log scrapers keep working.
1035
+ */
1036
+ var SimulationError = /*#__PURE__*/function (_Error) {
1037
+ function SimulationError(operation, status, body) {
1038
+ var _this;
1039
+ var marker = detectMarker(body);
1040
+ _this = _Error.call(this, operation + " (HTTP " + status + "): " + body) || this;
1041
+ _this.status = void 0;
1042
+ _this.marker = void 0;
1043
+ _this.body = void 0;
1044
+ _this.name = 'SimulationError';
1045
+ _this.status = status;
1046
+ _this.marker = marker;
1047
+ _this.body = body;
1048
+ return _this;
1049
+ }
1050
+ _inheritsLoose(SimulationError, _Error);
1051
+ return SimulationError;
1052
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1053
+ function detectMarker(body) {
1054
+ if (body.includes('simulation_busy:')) return 'simulation_busy';
1055
+ if (body.includes('simulation_outdated:')) return 'simulation_outdated';
1056
+ return null;
1057
+ }
1058
+ function throwSimulationError(_x, _x2) {
1059
+ return _throwSimulationError.apply(this, arguments);
1060
+ }
699
1061
  /**
700
1062
  * Instantly simulate a transaction
701
1063
  *
@@ -722,7 +1084,25 @@ function _readVariable() {
722
1084
  * console.log(result.receipt.result);
723
1085
  * ```
724
1086
  */
725
- function instantSimulation(_x, _x2) {
1087
+ function _throwSimulationError() {
1088
+ _throwSimulationError = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(operation, response) {
1089
+ var text;
1090
+ return _regenerator().w(function (_context) {
1091
+ while (1) switch (_context.n) {
1092
+ case 0:
1093
+ _context.n = 1;
1094
+ return response.text();
1095
+ case 1:
1096
+ text = _context.v;
1097
+ throw new SimulationError(operation, response.status, text);
1098
+ case 2:
1099
+ return _context.a(2);
1100
+ }
1101
+ }, _callee);
1102
+ }));
1103
+ return _throwSimulationError.apply(this, arguments);
1104
+ }
1105
+ function instantSimulation(_x3, _x4) {
726
1106
  return _instantSimulation.apply(this, arguments);
727
1107
  }
728
1108
  /**
@@ -745,17 +1125,17 @@ function instantSimulation(_x, _x2) {
745
1125
  * ```
746
1126
  */
747
1127
  function _instantSimulation() {
748
- _instantSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(request, options) {
1128
+ _instantSimulation = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(request, options) {
749
1129
  var _options$stxerApi;
750
- var apiEndpoint, response, text;
751
- return _regenerator().w(function (_context) {
752
- while (1) switch (_context.n) {
1130
+ var apiEndpoint, response;
1131
+ return _regenerator().w(function (_context2) {
1132
+ while (1) switch (_context2.n) {
753
1133
  case 0:
754
1134
  if (options === void 0) {
755
1135
  options = {};
756
1136
  }
757
1137
  apiEndpoint = (_options$stxerApi = options.stxerApi) != null ? _options$stxerApi : DEFAULT_STXER_API$1;
758
- _context.n = 1;
1138
+ _context2.n = 1;
759
1139
  return fetch(apiEndpoint + "/devtools/v2/simulations:instant", {
760
1140
  method: 'POST',
761
1141
  body: JSON.stringify(request),
@@ -765,24 +1145,21 @@ function _instantSimulation() {
765
1145
  }
766
1146
  });
767
1147
  case 1:
768
- response = _context.v;
1148
+ response = _context2.v;
769
1149
  if (response.ok) {
770
- _context.n = 3;
1150
+ _context2.n = 2;
771
1151
  break;
772
1152
  }
773
- _context.n = 2;
774
- return response.text();
1153
+ _context2.n = 2;
1154
+ return throwSimulationError('Instant simulation failed', response);
775
1155
  case 2:
776
- text = _context.v;
777
- throw new Error("Instant simulation failed: " + text);
778
- case 3:
779
- return _context.a(2, response.json());
1156
+ return _context2.a(2, response.json());
780
1157
  }
781
- }, _callee);
1158
+ }, _callee2);
782
1159
  }));
783
1160
  return _instantSimulation.apply(this, arguments);
784
1161
  }
785
- function createSimulationSession(_x3, _x4) {
1162
+ function createSimulationSession(_x5, _x6) {
786
1163
  return _createSimulationSession.apply(this, arguments);
787
1164
  }
788
1165
  /**
@@ -809,11 +1186,11 @@ function createSimulationSession(_x3, _x4) {
809
1186
  * ```
810
1187
  */
811
1188
  function _createSimulationSession() {
812
- _createSimulationSession = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, apiOptions) {
1189
+ _createSimulationSession = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options, apiOptions) {
813
1190
  var _apiOptions$stxerApi;
814
- var apiEndpoint, response, text, result;
815
- return _regenerator().w(function (_context2) {
816
- while (1) switch (_context2.n) {
1191
+ var apiEndpoint, response, result;
1192
+ return _regenerator().w(function (_context3) {
1193
+ while (1) switch (_context3.n) {
817
1194
  case 0:
818
1195
  if (options === void 0) {
819
1196
  options = {};
@@ -822,7 +1199,7 @@ function _createSimulationSession() {
822
1199
  apiOptions = {};
823
1200
  }
824
1201
  apiEndpoint = (_apiOptions$stxerApi = apiOptions.stxerApi) != null ? _apiOptions$stxerApi : DEFAULT_STXER_API$1;
825
- _context2.n = 1;
1202
+ _context3.n = 1;
826
1203
  return fetch(apiEndpoint + "/devtools/v2/simulations", {
827
1204
  method: 'POST',
828
1205
  body: JSON.stringify(options),
@@ -832,28 +1209,25 @@ function _createSimulationSession() {
832
1209
  }
833
1210
  });
834
1211
  case 1:
835
- response = _context2.v;
1212
+ response = _context3.v;
836
1213
  if (response.ok) {
837
- _context2.n = 3;
1214
+ _context3.n = 2;
838
1215
  break;
839
1216
  }
840
- _context2.n = 2;
841
- return response.text();
1217
+ _context3.n = 2;
1218
+ return throwSimulationError('Failed to create simulation session', response);
842
1219
  case 2:
843
- text = _context2.v;
844
- throw new Error("Failed to create simulation session: " + text);
845
- case 3:
846
- _context2.n = 4;
1220
+ _context3.n = 3;
847
1221
  return response.json();
848
- case 4:
849
- result = _context2.v;
850
- return _context2.a(2, result.id);
1222
+ case 3:
1223
+ result = _context3.v;
1224
+ return _context3.a(2, result.id);
851
1225
  }
852
- }, _callee2);
1226
+ }, _callee3);
853
1227
  }));
854
1228
  return _createSimulationSession.apply(this, arguments);
855
1229
  }
856
- function submitSimulationSteps(_x5, _x6, _x7) {
1230
+ function submitSimulationSteps(_x7, _x8, _x9) {
857
1231
  return _submitSimulationSteps.apply(this, arguments);
858
1232
  }
859
1233
  /**
@@ -875,17 +1249,17 @@ function submitSimulationSteps(_x5, _x6, _x7) {
875
1249
  * ```
876
1250
  */
877
1251
  function _submitSimulationSteps() {
878
- _submitSimulationSteps = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(sessionId, request, options) {
1252
+ _submitSimulationSteps = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId, request, options) {
879
1253
  var _options$stxerApi2;
880
- var apiEndpoint, response, text;
881
- return _regenerator().w(function (_context3) {
882
- while (1) switch (_context3.n) {
1254
+ var apiEndpoint, response;
1255
+ return _regenerator().w(function (_context4) {
1256
+ while (1) switch (_context4.n) {
883
1257
  case 0:
884
1258
  if (options === void 0) {
885
1259
  options = {};
886
1260
  }
887
1261
  apiEndpoint = (_options$stxerApi2 = options.stxerApi) != null ? _options$stxerApi2 : DEFAULT_STXER_API$1;
888
- _context3.n = 1;
1262
+ _context4.n = 1;
889
1263
  return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
890
1264
  method: 'POST',
891
1265
  body: JSON.stringify(request),
@@ -895,26 +1269,81 @@ function _submitSimulationSteps() {
895
1269
  }
896
1270
  });
897
1271
  case 1:
898
- response = _context3.v;
1272
+ response = _context4.v;
899
1273
  if (response.ok) {
900
- _context3.n = 3;
1274
+ _context4.n = 2;
901
1275
  break;
902
1276
  }
903
- _context3.n = 2;
904
- return response.text();
1277
+ _context4.n = 2;
1278
+ return throwSimulationError('Failed to submit simulation steps', response);
905
1279
  case 2:
906
- text = _context3.v;
907
- throw new Error("Failed to submit simulation steps: " + text);
908
- case 3:
909
- return _context3.a(2, response.json());
1280
+ return _context4.a(2, response.json());
910
1281
  }
911
- }, _callee3);
1282
+ }, _callee4);
912
1283
  }));
913
1284
  return _submitSimulationSteps.apply(this, arguments);
914
1285
  }
915
- function getSimulationResult(_x8, _x9) {
1286
+ function getSimulationResult(_x0, _x1) {
916
1287
  return _getSimulationResult.apply(this, arguments);
917
1288
  }
1289
+ /**
1290
+ * Get the current tip of a simulation session.
1291
+ *
1292
+ * Returns the latest synthetic tip when at least one `AdvanceBlocks`
1293
+ * step has run (`synthetic: true`, includes `vrf_seed` and
1294
+ * `tenure_change`). Returns the parent metadata pinned at session
1295
+ * start otherwise (`synthetic: false`, `vrf_seed` and `tenure_change`
1296
+ * omitted).
1297
+ *
1298
+ * Backed by `GET /devtools/v2/simulations/{id}/tip`. Older simulator
1299
+ * builds that predate this route respond 404.
1300
+ *
1301
+ * @example
1302
+ * ```typescript
1303
+ * import { getSimulationTip } from 'stxer';
1304
+ *
1305
+ * const tip = await getSimulationTip(sessionId);
1306
+ * if (tip.synthetic) {
1307
+ * console.log('synthetic tip vrf_seed:', tip.vrf_seed);
1308
+ * }
1309
+ * ```
1310
+ */
1311
+ function _getSimulationResult() {
1312
+ _getSimulationResult = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId, options) {
1313
+ var _options$stxerApi3;
1314
+ var apiEndpoint, response;
1315
+ return _regenerator().w(function (_context5) {
1316
+ while (1) switch (_context5.n) {
1317
+ case 0:
1318
+ if (options === void 0) {
1319
+ options = {};
1320
+ }
1321
+ apiEndpoint = (_options$stxerApi3 = options.stxerApi) != null ? _options$stxerApi3 : DEFAULT_STXER_API$1;
1322
+ _context5.n = 1;
1323
+ return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
1324
+ method: 'GET',
1325
+ headers: {
1326
+ Accept: 'application/json'
1327
+ }
1328
+ });
1329
+ case 1:
1330
+ response = _context5.v;
1331
+ if (response.ok) {
1332
+ _context5.n = 2;
1333
+ break;
1334
+ }
1335
+ _context5.n = 2;
1336
+ return throwSimulationError('Failed to get simulation result', response);
1337
+ case 2:
1338
+ return _context5.a(2, response.json());
1339
+ }
1340
+ }, _callee5);
1341
+ }));
1342
+ return _getSimulationResult.apply(this, arguments);
1343
+ }
1344
+ function getSimulationTip(_x10, _x11) {
1345
+ return _getSimulationTip.apply(this, arguments);
1346
+ }
918
1347
  /**
919
1348
  * Batch reads from a simulation session
920
1349
  *
@@ -937,57 +1366,54 @@ function getSimulationResult(_x8, _x9) {
937
1366
  * console.log(results.vars);
938
1367
  * ```
939
1368
  */
940
- function _getSimulationResult() {
941
- _getSimulationResult = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId, options) {
942
- var _options$stxerApi3;
943
- var apiEndpoint, response, text;
944
- return _regenerator().w(function (_context4) {
945
- while (1) switch (_context4.n) {
1369
+ function _getSimulationTip() {
1370
+ _getSimulationTip = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(sessionId, options) {
1371
+ var _options$stxerApi4;
1372
+ var apiEndpoint, response;
1373
+ return _regenerator().w(function (_context6) {
1374
+ while (1) switch (_context6.n) {
946
1375
  case 0:
947
1376
  if (options === void 0) {
948
1377
  options = {};
949
1378
  }
950
- apiEndpoint = (_options$stxerApi3 = options.stxerApi) != null ? _options$stxerApi3 : DEFAULT_STXER_API$1;
951
- _context4.n = 1;
952
- return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId, {
1379
+ apiEndpoint = (_options$stxerApi4 = options.stxerApi) != null ? _options$stxerApi4 : DEFAULT_STXER_API$1;
1380
+ _context6.n = 1;
1381
+ return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId + "/tip", {
953
1382
  method: 'GET',
954
1383
  headers: {
955
1384
  Accept: 'application/json'
956
1385
  }
957
1386
  });
958
1387
  case 1:
959
- response = _context4.v;
1388
+ response = _context6.v;
960
1389
  if (response.ok) {
961
- _context4.n = 3;
1390
+ _context6.n = 2;
962
1391
  break;
963
1392
  }
964
- _context4.n = 2;
965
- return response.text();
1393
+ _context6.n = 2;
1394
+ return throwSimulationError('Failed to get simulation tip', response);
966
1395
  case 2:
967
- text = _context4.v;
968
- throw new Error("Failed to get simulation result: " + text);
969
- case 3:
970
- return _context4.a(2, response.json());
1396
+ return _context6.a(2, response.json());
971
1397
  }
972
- }, _callee4);
1398
+ }, _callee6);
973
1399
  }));
974
- return _getSimulationResult.apply(this, arguments);
1400
+ return _getSimulationTip.apply(this, arguments);
975
1401
  }
976
- function simulationBatchReads(_x0, _x1, _x10) {
1402
+ function simulationBatchReads(_x12, _x13, _x14) {
977
1403
  return _simulationBatchReads.apply(this, arguments);
978
1404
  }
979
1405
  function _simulationBatchReads() {
980
- _simulationBatchReads = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId, request, options) {
981
- var _options$stxerApi4;
982
- var apiEndpoint, response, text;
983
- return _regenerator().w(function (_context5) {
984
- while (1) switch (_context5.n) {
1406
+ _simulationBatchReads = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(sessionId, request, options) {
1407
+ var _options$stxerApi5;
1408
+ var apiEndpoint, response;
1409
+ return _regenerator().w(function (_context7) {
1410
+ while (1) switch (_context7.n) {
985
1411
  case 0:
986
1412
  if (options === void 0) {
987
1413
  options = {};
988
1414
  }
989
- apiEndpoint = (_options$stxerApi4 = options.stxerApi) != null ? _options$stxerApi4 : DEFAULT_STXER_API$1;
990
- _context5.n = 1;
1415
+ apiEndpoint = (_options$stxerApi5 = options.stxerApi) != null ? _options$stxerApi5 : DEFAULT_STXER_API$1;
1416
+ _context7.n = 1;
991
1417
  return fetch(apiEndpoint + "/devtools/v2/simulations/" + sessionId + "/reads", {
992
1418
  method: 'POST',
993
1419
  body: JSON.stringify(request),
@@ -997,24 +1423,29 @@ function _simulationBatchReads() {
997
1423
  }
998
1424
  });
999
1425
  case 1:
1000
- response = _context5.v;
1426
+ response = _context7.v;
1001
1427
  if (response.ok) {
1002
- _context5.n = 3;
1428
+ _context7.n = 2;
1003
1429
  break;
1004
1430
  }
1005
- _context5.n = 2;
1006
- return response.text();
1431
+ _context7.n = 2;
1432
+ return throwSimulationError('Failed to batch reads from simulation', response);
1007
1433
  case 2:
1008
- text = _context5.v;
1009
- throw new Error("Failed to batch reads from simulation: " + text);
1010
- case 3:
1011
- return _context5.a(2, response.json());
1434
+ return _context7.a(2, response.json());
1012
1435
  }
1013
- }, _callee5);
1436
+ }, _callee7);
1014
1437
  }));
1015
1438
  return _simulationBatchReads.apply(this, arguments);
1016
1439
  }
1017
1440
 
1441
+ /**
1442
+ * Override the spending condition's `signer` (and `hashMode`) so the
1443
+ * simulator treats `tx-sender` as `sender`.
1444
+ *
1445
+ * Single-sig and multi-sig flavours are both handled — the multi-sig
1446
+ * spending condition is rebuilt with empty signature fields because
1447
+ * the simulator never validates signatures.
1448
+ */
1018
1449
  function setSender(tx, sender) {
1019
1450
  var _c32addressDecode = c32check.c32addressDecode(sender),
1020
1451
  addressVersion = _c32addressDecode[0],
@@ -1039,9 +1470,86 @@ function setSender(tx, sender) {
1039
1470
  };
1040
1471
  break;
1041
1472
  }
1473
+ default:
1474
+ throw new Error("unsupported address version: " + addressVersion);
1042
1475
  }
1043
1476
  return tx;
1044
1477
  }
1478
+ /**
1479
+ * Build an unsigned contract-call transaction with `sender` patched
1480
+ * in via {@link setSender}, then return the serialized hex (no `0x`
1481
+ * prefix). Drop the result directly into `{ Transaction: <hex> }`.
1482
+ *
1483
+ * @example
1484
+ * ```typescript
1485
+ * import { Cl } from '@stacks/transactions';
1486
+ * import { buildUnsignedContractCallHex } from 'stxer';
1487
+ *
1488
+ * const txHex = await buildUnsignedContractCallHex({
1489
+ * sender: 'SP3573...',
1490
+ * contract: 'SM3VDXK...sbtc-deposit',
1491
+ * functionName: 'complete-deposit-wrapper',
1492
+ * functionArgs: [Cl.bufferFromHex(txid), Cl.uint(0), Cl.uint(amount), ...],
1493
+ * nonce: 5,
1494
+ * });
1495
+ * await submitSimulationSteps(sim, { steps: [{ Transaction: txHex }] });
1496
+ * ```
1497
+ */
1498
+ function buildUnsignedContractCallHex(_x) {
1499
+ return _buildUnsignedContractCallHex.apply(this, arguments);
1500
+ }
1501
+ /**
1502
+ * Build a `Cl.contractPrincipal` from a `"SP….name"` id string.
1503
+ * Trips on standard principals or malformed ids — those should use
1504
+ * `Cl.principal` directly.
1505
+ */
1506
+ function _buildUnsignedContractCallHex() {
1507
+ _buildUnsignedContractCallHex = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(args) {
1508
+ var _args$fee, _args$network, _args$postConditionMo;
1509
+ var _args$contract$split, contractAddress, contractName, tx;
1510
+ return _regenerator().w(function (_context) {
1511
+ while (1) switch (_context.n) {
1512
+ case 0:
1513
+ _args$contract$split = args.contract.split('.'), contractAddress = _args$contract$split[0], contractName = _args$contract$split[1];
1514
+ if (contractName) {
1515
+ _context.n = 1;
1516
+ break;
1517
+ }
1518
+ throw new Error("bad contract id \"" + args.contract + "\" \u2014 expected SP\u2026.name");
1519
+ case 1:
1520
+ _context.n = 2;
1521
+ return transactions.makeUnsignedContractCall({
1522
+ contractAddress: contractAddress,
1523
+ contractName: contractName,
1524
+ functionName: args.functionName,
1525
+ functionArgs: args.functionArgs,
1526
+ fee: (_args$fee = args.fee) != null ? _args$fee : 1000,
1527
+ nonce: args.nonce,
1528
+ // Dummy 33-byte compressed pubkey. The simulator never validates
1529
+ // the signature; setSender overwrites the derived signer hash.
1530
+ publicKey: '0'.repeat(66),
1531
+ network: (_args$network = args.network) != null ? _args$network : 'mainnet',
1532
+ postConditionMode: (_args$postConditionMo = args.postConditionMode) != null ? _args$postConditionMo : transactions.PostConditionMode.Allow
1533
+ });
1534
+ case 2:
1535
+ tx = _context.v;
1536
+ setSender(tx, args.sender);
1537
+ return _context.a(2, transactions.serializeTransaction(tx));
1538
+ }
1539
+ }, _callee);
1540
+ }));
1541
+ return _buildUnsignedContractCallHex.apply(this, arguments);
1542
+ }
1543
+ function ftPrincipal(contractId) {
1544
+ var _contractId$split = contractId.split('.'),
1545
+ addr = _contractId$split[0],
1546
+ name = _contractId$split[1];
1547
+ if (!name) {
1548
+ throw new Error("bad contract id \"" + contractId + "\" \u2014 expected SP\u2026.name");
1549
+ }
1550
+ return transactions.Cl.contractPrincipal(addr, name);
1551
+ }
1552
+
1045
1553
  var SimulationBuilder = /*#__PURE__*/function () {
1046
1554
  function SimulationBuilder(options) {
1047
1555
  var _options$network, _options$apiEndpoint, _options$stacksNodeAP, _options$skipTracing;
@@ -1052,8 +1560,7 @@ var SimulationBuilder = /*#__PURE__*/function () {
1052
1560
  this.stacksNodeAPI = void 0;
1053
1561
  this.network = void 0;
1054
1562
  this.skipTracing = void 0;
1055
- // biome-ignore lint/style/useNumberNamespace: ignore this
1056
- this.block = NaN;
1563
+ this.block = Number.NaN;
1057
1564
  this.sender = '';
1058
1565
  this.steps = [];
1059
1566
  this.network = (_options$network = options.network) != null ? _options$network : 'mainnet';
@@ -1110,7 +1617,7 @@ var SimulationBuilder = /*#__PURE__*/function () {
1110
1617
  this.steps.push(_extends({}, params, {
1111
1618
  deployer: (_params$deployer = params.deployer) != null ? _params$deployer : this.sender,
1112
1619
  fee: (_params$fee3 = params.fee) != null ? _params$fee3 : 0,
1113
- clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : transactions.ClarityVersion.Clarity4
1620
+ clarity_version: (_params$clarity_versi = params.clarity_version) != null ? _params$clarity_versi : transactions.ClarityVersion.Clarity5
1114
1621
  }));
1115
1622
  return this;
1116
1623
  };
@@ -1141,7 +1648,7 @@ var SimulationBuilder = /*#__PURE__*/function () {
1141
1648
  type: 'SetContractCode',
1142
1649
  contract_id: params.contract_id,
1143
1650
  source_code: params.source_code,
1144
- clarity_version: (_params$clarity_versi2 = params.clarity_version) != null ? _params$clarity_versi2 : transactions.ClarityVersion.Clarity4
1651
+ clarity_version: (_params$clarity_versi2 = params.clarity_version) != null ? _params$clarity_versi2 : transactions.ClarityVersion.Clarity5
1145
1652
  });
1146
1653
  return this;
1147
1654
  };
@@ -1151,10 +1658,50 @@ var SimulationBuilder = /*#__PURE__*/function () {
1151
1658
  reads: reads
1152
1659
  });
1153
1660
  return this;
1154
- };
1155
- _proto.addTenureExtend = function addTenureExtend() {
1661
+ }
1662
+ /**
1663
+ * Add a `TenureExtend` step. Defaults to `cause: 'Extended'` (full
1664
+ * cost reset) — equivalent in server-side behavior to the legacy
1665
+ * zero-arg call.
1666
+ *
1667
+ * Pass an explicit `TenureExtendCause` to reset only one SIP-034
1668
+ * dimension (`ExtendedRuntime` / `ExtendedReadCount` / etc.).
1669
+ *
1670
+ * On the wire SDK 0.8.0 emits the modern `{ TenureExtend: { cause } }`
1671
+ * shape. The server still parses the legacy `[]` shape for any
1672
+ * caller emitting raw step objects.
1673
+ */;
1674
+ _proto.addTenureExtend = function addTenureExtend(cause) {
1675
+ if (cause === void 0) {
1676
+ cause = 'Extended';
1677
+ }
1156
1678
  this.steps.push({
1157
- type: 'TenureExtend'
1679
+ type: 'TenureExtend',
1680
+ cause: cause
1681
+ });
1682
+ return this;
1683
+ }
1684
+ /**
1685
+ * Synthesize bitcoin and stacks blocks on top of the simulation's
1686
+ * pinned parent tip. Used to model burn-block / tenure boundaries
1687
+ * (bridge contracts, time-locked redemptions, locked-STX unlock).
1688
+ *
1689
+ * The simulator validates the request shape; older simulator builds
1690
+ * that don't yet support `AdvanceBlocks` reject this variant with
1691
+ * HTTP 400.
1692
+ *
1693
+ * @example
1694
+ * ```typescript
1695
+ * builder.addAdvanceBlocks({
1696
+ * bitcoin_blocks: 1,
1697
+ * stacks_blocks_per_bitcoin: 1,
1698
+ * });
1699
+ * ```
1700
+ */;
1701
+ _proto.addAdvanceBlocks = function addAdvanceBlocks(request) {
1702
+ this.steps.push({
1703
+ type: 'AdvanceBlocks',
1704
+ request: request
1158
1705
  });
1159
1706
  return this;
1160
1707
  };
@@ -1369,9 +1916,17 @@ var SimulationBuilder = /*#__PURE__*/function () {
1369
1916
  Reads: step.reads
1370
1917
  });
1371
1918
  } else if (step.type === 'TenureExtend') {
1372
- // TenureExtend - format: []
1919
+ // TenureExtend - modern wire shape (legacy `[]` is still parsed
1920
+ // server-side for direct-emit consumers, but the builder always
1921
+ // emits the explicit cause).
1373
1922
  v2Steps.push({
1374
- TenureExtend: []
1923
+ TenureExtend: {
1924
+ cause: step.cause
1925
+ }
1926
+ });
1927
+ } else if (step.type === 'AdvanceBlocks') {
1928
+ v2Steps.push({
1929
+ AdvanceBlocks: step.request
1375
1930
  });
1376
1931
  } else {
1377
1932
  console.log("Invalid simulation step: " + step);
@@ -1412,12 +1967,6 @@ var SimulationBuilder = /*#__PURE__*/function () {
1412
1967
  };
1413
1968
  return SimulationBuilder;
1414
1969
  }();
1415
- // Helper function to convert Uint8Array to hex string
1416
- function bytesToHex(bytes) {
1417
- return Array.from(bytes).map(function (b) {
1418
- return b.toString(16).padStart(2, '0');
1419
- }).join('');
1420
- }
1421
1970
  // Helper function to convert ClarityVersion to number
1422
1971
  function clarityVersionToNumber(version) {
1423
1972
  switch (version) {
@@ -1429,10 +1978,242 @@ function clarityVersionToNumber(version) {
1429
1978
  return 3;
1430
1979
  case transactions.ClarityVersion.Clarity4:
1431
1980
  return 4;
1981
+ case transactions.ClarityVersion.Clarity5:
1982
+ return 5;
1432
1983
  default:
1433
- return 4;
1984
+ return 5;
1434
1985
  }
1435
1986
  }
1987
+ /**
1988
+ * Build, submit, and decode a contract-call transaction. The caller
1989
+ * supplies the principal to use as `tx-sender`; nonce is auto-fetched
1990
+ * via {@link getNonce} unless `nonce` is explicitly provided.
1991
+ */
1992
+ function callContract(_x2, _x3, _x4) {
1993
+ return _callContract.apply(this, arguments);
1994
+ }
1995
+ /**
1996
+ * Read the SIP-010 / hBTC-style `(get-balance principal)` value.
1997
+ * Returns 0n if the read returns `(err …)`. Throws on infra failures.
1998
+ */
1999
+ function _callContract() {
2000
+ _callContract = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId, args, options) {
2001
+ var _args$nonce;
2002
+ var nonce, txHex, r, step, receipt, _t, _t2;
2003
+ return _regenerator().w(function (_context4) {
2004
+ while (1) switch (_context4.n) {
2005
+ case 0:
2006
+ if (options === void 0) {
2007
+ options = {};
2008
+ }
2009
+ if (!((_args$nonce = args.nonce) != null)) {
2010
+ _context4.n = 1;
2011
+ break;
2012
+ }
2013
+ _t = _args$nonce;
2014
+ _context4.n = 3;
2015
+ break;
2016
+ case 1:
2017
+ _t2 = Number;
2018
+ _context4.n = 2;
2019
+ return getNonce(sessionId, args.sender, options);
2020
+ case 2:
2021
+ _t = _t2(_context4.v);
2022
+ case 3:
2023
+ nonce = _t;
2024
+ _context4.n = 4;
2025
+ return buildUnsignedContractCallHex(_extends({}, args, {
2026
+ nonce: nonce
2027
+ }));
2028
+ case 4:
2029
+ txHex = _context4.v;
2030
+ _context4.n = 5;
2031
+ return submitSimulationSteps(sessionId, {
2032
+ steps: [{
2033
+ Transaction: txHex
2034
+ }]
2035
+ }, options);
2036
+ case 5:
2037
+ r = _context4.v;
2038
+ step = r.steps[0];
2039
+ if ('Transaction' in step) {
2040
+ _context4.n = 6;
2041
+ break;
2042
+ }
2043
+ throw new Error("expected Transaction step, got " + JSON.stringify(step).slice(0, 200));
2044
+ case 6:
2045
+ if (!('Err' in step.Transaction)) {
2046
+ _context4.n = 7;
2047
+ break;
2048
+ }
2049
+ throw new Error("Transaction Err: " + step.Transaction.Err);
2050
+ case 7:
2051
+ receipt = step.Transaction.Ok;
2052
+ return _context4.a(2, {
2053
+ result: transactions.cvToString(transactions.deserializeCV(receipt.result)),
2054
+ resultHex: receipt.result,
2055
+ vmError: receipt.vm_error,
2056
+ pcAborted: receipt.post_condition_aborted,
2057
+ receipt: receipt
2058
+ });
2059
+ }
2060
+ }, _callee4);
2061
+ }));
2062
+ return _callContract.apply(this, arguments);
2063
+ }
2064
+ function getFtBalance(_x5, _x6, _x7, _x8) {
2065
+ return _getFtBalance.apply(this, arguments);
2066
+ }
2067
+ /** Read a principal's STX balance (uSTX) from a simulation session. */
2068
+ function _getFtBalance() {
2069
+ _getFtBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId, contractId, principal, options) {
2070
+ var _r$readonly;
2071
+ var r, v, decoded;
2072
+ return _regenerator().w(function (_context5) {
2073
+ while (1) switch (_context5.n) {
2074
+ case 0:
2075
+ if (options === void 0) {
2076
+ options = {};
2077
+ }
2078
+ _context5.n = 1;
2079
+ return simulationBatchReads(sessionId, {
2080
+ readonly: [[contractId, 'get-balance', transactions.serializeCV(transactions.Cl.principal(principal))]]
2081
+ }, options);
2082
+ case 1:
2083
+ r = _context5.v;
2084
+ v = (_r$readonly = r.readonly) == null ? void 0 : _r$readonly[0];
2085
+ if (!(!v || !('Ok' in v))) {
2086
+ _context5.n = 2;
2087
+ break;
2088
+ }
2089
+ throw new Error("get-balance(" + contractId + ") failed: " + JSON.stringify(v));
2090
+ case 2:
2091
+ decoded = transactions.deserializeCV(v.Ok);
2092
+ if (!(decoded.type === transactions.ClarityType.ResponseErr)) {
2093
+ _context5.n = 3;
2094
+ break;
2095
+ }
2096
+ return _context5.a(2, 0n);
2097
+ case 3:
2098
+ if (!(decoded.type !== transactions.ClarityType.ResponseOk)) {
2099
+ _context5.n = 4;
2100
+ break;
2101
+ }
2102
+ throw new Error("unexpected get-balance shape: " + transactions.cvToString(decoded));
2103
+ case 4:
2104
+ if (!(decoded.value.type !== transactions.ClarityType.UInt)) {
2105
+ _context5.n = 5;
2106
+ break;
2107
+ }
2108
+ throw new Error("expected uint inside (ok \u2026), got " + decoded.value.type);
2109
+ case 5:
2110
+ return _context5.a(2, BigInt(decoded.value.value));
2111
+ }
2112
+ }, _callee5);
2113
+ }));
2114
+ return _getFtBalance.apply(this, arguments);
2115
+ }
2116
+ function getStxBalance(_x9, _x0, _x1) {
2117
+ return _getStxBalance.apply(this, arguments);
2118
+ }
2119
+ /** Read a principal's current nonce. Returns 0n if never seen. */
2120
+ function _getStxBalance() {
2121
+ _getStxBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(sessionId, principal, options) {
2122
+ var _r$stx;
2123
+ var r, v;
2124
+ return _regenerator().w(function (_context6) {
2125
+ while (1) switch (_context6.n) {
2126
+ case 0:
2127
+ if (options === void 0) {
2128
+ options = {};
2129
+ }
2130
+ _context6.n = 1;
2131
+ return simulationBatchReads(sessionId, {
2132
+ stx: [principal]
2133
+ }, options);
2134
+ case 1:
2135
+ r = _context6.v;
2136
+ v = (_r$stx = r.stx) == null ? void 0 : _r$stx[0];
2137
+ if (!(!v || !('Ok' in v))) {
2138
+ _context6.n = 2;
2139
+ break;
2140
+ }
2141
+ throw new Error("stx balance read for " + principal + " failed");
2142
+ case 2:
2143
+ return _context6.a(2, BigInt(v.Ok));
2144
+ }
2145
+ }, _callee6);
2146
+ }));
2147
+ return _getStxBalance.apply(this, arguments);
2148
+ }
2149
+ function getNonce(_x10, _x11, _x12) {
2150
+ return _getNonce.apply(this, arguments);
2151
+ }
2152
+ /**
2153
+ * Read a Clarity data variable. Returns the decoded `ClarityValue`,
2154
+ * or throws if the read failed.
2155
+ */
2156
+ function _getNonce() {
2157
+ _getNonce = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(sessionId, principal, options) {
2158
+ var _r$nonces;
2159
+ var r, v;
2160
+ return _regenerator().w(function (_context7) {
2161
+ while (1) switch (_context7.n) {
2162
+ case 0:
2163
+ if (options === void 0) {
2164
+ options = {};
2165
+ }
2166
+ _context7.n = 1;
2167
+ return simulationBatchReads(sessionId, {
2168
+ nonces: [principal]
2169
+ }, options);
2170
+ case 1:
2171
+ r = _context7.v;
2172
+ v = (_r$nonces = r.nonces) == null ? void 0 : _r$nonces[0];
2173
+ if (!(!v || !('Ok' in v))) {
2174
+ _context7.n = 2;
2175
+ break;
2176
+ }
2177
+ return _context7.a(2, 0n);
2178
+ case 2:
2179
+ return _context7.a(2, BigInt(v.Ok));
2180
+ }
2181
+ }, _callee7);
2182
+ }));
2183
+ return _getNonce.apply(this, arguments);
2184
+ }
2185
+ function readDataVar(_x13, _x14, _x15, _x16) {
2186
+ return _readDataVar.apply(this, arguments);
2187
+ }
2188
+ function _readDataVar() {
2189
+ _readDataVar = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(sessionId, contractId, varName, options) {
2190
+ var _r$vars;
2191
+ var r, v;
2192
+ return _regenerator().w(function (_context8) {
2193
+ while (1) switch (_context8.n) {
2194
+ case 0:
2195
+ if (options === void 0) {
2196
+ options = {};
2197
+ }
2198
+ _context8.n = 1;
2199
+ return simulationBatchReads(sessionId, {
2200
+ vars: [[contractId, varName]]
2201
+ }, options);
2202
+ case 1:
2203
+ r = _context8.v;
2204
+ v = (_r$vars = r.vars) == null ? void 0 : _r$vars[0];
2205
+ if (!(!v || !('Ok' in v))) {
2206
+ _context8.n = 2;
2207
+ break;
2208
+ }
2209
+ throw new Error("var-get " + contractId + " " + varName + " failed: " + JSON.stringify(v));
2210
+ case 2:
2211
+ return _context8.a(2, transactions.deserializeCV(v.Ok));
2212
+ }
2213
+ }, _callee8);
2214
+ }));
2215
+ return _readDataVar.apply(this, arguments);
2216
+ }
1436
2217
 
1437
2218
  /**
1438
2219
  * Fetch the current tip information from the sidecar.
@@ -1498,17 +2279,39 @@ exports.DEFAULT_STXER_API = DEFAULT_STXER_API$1;
1498
2279
  exports.STXER_API_MAINNET = STXER_API_MAINNET;
1499
2280
  exports.STXER_API_TESTNET = STXER_API_TESTNET;
1500
2281
  exports.SimulationBuilder = SimulationBuilder;
2282
+ exports.SimulationError = SimulationError;
1501
2283
  exports.batchRead = batchRead;
2284
+ exports.buildBitcoinHeader = buildBitcoinHeader;
2285
+ exports.buildUnsignedContractCallHex = buildUnsignedContractCallHex;
2286
+ exports.bytesToHex = bytesToHex;
2287
+ exports.callContract = callContract;
1502
2288
  exports.callReadonly = callReadonly;
1503
2289
  exports.createSimulationSession = createSimulationSession;
2290
+ exports.forgeBitcoinTx = forgeBitcoinTx;
2291
+ exports.ftPrincipal = ftPrincipal;
1504
2292
  exports.getContractAST = getContractAST;
2293
+ exports.getFtBalance = getFtBalance;
2294
+ exports.getNonce = getNonce;
1505
2295
  exports.getSimulationResult = getSimulationResult;
2296
+ exports.getSimulationTip = getSimulationTip;
2297
+ exports.getStxBalance = getStxBalance;
1506
2298
  exports.getTip = getTip;
2299
+ exports.hexToBytes = hexToBytes;
1507
2300
  exports.instantSimulation = instantSimulation;
2301
+ exports.merkleProof = merkleProof;
2302
+ exports.opReturnScript = opReturnScript;
2303
+ exports.p2pkhScript = p2pkhScript;
2304
+ exports.p2wpkhScript = p2wpkhScript;
1508
2305
  exports.parseContract = parseContract;
1509
2306
  exports.parseSimulationEvent = parseSimulationEvent;
2307
+ exports.readDataVar = readDataVar;
1510
2308
  exports.readMap = readMap;
1511
2309
  exports.readVariable = readVariable;
2310
+ exports.setSender = setSender;
2311
+ exports.sha256 = sha256;
2312
+ exports.sha256d = sha256d;
1512
2313
  exports.simulationBatchReads = simulationBatchReads;
2314
+ exports.singleTxMerkleRoot = singleTxMerkleRoot;
1513
2315
  exports.submitSimulationSteps = submitSimulationSteps;
2316
+ exports.verifyMerkleProof = verifyMerkleProof;
1514
2317
  //# sourceMappingURL=stxer.cjs.development.js.map