@babylonlabs-io/ts-sdk 0.38.1 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/{PeginManager-Cp2Tn5sH.js → PeginManager-DXrfY4d6.js} +388 -334
  2. package/dist/{PeginManager-Cp2Tn5sH.js.map → PeginManager-DXrfY4d6.js.map} +1 -1
  3. package/dist/PeginManager-zkTJOy_U.cjs +2 -0
  4. package/dist/{PeginManager-DaDs-bGr.cjs.map → PeginManager-zkTJOy_U.cjs.map} +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +128 -127
  7. package/dist/tbv/core/clients/eth/types.d.ts +2 -0
  8. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  9. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +5 -0
  10. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  11. package/dist/tbv/core/clients/index.cjs +1 -1
  12. package/dist/tbv/core/clients/index.js +1 -1
  13. package/dist/tbv/core/index.cjs +1 -1
  14. package/dist/tbv/core/index.js +125 -124
  15. package/dist/tbv/core/managers/PeginManager.d.ts +25 -0
  16. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  17. package/dist/tbv/core/managers/index.cjs +1 -1
  18. package/dist/tbv/core/managers/index.d.ts +2 -2
  19. package/dist/tbv/core/managers/index.d.ts.map +1 -1
  20. package/dist/tbv/core/managers/index.js +5 -4
  21. package/dist/tbv/index.cjs +1 -1
  22. package/dist/tbv/index.js +125 -124
  23. package/dist/{vault-registry-reader-CbJHSxVe.cjs → vault-registry-reader-BM_993Lb.cjs} +2 -2
  24. package/dist/{vault-registry-reader-CbJHSxVe.cjs.map → vault-registry-reader-BM_993Lb.cjs.map} +1 -1
  25. package/dist/{vault-registry-reader-BrARgFre.js → vault-registry-reader-DXvw-1f6.js} +28 -16
  26. package/dist/{vault-registry-reader-BrARgFre.js.map → vault-registry-reader-DXvw-1f6.js.map} +1 -1
  27. package/package.json +1 -1
  28. package/dist/PeginManager-DaDs-bGr.cjs +0 -2
@@ -1,100 +1,100 @@
1
- var Dt = Object.defineProperty;
2
- var zt = (n, t, e) => t in n ? Dt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
1
+ var qt = Object.defineProperty;
2
+ var zt = (n, t, e) => t in n ? qt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
3
  var x = (n, t, e) => zt(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { s as ot, c as St, H as qt, r as V, a as F, b as at, u as Gt, d as ct, e as lt, f as ut, g as jt } from "./sha2-BYVxyZzX.js";
4
+ import { s as it, c as It, H as Yt, r as M, a as X, b as lt, u as jt, d as ut, e as ht, f as dt, g as Zt } from "./sha2-BYVxyZzX.js";
5
5
  import * as Ct from "bitcoinjs-lib";
6
- import { Transaction as Zt, Psbt as ht } from "bitcoinjs-lib";
6
+ import { Transaction as Qt, Psbt as gt } from "bitcoinjs-lib";
7
7
  import { Buffer as J } from "buffer";
8
- import { isAddressEqual as dt, encodeFunctionData as ft, zeroAddress as Yt } from "viem";
9
- import { B as C } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
8
+ import { isAddressEqual as ft, encodeFunctionData as tt, zeroAddress as Jt } from "viem";
9
+ import { B as I } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
10
10
  import { h as H } from "./errors-CznAK5NB.js";
11
- import { expandWotsSeed as Qt, expandHashlockSecret as Jt, expandAuthAnchor as te, deriveVaultId as gt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
12
- import { b as pt, a as ee, f as mt } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
13
- import { b as ne, e as se, f as oe } from "./peginInput-BPRB9tUi.js";
14
- import { u as K, h as tt, e as B, p as re, i as wt, s as T, j as bt, X as ie } from "./bitcoin-B5aNKtsk.js";
15
- import { c as ae } from "./signing-DaLvGwQe.js";
16
- import { M as Pt } from "./validation-CxqROCno.js";
17
- import { c as ce, a as le } from "./PayoutManager-D29D-K-V.js";
18
- import { s as ue, f as G, i as he, w as yt } from "./waitForTransactionReceiptSmartAware-CmgFXFza.js";
19
- import { p as de, f as fe } from "./fundPeginTransaction-t-6TsHAY.js";
20
- import { p as ge, f as pe } from "./mempoolApi-CAIge7Nj.js";
21
- const N = /* @__PURE__ */ BigInt(2 ** 32 - 1), xt = /* @__PURE__ */ BigInt(32);
22
- function me(n, t = !1) {
23
- return t ? { h: Number(n & N), l: Number(n >> xt & N) } : { h: Number(n >> xt & N) | 0, l: Number(n & N) | 0 };
24
- }
11
+ import { expandWotsSeed as te, expandHashlockSecret as ee, expandAuthAnchor as ne, deriveVaultId as pt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
12
+ import { b as mt, a as se, f as bt } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
13
+ import { b as oe, e as re, f as ie } from "./peginInput-BPRB9tUi.js";
14
+ import { u as K, h as et, e as v, p as ae, i as wt, s as T, j as Pt, X as ce } from "./bitcoin-B5aNKtsk.js";
15
+ import { c as le } from "./signing-DaLvGwQe.js";
16
+ import { M as yt } from "./validation-CxqROCno.js";
17
+ import { c as ue, a as he } from "./PayoutManager-D29D-K-V.js";
18
+ import { s as de, f as z, i as ge, w as xt } from "./waitForTransactionReceiptSmartAware-CmgFXFza.js";
19
+ import { p as fe, f as pe } from "./fundPeginTransaction-t-6TsHAY.js";
20
+ import { p as me, f as be } from "./mempoolApi-CAIge7Nj.js";
21
+ const N = /* @__PURE__ */ BigInt(2 ** 32 - 1), kt = /* @__PURE__ */ BigInt(32);
25
22
  function we(n, t = !1) {
23
+ return t ? { h: Number(n & N), l: Number(n >> kt & N) } : { h: Number(n >> kt & N) | 0, l: Number(n & N) | 0 };
24
+ }
25
+ function Pe(n, t = !1) {
26
26
  const e = n.length;
27
27
  let s = new Uint32Array(e), o = new Uint32Array(e);
28
28
  for (let r = 0; r < e; r++) {
29
- const { h: i, l: a } = me(n[r], t);
29
+ const { h: i, l: a } = we(n[r], t);
30
30
  [s[r], o[r]] = [i, a];
31
31
  }
32
32
  return [s, o];
33
33
  }
34
- const be = (n, t, e) => n << e | t >>> 32 - e, Pe = (n, t, e) => t << e | n >>> 32 - e, ye = (n, t, e) => t << e - 32 | n >>> 64 - e, xe = (n, t, e) => n << e - 32 | t >>> 64 - e, U = 32, j = 32, et = 36, Ht = 32, D = 4, ke = D + U + D + Ht;
35
- function nt(n, t, e) {
34
+ const ye = (n, t, e) => n << e | t >>> 32 - e, xe = (n, t, e) => t << e | n >>> 32 - e, ke = (n, t, e) => t << e - 32 | n >>> 64 - e, Ee = (n, t, e) => n << e - 32 | t >>> 64 - e, U = 32, Y = 32, nt = 36, Ht = 32, D = 4, Te = D + U + D + Ht;
35
+ function st(n, t, e) {
36
36
  n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = e & 255;
37
37
  }
38
- function Ee(n) {
39
- if (n.txid.length !== j)
38
+ function _e(n) {
39
+ if (n.txid.length !== Y)
40
40
  throw new Error(
41
- `outpoint.txid must be exactly ${j} bytes, got ${n.txid.length}`
41
+ `outpoint.txid must be exactly ${Y} bytes, got ${n.txid.length}`
42
42
  );
43
43
  if (!Number.isInteger(n.vout) || n.vout < 0 || n.vout > 4294967295)
44
44
  throw new Error(`outpoint.vout must be a u32, got ${n.vout}`);
45
- const t = new Uint8Array(et);
46
- return t.set(n.txid, 0), nt(t, j, n.vout), t;
45
+ const t = new Uint8Array(nt);
46
+ return t.set(n.txid, 0), st(t, Y, n.vout), t;
47
47
  }
48
- function kt(n, t) {
48
+ function Et(n, t) {
49
49
  const e = Math.min(n.length, t.length);
50
50
  for (let s = 0; s < e; s++)
51
51
  if (n[s] !== t[s]) return n[s] - t[s];
52
52
  return n.length - t.length;
53
53
  }
54
- function Te(n) {
54
+ function Be(n) {
55
55
  if (n.length === 0)
56
56
  throw new Error(
57
57
  "buildFundingOutpointsCommitment: outpoints must be non-empty"
58
58
  );
59
- const t = n.map(Ee);
60
- t.sort(kt);
59
+ const t = n.map(_e);
60
+ t.sort(Et);
61
61
  for (let s = 1; s < t.length; s++)
62
- if (kt(t[s - 1], t[s]) === 0)
62
+ if (Et(t[s - 1], t[s]) === 0)
63
63
  throw new Error(
64
64
  "buildFundingOutpointsCommitment: duplicate outpoint detected"
65
65
  );
66
- const e = new Uint8Array(t.length * et);
66
+ const e = new Uint8Array(t.length * nt);
67
67
  for (let s = 0; s < t.length; s++)
68
- e.set(t[s], s * et);
69
- return ot(e);
68
+ e.set(t[s], s * nt);
69
+ return it(e);
70
70
  }
71
71
  function ve(n) {
72
72
  if (n.depositorBtcPubkey.length !== U)
73
73
  throw new Error(
74
74
  `vaultContext: depositorBtcPubkey must be exactly ${U} bytes, got ${n.depositorBtcPubkey.length}`
75
75
  );
76
- const t = Te(n.fundingOutpoints), e = new Uint8Array(ke);
76
+ const t = Be(n.fundingOutpoints), e = new Uint8Array(Te);
77
77
  let s = 0;
78
- return nt(e, s, U), s += D, e.set(n.depositorBtcPubkey, s), s += U, nt(e, s, Ht), s += D, e.set(t, s), e;
78
+ return st(e, s, U), s += D, e.set(n.depositorBtcPubkey, s), s += U, st(e, s, Ht), s += D, e.set(t, s), e;
79
79
  }
80
- const _e = "babylon-btc-vault", Ot = 32, Et = Ot * 2, Be = /^[0-9a-f]+$/;
81
- async function Ae(n, t) {
82
- const e = ve(t), s = K(e), o = await n.deriveContextHash(_e, s);
80
+ const Se = "babylon-btc-vault", Ot = 32, Tt = Ot * 2, Ae = /^[0-9a-f]+$/;
81
+ async function Ie(n, t) {
82
+ const e = ve(t), s = K(e), o = await n.deriveContextHash(Se, s);
83
83
  if (typeof o != "string")
84
84
  throw new Error(
85
85
  `deriveVaultRoot: wallet must return a string, got ${typeof o}`
86
86
  );
87
- if (o.length !== Et)
87
+ if (o.length !== Tt)
88
88
  throw new Error(
89
- `deriveVaultRoot: wallet must return a ${Et}-character hex string (${Ot} bytes), got length ${o.length}`
89
+ `deriveVaultRoot: wallet must return a ${Tt}-character hex string (${Ot} bytes), got length ${o.length}`
90
90
  );
91
- if (!Be.test(o))
91
+ if (!Ae.test(o))
92
92
  throw new Error(
93
93
  "deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
94
94
  );
95
- return tt(o);
95
+ return et(o);
96
96
  }
97
- const Ie = /* @__PURE__ */ Uint8Array.from([
97
+ const Ce = /* @__PURE__ */ Uint8Array.from([
98
98
  7,
99
99
  4,
100
100
  13,
@@ -111,36 +111,36 @@ const Ie = /* @__PURE__ */ Uint8Array.from([
111
111
  14,
112
112
  11,
113
113
  8
114
- ]), $t = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), Se = $t.map((n) => (9 * n + 5) % 16), Rt = /* @__PURE__ */ (() => {
115
- const e = [[$t], [Se]];
114
+ ]), $t = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), He = $t.map((n) => (9 * n + 5) % 16), Rt = /* @__PURE__ */ (() => {
115
+ const e = [[$t], [He]];
116
116
  for (let s = 0; s < 4; s++)
117
117
  for (let o of e)
118
- o.push(o[s].map((r) => Ie[r]));
118
+ o.push(o[s].map((r) => Ce[r]));
119
119
  return e;
120
- })(), Ut = Rt[0], Vt = Rt[1], Nt = /* @__PURE__ */ [
120
+ })(), Ut = Rt[0], Mt = Rt[1], Nt = /* @__PURE__ */ [
121
121
  [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
122
122
  [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
123
123
  [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
124
124
  [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
125
125
  [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
126
- ].map((n) => Uint8Array.from(n)), Ce = /* @__PURE__ */ Ut.map((n, t) => n.map((e) => Nt[t][e])), He = /* @__PURE__ */ Vt.map((n, t) => n.map((e) => Nt[t][e])), Oe = /* @__PURE__ */ Uint32Array.from([
126
+ ].map((n) => Uint8Array.from(n)), Oe = /* @__PURE__ */ Ut.map((n, t) => n.map((e) => Nt[t][e])), $e = /* @__PURE__ */ Mt.map((n, t) => n.map((e) => Nt[t][e])), Re = /* @__PURE__ */ Uint32Array.from([
127
127
  0,
128
128
  1518500249,
129
129
  1859775393,
130
130
  2400959708,
131
131
  2840853838
132
- ]), $e = /* @__PURE__ */ Uint32Array.from([
132
+ ]), Ue = /* @__PURE__ */ Uint32Array.from([
133
133
  1352829926,
134
134
  1548603684,
135
135
  1836072691,
136
136
  2053994217,
137
137
  0
138
138
  ]);
139
- function Tt(n, t, e, s) {
139
+ function _t(n, t, e, s) {
140
140
  return n === 0 ? t ^ e ^ s : n === 1 ? t & e | ~t & s : n === 2 ? (t | ~e) ^ s : n === 3 ? t & s | e & ~s : t ^ (e | ~s);
141
141
  }
142
- const M = /* @__PURE__ */ new Uint32Array(16);
143
- class Re extends qt {
142
+ const V = /* @__PURE__ */ new Uint32Array(16);
143
+ class Me extends Yt {
144
144
  constructor() {
145
145
  super(64, 20, 8, !0);
146
146
  x(this, "h0", 1732584193);
@@ -157,52 +157,52 @@ class Re extends qt {
157
157
  this.h0 = e | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
158
158
  }
159
159
  process(e, s) {
160
- for (let f = 0; f < 16; f++, s += 4)
161
- M[f] = e.getUint32(s, !0);
162
- let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, d = c, l = this.h3 | 0, m = l, w = this.h4 | 0, b = w;
163
- for (let f = 0; f < 5; f++) {
164
- const g = 4 - f, k = Oe[f], A = $e[f], E = Ut[f], p = Vt[f], P = Ce[f], y = He[f];
165
- for (let u = 0; u < 16; u++) {
166
- const h = V(o + Tt(f, i, c, l) + M[E[u]] + k, P[u]) + w | 0;
167
- o = w, w = l, l = V(c, 10) | 0, c = i, i = h;
160
+ for (let g = 0; g < 16; g++, s += 4)
161
+ V[g] = e.getUint32(s, !0);
162
+ let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, l = this.h3 | 0, m = l, b = this.h4 | 0, w = b;
163
+ for (let g = 0; g < 5; g++) {
164
+ const f = 4 - g, k = Re[g], S = Ue[g], E = Ut[g], p = Mt[g], P = Oe[g], y = $e[g];
165
+ for (let h = 0; h < 16; h++) {
166
+ const d = M(o + _t(g, i, c, l) + V[E[h]] + k, P[h]) + b | 0;
167
+ o = b, b = l, l = M(c, 10) | 0, c = i, i = d;
168
168
  }
169
- for (let u = 0; u < 16; u++) {
170
- const h = V(r + Tt(g, a, d, m) + M[p[u]] + A, y[u]) + b | 0;
171
- r = b, b = m, m = V(d, 10) | 0, d = a, a = h;
169
+ for (let h = 0; h < 16; h++) {
170
+ const d = M(r + _t(f, a, u, m) + V[p[h]] + S, y[h]) + w | 0;
171
+ r = w, w = m, m = M(u, 10) | 0, u = a, a = d;
172
172
  }
173
173
  }
174
- this.set(this.h1 + c + m | 0, this.h2 + l + b | 0, this.h3 + w + r | 0, this.h4 + o + a | 0, this.h0 + i + d | 0);
174
+ this.set(this.h1 + c + m | 0, this.h2 + l + w | 0, this.h3 + b + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
175
175
  }
176
176
  roundClean() {
177
- F(M);
177
+ X(V);
178
178
  }
179
179
  destroy() {
180
- this.destroyed = !0, F(this.buffer), this.set(0, 0, 0, 0, 0);
180
+ this.destroyed = !0, X(this.buffer), this.set(0, 0, 0, 0, 0);
181
181
  }
182
182
  }
183
- const Ue = /* @__PURE__ */ St(() => new Re()), Ve = BigInt(0), $ = BigInt(1), Ne = BigInt(2), Me = BigInt(7), We = BigInt(256), Le = BigInt(113), Mt = [], Wt = [], Lt = [];
183
+ const Ne = /* @__PURE__ */ It(() => new Me()), Ve = BigInt(0), $ = BigInt(1), Le = BigInt(2), We = BigInt(7), Fe = BigInt(256), Xe = BigInt(113), Vt = [], Lt = [], Wt = [];
184
184
  for (let n = 0, t = $, e = 1, s = 0; n < 24; n++) {
185
- [e, s] = [s, (2 * e + 3 * s) % 5], Mt.push(2 * (5 * s + e)), Wt.push((n + 1) * (n + 2) / 2 % 64);
185
+ [e, s] = [s, (2 * e + 3 * s) % 5], Vt.push(2 * (5 * s + e)), Lt.push((n + 1) * (n + 2) / 2 % 64);
186
186
  let o = Ve;
187
187
  for (let r = 0; r < 7; r++)
188
- t = (t << $ ^ (t >> Me) * Le) % We, t & Ne && (o ^= $ << ($ << BigInt(r)) - $);
189
- Lt.push(o);
188
+ t = (t << $ ^ (t >> We) * Xe) % Fe, t & Le && (o ^= $ << ($ << BigInt(r)) - $);
189
+ Wt.push(o);
190
190
  }
191
- const Xt = we(Lt, !0), Xe = Xt[0], Fe = Xt[1], vt = (n, t, e) => e > 32 ? ye(n, t, e) : be(n, t, e), _t = (n, t, e) => e > 32 ? xe(n, t, e) : Pe(n, t, e);
192
- function Ke(n, t = 24) {
191
+ const Ft = Pe(Wt, !0), Ke = Ft[0], De = Ft[1], Bt = (n, t, e) => e > 32 ? ke(n, t, e) : ye(n, t, e), vt = (n, t, e) => e > 32 ? Ee(n, t, e) : xe(n, t, e);
192
+ function Ge(n, t = 24) {
193
193
  const e = new Uint32Array(10);
194
194
  for (let s = 24 - t; s < 24; s++) {
195
195
  for (let i = 0; i < 10; i++)
196
196
  e[i] = n[i] ^ n[i + 10] ^ n[i + 20] ^ n[i + 30] ^ n[i + 40];
197
197
  for (let i = 0; i < 10; i += 2) {
198
- const a = (i + 8) % 10, c = (i + 2) % 10, d = e[c], l = e[c + 1], m = vt(d, l, 1) ^ e[a], w = _t(d, l, 1) ^ e[a + 1];
199
- for (let b = 0; b < 50; b += 10)
200
- n[i + b] ^= m, n[i + b + 1] ^= w;
198
+ const a = (i + 8) % 10, c = (i + 2) % 10, u = e[c], l = e[c + 1], m = Bt(u, l, 1) ^ e[a], b = vt(u, l, 1) ^ e[a + 1];
199
+ for (let w = 0; w < 50; w += 10)
200
+ n[i + w] ^= m, n[i + w + 1] ^= b;
201
201
  }
202
202
  let o = n[2], r = n[3];
203
203
  for (let i = 0; i < 24; i++) {
204
- const a = Wt[i], c = vt(o, r, a), d = _t(o, r, a), l = Mt[i];
205
- o = n[l], r = n[l + 1], n[l] = c, n[l + 1] = d;
204
+ const a = Lt[i], c = Bt(o, r, a), u = vt(o, r, a), l = Vt[i];
205
+ o = n[l], r = n[l + 1], n[l] = c, n[l + 1] = u;
206
206
  }
207
207
  for (let i = 0; i < 50; i += 10) {
208
208
  for (let a = 0; a < 10; a++)
@@ -210,11 +210,11 @@ function Ke(n, t = 24) {
210
210
  for (let a = 0; a < 10; a++)
211
211
  n[i + a] ^= ~e[(a + 2) % 10] & e[(a + 4) % 10];
212
212
  }
213
- n[0] ^= Xe[s], n[1] ^= Fe[s];
213
+ n[0] ^= Ke[s], n[1] ^= De[s];
214
214
  }
215
- F(e);
215
+ X(e);
216
216
  }
217
- class rt {
217
+ class at {
218
218
  // NOTE: we accept arguments in bytes instead of bits here.
219
219
  constructor(t, e, s, o = !1, r = 24) {
220
220
  x(this, "state");
@@ -228,18 +228,18 @@ class rt {
228
228
  x(this, "outputLen");
229
229
  x(this, "enableXOF", !1);
230
230
  x(this, "rounds");
231
- if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r, at(s, "outputLen"), !(0 < t && t < 200))
231
+ if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r, lt(s, "outputLen"), !(0 < t && t < 200))
232
232
  throw new Error("only keccak-f1600 function is supported");
233
- this.state = new Uint8Array(200), this.state32 = Gt(this.state);
233
+ this.state = new Uint8Array(200), this.state32 = jt(this.state);
234
234
  }
235
235
  clone() {
236
236
  return this._cloneInto();
237
237
  }
238
238
  keccak() {
239
- ct(this.state32), Ke(this.state32, this.rounds), ct(this.state32), this.posOut = 0, this.pos = 0;
239
+ ut(this.state32), Ge(this.state32, this.rounds), ut(this.state32), this.posOut = 0, this.pos = 0;
240
240
  }
241
241
  update(t) {
242
- lt(this), ut(t);
242
+ ht(this), dt(t);
243
243
  const { blockLen: e, state: s } = this, o = t.length;
244
244
  for (let r = 0; r < o; ) {
245
245
  const i = Math.min(e - this.pos, o - r);
@@ -257,7 +257,7 @@ class rt {
257
257
  t[s] ^= e, (e & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
258
258
  }
259
259
  writeInto(t) {
260
- lt(this, !1), ut(t), this.finish();
260
+ ht(this, !1), dt(t), this.finish();
261
261
  const e = this.state, { blockLen: s } = this;
262
262
  for (let o = 0, r = t.length; o < r; ) {
263
263
  this.posOut >= s && this.keccak();
@@ -272,10 +272,10 @@ class rt {
272
272
  return this.writeInto(t);
273
273
  }
274
274
  xof(t) {
275
- return at(t), this.xofInto(new Uint8Array(t));
275
+ return lt(t), this.xofInto(new Uint8Array(t));
276
276
  }
277
277
  digestInto(t) {
278
- if (jt(t, this), this.finished)
278
+ if (Zt(t, this), this.finished)
279
279
  throw new Error("digest() was already called");
280
280
  return this.writeInto(t), this.destroy(), t;
281
281
  }
@@ -283,30 +283,30 @@ class rt {
283
283
  return this.digestInto(new Uint8Array(this.outputLen));
284
284
  }
285
285
  destroy() {
286
- this.destroyed = !0, F(this.state);
286
+ this.destroyed = !0, X(this.state);
287
287
  }
288
288
  _cloneInto(t) {
289
289
  const { blockLen: e, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
290
- return t || (t = new rt(e, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
290
+ return t || (t = new at(e, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
291
291
  }
292
292
  }
293
- const De = (n, t, e, s = {}) => St(() => new rt(t, n, e), s), ze = /* @__PURE__ */ De(1, 136, 32), Bt = 64, v = 20, st = 4, Ft = 2, qe = 0, Ge = 1, W = [64, 64], je = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
294
- function it(n) {
295
- return Ue(ot(n));
293
+ const qe = (n, t, e, s = {}) => It(() => new at(t, n, e), s), ze = /* @__PURE__ */ qe(1, 136, 32), St = 64, _ = 20, ot = 4, Xt = 2, Ye = 0, je = 1, L = [64, 64], Ze = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
294
+ function ct(n) {
295
+ return Ne(it(n));
296
296
  }
297
297
  function Kt(n) {
298
298
  return (1 << n) - 1;
299
299
  }
300
- function Ze(n) {
300
+ function Qe(n) {
301
301
  let t = 1;
302
302
  for (; t * t < n + 1; ) t++;
303
303
  return Math.max(t, 2);
304
304
  }
305
- function Ye(n) {
306
- const t = st, e = n * Kt(t);
307
- return { d: t, n, checksum_radix: Ze(e) };
305
+ function Je(n) {
306
+ const t = ot, e = n * Kt(t);
307
+ return { d: t, n, checksum_radix: Qe(e) };
308
308
  }
309
- function Z(n, t) {
309
+ function j(n, t) {
310
310
  const e = [];
311
311
  let s = t;
312
312
  for (; s > 0; )
@@ -315,56 +315,56 @@ function Z(n, t) {
315
315
  o.set(n);
316
316
  for (let r = 0; r < e.length; r++)
317
317
  o[n.length + r] = e[r];
318
- return it(o);
318
+ return ct(o);
319
319
  }
320
- function Y(n, t) {
320
+ function Z(n, t) {
321
321
  let e = n;
322
322
  for (let s = 0; s < t; s++)
323
- e = it(e);
323
+ e = ct(e);
324
324
  return e;
325
325
  }
326
- function Qe(n, t) {
326
+ function tn(n, t) {
327
327
  const e = Kt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * e / t.checksum_radix), r = [];
328
328
  for (let l = 0; l < t.n; l++) {
329
- const m = Z(n, l + Ft), w = Y(m, e);
330
- r.push(Array.from(w));
329
+ const m = j(n, l + Xt), b = Z(m, e);
330
+ r.push(Array.from(b));
331
331
  }
332
- const i = Z(
332
+ const i = j(
333
333
  n,
334
- qe
335
- ), a = Y(
334
+ Ye
335
+ ), a = Z(
336
336
  i,
337
337
  s
338
- ), c = Z(
338
+ ), c = j(
339
339
  n,
340
- Ge
341
- ), d = Y(
340
+ je
341
+ ), u = Z(
342
342
  c,
343
343
  o
344
344
  );
345
345
  return {
346
346
  config: t,
347
347
  message_terminals: r,
348
- checksum_major_terminal: Array.from(d),
348
+ checksum_major_terminal: Array.from(u),
349
349
  checksum_minor_terminal: Array.from(a)
350
350
  };
351
351
  }
352
- async function Je(n) {
352
+ async function en(n) {
353
353
  try {
354
- if (n.length !== Bt)
354
+ if (n.length !== St)
355
355
  throw new Error(
356
- `WOTS seed must be exactly ${Bt} bytes, got ${n.length}`
356
+ `WOTS seed must be exactly ${St} bytes, got ${n.length}`
357
357
  );
358
358
  const t = [];
359
- for (let e = 0; e < W.length; e++) {
360
- const s = W[e], o = Ye(s), r = new Uint8Array(n.length + 1);
359
+ for (let e = 0; e < L.length; e++) {
360
+ const s = L[e], o = Je(s), r = new Uint8Array(n.length + 1);
361
361
  r.set(n), r[n.length] = e;
362
- const i = it(r);
362
+ const i = ct(r);
363
363
  try {
364
- const a = Qe(i, o);
365
- if (a.config.d !== st)
364
+ const a = tn(i, o);
365
+ if (a.config.d !== ot)
366
366
  throw new Error(
367
- `Block ${e}: expected d=${st}, got d=${a.config.d}`
367
+ `Block ${e}: expected d=${ot}, got d=${a.config.d}`
368
368
  );
369
369
  if (a.config.n !== s)
370
370
  throw new Error(
@@ -375,26 +375,26 @@ async function Je(n) {
375
375
  `Block ${e}: expected ${s} message terminals, got ${a.message_terminals.length}`
376
376
  );
377
377
  for (let c = 0; c < a.message_terminals.length; c++)
378
- if (a.message_terminals[c].length !== v)
378
+ if (a.message_terminals[c].length !== _)
379
379
  throw new Error(
380
- `Block ${e} terminal ${c}: expected ${v} bytes, got ${a.message_terminals[c].length}`
380
+ `Block ${e} terminal ${c}: expected ${_} bytes, got ${a.message_terminals[c].length}`
381
381
  );
382
- if (a.checksum_minor_terminal.length !== v)
382
+ if (a.checksum_minor_terminal.length !== _)
383
383
  throw new Error(
384
- `Block ${e} checksum_minor: expected ${v} bytes`
384
+ `Block ${e} checksum_minor: expected ${_} bytes`
385
385
  );
386
- if (a.checksum_major_terminal.length !== v)
386
+ if (a.checksum_major_terminal.length !== _)
387
387
  throw new Error(
388
- `Block ${e} checksum_major: expected ${v} bytes`
388
+ `Block ${e} checksum_major: expected ${_} bytes`
389
389
  );
390
390
  t.push(a);
391
391
  } finally {
392
392
  r.fill(0), i.fill(0);
393
393
  }
394
394
  }
395
- if (t.length !== W.length)
395
+ if (t.length !== L.length)
396
396
  throw new Error(
397
- `Expected ${W.length} blocks, got ${t.length}`
397
+ `Expected ${L.length} blocks, got ${t.length}`
398
398
  );
399
399
  return t;
400
400
  } finally {
@@ -402,9 +402,9 @@ async function Je(n) {
402
402
  }
403
403
  }
404
404
  function Q(n, t, e) {
405
- if (n.length !== v)
405
+ if (n.length !== _)
406
406
  throw new Error(
407
- `Block ${t} ${e}: expected ${v} bytes, got ${n.length}`
407
+ `Block ${t} ${e}: expected ${_} bytes, got ${n.length}`
408
408
  );
409
409
  for (let s = 0; s < n.length; s++) {
410
410
  const o = n[s];
@@ -414,7 +414,7 @@ function Q(n, t, e) {
414
414
  );
415
415
  }
416
416
  }
417
- function tn(n) {
417
+ function nn(n) {
418
418
  if (n.length === 0)
419
419
  throw new Error("Public keys array must not be empty");
420
420
  for (let r = 0; r < n.length; r++) {
@@ -425,32 +425,32 @@ function tn(n) {
425
425
  }
426
426
  let t = 0;
427
427
  for (const r of n)
428
- t += Ft + r.message_terminals.length;
429
- const e = new Uint8Array(t * v);
428
+ t += Xt + r.message_terminals.length;
429
+ const e = new Uint8Array(t * _);
430
430
  let s = 0;
431
431
  for (const r of n) {
432
- e.set(r.checksum_minor_terminal, s), s += v, e.set(r.checksum_major_terminal, s), s += v;
432
+ e.set(r.checksum_minor_terminal, s), s += _, e.set(r.checksum_major_terminal, s), s += _;
433
433
  for (const i of r.message_terminals)
434
- e.set(i, s), s += v;
434
+ e.set(i, s), s += _;
435
435
  }
436
436
  const o = ze(e);
437
- return `0x${je(o)}`;
437
+ return `0x${Ze(o)}`;
438
438
  }
439
- async function en(n, t) {
439
+ async function sn(n, t) {
440
440
  const e = [], s = [], o = [], r = [];
441
441
  try {
442
442
  for (let i = 0; i < t; i++) {
443
- const a = await Qt(n, i);
443
+ const a = await te(n, i);
444
444
  try {
445
- const d = await Je(a);
446
- e.push(d), s.push(tn(d));
445
+ const u = await en(a);
446
+ e.push(u), s.push(nn(u));
447
447
  } finally {
448
448
  a.fill(0);
449
449
  }
450
- const c = await Jt(n, i);
450
+ const c = await ee(n, i);
451
451
  try {
452
- const d = K(c);
453
- o.push(d), r.push(ce(B(d)).slice(2));
452
+ const u = K(c);
453
+ o.push(u), r.push(ue(v(u)).slice(2));
454
454
  } finally {
455
455
  c.fill(0);
456
456
  }
@@ -460,33 +460,33 @@ async function en(n, t) {
460
460
  }
461
461
  return { perVaultWotsKeys: e, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
462
462
  }
463
- const nn = /^0x[0-9a-f]+$/i, sn = /^[0-9a-f]+$/i, on = /^[A-Za-z0-9+/]+={0,2}$/;
463
+ const on = /^0x[0-9a-f]+$/i, rn = /^[0-9a-f]+$/i, an = /^[A-Za-z0-9+/]+={0,2}$/;
464
464
  function R(n) {
465
465
  if (typeof n != "string" || n.length === 0)
466
466
  throw new Error("BTC wallet returned empty public key");
467
- return re(n).toLowerCase();
467
+ return ae(n).toLowerCase();
468
468
  }
469
- function rn(n) {
469
+ function cn(n) {
470
470
  if (typeof n != "string" || n.length === 0)
471
471
  throw new Error("BTC wallet returned empty BIP-322 signature");
472
472
  if (n.startsWith("0x") || n.startsWith("0X")) {
473
- if (!nn.test(n) || n.length < 4 || n.length % 2 !== 0)
473
+ if (!on.test(n) || n.length < 4 || n.length % 2 !== 0)
474
474
  throw new Error("BTC wallet returned malformed hex BIP-322 signature");
475
475
  return n.toLowerCase();
476
476
  }
477
- if (sn.test(n)) {
477
+ if (rn.test(n)) {
478
478
  if (n.length % 2 !== 0)
479
479
  throw new Error("BTC wallet returned malformed hex BIP-322 signature");
480
480
  return `0x${n.toLowerCase()}`;
481
481
  }
482
- if (!on.test(n) || n.length % 4 !== 0)
482
+ if (!an.test(n) || n.length % 4 !== 0)
483
483
  throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
484
484
  const t = J.from(n, "base64");
485
485
  if (t.length === 0 || t.toString("base64") !== n)
486
486
  throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
487
487
  return `0x${t.toString("hex")}`;
488
488
  }
489
- async function an(n, t, e) {
489
+ async function ln(n, t, e) {
490
490
  if (typeof n.signPsbts == "function") {
491
491
  const o = await n.signPsbts(t, e);
492
492
  if (o.length !== t.length)
@@ -502,8 +502,8 @@ async function an(n, t, e) {
502
502
  }
503
503
  return s;
504
504
  }
505
- const cn = 0, L = 25, At = 9999, X = "00".repeat(32);
506
- function ln(n, t) {
505
+ const Dt = 0, W = 25, rt = 9999, F = "00".repeat(32);
506
+ function un(n, t) {
507
507
  const e = {
508
508
  bitcoin: "bc",
509
509
  testnet: "tb",
@@ -517,17 +517,17 @@ function ln(n, t) {
517
517
  return !1;
518
518
  }
519
519
  }
520
- function un(n, t, e, s) {
520
+ function hn(n, t, e, s) {
521
521
  const o = e == null ? void 0 : e[`${n}:${t}`];
522
522
  return o ? Promise.resolve({
523
523
  txid: n,
524
524
  vout: t,
525
525
  value: o.value,
526
526
  scriptPubKey: o.scriptPubKey
527
- }) : pe(n, t, s);
527
+ }) : be(n, t, s);
528
528
  }
529
- const It = 12e4;
530
- class An {
529
+ const At = 12e4;
530
+ class Rn {
531
531
  /**
532
532
  * Creates a new PeginManager instance.
533
533
  *
@@ -559,45 +559,45 @@ class An {
559
559
  `Pre-PegIn changeAddress "${t.changeAddress}" is not derived from the connected wallet's public key. Refusing to build a tx that would send change to an address the signing key doesn't control.`
560
560
  );
561
561
  const o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
562
- (g) => ({
563
- txid: tt(g.txid),
564
- vout: g.vout
562
+ (f) => ({
563
+ txid: et(f.txid),
564
+ vout: f.vout
565
565
  })
566
- ), i = await Ae(this.config.btcWallet, {
567
- depositorBtcPubkey: tt(s),
566
+ ), i = await Ie(this.config.btcWallet, {
567
+ depositorBtcPubkey: et(s),
568
568
  fundingOutpoints: r
569
569
  });
570
570
  let a, c;
571
571
  try {
572
- const g = await te(i);
572
+ const f = await ne(i);
573
573
  try {
574
- a = K(g), c = K(ot(g));
574
+ a = K(f), c = K(it(f));
575
575
  } finally {
576
- g.fill(0);
576
+ f.fill(0);
577
577
  }
578
- } catch (g) {
579
- throw i.fill(0), g;
578
+ } catch (f) {
579
+ throw i.fill(0), f;
580
580
  }
581
- const d = await en(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: w, hashlocks: b } = d, f = await this.preparePeginCommit({
581
+ const u = await sn(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: b, hashlocks: w } = u, g = await this.preparePeginCommit({
582
582
  depositorBtcPubkeyRaw: e,
583
583
  depositorBtcPubkey: s,
584
- hashlocks: b,
584
+ hashlocks: w,
585
585
  authAnchorHash: c,
586
586
  sizing: o,
587
587
  params: t
588
588
  });
589
- for (let g = 0; g < f.perVault.length; g++)
590
- if (f.perVault[g].htlcVout !== g)
589
+ for (let f = 0; f < g.perVault.length; f++)
590
+ if (g.perVault[f].htlcVout !== f)
591
591
  throw new Error(
592
- `Internal invariant violation: htlcVout/index mismatch at vault ${g} (expected ${g}, got ${f.perVault[g].htlcVout})`
592
+ `Internal invariant violation: htlcVout/index mismatch at vault ${f} (expected ${f}, got ${g.perVault[f].htlcVout})`
593
593
  );
594
- return le(
595
- f.fundedPrePeginTxHex,
594
+ return he(
595
+ g.fundedPrePeginTxHex,
596
596
  t.amounts.length,
597
597
  c
598
598
  ), {
599
599
  transaction: {
600
- ...f,
600
+ ...g,
601
601
  selectedUTXOs: o.selectedUTXOs,
602
602
  fee: o.fee,
603
603
  changeAmount: o.changeAmount
@@ -606,7 +606,7 @@ class An {
606
606
  derivedSecrets: {
607
607
  perVaultWotsKeys: l,
608
608
  wotsPkHashes: m,
609
- htlcSecretHexes: w,
609
+ htlcSecretHexes: b,
610
610
  authAnchorHex: a
611
611
  }
612
612
  };
@@ -629,8 +629,8 @@ class An {
629
629
  */
630
630
  async prepareSizing(t, e) {
631
631
  const s = e.amounts.map(
632
- () => X
633
- ), o = e.vaultKeeperBtcPubkeys.length, r = await pt({
632
+ () => F
633
+ ), o = e.vaultKeeperBtcPubkeys.length, r = await mt({
634
634
  depositorPubkey: t,
635
635
  vaultProviderPubkey: T(e.vaultProviderBtcPubkey),
636
636
  vaultKeeperPubkeys: e.vaultKeeperBtcPubkeys.map(T),
@@ -643,14 +643,14 @@ class An {
643
643
  councilQuorum: e.councilQuorum,
644
644
  councilSize: e.councilSize,
645
645
  network: this.config.btcNetwork,
646
- authAnchorHash: X
647
- }), i = ue(
646
+ authAnchorHash: F
647
+ }), i = de(
648
648
  [...e.availableUTXOs],
649
649
  r.totalOutputValue,
650
650
  e.mempoolFeeRate,
651
- de(
651
+ fe(
652
652
  r.htlcValues.length,
653
- X
653
+ F
654
654
  )
655
655
  );
656
656
  return {
@@ -668,85 +668,85 @@ class An {
668
668
  authAnchorHash: r,
669
669
  sizing: i,
670
670
  params: a
671
- } = t, c = X.toLowerCase();
672
- for (let h = 0; h < o.length; h++)
673
- if (o[h].toLowerCase() === c)
671
+ } = t, c = F.toLowerCase();
672
+ for (let d = 0; d < o.length; d++)
673
+ if (o[d].toLowerCase() === c)
674
674
  throw new Error(
675
- `preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${h} — internal substitution bug`
675
+ `preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${d} — internal substitution bug`
676
676
  );
677
677
  if (r.toLowerCase() === c)
678
678
  throw new Error(
679
679
  "preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
680
680
  );
681
- const d = T(a.vaultProviderBtcPubkey), l = a.vaultKeeperBtcPubkeys.map(T), m = a.universalChallengerBtcPubkeys.map(T), w = l.length, b = {
681
+ const u = T(a.vaultProviderBtcPubkey), l = a.vaultKeeperBtcPubkeys.map(T), m = a.universalChallengerBtcPubkeys.map(T), b = l.length, w = {
682
682
  depositorPubkey: s,
683
- vaultProviderPubkey: d,
683
+ vaultProviderPubkey: u,
684
684
  vaultKeeperPubkeys: l,
685
685
  universalChallengerPubkeys: m,
686
686
  hashlocks: o,
687
687
  timelockRefund: a.timelockRefund,
688
688
  pegInAmounts: a.amounts,
689
689
  feeRate: a.protocolFeeRate,
690
- numLocalChallengers: w,
690
+ numLocalChallengers: b,
691
691
  councilQuorum: a.councilQuorum,
692
692
  councilSize: a.councilSize,
693
693
  network: this.config.btcNetwork,
694
694
  authAnchorHash: r
695
- }, f = await pt(b), g = bt(this.config.btcNetwork), k = fe({
696
- unfundedTxHex: f.psbtHex,
695
+ }, g = await mt(w), f = Pt(this.config.btcNetwork), k = pe({
696
+ unfundedTxHex: g.psbtHex,
697
697
  selectedUTXOs: i.selectedUTXOs,
698
698
  changeAddress: a.changeAddress,
699
699
  changeAmount: i.changeAmount,
700
- network: g
701
- }), A = T(G(k)), E = [], p = [], P = [];
702
- for (let h = 0; h < o.length; h++) {
703
- const _ = await ee({
704
- prePeginParams: b,
700
+ network: f
701
+ }), S = T(z(k)), E = [], p = [], P = [];
702
+ for (let d = 0; d < o.length; d++) {
703
+ const B = await se({
704
+ prePeginParams: w,
705
705
  timelockPegin: a.timelockPegin,
706
706
  fundedPrePeginTxHex: k,
707
- htlcVout: h
708
- }), I = await ne({
709
- peginTxHex: _.txHex,
707
+ htlcVout: d
708
+ }), A = await oe({
709
+ peginTxHex: B.txHex,
710
710
  fundedPrePeginTxHex: k,
711
711
  depositorPubkey: s,
712
- vaultProviderPubkey: d,
712
+ vaultProviderPubkey: u,
713
713
  vaultKeeperPubkeys: l,
714
714
  universalChallengerPubkeys: m,
715
- hashlock: o[h],
715
+ hashlock: o[d],
716
716
  timelockRefund: a.timelockRefund,
717
717
  network: this.config.btcNetwork
718
718
  });
719
- E.push(_), p.push(I.psbtHex), P.push(
720
- ae(e, 1)
719
+ E.push(B), p.push(A.psbtHex), P.push(
720
+ le(e, 1)
721
721
  );
722
722
  }
723
- const y = await an(
723
+ const y = await ln(
724
724
  this.config.btcWallet,
725
725
  p,
726
726
  P
727
- ), u = [];
728
- for (let h = 0; h < y.length; h++) {
729
- mt({
730
- requestedPsbtHex: p[h],
731
- returnedPsbtHex: y[h]
727
+ ), h = [];
728
+ for (let d = 0; d < y.length; d++) {
729
+ bt({
730
+ requestedPsbtHex: p[d],
731
+ returnedPsbtHex: y[d]
732
732
  });
733
- const _ = se(
734
- y[h],
733
+ const B = re(
734
+ y[d],
735
735
  s
736
- ), I = oe(y[h]);
737
- u.push({
738
- htlcVout: h,
739
- htlcValue: f.htlcValues[h],
740
- peginTxHex: I,
741
- peginTxid: E[h].txid,
742
- peginInputSignature: _,
743
- vaultScriptPubKey: E[h].vaultScriptPubKey
736
+ ), A = ie(y[d]);
737
+ h.push({
738
+ htlcVout: d,
739
+ htlcValue: g.htlcValues[d],
740
+ peginTxHex: A,
741
+ peginTxid: E[d].txid,
742
+ peginInputSignature: B,
743
+ vaultScriptPubKey: E[d].vaultScriptPubKey
744
744
  });
745
745
  }
746
746
  return {
747
747
  fundedPrePeginTxHex: k,
748
- prePeginTxid: A,
749
- perVault: u
748
+ prePeginTxid: S,
749
+ perVault: h
750
750
  };
751
751
  }
752
752
  /**
@@ -765,37 +765,37 @@ class An {
765
765
  * @throws Error if signing or broadcasting fails
766
766
  */
767
767
  async signAndBroadcast(t) {
768
- const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = Zt.fromHex(o);
768
+ const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = Qt.fromHex(o);
769
769
  if (r.ins.length === 0)
770
770
  throw new Error("Transaction has no inputs");
771
- const i = new ht();
771
+ const i = new gt();
772
772
  i.setVersion(r.version), i.setLocktime(r.locktime);
773
773
  const a = J.from(
774
774
  R(s),
775
775
  "hex"
776
- ), c = this.config.mempoolApiUrl, d = r.ins.map((p) => {
776
+ ), c = this.config.mempoolApiUrl, u = r.ins.map((p) => {
777
777
  const P = J.from(p.hash).reverse().toString("hex"), y = p.index;
778
- return un(P, y, t.localPrevouts, c).then(
779
- (u) => ({ input: p, utxoData: u, txid: P, vout: y })
778
+ return hn(P, y, t.localPrevouts, c).then(
779
+ (h) => ({ input: p, utxoData: h, txid: P, vout: y })
780
780
  );
781
- }), l = await Promise.all(d), m = l.reduce(
781
+ }), l = await Promise.all(u), m = l.reduce(
782
782
  (p, P) => p + BigInt(P.utxoData.value),
783
783
  0n
784
- ), w = r.outs.reduce(
784
+ ), b = r.outs.reduce(
785
785
  (p, P) => p + BigInt(P.value),
786
786
  0n
787
787
  );
788
- if (m < w)
788
+ if (m < b)
789
789
  throw new Error(
790
- `UTXO value mismatch: total input value (${m} sat) is less than total output value (${w} sat). This may indicate the mempool API returned manipulated UTXO data.`
790
+ `UTXO value mismatch: total input value (${m} sat) is less than total output value (${b} sat). This may indicate the mempool API returned manipulated UTXO data.`
791
791
  );
792
- const b = m - w;
793
- if (b > Pt)
792
+ const w = m - b;
793
+ if (w > yt)
794
794
  throw new Error(
795
- `Implied transaction fee (${b} sat) exceeds maximum reasonable fee (${Pt} sat). This may indicate manipulated UTXO data.`
795
+ `Implied transaction fee (${w} sat) exceeds maximum reasonable fee (${yt} sat). This may indicate manipulated UTXO data.`
796
796
  );
797
- for (const { input: p, utxoData: P, txid: y, vout: u } of l) {
798
- const h = he(
797
+ for (const { input: p, utxoData: P, txid: y, vout: h } of l) {
798
+ const d = ge(
799
799
  {
800
800
  value: P.value,
801
801
  scriptPubKey: P.scriptPubKey
@@ -806,7 +806,7 @@ class An {
806
806
  hash: p.hash,
807
807
  index: p.index,
808
808
  sequence: p.sequence,
809
- ...h
809
+ ...d
810
810
  });
811
811
  }
812
812
  for (const p of r.outs)
@@ -814,12 +814,12 @@ class An {
814
814
  script: p.script,
815
815
  value: p.value
816
816
  });
817
- const f = i.toHex(), g = await this.config.btcWallet.signPsbt(f);
818
- mt({
819
- requestedPsbtHex: f,
820
- returnedPsbtHex: g
817
+ const g = i.toHex(), f = await this.config.btcWallet.signPsbt(g);
818
+ bt({
819
+ requestedPsbtHex: g,
820
+ returnedPsbtHex: f
821
821
  });
822
- const k = ht.fromHex(g);
822
+ const k = gt.fromHex(f);
823
823
  try {
824
824
  k.finalizeAllInputs();
825
825
  } catch (p) {
@@ -830,8 +830,8 @@ class An {
830
830
  `PSBT finalization failed and wallet did not auto-finalize: ${p}`
831
831
  );
832
832
  }
833
- const A = k.extractTransaction().toHex();
834
- return await ge(A, c);
833
+ const S = k.extractTransaction().toHex();
834
+ return await me(S, c);
835
835
  }
836
836
  /**
837
837
  * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
@@ -866,32 +866,32 @@ class An {
866
866
  htlcVout: i,
867
867
  depositorPayoutBtcAddress: a,
868
868
  depositorWotsPkHash: c,
869
- popSignature: d
869
+ popSignature: u
870
870
  } = t;
871
871
  if (!this.config.ethWallet.account)
872
872
  throw new Error("Ethereum wallet account not found");
873
873
  const l = this.config.ethWallet.account.address;
874
- if (!dt(d.depositorEthAddress, l))
874
+ if (!ft(u.depositorEthAddress, l))
875
875
  throw new Error(
876
- `Proof of possession was signed for ${d.depositorEthAddress} but the Ethereum wallet is currently connected to ${l}. Reconnect the original account or call signProofOfPossession() again.`
876
+ `Proof of possession was signed for ${u.depositorEthAddress} but the Ethereum wallet is currently connected to ${l}. Reconnect the original account or call signProofOfPossession() again.`
877
877
  );
878
- const m = await this.assertPopMatchesBtcWallet(d), w = d.btcPopSignature, b = B(d.depositorBtcPubkey), f = B(e), g = B(s), k = a ?? await this.config.btcWallet.getAddress(), A = this.resolvePayoutScriptPubKey(
878
+ const m = await this.assertPopMatchesBtcWallet(u), b = u.btcPopSignature, w = v(u.depositorBtcPubkey), g = v(e), f = v(s), k = a ?? await this.config.btcWallet.getAddress(), S = this.resolvePayoutScriptPubKey(
879
879
  m,
880
880
  k
881
- ), E = G(g), p = await gt(
881
+ ), E = z(f), p = await pt(
882
882
  T(E),
883
883
  T(l)
884
- ), P = B(p);
884
+ ), P = v(p);
885
885
  if (await this.checkVaultExists(P))
886
886
  throw new Error(
887
887
  `Vault already exists (ID: ${P}, peginTxHash: ${E}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
888
888
  );
889
- const u = this.config.publicClient;
890
- let h;
889
+ const h = this.config.publicClient;
890
+ let d;
891
891
  try {
892
- h = await u.readContract({
892
+ d = await h.readContract({
893
893
  address: this.config.vaultContracts.btcVaultRegistry,
894
- abi: C,
894
+ abi: I,
895
895
  functionName: "getPegInFee",
896
896
  args: [o]
897
897
  });
@@ -901,55 +901,55 @@ class An {
901
901
  { cause: O }
902
902
  );
903
903
  }
904
- const _ = await this.resolveMaxAcceptableCommissionBps(
904
+ const B = await this.resolveMaxAcceptableCommissionBps(
905
905
  o,
906
906
  t.quotedCommissionBps
907
- ), I = ft({
908
- abi: C,
907
+ ), A = tt({
908
+ abi: I,
909
909
  functionName: "submitPeginRequest",
910
910
  args: [
911
911
  l,
912
- b,
913
912
  w,
914
- f,
913
+ b,
915
914
  g,
915
+ f,
916
916
  o,
917
- _,
917
+ B,
918
918
  r,
919
919
  i,
920
- A,
920
+ S,
921
921
  c
922
922
  ]
923
923
  });
924
- let S;
924
+ let C;
925
925
  try {
926
- S = await u.estimateGas({
926
+ C = await h.estimateGas({
927
927
  to: this.config.vaultContracts.btcVaultRegistry,
928
- data: I,
929
- value: h,
928
+ data: A,
929
+ value: d,
930
930
  account: this.config.ethWallet.account.address
931
931
  });
932
932
  } catch (O) {
933
933
  H(O);
934
934
  }
935
- let z;
935
+ let G;
936
936
  try {
937
- z = await this.config.ethWallet.sendTransaction({
937
+ G = await this.config.ethWallet.sendTransaction({
938
938
  to: this.config.vaultContracts.btcVaultRegistry,
939
- data: I,
940
- value: h,
939
+ data: A,
940
+ value: d,
941
941
  account: this.config.ethWallet.account,
942
942
  chain: this.config.ethChain,
943
- gas: S
943
+ gas: C
944
944
  });
945
945
  } catch (O) {
946
946
  H(O);
947
947
  }
948
- const q = await yt({
949
- publicClient: u,
948
+ const q = await xt({
949
+ publicClient: h,
950
950
  walletAddress: this.config.ethWallet.account.address,
951
- hash: z,
952
- timeout: It
951
+ hash: G,
952
+ timeout: At
953
953
  });
954
954
  return q.status === "reverted" && H(
955
955
  new Error(
@@ -978,69 +978,69 @@ class An {
978
978
  if (!this.config.ethWallet.account)
979
979
  throw new Error("Ethereum wallet account not found");
980
980
  const i = this.config.ethWallet.account.address;
981
- if (!dt(r.depositorEthAddress, i))
981
+ if (!ft(r.depositorEthAddress, i))
982
982
  throw new Error(
983
983
  `Proof of possession was signed for ${r.depositorEthAddress} but the Ethereum wallet is currently connected to ${i}. Reconnect the original account or call signProofOfPossession() again.`
984
984
  );
985
- const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, d = o.map(
986
- (u) => this.resolvePayoutScriptPubKey(
985
+ const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, u = o.map(
986
+ (h) => this.resolvePayoutScriptPubKey(
987
987
  a,
988
- u.depositorPayoutBtcAddress
988
+ h.depositorPayoutBtcAddress
989
989
  )
990
990
  ), l = [];
991
- for (const u of o) {
992
- const h = B(
993
- u.depositorSignedPeginTx
994
- ), _ = G(h), I = await gt(
995
- T(_),
991
+ for (const h of o) {
992
+ const d = v(
993
+ h.depositorSignedPeginTx
994
+ ), B = z(d), A = await pt(
995
+ T(B),
996
996
  T(i)
997
- ), S = B(I);
998
- if (await this.checkVaultExists(S))
997
+ ), C = v(A);
998
+ if (await this.checkVaultExists(C))
999
999
  throw new Error(
1000
- `Vault already exists (ID: ${S}, peginTxHash: ${_}). To create a new vault, use different UTXOs or a different amount.`
1000
+ `Vault already exists (ID: ${C}, peginTxHash: ${B}). To create a new vault, use different UTXOs or a different amount.`
1001
1001
  );
1002
- l.push({ vaultId: S, peginTxHash: _ });
1002
+ l.push({ vaultId: C, peginTxHash: B });
1003
1003
  }
1004
1004
  const m = this.config.publicClient;
1005
- let w;
1005
+ let b;
1006
1006
  try {
1007
- w = await m.readContract({
1007
+ b = await m.readContract({
1008
1008
  address: this.config.vaultContracts.btcVaultRegistry,
1009
- abi: C,
1009
+ abi: I,
1010
1010
  functionName: "getPegInFee",
1011
1011
  args: [e]
1012
1012
  });
1013
- } catch (u) {
1013
+ } catch (h) {
1014
1014
  throw new Error(
1015
1015
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
1016
- { cause: u }
1016
+ { cause: h }
1017
1017
  );
1018
1018
  }
1019
- const b = w * BigInt(o.length), f = await this.resolveMaxAcceptableCommissionBps(
1019
+ const w = b * BigInt(o.length), g = await this.resolveMaxAcceptableCommissionBps(
1020
1020
  e,
1021
1021
  t.quotedCommissionBps
1022
- ), g = B(
1022
+ ), f = v(
1023
1023
  r.depositorBtcPubkey
1024
- ), k = B(s), A = o.map((u, h) => ({
1025
- depositorBtcPubKey: g,
1024
+ ), k = v(s), S = o.map((h, d) => ({
1025
+ depositorBtcPubKey: f,
1026
1026
  btcPopSignature: c,
1027
1027
  unsignedPrePeginTx: k,
1028
- depositorSignedPeginTx: B(
1029
- u.depositorSignedPeginTx
1028
+ depositorSignedPeginTx: v(
1029
+ h.depositorSignedPeginTx
1030
1030
  ),
1031
- hashlock: u.hashlock,
1032
- htlcVout: u.htlcVout,
1033
- referralCode: cn,
1034
- depositorPayoutBtcAddress: d[h],
1035
- depositorWotsPkHash: u.depositorWotsPkHash
1036
- })), E = ft({
1037
- abi: C,
1031
+ hashlock: h.hashlock,
1032
+ htlcVout: h.htlcVout,
1033
+ referralCode: Dt,
1034
+ depositorPayoutBtcAddress: u[d],
1035
+ depositorWotsPkHash: h.depositorWotsPkHash
1036
+ })), E = tt({
1037
+ abi: I,
1038
1038
  functionName: "submitPeginRequestBatch",
1039
1039
  args: [
1040
1040
  i,
1041
1041
  e,
1042
- f,
1043
- A
1042
+ g,
1043
+ S
1044
1044
  ]
1045
1045
  });
1046
1046
  let p;
@@ -1048,30 +1048,30 @@ class An {
1048
1048
  p = await m.estimateGas({
1049
1049
  to: this.config.vaultContracts.btcVaultRegistry,
1050
1050
  data: E,
1051
- value: b,
1051
+ value: w,
1052
1052
  account: this.config.ethWallet.account.address
1053
1053
  });
1054
- } catch (u) {
1055
- H(u);
1054
+ } catch (h) {
1055
+ H(h);
1056
1056
  }
1057
1057
  let P;
1058
1058
  try {
1059
1059
  P = await this.config.ethWallet.sendTransaction({
1060
1060
  to: this.config.vaultContracts.btcVaultRegistry,
1061
1061
  data: E,
1062
- value: b,
1062
+ value: w,
1063
1063
  account: this.config.ethWallet.account,
1064
1064
  chain: this.config.ethChain,
1065
1065
  gas: p
1066
1066
  });
1067
- } catch (u) {
1068
- H(u);
1067
+ } catch (h) {
1068
+ H(h);
1069
1069
  }
1070
- const y = await yt({
1070
+ const y = await xt({
1071
1071
  publicClient: m,
1072
1072
  walletAddress: this.config.ethWallet.account.address,
1073
1073
  hash: P,
1074
- timeout: It
1074
+ timeout: At
1075
1075
  });
1076
1076
  return y.status === "reverted" && H(
1077
1077
  new Error(
@@ -1089,7 +1089,7 @@ class An {
1089
1089
  try {
1090
1090
  s = await this.config.publicClient.readContract({
1091
1091
  address: this.config.vaultContracts.btcVaultRegistry,
1092
- abi: C,
1092
+ abi: I,
1093
1093
  functionName: "getVaultProviderCommission",
1094
1094
  args: [t]
1095
1095
  });
@@ -1100,18 +1100,18 @@ class An {
1100
1100
  );
1101
1101
  }
1102
1102
  if (e !== void 0) {
1103
- if (s > e + L)
1103
+ if (s > e + W)
1104
1104
  throw new Error(
1105
- `Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${s} bps (allowed drift ${L} bps). Please refresh to see the new commission and try again.`
1105
+ `Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${s} bps (allowed drift ${W} bps). Please refresh to see the new commission and try again.`
1106
1106
  );
1107
1107
  return Math.min(
1108
- e + L,
1109
- At
1108
+ e + W,
1109
+ rt
1110
1110
  );
1111
1111
  }
1112
1112
  return Math.min(
1113
- s + L,
1114
- At
1113
+ s + W,
1114
+ rt
1115
1115
  );
1116
1116
  }
1117
1117
  /**
@@ -1130,10 +1130,10 @@ class An {
1130
1130
  async checkVaultExists(t) {
1131
1131
  return (await this.config.publicClient.readContract({
1132
1132
  address: this.config.vaultContracts.btcVaultRegistry,
1133
- abi: C,
1133
+ abi: I,
1134
1134
  functionName: "getBtcVaultBasicInfo",
1135
1135
  args: [t]
1136
- })).depositor !== Yt;
1136
+ })).depositor !== Jt;
1137
1137
  }
1138
1138
  /**
1139
1139
  * Resolve the BTC scriptPubKey to register as the depositor's payout sink.
@@ -1157,12 +1157,12 @@ class An {
1157
1157
  t,
1158
1158
  this.config.btcNetwork
1159
1159
  ))
1160
- throw T(t).length === ie && ln(e, this.config.btcNetwork) ? new Error(
1160
+ throw T(t).length === ce && un(e, this.config.btcNetwork) ? new Error(
1161
1161
  `BTC payout address "${e}" is a P2WPKH (Native SegWit) address, but the connected wallet only exposes an x-only public key. P2WPKH validation requires a compressed key with known y-parity. Use a P2TR (Taproot) payout address instead.`
1162
1162
  ) : new Error(
1163
1163
  `BTC payout address "${e}" is not derived from the connected wallet's public key. The payout sink must be controlled by the same key that signs the pegin; refusing to register a mismatched address.`
1164
1164
  );
1165
- const s = bt(this.config.btcNetwork);
1165
+ const s = Pt(this.config.btcNetwork);
1166
1166
  try {
1167
1167
  return `0x${Ct.address.toOutputScript(e, s).toString("hex")}`;
1168
1168
  } catch {
@@ -1187,7 +1187,7 @@ class An {
1187
1187
  "bip322-simple"
1188
1188
  );
1189
1189
  return {
1190
- btcPopSignature: rn(r),
1190
+ btcPopSignature: cn(r),
1191
1191
  depositorEthAddress: t,
1192
1192
  depositorBtcPubkey: e
1193
1193
  };
@@ -1225,13 +1225,67 @@ class An {
1225
1225
  return this.config.vaultContracts.btcVaultRegistry;
1226
1226
  }
1227
1227
  }
1228
+ const dn = 80, gn = 250, fn = 300, pn = 22, Gt = "ab";
1229
+ function mn(n, t) {
1230
+ const e = Gt.repeat(fn), s = T(n).toLowerCase(), o = t.toString(16).padStart(8, "0"), r = `${s}${o}`, i = e.slice(r.length);
1231
+ return `0x${r}${i}`;
1232
+ }
1233
+ function bn(n, t) {
1234
+ const e = (s) => `0x${Gt.repeat(s)}`;
1235
+ return {
1236
+ depositorBtcPubKey: e(32),
1237
+ btcPopSignature: e(dn),
1238
+ unsignedPrePeginTx: e(gn),
1239
+ depositorSignedPeginTx: mn(
1240
+ n,
1241
+ t
1242
+ ),
1243
+ hashlock: e(32),
1244
+ htlcVout: t,
1245
+ referralCode: Dt,
1246
+ depositorPayoutBtcAddress: e(pn),
1247
+ depositorWotsPkHash: e(32)
1248
+ };
1249
+ }
1250
+ async function Un(n) {
1251
+ const { publicClient: t, btcVaultRegistry: e, depositorEthAddress: s, vaultProvider: o, batchSize: r } = n;
1252
+ if (r <= 0)
1253
+ throw new Error(
1254
+ `estimateSubmitPeginRequestBatchGas requires batchSize >= 1 (received ${r})`
1255
+ );
1256
+ const a = await t.readContract({
1257
+ address: e,
1258
+ abi: I,
1259
+ functionName: "getPegInFee",
1260
+ args: [o]
1261
+ }) * BigInt(r), c = Array.from(
1262
+ { length: r },
1263
+ (l, m) => bn(s, m)
1264
+ ), u = tt({
1265
+ abi: I,
1266
+ functionName: "submitPeginRequestBatch",
1267
+ args: [
1268
+ s,
1269
+ o,
1270
+ rt,
1271
+ c
1272
+ ]
1273
+ });
1274
+ return t.estimateGas({
1275
+ to: e,
1276
+ data: u,
1277
+ value: a,
1278
+ account: s
1279
+ });
1280
+ }
1228
1281
  export {
1229
- An as P,
1230
- _e as V,
1282
+ Rn as P,
1283
+ Se as V,
1231
1284
  ve as a,
1232
- Te as b,
1233
- tn as c,
1234
- Je as d,
1235
- Ae as e
1285
+ Be as b,
1286
+ nn as c,
1287
+ en as d,
1288
+ Un as e,
1289
+ Ie as f
1236
1290
  };
1237
- //# sourceMappingURL=PeginManager-Cp2Tn5sH.js.map
1291
+ //# sourceMappingURL=PeginManager-DXrfY4d6.js.map