@babylonlabs-io/ts-sdk 0.4.0 → 0.4.1-rc.1

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 (35) hide show
  1. package/dist/{PayoutManager-BK1jKgL5.js → PayoutManager-B8vLG1dE.js} +95 -95
  2. package/dist/PayoutManager-B8vLG1dE.js.map +1 -0
  3. package/dist/{PayoutManager-CzKMN6xT.cjs → PayoutManager-Shw7TY5P.cjs} +2 -2
  4. package/dist/PayoutManager-Shw7TY5P.cjs.map +1 -0
  5. package/dist/challengeAssert-ClJYoKxJ.cjs +2 -0
  6. package/dist/challengeAssert-ClJYoKxJ.cjs.map +1 -0
  7. package/dist/{challengeAssert-Dvcg38_y.js → challengeAssert-ZXE00zkT.js} +200 -189
  8. package/dist/challengeAssert-ZXE00zkT.js.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +59 -56
  14. package/dist/index.js.map +1 -1
  15. package/dist/tbv/core/index.cjs +1 -1
  16. package/dist/tbv/core/index.js +63 -62
  17. package/dist/tbv/core/managers/PeginManager.d.ts +6 -4
  18. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  19. package/dist/tbv/core/primitives/__tests__/challengers.test.d.ts +2 -0
  20. package/dist/tbv/core/primitives/__tests__/challengers.test.d.ts.map +1 -0
  21. package/dist/tbv/core/primitives/challengers.d.ts +23 -0
  22. package/dist/tbv/core/primitives/challengers.d.ts.map +1 -0
  23. package/dist/tbv/core/primitives/index.cjs +1 -1
  24. package/dist/tbv/core/primitives/index.d.ts +4 -0
  25. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  26. package/dist/tbv/core/primitives/index.js +23 -22
  27. package/dist/tbv/index.cjs +1 -1
  28. package/dist/tbv/index.js +63 -62
  29. package/package.json +19 -19
  30. package/LICENSE +0 -169
  31. package/dist/PayoutManager-BK1jKgL5.js.map +0 -1
  32. package/dist/PayoutManager-CzKMN6xT.cjs.map +0 -1
  33. package/dist/challengeAssert-DOa5L0kv.cjs +0 -2
  34. package/dist/challengeAssert-DOa5L0kv.cjs.map +0 -1
  35. package/dist/challengeAssert-Dvcg38_y.js.map +0 -1
@@ -3,15 +3,15 @@ var _ = (n, t, e) => t in n ? q(n, t, { enumerable: !0, configurable: !0, writab
3
3
  var H = (n, t, e) => _(n, typeof t != "symbol" ? t + "" : t, e);
4
4
  import * as L from "bitcoinjs-lib";
5
5
  import { script as j, Transaction as S, address as J, Psbt as C } from "bitcoinjs-lib";
6
- import { Buffer as g } from "buffer";
7
- import { P as Z, r as G, D as z, M as W, B as Q, T as Y, y as U, s as k, b as tt, x as et, a as nt, c as st, e as rt, p as I, n as at, v as V, d as M, f as R } from "./challengeAssert-Dvcg38_y.js";
6
+ import { Buffer as f } from "buffer";
7
+ import { P as Z, w as G, D, M as W, B as Q, T as Y, z as U, s as k, b as tt, y as et, a as nt, d as st, e as rt, q as I, o as at, v as V, f as M, g as R } from "./challengeAssert-ZXE00zkT.js";
8
8
  import { createPublicClient as K, http as N, encodeFunctionData as ot, zeroAddress as it } from "viem";
9
9
  import "@babylonlabs-io/babylon-tbv-rust-wasm";
10
10
  function ct(n, t, e) {
11
11
  if (n.length === 0)
12
12
  throw new Error("Insufficient funds: no UTXOs available");
13
13
  const s = n.filter((a) => {
14
- const u = g.from(a.scriptPubKey, "hex");
14
+ const u = f.from(a.scriptPubKey, "hex");
15
15
  return !!j.decompile(u);
16
16
  });
17
17
  if (s.length === 0)
@@ -22,8 +22,8 @@ function ct(n, t, e) {
22
22
  let c = 0n, i = 0n;
23
23
  for (const a of o) {
24
24
  r.push(a), c += BigInt(a.value);
25
- const u = r.length * Z, l = 2 * W, d = u + l + Y;
26
- if (i = BigInt(Math.ceil(d * e)) + BigInt(G(e)), c - t - i > z) {
25
+ const u = r.length * Z, l = 2 * W, p = u + l + Y;
26
+ if (i = BigInt(Math.ceil(p * e)) + BigInt(G(e)), c - t - i > D) {
27
27
  const h = BigInt(
28
28
  Math.ceil(W * e)
29
29
  );
@@ -44,7 +44,7 @@ function ct(n, t, e) {
44
44
  );
45
45
  }
46
46
  function wt(n) {
47
- return n > z;
47
+ return n > D;
48
48
  }
49
49
  function Tt() {
50
50
  return Q;
@@ -66,7 +66,7 @@ function vt(n, t, e) {
66
66
  const s = U(e), o = new S();
67
67
  o.version = 2;
68
68
  for (const a of n) {
69
- const u = g.from(a.txid, "hex").reverse();
69
+ const u = f.from(a.txid, "hex").reverse();
70
70
  o.addInput(u, a.vout);
71
71
  }
72
72
  const r = [];
@@ -75,9 +75,9 @@ function vt(n, t, e) {
75
75
  let l;
76
76
  try {
77
77
  l = J.toOutputScript(u.address, s);
78
- } catch (d) {
78
+ } catch (p) {
79
79
  throw new Error(
80
- `Failed to decode address "${u.address}": ${d instanceof Error ? d.message : String(d)}`
80
+ `Failed to decode address "${u.address}": ${p instanceof Error ? p.message : String(p)}`
81
81
  );
82
82
  }
83
83
  o.addOutput(l, Number(u.amount)), r.push({
@@ -99,9 +99,9 @@ function vt(n, t, e) {
99
99
  }
100
100
  function kt(n, t, e) {
101
101
  const s = S.fromHex(n), o = new C();
102
- if (o.setVersion(s.version), o.setLocktime(s.locktime), !g.isBuffer(e) || e.length !== 32)
102
+ if (o.setVersion(s.version), o.setLocktime(s.locktime), !f.isBuffer(e) || e.length !== 32)
103
103
  throw new Error(
104
- `Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${g.isBuffer(e) ? `${e.length}-byte Buffer` : typeof e}`
104
+ `Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${f.isBuffer(e) ? `${e.length}-byte Buffer` : typeof e}`
105
105
  );
106
106
  if (t.length !== s.ins.length)
107
107
  throw new Error(
@@ -111,26 +111,26 @@ function kt(n, t, e) {
111
111
  const c = s.ins[r], i = t[r];
112
112
  if (!i)
113
113
  throw new Error(`Missing UTXO data for input ${r}`);
114
- const a = g.from(c.hash).reverse().toString("hex"), u = c.index;
114
+ const a = f.from(c.hash).reverse().toString("hex"), u = c.index;
115
115
  if (i.txid !== a || i.vout !== u)
116
116
  throw new Error(
117
117
  `Input ${r} outpoint mismatch: transaction expects ${a}:${u}, but UTXO ${i.txid}:${i.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
118
118
  );
119
- const l = g.from(i.scriptPubKey, "hex");
119
+ const l = f.from(i.scriptPubKey, "hex");
120
120
  if (!(l.length === 34 && l[0] === 81 && // OP_1 (witness version 1)
121
121
  l[1] === 32))
122
122
  throw new Error(
123
123
  `Input ${r} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${i.scriptPubKey.substring(0, 20)}...`
124
124
  );
125
- const f = {
126
- script: g.from(i.scriptPubKey, "hex"),
125
+ const y = {
126
+ script: f.from(i.scriptPubKey, "hex"),
127
127
  value: i.value
128
128
  };
129
129
  o.addInput({
130
130
  hash: c.hash,
131
131
  index: c.index,
132
132
  sequence: c.sequence,
133
- witnessUtxo: f,
133
+ witnessUtxo: y,
134
134
  tapInternalKey: e
135
135
  });
136
136
  }
@@ -156,7 +156,7 @@ function ut(n) {
156
156
  n[1] === 32 ? "P2TR" : "UNKNOWN";
157
157
  }
158
158
  function lt(n, t) {
159
- const e = g.from(n.scriptPubKey, "hex"), s = ut(e);
159
+ const e = f.from(n.scriptPubKey, "hex"), s = ut(e);
160
160
  switch (s) {
161
161
  case B.P2WPKH:
162
162
  return {
@@ -173,7 +173,7 @@ function lt(n, t) {
173
173
  script: e,
174
174
  value: n.value
175
175
  },
176
- witnessScript: g.from(n.witnessScript, "hex")
176
+ witnessScript: f.from(n.witnessScript, "hex")
177
177
  };
178
178
  }
179
179
  case B.P2TR: {
@@ -597,7 +597,7 @@ function Ct(n) {
597
597
  const e = t.substring(0, 10);
598
598
  return t in x || e in x;
599
599
  }
600
- function D(n) {
600
+ function z(n) {
601
601
  console.error("[Contract Error] Raw error:", n);
602
602
  const t = O(n);
603
603
  if (console.error("[Contract Error] Extracted error data:", t), t) {
@@ -650,7 +650,7 @@ class Ut {
650
650
  * @throws Error if wallet operations fail or insufficient funds
651
651
  */
652
652
  async prepareAtomicPegin(t) {
653
- const e = await this.config.btcWallet.getPublicKeyHex(), s = e.length === 66 ? e.slice(2) : e, o = k(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(k), c = t.universalChallengerBtcPubkeys.map(k), i = {
653
+ const e = await this.config.btcWallet.getPublicKeyHex(), s = e.length === 66 ? e.slice(2) : e, o = k(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(k), c = t.universalChallengerBtcPubkeys.map(k), i = r.length, a = {
654
654
  depositorPubkey: s,
655
655
  vaultProviderPubkey: o,
656
656
  vaultKeeperPubkeys: r,
@@ -658,28 +658,28 @@ class Ut {
658
658
  hashH: t.hashH,
659
659
  timelockRefund: t.timelockRefund,
660
660
  pegInAmount: t.amount,
661
- feeRate: BigInt(t.feeRate),
662
- numLocalChallengers: t.numLocalChallengers,
661
+ feeRate: t.protocolFeeRate,
662
+ numLocalChallengers: i,
663
663
  councilQuorum: t.councilQuorum,
664
664
  councilSize: t.councilSize,
665
665
  network: this.config.btcNetwork
666
- }, a = await tt(i), u = ct(
666
+ }, u = await tt(a), l = ct(
667
667
  [...t.availableUTXOs],
668
- a.totalOutputValue,
669
- t.feeRate
670
- ), l = U(this.config.btcNetwork), d = et({
671
- unfundedTxHex: a.psbtHex,
672
- selectedUTXOs: u.selectedUTXOs,
668
+ u.totalOutputValue,
669
+ t.mempoolFeeRate
670
+ ), p = U(this.config.btcNetwork), y = et({
671
+ unfundedTxHex: u.psbtHex,
672
+ selectedUTXOs: l.selectedUTXOs,
673
673
  changeAddress: t.changeAddress,
674
- changeAmount: u.changeAmount,
675
- network: l
676
- }), f = k(X(d)), h = await nt({
677
- prePeginParams: i,
674
+ changeAmount: l.changeAmount,
675
+ network: p
676
+ }), h = k(X(y)), b = await nt({
677
+ prePeginParams: a,
678
678
  timelockPegin: t.timelockPegin,
679
- fundedPrePeginTxid: f
679
+ fundedPrePeginTxid: h
680
680
  }), m = await st({
681
- peginTxHex: h.txHex,
682
- fundedPrePeginTxHex: d,
681
+ peginTxHex: b.txHex,
682
+ fundedPrePeginTxHex: y,
683
683
  depositorPubkey: s,
684
684
  vaultProviderPubkey: o,
685
685
  vaultKeeperPubkeys: r,
@@ -687,7 +687,7 @@ class Ut {
687
687
  hashH: t.hashH,
688
688
  timelockRefund: t.timelockRefund,
689
689
  network: this.config.btcNetwork
690
- }), P = await this.config.btcWallet.signPsbt(
690
+ }), d = await this.config.btcWallet.signPsbt(
691
691
  m.psbtHex,
692
692
  {
693
693
  autoFinalized: !1,
@@ -699,22 +699,22 @@ class Ut {
699
699
  }
700
700
  ]
701
701
  }
702
- ), p = rt(
703
- P,
702
+ ), g = rt(
703
+ d,
704
704
  s
705
705
  );
706
706
  return {
707
- fundedPrePeginTxHex: d,
708
- htlcValue: a.htlcValue,
709
- signedPeginInputPsbtHex: P,
710
- peginInputSignature: p,
711
- vaultScriptPubKey: h.vaultScriptPubKey,
712
- peginTxHex: h.txHex,
713
- prePeginTxid: f,
714
- peginTxid: h.txid,
715
- selectedUTXOs: u.selectedUTXOs,
716
- fee: u.fee,
717
- changeAmount: u.changeAmount
707
+ fundedPrePeginTxHex: y,
708
+ htlcValue: u.htlcValue,
709
+ signedPeginInputPsbtHex: d,
710
+ peginInputSignature: g,
711
+ vaultScriptPubKey: b.vaultScriptPubKey,
712
+ peginTxHex: b.txHex,
713
+ prePeginTxid: h,
714
+ peginTxid: b.txid,
715
+ selectedUTXOs: l.selectedUTXOs,
716
+ fee: l.fee,
717
+ changeAmount: l.changeAmount
718
718
  };
719
719
  }
720
720
  /**
@@ -743,53 +743,53 @@ class Ut {
743
743
  throw new Error(
744
744
  "Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)"
745
745
  );
746
- const a = g.from(i, "hex");
746
+ const a = f.from(i, "hex");
747
747
  if (a.length !== 32)
748
748
  throw new Error(
749
749
  `Invalid depositorBtcPubkey length: expected 32 bytes, got ${a.length}`
750
750
  );
751
- const u = this.config.mempoolApiUrl, l = r.ins.map((p) => {
752
- const y = g.from(p.hash).reverse().toString("hex"), b = p.index;
753
- return gt(y, b, u).then((w) => ({
754
- input: p,
751
+ const u = this.config.mempoolApiUrl, l = r.ins.map((d) => {
752
+ const g = f.from(d.hash).reverse().toString("hex"), P = d.index;
753
+ return gt(g, P, u).then((w) => ({
754
+ input: d,
755
755
  utxoData: w,
756
- txid: y,
757
- vout: b
756
+ txid: g,
757
+ vout: P
758
758
  }));
759
- }), d = await Promise.all(l);
760
- for (const { input: p, utxoData: y, txid: b, vout: w } of d) {
759
+ }), p = await Promise.all(l);
760
+ for (const { input: d, utxoData: g, txid: P, vout: w } of p) {
761
761
  const T = lt(
762
762
  {
763
- value: y.value,
764
- scriptPubKey: y.scriptPubKey
763
+ value: g.value,
764
+ scriptPubKey: g.scriptPubKey
765
765
  },
766
766
  a
767
767
  );
768
768
  c.addInput({
769
- hash: p.hash,
770
- index: p.index,
771
- sequence: p.sequence,
769
+ hash: d.hash,
770
+ index: d.index,
771
+ sequence: d.sequence,
772
772
  ...T
773
773
  });
774
774
  }
775
- for (const p of r.outs)
775
+ for (const d of r.outs)
776
776
  c.addOutput({
777
- script: p.script,
778
- value: p.value
777
+ script: d.script,
778
+ value: d.value
779
779
  });
780
- const f = await this.config.btcWallet.signPsbt(c.toHex()), h = C.fromHex(f);
780
+ const y = await this.config.btcWallet.signPsbt(c.toHex()), h = C.fromHex(y);
781
781
  try {
782
782
  h.finalizeAllInputs();
783
- } catch (p) {
783
+ } catch (d) {
784
784
  if (!h.data.inputs.every(
785
- (b) => b.finalScriptWitness || b.finalScriptSig
785
+ (P) => P.finalScriptWitness || P.finalScriptSig
786
786
  ))
787
787
  throw new Error(
788
- `PSBT finalization failed and wallet did not auto-finalize: ${p}`
788
+ `PSBT finalization failed and wallet did not auto-finalize: ${d}`
789
789
  );
790
790
  }
791
- const m = h.extractTransaction().toHex();
792
- return await pt(m, u);
791
+ const b = h.extractTransaction().toHex();
792
+ return await pt(b, u);
793
793
  }
794
794
  /**
795
795
  * Registers a peg-in on Ethereum by calling the BTCVaultsManager contract.
@@ -822,17 +822,17 @@ class Ut {
822
822
  } = t;
823
823
  if (!this.config.ethWallet.account)
824
824
  throw new Error("Ethereum wallet account not found");
825
- const d = this.config.ethWallet.account.address, f = await this.resolvePopSignature(
826
- d,
825
+ const p = this.config.ethWallet.account.address, y = await this.resolvePopSignature(
826
+ p,
827
827
  l
828
828
  );
829
829
  i && await i();
830
- const h = I(e), m = I(s), P = I(o), p = await this.resolvePayoutScriptPubKey(
830
+ const h = I(e), b = I(s), m = I(o), d = await this.resolvePayoutScriptPubKey(
831
831
  a
832
- ), y = X(P);
833
- if (await this.checkVaultExists(y))
832
+ ), g = X(m);
833
+ if (await this.checkVaultExists(g))
834
834
  throw new Error(
835
- `Vault already exists for this transaction (ID: ${y}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`
835
+ `Vault already exists for this transaction (ID: ${g}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`
836
836
  );
837
837
  const w = K({
838
838
  chain: this.config.ethChain,
@@ -851,47 +851,47 @@ class Ut {
851
851
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
852
852
  );
853
853
  }
854
- const A = ot({
854
+ const F = ot({
855
855
  abi: $,
856
856
  functionName: "submitPeginRequest",
857
857
  args: [
858
- d,
858
+ p,
859
859
  h,
860
- f,
860
+ y,
861
+ b,
861
862
  m,
862
- P,
863
863
  r,
864
864
  c,
865
- p,
865
+ d,
866
866
  u
867
867
  ]
868
868
  });
869
- let F;
869
+ let A;
870
870
  try {
871
- F = await w.estimateGas({
871
+ A = await w.estimateGas({
872
872
  to: this.config.vaultContracts.btcVaultsManager,
873
- data: A,
873
+ data: F,
874
874
  value: T,
875
875
  account: this.config.ethWallet.account.address
876
876
  });
877
877
  } catch (v) {
878
- D(v);
878
+ z(v);
879
879
  }
880
880
  try {
881
881
  return {
882
882
  ethTxHash: await this.config.ethWallet.sendTransaction({
883
883
  to: this.config.vaultContracts.btcVaultsManager,
884
- data: A,
884
+ data: F,
885
885
  value: T,
886
886
  account: this.config.ethWallet.account,
887
887
  chain: this.config.ethChain,
888
- gas: F
888
+ gas: A
889
889
  }),
890
- vaultId: y,
891
- btcPopSignature: f
890
+ vaultId: g,
891
+ btcPopSignature: y
892
892
  };
893
893
  } catch (v) {
894
- D(v);
894
+ z(v);
895
895
  }
896
896
  }
897
897
  /**
@@ -960,7 +960,7 @@ class Ut {
960
960
  o,
961
961
  "bip322-simple"
962
962
  );
963
- return r.startsWith("0x") ? r : `0x${g.from(r, "base64").toString("hex")}`;
963
+ return r.startsWith("0x") ? r : `0x${f.from(r, "base64").toString("hex")}`;
964
964
  }
965
965
  /**
966
966
  * Gets the configured Bitcoin network.
@@ -1150,6 +1150,6 @@ export {
1150
1150
  ct as s,
1151
1151
  $t as t,
1152
1152
  Ct as u,
1153
- D as v
1153
+ z as v
1154
1154
  };
1155
- //# sourceMappingURL=PayoutManager-BK1jKgL5.js.map
1155
+ //# sourceMappingURL=PayoutManager-B8vLG1dE.js.map