@babylonlabs-io/ts-sdk 0.60.0 → 0.61.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 (45) hide show
  1. package/dist/{PeginManager-DKyNgvq1.js → PeginManager-C2vPVud-.js} +315 -278
  2. package/dist/PeginManager-C2vPVud-.js.map +1 -0
  3. package/dist/PeginManager-Cu5Dh6L-.cjs +2 -0
  4. package/dist/PeginManager-Cu5Dh6L-.cjs.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +36 -36
  7. package/dist/index.js.map +1 -1
  8. package/dist/parseFundingOutpoints-DUuOAUjA.cjs +2 -0
  9. package/dist/{deriveVaultRoot-D0RY5GJc.js.map → parseFundingOutpoints-DUuOAUjA.cjs.map} +1 -1
  10. package/dist/parseFundingOutpoints-deCXK7ft.js +86 -0
  11. package/dist/parseFundingOutpoints-deCXK7ft.js.map +1 -0
  12. package/dist/signPsbtsWithFallback-Xs4jZw5z.cjs.map +1 -1
  13. package/dist/signPsbtsWithFallback-eY1YgV13.js.map +1 -1
  14. package/dist/tbv/core/deposit-terms/__tests__/prePeginApproval.test.d.ts +8 -0
  15. package/dist/tbv/core/deposit-terms/__tests__/prePeginApproval.test.d.ts.map +1 -0
  16. package/dist/tbv/core/deposit-terms/depositTerms.d.ts +3 -0
  17. package/dist/tbv/core/deposit-terms/depositTerms.d.ts.map +1 -1
  18. package/dist/tbv/core/deposit-terms/index.d.ts +1 -0
  19. package/dist/tbv/core/deposit-terms/index.d.ts.map +1 -1
  20. package/dist/tbv/core/deposit-terms/prePeginApproval.d.ts +37 -0
  21. package/dist/tbv/core/deposit-terms/prePeginApproval.d.ts.map +1 -0
  22. package/dist/tbv/core/index.cjs +1 -1
  23. package/dist/tbv/core/index.js +52 -52
  24. package/dist/tbv/core/index.js.map +1 -1
  25. package/dist/tbv/core/managers/PeginManager.d.ts +8 -0
  26. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  27. package/dist/tbv/core/managers/index.cjs +1 -1
  28. package/dist/tbv/core/managers/index.js +1 -1
  29. package/dist/tbv/core/vault-secrets/index.cjs +1 -1
  30. package/dist/tbv/core/vault-secrets/index.js +6 -7
  31. package/dist/tbv/core/vault-secrets/index.js.map +1 -1
  32. package/dist/tbv/index.cjs +1 -1
  33. package/dist/tbv/index.js +52 -52
  34. package/dist/tbv/index.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/PeginManager-DKyNgvq1.js.map +0 -1
  37. package/dist/PeginManager-OXUOsgz2.cjs +0 -2
  38. package/dist/PeginManager-OXUOsgz2.cjs.map +0 -1
  39. package/dist/deriveVaultRoot-D0RY5GJc.js +0 -72
  40. package/dist/deriveVaultRoot-p4uGsM7w.cjs +0 -2
  41. package/dist/deriveVaultRoot-p4uGsM7w.cjs.map +0 -1
  42. package/dist/parseFundingOutpoints-C_-PT9BT.cjs +0 -2
  43. package/dist/parseFundingOutpoints-C_-PT9BT.cjs.map +0 -1
  44. package/dist/parseFundingOutpoints-GSM-IaaK.js +0 -17
  45. package/dist/parseFundingOutpoints-GSM-IaaK.js.map +0 -1
@@ -1,42 +1,42 @@
1
- var Wt = Object.defineProperty;
2
- var Lt = (s, e, t) => e in s ? Wt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var y = (s, e, t) => Lt(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { c as Bt, H as Dt, r as M, a as W, b as ot, u as Xt, d as nt, e as rt, f as it, g as Kt, s as Et } from "./sha2-BYVxyZzX.js";
5
- import * as vt from "bitcoinjs-lib";
6
- import { Transaction as qt, Psbt as at } from "bitcoinjs-lib";
1
+ var Lt = Object.defineProperty;
2
+ var Xt = (s, e, t) => e in s ? Lt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var y = (s, e, t) => Xt(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { c as vt, H as Kt, r as M, a as W, b as nt, u as qt, d as rt, e as it, f as at, g as Gt, s as Bt } from "./sha2-BYVxyZzX.js";
5
+ import * as Et from "bitcoinjs-lib";
6
+ import { Transaction as At, Psbt as ct } from "bitcoinjs-lib";
7
7
  import { Buffer as j } from "buffer";
8
- import { isAddressEqual as ct, encodeFunctionData as Q, zeroAddress as Gt } from "viem";
8
+ import { isAddressEqual as lt, encodeFunctionData as Q, zeroAddress as zt } from "viem";
9
9
  import { B as H } from "./BTCVaultRegistry.abi-B3BLhpJ4.js";
10
10
  import { h as R } from "./errors-Blc-JWnI.js";
11
- import { expandWotsSeed as zt, expandHashlockSecret as Yt, expandAuthAnchor as jt, deriveVaultId as lt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
12
- import { a as ut, b as Qt, d as ht, f as Zt } from "./verifyScriptPathSchnorrSignature-Bav08_7R.js";
13
- import { b as Jt, e as te, f as ee } from "./peginInput-HQPWZfly.js";
14
- import { u as Z, e as S, p as se, i as dt, h as gt, s as v, k as ft, X as oe } from "./bitcoin-d9eaaZB_.js";
15
- import { M as L, B as ne } from "./constants-GjWXdaqV.js";
16
- import { c as re } from "./signing-DaLvGwQe.js";
11
+ import { expandWotsSeed as Yt, expandHashlockSecret as jt, expandAuthAnchor as Qt, deriveVaultId as ut } from "@babylonlabs-io/babylon-tbv-rust-wasm";
12
+ import { a as ht, b as Zt, d as dt, f as Jt } from "./verifyScriptPathSchnorrSignature-Bav08_7R.js";
13
+ import { b as te, e as ee, f as se } from "./peginInput-HQPWZfly.js";
14
+ import { p as oe, h as Z, u as J, e as _, i as gt, s as E, k as ft, X as ne } from "./bitcoin-d9eaaZB_.js";
15
+ import { M as D, B as re } from "./constants-GjWXdaqV.js";
16
+ import { c as ie } from "./signing-DaLvGwQe.js";
17
17
  import { M as pt } from "./validation-Dj3dqYtl.js";
18
- import { d as ie } from "./deriveVaultRoot-D0RY5GJc.js";
19
- import { c as ae, a as ce, s as mt, b as le } from "./signPsbtsWithFallback-eY1YgV13.js";
20
- import { s as ue, f as X, i as he, w as bt } from "./waitForTransactionReceiptSmartAware-lobLm0q0.js";
21
- import { p as de, f as ge } from "./fundPeginTransaction-B2wyjqp0.js";
22
- import { p as fe, V as pe, i as me } from "./mempoolApi-DC7pID6B.js";
18
+ import { p as ae, d as Ct } from "./parseFundingOutpoints-deCXK7ft.js";
19
+ import { c as ce, a as le, s as mt, b as ue } from "./signPsbtsWithFallback-eY1YgV13.js";
20
+ import { s as he, f as X, i as de, w as bt } from "./waitForTransactionReceiptSmartAware-lobLm0q0.js";
21
+ import { p as ge, f as fe } from "./fundPeginTransaction-B2wyjqp0.js";
22
+ import { p as pe, V as me, i as be } from "./mempoolApi-DC7pID6B.js";
23
23
  const U = /* @__PURE__ */ BigInt(2 ** 32 - 1), Pt = /* @__PURE__ */ BigInt(32);
24
- function be(s, e = !1) {
24
+ function Pe(s, e = !1) {
25
25
  return e ? { h: Number(s & U), l: Number(s >> Pt & U) } : { h: Number(s >> Pt & U) | 0, l: Number(s & U) | 0 };
26
26
  }
27
- function Pe(s, e = !1) {
27
+ function we(s, e = !1) {
28
28
  const t = s.length;
29
29
  let o = new Uint32Array(t), n = new Uint32Array(t);
30
30
  for (let r = 0; r < t; r++) {
31
- const { h: i, l: a } = be(s[r], e);
31
+ const { h: i, l: a } = Pe(s[r], e);
32
32
  [o[r], n[r]] = [i, a];
33
33
  }
34
34
  return [o, n];
35
35
  }
36
- const we = (s, e, t) => s << t | e >>> 32 - t, xe = (s, e, t) => e << t | s >>> 32 - t, ye = (s, e, t) => e << t - 32 | s >>> 64 - t, ke = (s, e, t) => s << t - 32 | e >>> 64 - t, Te = 64;
36
+ const xe = (s, e, t) => s << t | e >>> 32 - t, ye = (s, e, t) => e << t | s >>> 32 - t, ke = (s, e, t) => e << t - 32 | s >>> 64 - t, Te = (s, e, t) => s << t - 32 | e >>> 64 - t, ve = 64;
37
37
  function Be(s) {
38
38
  const e = s.prepeginTxid.toLowerCase();
39
- if (!/^[0-9a-f]+$/.test(e) || e.length !== Te)
39
+ if (!/^[0-9a-f]+$/.test(e) || e.length !== ve)
40
40
  throw new Error(
41
41
  `buildDepositTerms: prepeginTxid must be 64 hex chars, got "${s.prepeginTxid}"`
42
42
  );
@@ -44,11 +44,11 @@ function Be(s) {
44
44
  throw new Error("buildDepositTerms: at least one pegin amount is required");
45
45
  if (s.timelockPegin <= 0 || s.timelockAssert <= 0 || s.timelockRefund <= 0)
46
46
  throw new Error("buildDepositTerms: timelocks must be positive");
47
- if (!Number.isInteger(s.maxAcceptableCommissionBps) || s.maxAcceptableCommissionBps < 0 || s.maxAcceptableCommissionBps >= L)
47
+ if (!Number.isInteger(s.maxAcceptableCommissionBps) || s.maxAcceptableCommissionBps < 0 || s.maxAcceptableCommissionBps >= D)
48
48
  throw new Error(
49
- `buildDepositTerms: maxAcceptableCommissionBps must be an integer in [0, ${L}), got ${s.maxAcceptableCommissionBps}`
49
+ `buildDepositTerms: maxAcceptableCommissionBps must be an integer in [0, ${D}), got ${s.maxAcceptableCommissionBps}`
50
50
  );
51
- const t = BigInt(ne), o = s.peginAmounts.map(
51
+ const t = BigInt(re), o = s.peginAmounts.map(
52
52
  (n, r) => ({
53
53
  htlcVout: r,
54
54
  vaultProviderBtcPubkey: s.vaultProviderBtcPubkey,
@@ -75,7 +75,63 @@ function Be(s) {
75
75
  vaults: o
76
76
  };
77
77
  }
78
- const Ee = /* @__PURE__ */ Uint8Array.from([
78
+ const Ee = /^0x[0-9a-f]+$/i, Ae = /^[0-9a-f]+$/i, Ce = /^[A-Za-z0-9+/]+={0,2}$/;
79
+ function $(s) {
80
+ if (typeof s != "string" || s.length === 0)
81
+ throw new Error("BTC wallet returned empty public key");
82
+ return oe(s).toLowerCase();
83
+ }
84
+ function _e(s) {
85
+ if (typeof s != "string" || s.length === 0)
86
+ throw new Error("BTC wallet returned empty BIP-322 signature");
87
+ if (s.startsWith("0x") || s.startsWith("0X")) {
88
+ if (!Ee.test(s) || s.length < 4 || s.length % 2 !== 0)
89
+ throw new Error("BTC wallet returned malformed hex BIP-322 signature");
90
+ return s.toLowerCase();
91
+ }
92
+ if (Ae.test(s)) {
93
+ if (s.length % 2 !== 0)
94
+ throw new Error("BTC wallet returned malformed hex BIP-322 signature");
95
+ return `0x${s.toLowerCase()}`;
96
+ }
97
+ if (!Ce.test(s) || s.length % 4 !== 0)
98
+ throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
99
+ const e = j.from(s, "base64");
100
+ if (e.length === 0 || e.toString("base64") !== s)
101
+ throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
102
+ return `0x${e.toString("hex")}`;
103
+ }
104
+ async function Se(s) {
105
+ const { wallet: e, depositTerms: t, fundedPrePeginTxHex: o, depositorBtcPubkey: n } = s, r = typeof e.approveDepositTerms == "function" ? e.approveDepositTerms : void 0;
106
+ if (!r && !t)
107
+ return;
108
+ const i = o.startsWith("0x") ? o.slice(2) : o, c = At.fromHex(i).getId();
109
+ if (t && t.prepeginTxid.replace(/^0x/, "").toLowerCase() !== c)
110
+ throw new Error(
111
+ `Deposit terms do not match the transaction being broadcast: terms are for prepeginTxid ${t.prepeginTxid}, but this transaction is ${c}.`
112
+ );
113
+ if (!r)
114
+ return;
115
+ if (!t)
116
+ throw new Error(
117
+ "This wallet requires approved deposit terms before signing the Pre-PegIn transaction, but none were provided. Pass PreparePeginResult.depositTerms (fresh flows) or a resume rebuild."
118
+ );
119
+ if (typeof e.deriveContextHash != "function")
120
+ throw new Error(
121
+ "A deposit-approval wallet must also implement deriveContextHash, but this one does not."
122
+ );
123
+ const l = ae(o);
124
+ (await Ct(
125
+ { deriveContextHash: e.deriveContextHash.bind(e) },
126
+ {
127
+ depositorBtcPubkey: Z(
128
+ $(n)
129
+ ),
130
+ fundingOutpoints: l
131
+ }
132
+ )).fill(0), await r(t);
133
+ }
134
+ const Ie = /* @__PURE__ */ Uint8Array.from([
79
135
  7,
80
136
  4,
81
137
  13,
@@ -92,25 +148,25 @@ const Ee = /* @__PURE__ */ Uint8Array.from([
92
148
  14,
93
149
  11,
94
150
  8
95
- ]), At = Uint8Array.from(new Array(16).fill(0).map((s, e) => e)), ve = At.map((s) => (9 * s + 5) % 16), _t = /* @__PURE__ */ (() => {
96
- const t = [[At], [ve]];
151
+ ]), _t = Uint8Array.from(new Array(16).fill(0).map((s, e) => e)), He = _t.map((s) => (9 * s + 5) % 16), St = /* @__PURE__ */ (() => {
152
+ const t = [[_t], [He]];
97
153
  for (let o = 0; o < 4; o++)
98
154
  for (let n of t)
99
- n.push(n[o].map((r) => Ee[r]));
155
+ n.push(n[o].map((r) => Ie[r]));
100
156
  return t;
101
- })(), St = _t[0], Ct = _t[1], It = /* @__PURE__ */ [
157
+ })(), It = St[0], Ht = St[1], Rt = /* @__PURE__ */ [
102
158
  [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
103
159
  [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
104
160
  [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
105
161
  [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
106
162
  [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
107
- ].map((s) => Uint8Array.from(s)), Ae = /* @__PURE__ */ St.map((s, e) => s.map((t) => It[e][t])), _e = /* @__PURE__ */ Ct.map((s, e) => s.map((t) => It[e][t])), Se = /* @__PURE__ */ Uint32Array.from([
163
+ ].map((s) => Uint8Array.from(s)), Re = /* @__PURE__ */ It.map((s, e) => s.map((t) => Rt[e][t])), $e = /* @__PURE__ */ Ht.map((s, e) => s.map((t) => Rt[e][t])), Oe = /* @__PURE__ */ Uint32Array.from([
108
164
  0,
109
165
  1518500249,
110
166
  1859775393,
111
167
  2400959708,
112
168
  2840853838
113
- ]), Ce = /* @__PURE__ */ Uint32Array.from([
169
+ ]), Ve = /* @__PURE__ */ Uint32Array.from([
114
170
  1352829926,
115
171
  1548603684,
116
172
  1836072691,
@@ -121,7 +177,7 @@ function wt(s, e, t, o) {
121
177
  return s === 0 ? e ^ t ^ o : s === 1 ? e & t | ~e & o : s === 2 ? (e | ~t) ^ o : s === 3 ? e & o | t & ~o : e ^ (t | ~o);
122
178
  }
123
179
  const F = /* @__PURE__ */ new Uint32Array(16);
124
- class Ie extends Dt {
180
+ class Me extends Kt {
125
181
  constructor() {
126
182
  super(64, 20, 8, !0);
127
183
  y(this, "h0", 1732584193);
@@ -140,19 +196,19 @@ class Ie extends Dt {
140
196
  process(t, o) {
141
197
  for (let d = 0; d < 16; d++, o += 4)
142
198
  F[d] = t.getUint32(o, !0);
143
- let n = this.h0 | 0, r = n, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, l = this.h3 | 0, m = l, P = this.h4 | 0, w = P;
199
+ let n = this.h0 | 0, r = n, i = this.h1 | 0, a = i, c = this.h2 | 0, l = c, u = this.h3 | 0, m = u, P = this.h4 | 0, w = P;
144
200
  for (let d = 0; d < 5; d++) {
145
- const E = 4 - d, k = Se[d], f = Ce[d], A = St[d], p = Ct[d], b = Ae[d], T = _e[d];
201
+ const B = 4 - d, k = Oe[d], f = Ve[d], A = It[d], p = Ht[d], b = Re[d], T = $e[d];
146
202
  for (let h = 0; h < 16; h++) {
147
- const x = M(n + wt(d, i, c, l) + F[A[h]] + k, b[h]) + P | 0;
148
- n = P, P = l, l = M(c, 10) | 0, c = i, i = x;
203
+ const x = M(n + wt(d, i, c, u) + F[A[h]] + k, b[h]) + P | 0;
204
+ n = P, P = u, u = M(c, 10) | 0, c = i, i = x;
149
205
  }
150
206
  for (let h = 0; h < 16; h++) {
151
- const x = M(r + wt(E, a, u, m) + F[p[h]] + f, T[h]) + w | 0;
152
- r = w, w = m, m = M(u, 10) | 0, u = a, a = x;
207
+ const x = M(r + wt(B, a, l, m) + F[p[h]] + f, T[h]) + w | 0;
208
+ r = w, w = m, m = M(l, 10) | 0, l = a, a = x;
153
209
  }
154
210
  }
155
- this.set(this.h1 + c + m | 0, this.h2 + l + w | 0, this.h3 + P + r | 0, this.h4 + n + a | 0, this.h0 + i + u | 0);
211
+ this.set(this.h1 + c + m | 0, this.h2 + u + w | 0, this.h3 + P + r | 0, this.h4 + n + a | 0, this.h0 + i + l | 0);
156
212
  }
157
213
  roundClean() {
158
214
  W(F);
@@ -161,29 +217,29 @@ class Ie extends Dt {
161
217
  this.destroyed = !0, W(this.buffer), this.set(0, 0, 0, 0, 0);
162
218
  }
163
219
  }
164
- const He = /* @__PURE__ */ Bt(() => new Ie()), Re = BigInt(0), O = BigInt(1), $e = BigInt(2), Oe = BigInt(7), Ve = BigInt(256), Me = BigInt(113), Ht = [], Rt = [], $t = [];
165
- for (let s = 0, e = O, t = 1, o = 0; s < 24; s++) {
166
- [t, o] = [o, (2 * t + 3 * o) % 5], Ht.push(2 * (5 * o + t)), Rt.push((s + 1) * (s + 2) / 2 % 64);
167
- let n = Re;
220
+ const Ue = /* @__PURE__ */ vt(() => new Me()), Fe = BigInt(0), V = BigInt(1), Ne = BigInt(2), We = BigInt(7), De = BigInt(256), Le = BigInt(113), $t = [], Ot = [], Vt = [];
221
+ for (let s = 0, e = V, t = 1, o = 0; s < 24; s++) {
222
+ [t, o] = [o, (2 * t + 3 * o) % 5], $t.push(2 * (5 * o + t)), Ot.push((s + 1) * (s + 2) / 2 % 64);
223
+ let n = Fe;
168
224
  for (let r = 0; r < 7; r++)
169
- e = (e << O ^ (e >> Oe) * Me) % Ve, e & $e && (n ^= O << (O << BigInt(r)) - O);
170
- $t.push(n);
225
+ e = (e << V ^ (e >> We) * Le) % De, e & Ne && (n ^= V << (V << BigInt(r)) - V);
226
+ Vt.push(n);
171
227
  }
172
- const Ot = Pe($t, !0), Ue = Ot[0], Fe = Ot[1], xt = (s, e, t) => t > 32 ? ye(s, e, t) : we(s, e, t), yt = (s, e, t) => t > 32 ? ke(s, e, t) : xe(s, e, t);
173
- function Ne(s, e = 24) {
228
+ const Mt = we(Vt, !0), Xe = Mt[0], Ke = Mt[1], xt = (s, e, t) => t > 32 ? ke(s, e, t) : xe(s, e, t), yt = (s, e, t) => t > 32 ? Te(s, e, t) : ye(s, e, t);
229
+ function qe(s, e = 24) {
174
230
  const t = new Uint32Array(10);
175
231
  for (let o = 24 - e; o < 24; o++) {
176
232
  for (let i = 0; i < 10; i++)
177
233
  t[i] = s[i] ^ s[i + 10] ^ s[i + 20] ^ s[i + 30] ^ s[i + 40];
178
234
  for (let i = 0; i < 10; i += 2) {
179
- const a = (i + 8) % 10, c = (i + 2) % 10, u = t[c], l = t[c + 1], m = xt(u, l, 1) ^ t[a], P = yt(u, l, 1) ^ t[a + 1];
235
+ const a = (i + 8) % 10, c = (i + 2) % 10, l = t[c], u = t[c + 1], m = xt(l, u, 1) ^ t[a], P = yt(l, u, 1) ^ t[a + 1];
180
236
  for (let w = 0; w < 50; w += 10)
181
237
  s[i + w] ^= m, s[i + w + 1] ^= P;
182
238
  }
183
239
  let n = s[2], r = s[3];
184
240
  for (let i = 0; i < 24; i++) {
185
- const a = Rt[i], c = xt(n, r, a), u = yt(n, r, a), l = Ht[i];
186
- n = s[l], r = s[l + 1], s[l] = c, s[l + 1] = u;
241
+ const a = Ot[i], c = xt(n, r, a), l = yt(n, r, a), u = $t[i];
242
+ n = s[u], r = s[u + 1], s[u] = c, s[u + 1] = l;
187
243
  }
188
244
  for (let i = 0; i < 50; i += 10) {
189
245
  for (let a = 0; a < 10; a++)
@@ -191,11 +247,11 @@ function Ne(s, e = 24) {
191
247
  for (let a = 0; a < 10; a++)
192
248
  s[i + a] ^= ~t[(a + 2) % 10] & t[(a + 4) % 10];
193
249
  }
194
- s[0] ^= Ue[o], s[1] ^= Fe[o];
250
+ s[0] ^= Xe[o], s[1] ^= Ke[o];
195
251
  }
196
252
  W(t);
197
253
  }
198
- class et {
254
+ class st {
199
255
  // NOTE: we accept arguments in bytes instead of bits here.
200
256
  constructor(e, t, o, n = !1, r = 24) {
201
257
  y(this, "state");
@@ -209,18 +265,18 @@ class et {
209
265
  y(this, "outputLen");
210
266
  y(this, "enableXOF", !1);
211
267
  y(this, "rounds");
212
- if (this.blockLen = e, this.suffix = t, this.outputLen = o, this.enableXOF = n, this.rounds = r, ot(o, "outputLen"), !(0 < e && e < 200))
268
+ if (this.blockLen = e, this.suffix = t, this.outputLen = o, this.enableXOF = n, this.rounds = r, nt(o, "outputLen"), !(0 < e && e < 200))
213
269
  throw new Error("only keccak-f1600 function is supported");
214
- this.state = new Uint8Array(200), this.state32 = Xt(this.state);
270
+ this.state = new Uint8Array(200), this.state32 = qt(this.state);
215
271
  }
216
272
  clone() {
217
273
  return this._cloneInto();
218
274
  }
219
275
  keccak() {
220
- nt(this.state32), Ne(this.state32, this.rounds), nt(this.state32), this.posOut = 0, this.pos = 0;
276
+ rt(this.state32), qe(this.state32, this.rounds), rt(this.state32), this.posOut = 0, this.pos = 0;
221
277
  }
222
278
  update(e) {
223
- rt(this), it(e);
279
+ it(this), at(e);
224
280
  const { blockLen: t, state: o } = this, n = e.length;
225
281
  for (let r = 0; r < n; ) {
226
282
  const i = Math.min(t - this.pos, n - r);
@@ -238,7 +294,7 @@ class et {
238
294
  e[o] ^= t, (t & 128) !== 0 && o === n - 1 && this.keccak(), e[n - 1] ^= 128, this.keccak();
239
295
  }
240
296
  writeInto(e) {
241
- rt(this, !1), it(e), this.finish();
297
+ it(this, !1), at(e), this.finish();
242
298
  const t = this.state, { blockLen: o } = this;
243
299
  for (let n = 0, r = e.length; n < r; ) {
244
300
  this.posOut >= o && this.keccak();
@@ -253,10 +309,10 @@ class et {
253
309
  return this.writeInto(e);
254
310
  }
255
311
  xof(e) {
256
- return ot(e), this.xofInto(new Uint8Array(e));
312
+ return nt(e), this.xofInto(new Uint8Array(e));
257
313
  }
258
314
  digestInto(e) {
259
- if (Kt(e, this), this.finished)
315
+ if (Gt(e, this), this.finished)
260
316
  throw new Error("digest() was already called");
261
317
  return this.writeInto(e), this.destroy(), e;
262
318
  }
@@ -268,24 +324,24 @@ class et {
268
324
  }
269
325
  _cloneInto(e) {
270
326
  const { blockLen: t, suffix: o, outputLen: n, rounds: r, enableXOF: i } = this;
271
- return e || (e = new et(t, o, n, i, r)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = r, e.suffix = o, e.outputLen = n, e.enableXOF = i, e.destroyed = this.destroyed, e;
327
+ return e || (e = new st(t, o, n, i, r)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = r, e.suffix = o, e.outputLen = n, e.enableXOF = i, e.destroyed = this.destroyed, e;
272
328
  }
273
329
  }
274
- const We = (s, e, t, o = {}) => Bt(() => new et(e, s, t), o), Le = /* @__PURE__ */ We(1, 136, 32), kt = 64, _ = 20, J = 4, Vt = 2, De = 0, Xe = 1, N = [64, 64], Ke = (s) => Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
275
- function st(s) {
276
- return He(Et(s));
330
+ const Ge = (s, e, t, o = {}) => vt(() => new st(e, s, t), o), ze = /* @__PURE__ */ Ge(1, 136, 32), kt = 64, C = 20, tt = 4, Ut = 2, Ye = 0, je = 1, N = [64, 64], Qe = (s) => Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
331
+ function ot(s) {
332
+ return Ue(Bt(s));
277
333
  }
278
- function Mt(s) {
334
+ function Ft(s) {
279
335
  return (1 << s) - 1;
280
336
  }
281
- function qe(s) {
337
+ function Ze(s) {
282
338
  let e = 1;
283
339
  for (; e * e < s + 1; ) e++;
284
340
  return Math.max(e, 2);
285
341
  }
286
- function Ge(s) {
287
- const e = J, t = s * Mt(e);
288
- return { d: e, n: s, checksum_radix: qe(t) };
342
+ function Je(s) {
343
+ const e = tt, t = s * Ft(e);
344
+ return { d: e, n: s, checksum_radix: Ze(t) };
289
345
  }
290
346
  function K(s, e) {
291
347
  const t = [];
@@ -296,41 +352,41 @@ function K(s, e) {
296
352
  n.set(s);
297
353
  for (let r = 0; r < t.length; r++)
298
354
  n[s.length + r] = t[r];
299
- return st(n);
355
+ return ot(n);
300
356
  }
301
357
  function q(s, e) {
302
358
  let t = s;
303
359
  for (let o = 0; o < e; o++)
304
- t = st(t);
360
+ t = ot(t);
305
361
  return t;
306
362
  }
307
- function ze(s, e) {
308
- const t = Mt(e.d), o = e.checksum_radix - 1, n = Math.floor(e.n * t / e.checksum_radix), r = [];
309
- for (let l = 0; l < e.n; l++) {
310
- const m = K(s, l + Vt), P = q(m, t);
363
+ function ts(s, e) {
364
+ const t = Ft(e.d), o = e.checksum_radix - 1, n = Math.floor(e.n * t / e.checksum_radix), r = [];
365
+ for (let u = 0; u < e.n; u++) {
366
+ const m = K(s, u + Ut), P = q(m, t);
311
367
  r.push(Array.from(P));
312
368
  }
313
369
  const i = K(
314
370
  s,
315
- De
371
+ Ye
316
372
  ), a = q(
317
373
  i,
318
374
  o
319
375
  ), c = K(
320
376
  s,
321
- Xe
322
- ), u = q(
377
+ je
378
+ ), l = q(
323
379
  c,
324
380
  n
325
381
  );
326
382
  return {
327
383
  config: e,
328
384
  message_terminals: r,
329
- checksum_major_terminal: Array.from(u),
385
+ checksum_major_terminal: Array.from(l),
330
386
  checksum_minor_terminal: Array.from(a)
331
387
  };
332
388
  }
333
- async function Ye(s) {
389
+ async function es(s) {
334
390
  try {
335
391
  if (s.length !== kt)
336
392
  throw new Error(
@@ -338,14 +394,14 @@ async function Ye(s) {
338
394
  );
339
395
  const e = [];
340
396
  for (let t = 0; t < N.length; t++) {
341
- const o = N[t], n = Ge(o), r = new Uint8Array(s.length + 1);
397
+ const o = N[t], n = Je(o), r = new Uint8Array(s.length + 1);
342
398
  r.set(s), r[s.length] = t;
343
- const i = st(r);
399
+ const i = ot(r);
344
400
  try {
345
- const a = ze(i, n);
346
- if (a.config.d !== J)
401
+ const a = ts(i, n);
402
+ if (a.config.d !== tt)
347
403
  throw new Error(
348
- `Block ${t}: expected d=${J}, got d=${a.config.d}`
404
+ `Block ${t}: expected d=${tt}, got d=${a.config.d}`
349
405
  );
350
406
  if (a.config.n !== o)
351
407
  throw new Error(
@@ -356,17 +412,17 @@ async function Ye(s) {
356
412
  `Block ${t}: expected ${o} message terminals, got ${a.message_terminals.length}`
357
413
  );
358
414
  for (let c = 0; c < a.message_terminals.length; c++)
359
- if (a.message_terminals[c].length !== _)
415
+ if (a.message_terminals[c].length !== C)
360
416
  throw new Error(
361
- `Block ${t} terminal ${c}: expected ${_} bytes, got ${a.message_terminals[c].length}`
417
+ `Block ${t} terminal ${c}: expected ${C} bytes, got ${a.message_terminals[c].length}`
362
418
  );
363
- if (a.checksum_minor_terminal.length !== _)
419
+ if (a.checksum_minor_terminal.length !== C)
364
420
  throw new Error(
365
- `Block ${t} checksum_minor: expected ${_} bytes`
421
+ `Block ${t} checksum_minor: expected ${C} bytes`
366
422
  );
367
- if (a.checksum_major_terminal.length !== _)
423
+ if (a.checksum_major_terminal.length !== C)
368
424
  throw new Error(
369
- `Block ${t} checksum_major: expected ${_} bytes`
425
+ `Block ${t} checksum_major: expected ${C} bytes`
370
426
  );
371
427
  e.push(a);
372
428
  } finally {
@@ -383,9 +439,9 @@ async function Ye(s) {
383
439
  }
384
440
  }
385
441
  function G(s, e, t) {
386
- if (s.length !== _)
442
+ if (s.length !== C)
387
443
  throw new Error(
388
- `Block ${e} ${t}: expected ${_} bytes, got ${s.length}`
444
+ `Block ${e} ${t}: expected ${C} bytes, got ${s.length}`
389
445
  );
390
446
  for (let o = 0; o < s.length; o++) {
391
447
  const n = s[o];
@@ -395,7 +451,7 @@ function G(s, e, t) {
395
451
  );
396
452
  }
397
453
  }
398
- function je(s) {
454
+ function ss(s) {
399
455
  if (s.length === 0)
400
456
  throw new Error("Public keys array must not be empty");
401
457
  for (let r = 0; r < s.length; r++) {
@@ -406,32 +462,32 @@ function je(s) {
406
462
  }
407
463
  let e = 0;
408
464
  for (const r of s)
409
- e += Vt + r.message_terminals.length;
410
- const t = new Uint8Array(e * _);
465
+ e += Ut + r.message_terminals.length;
466
+ const t = new Uint8Array(e * C);
411
467
  let o = 0;
412
468
  for (const r of s) {
413
- t.set(r.checksum_minor_terminal, o), o += _, t.set(r.checksum_major_terminal, o), o += _;
469
+ t.set(r.checksum_minor_terminal, o), o += C, t.set(r.checksum_major_terminal, o), o += C;
414
470
  for (const i of r.message_terminals)
415
- t.set(i, o), o += _;
471
+ t.set(i, o), o += C;
416
472
  }
417
- const n = Le(t);
418
- return `0x${Ke(n)}`;
473
+ const n = ze(t);
474
+ return `0x${Qe(n)}`;
419
475
  }
420
- async function Qe(s, e) {
476
+ async function os(s, e) {
421
477
  const t = [], o = [], n = [], r = [];
422
478
  try {
423
479
  for (let i = 0; i < e; i++) {
424
- const a = await zt(s, i);
480
+ const a = await Yt(s, i);
425
481
  try {
426
- const u = await Ye(a);
427
- t.push(u), o.push(je(u));
482
+ const l = await es(a);
483
+ t.push(l), o.push(ss(l));
428
484
  } finally {
429
485
  a.fill(0);
430
486
  }
431
- const c = await Yt(s, i);
487
+ const c = await jt(s, i);
432
488
  try {
433
- const u = Z(c);
434
- n.push(u), r.push(ae(S(u)).slice(2));
489
+ const l = J(c);
490
+ n.push(l), r.push(ce(_(l)).slice(2));
435
491
  } finally {
436
492
  c.fill(0);
437
493
  }
@@ -441,45 +497,19 @@ async function Qe(s, e) {
441
497
  }
442
498
  return { perVaultWotsKeys: t, wotsPkHashes: o, htlcSecretHexes: n, hashlocks: r };
443
499
  }
444
- const Ze = /^0x[0-9a-f]+$/i, Je = /^[0-9a-f]+$/i, ts = /^[A-Za-z0-9+/]+={0,2}$/;
445
- function V(s) {
446
- if (typeof s != "string" || s.length === 0)
447
- throw new Error("BTC wallet returned empty public key");
448
- return se(s).toLowerCase();
449
- }
450
- function es(s) {
451
- if (typeof s != "string" || s.length === 0)
452
- throw new Error("BTC wallet returned empty BIP-322 signature");
453
- if (s.startsWith("0x") || s.startsWith("0X")) {
454
- if (!Ze.test(s) || s.length < 4 || s.length % 2 !== 0)
455
- throw new Error("BTC wallet returned malformed hex BIP-322 signature");
456
- return s.toLowerCase();
457
- }
458
- if (Je.test(s)) {
459
- if (s.length % 2 !== 0)
460
- throw new Error("BTC wallet returned malformed hex BIP-322 signature");
461
- return `0x${s.toLowerCase()}`;
462
- }
463
- if (!ts.test(s) || s.length % 4 !== 0)
464
- throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
465
- const e = j.from(s, "base64");
466
- if (e.length === 0 || e.toString("base64") !== s)
467
- throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
468
- return `0x${e.toString("hex")}`;
469
- }
470
- const Ut = 0, tt = 25, Ft = 9999;
500
+ const Nt = 0, et = 25, Wt = 9999;
471
501
  function z(s) {
472
- if (!Number.isInteger(s) || s < 0 || s >= L)
502
+ if (!Number.isInteger(s) || s < 0 || s >= D)
473
503
  throw new Error(
474
- `Quoted commissionBps must be an integer in [0, ${L}), got ${s}`
504
+ `Quoted commissionBps must be an integer in [0, ${D}), got ${s}`
475
505
  );
476
506
  return Math.min(
477
- s + tt,
478
- Ft
507
+ s + et,
508
+ Wt
479
509
  );
480
510
  }
481
511
  const Y = "00".repeat(32);
482
- function ss(s, e) {
512
+ function ns(s, e) {
483
513
  const t = {
484
514
  bitcoin: "bc",
485
515
  testnet: "tb",
@@ -487,23 +517,23 @@ function ss(s, e) {
487
517
  regtest: "bcrt"
488
518
  };
489
519
  try {
490
- const o = vt.address.fromBech32(s);
520
+ const o = Et.address.fromBech32(s);
491
521
  return o.prefix === t[e] && o.version === 0 && o.data.length === 20;
492
522
  } catch {
493
523
  return !1;
494
524
  }
495
525
  }
496
- function os(s, e, t, o) {
526
+ function rs(s, e, t, o) {
497
527
  const n = t == null ? void 0 : t[`${s}:${e}`];
498
528
  return n ? Promise.resolve({
499
529
  txid: s,
500
530
  vout: e,
501
531
  value: n.value,
502
532
  scriptPubKey: n.scriptPubKey
503
- }) : me(s, e, o);
533
+ }) : be(s, e, o);
504
534
  }
505
535
  const Tt = 12e4;
506
- class Ss {
536
+ class Is {
507
537
  /**
508
538
  * Creates a new PeginManager instance.
509
539
  *
@@ -526,8 +556,8 @@ class Ss {
526
556
  async preparePegin(e) {
527
557
  if (e.amounts.length === 0)
528
558
  throw new Error("amounts must contain at least one entry");
529
- const t = await this.config.btcWallet.getPublicKeyHex(), o = V(t);
530
- if (!dt(
559
+ const t = await this.config.btcWallet.getPublicKeyHex(), o = $(t);
560
+ if (!gt(
531
561
  e.changeAddress,
532
562
  t,
533
563
  this.config.btcNetwork
@@ -537,25 +567,25 @@ class Ss {
537
567
  );
538
568
  const n = await this.prepareSizing(o, e), r = n.selectedUTXOs.map(
539
569
  (f) => ({
540
- txid: gt(f.txid),
570
+ txid: Z(f.txid),
541
571
  vout: f.vout
542
572
  })
543
- ), i = await ie(this.config.btcWallet, {
544
- depositorBtcPubkey: gt(o),
573
+ ), i = await Ct(this.config.btcWallet, {
574
+ depositorBtcPubkey: Z(o),
545
575
  fundingOutpoints: r
546
576
  });
547
577
  let a, c;
548
578
  try {
549
- const f = await jt(i);
579
+ const f = await Qt(i);
550
580
  try {
551
- a = Z(f), c = Z(Et(f));
581
+ a = J(f), c = J(Bt(f));
552
582
  } finally {
553
583
  f.fill(0);
554
584
  }
555
585
  } catch (f) {
556
586
  throw i.fill(0), f;
557
587
  }
558
- const u = await Qe(i, e.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: P, hashlocks: w } = u, d = await this.preparePeginCommit({
588
+ const l = await os(i, e.amounts.length), { perVaultWotsKeys: u, wotsPkHashes: m, htlcSecretHexes: P, hashlocks: w } = l, d = await this.preparePeginCommit({
559
589
  depositorBtcPubkeyRaw: t,
560
590
  depositorBtcPubkey: o,
561
591
  hashlocks: w,
@@ -568,12 +598,12 @@ class Ss {
568
598
  throw new Error(
569
599
  `Internal invariant violation: htlcVout/index mismatch at vault ${f} (expected ${f}, got ${d.perVault[f].htlcVout})`
570
600
  );
571
- ce(
601
+ le(
572
602
  d.fundedPrePeginTxHex,
573
603
  e.amounts.length,
574
604
  c
575
605
  );
576
- const { depositTerms: E, ...k } = d;
606
+ const { depositTerms: B, ...k } = d;
577
607
  return {
578
608
  transaction: {
579
609
  ...k,
@@ -583,12 +613,12 @@ class Ss {
583
613
  },
584
614
  depositorBtcPubkey: o,
585
615
  derivedSecrets: {
586
- perVaultWotsKeys: l,
616
+ perVaultWotsKeys: u,
587
617
  wotsPkHashes: m,
588
618
  htlcSecretHexes: P,
589
619
  authAnchorHex: a
590
620
  },
591
- depositTerms: E
621
+ depositTerms: B
592
622
  };
593
623
  }
594
624
  /**
@@ -610,12 +640,12 @@ class Ss {
610
640
  async prepareSizing(e, t) {
611
641
  const o = t.amounts.map(
612
642
  () => Y
613
- ), n = t.vaultKeeperBtcPubkeys.length, r = await ut({
643
+ ), n = t.vaultKeeperBtcPubkeys.length, r = await ht({
614
644
  vaultCoreVersion: t.vaultCoreVersion,
615
645
  depositorPubkey: e,
616
- vaultProviderPubkey: v(t.vaultProviderBtcPubkey),
617
- vaultKeeperPubkeys: t.vaultKeeperBtcPubkeys.map(v),
618
- universalChallengerPubkeys: t.universalChallengerBtcPubkeys.map(v),
646
+ vaultProviderPubkey: E(t.vaultProviderBtcPubkey),
647
+ vaultKeeperPubkeys: t.vaultKeeperBtcPubkeys.map(E),
648
+ universalChallengerPubkeys: t.universalChallengerBtcPubkeys.map(E),
619
649
  hashlocks: o,
620
650
  timelockRefund: t.timelockRefund,
621
651
  pegInAmounts: t.amounts,
@@ -626,11 +656,11 @@ class Ss {
626
656
  councilSize: t.councilSize,
627
657
  network: this.config.btcNetwork,
628
658
  authAnchorHash: Y
629
- }), i = ue(
659
+ }), i = he(
630
660
  [...t.availableUTXOs],
631
661
  r.totalOutputValue,
632
662
  t.mempoolFeeRate,
633
- de(r.htlcValues.length, !0)
663
+ ge(r.htlcValues.length, !0)
634
664
  );
635
665
  return {
636
666
  selectedUTXOs: i.selectedUTXOs,
@@ -657,13 +687,13 @@ class Ss {
657
687
  throw new Error(
658
688
  "preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
659
689
  );
660
- const u = v(
690
+ const l = E(
661
691
  a.vaultProviderBtcPubkey
662
- ), l = a.vaultKeeperBtcPubkeys.map(v), m = a.universalChallengerBtcPubkeys.map(v), P = l.length, w = {
692
+ ), u = a.vaultKeeperBtcPubkeys.map(E), m = a.universalChallengerBtcPubkeys.map(E), P = u.length, w = {
663
693
  vaultCoreVersion: a.vaultCoreVersion,
664
694
  depositorPubkey: o,
665
- vaultProviderPubkey: u,
666
- vaultKeeperPubkeys: l,
695
+ vaultProviderPubkey: l,
696
+ vaultKeeperPubkeys: u,
667
697
  universalChallengerPubkeys: m,
668
698
  hashlocks: n,
669
699
  timelockRefund: a.timelockRefund,
@@ -675,40 +705,40 @@ class Ss {
675
705
  councilSize: a.councilSize,
676
706
  network: this.config.btcNetwork,
677
707
  authAnchorHash: r
678
- }, d = await ut(w), E = ft(this.config.btcNetwork), k = ge({
708
+ }, d = await ht(w), B = ft(this.config.btcNetwork), k = fe({
679
709
  unfundedTxHex: d.psbtHex,
680
710
  selectedUTXOs: i.selectedUTXOs,
681
711
  changeAddress: a.changeAddress,
682
712
  changeAmount: i.changeAmount,
683
- network: E
684
- }), f = i.selectedUTXOs.reduce((g, B) => g + BigInt(B.value), 0n) - d.totalOutputValue - i.changeAmount;
713
+ network: B
714
+ }), f = i.selectedUTXOs.reduce((g, v) => g + BigInt(v.value), 0n) - d.totalOutputValue - i.changeAmount;
685
715
  if (f !== i.fee)
686
716
  throw new Error(
687
717
  `Pre-PegIn funded fee ${f} does not match the sizing-pass fee ${i.fee}; refusing to publish a deposit-terms fee bound the funded transaction does not pay.`
688
718
  );
689
- const A = v(
719
+ const A = E(
690
720
  X(k)
691
721
  ), p = [], b = [], T = [];
692
722
  for (let g = 0; g < n.length; g++) {
693
- const B = await Qt({
723
+ const v = await Zt({
694
724
  prePeginParams: w,
695
725
  timelockPegin: a.timelockPegin,
696
726
  fundedPrePeginTxHex: k,
697
727
  htlcVout: g
698
- }), I = await Jt({
728
+ }), I = await te({
699
729
  vaultCoreVersion: a.vaultCoreVersion,
700
- peginTxHex: B.txHex,
730
+ peginTxHex: v.txHex,
701
731
  fundedPrePeginTxHex: k,
702
732
  depositorPubkey: o,
703
- vaultProviderPubkey: u,
704
- vaultKeeperPubkeys: l,
733
+ vaultProviderPubkey: l,
734
+ vaultKeeperPubkeys: u,
705
735
  universalChallengerPubkeys: m,
706
736
  hashlock: n[g],
707
737
  timelockRefund: a.timelockRefund,
708
738
  network: this.config.btcNetwork
709
739
  });
710
- p.push(B), b.push(I.psbtHex), T.push(
711
- re(t, 1)
740
+ p.push(v), b.push(I.psbtHex), T.push(
741
+ ie(t, 1)
712
742
  );
713
743
  }
714
744
  const h = Be({
@@ -719,8 +749,8 @@ class Ss {
719
749
  timelockRefund: a.timelockRefund,
720
750
  prepeginTxid: A,
721
751
  prepeginMaxFee: i.fee,
722
- vaultProviderBtcPubkey: u,
723
- vaultKeeperBtcPubkeys: l,
752
+ vaultProviderBtcPubkey: l,
753
+ vaultKeeperBtcPubkeys: u,
724
754
  universalChallengerBtcPubkeys: m,
725
755
  maxAcceptableCommissionBps: z(
726
756
  a.commissionBps
@@ -730,40 +760,40 @@ class Ss {
730
760
  peginMaxFee: d.minPeginFee
731
761
  });
732
762
  mt(this.config.btcWallet) && await this.config.btcWallet.approveDepositTerms(h);
733
- const x = await le(
763
+ const x = await ue(
734
764
  this.config.btcWallet,
735
765
  b,
736
766
  T
737
- ), C = [];
767
+ ), S = [];
738
768
  for (let g = 0; g < x.length; g++) {
739
- ht({
769
+ dt({
740
770
  requestedPsbtHex: b[g],
741
771
  returnedPsbtHex: x[g]
742
772
  });
743
- const B = te(
773
+ const v = ee(
744
774
  x[g],
745
775
  o
746
776
  );
747
- Zt({
777
+ Jt({
748
778
  requestedPsbtHex: b[g],
749
- signatureHex: B,
779
+ signatureHex: v,
750
780
  signerXOnlyPubkeyHex: o,
751
781
  inputIndex: 0
752
782
  });
753
- const I = ee(x[g]);
754
- C.push({
783
+ const I = se(x[g]);
784
+ S.push({
755
785
  htlcVout: g,
756
786
  htlcValue: d.htlcValues[g],
757
787
  peginTxHex: I,
758
788
  peginTxid: p[g].txid,
759
- peginInputSignature: B,
789
+ peginInputSignature: v,
760
790
  vaultScriptPubKey: p[g].vaultScriptPubKey
761
791
  });
762
792
  }
763
793
  return {
764
794
  fundedPrePeginTxHex: k,
765
795
  prePeginTxid: A,
766
- perVault: C,
796
+ perVault: S,
767
797
  depositTerms: h
768
798
  };
769
799
  }
@@ -783,20 +813,20 @@ class Ss {
783
813
  * @throws Error if signing or broadcasting fails
784
814
  */
785
815
  async signAndBroadcast(e) {
786
- const { fundedPrePeginTxHex: t, depositorBtcPubkey: o } = e, n = t.startsWith("0x") ? t.slice(2) : t, r = qt.fromHex(n);
816
+ const { fundedPrePeginTxHex: t, depositorBtcPubkey: o } = e, n = t.startsWith("0x") ? t.slice(2) : t, r = At.fromHex(n);
787
817
  if (r.ins.length === 0)
788
818
  throw new Error("Transaction has no inputs");
789
- const i = new at();
819
+ const i = new ct();
790
820
  i.setVersion(r.version), i.setLocktime(r.locktime);
791
821
  const a = j.from(
792
- V(o),
822
+ $(o),
793
823
  "hex"
794
- ), c = this.config.mempoolApiUrl, u = r.ins.map((p) => {
824
+ ), c = this.config.mempoolApiUrl, l = r.ins.map((p) => {
795
825
  const b = j.from(p.hash).reverse().toString("hex"), T = p.index;
796
- return os(b, T, e.localPrevouts, c).then(
826
+ return rs(b, T, e.localPrevouts, c).then(
797
827
  (h) => ({ input: p, utxoData: h, txid: b, vout: T })
798
828
  );
799
- }), l = await Promise.all(u), m = l.reduce(
829
+ }), u = await Promise.all(l), m = u.reduce(
800
830
  (p, b) => p + BigInt(b.utxoData.value),
801
831
  0n
802
832
  ), P = r.outs.reduce(
@@ -812,8 +842,8 @@ class Ss {
812
842
  throw new Error(
813
843
  `Implied transaction fee (${w} sat) exceeds maximum reasonable fee (${pt} sat). This may indicate manipulated UTXO data.`
814
844
  );
815
- for (const { input: p, utxoData: b, txid: T, vout: h } of l) {
816
- const x = he(
845
+ for (const { input: p, utxoData: b, txid: T, vout: h } of u) {
846
+ const x = de(
817
847
  {
818
848
  value: b.value,
819
849
  scriptPubKey: b.scriptPubKey
@@ -832,12 +862,18 @@ class Ss {
832
862
  script: p.script,
833
863
  value: p.value
834
864
  });
835
- const d = i.toHex(), E = await this.config.btcWallet.signPsbt(d);
836
- ht({
865
+ await Se({
866
+ wallet: this.config.btcWallet,
867
+ depositTerms: e.depositTerms,
868
+ fundedPrePeginTxHex: t,
869
+ depositorBtcPubkey: o
870
+ });
871
+ const d = i.toHex(), B = await this.config.btcWallet.signPsbt(d);
872
+ dt({
837
873
  requestedPsbtHex: d,
838
- returnedPsbtHex: E
874
+ returnedPsbtHex: B
839
875
  });
840
- const k = at.fromHex(E);
876
+ const k = ct.fromHex(B);
841
877
  try {
842
878
  k.finalizeAllInputs();
843
879
  } catch (p) {
@@ -849,7 +885,7 @@ class Ss {
849
885
  );
850
886
  }
851
887
  const f = k.extractTransaction().toHex();
852
- return await fe(f, c);
888
+ return await pe(f, c);
853
889
  }
854
890
  /**
855
891
  * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
@@ -884,24 +920,24 @@ class Ss {
884
920
  htlcVout: i,
885
921
  depositorPayoutBtcAddress: a,
886
922
  depositorWotsPkHash: c,
887
- popSignature: u
923
+ popSignature: l
888
924
  } = e;
889
925
  if (!this.config.ethWallet.account)
890
926
  throw new Error("Ethereum wallet account not found");
891
- const l = this.config.ethWallet.account.address;
892
- if (!ct(u.depositorEthAddress, l))
927
+ const u = this.config.ethWallet.account.address;
928
+ if (!lt(l.depositorEthAddress, u))
893
929
  throw new Error(
894
- `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.`
930
+ `Proof of possession was signed for ${l.depositorEthAddress} but the Ethereum wallet is currently connected to ${u}. Reconnect the original account or call signProofOfPossession() again.`
895
931
  );
896
- const m = await this.assertPopMatchesBtcWallet(u), P = u.btcPopSignature, w = S(
897
- u.depositorBtcPubkey
898
- ), d = S(t), E = S(o), k = a ?? await this.config.btcWallet.getAddress(), f = this.resolvePayoutScriptPubKey(
932
+ const m = await this.assertPopMatchesBtcWallet(l), P = l.btcPopSignature, w = _(
933
+ l.depositorBtcPubkey
934
+ ), d = _(t), B = _(o), k = a ?? await this.config.btcWallet.getAddress(), f = this.resolvePayoutScriptPubKey(
899
935
  m,
900
936
  k
901
- ), A = X(E), p = await lt(
902
- v(A),
903
- v(l)
904
- ), b = S(p);
937
+ ), A = X(B), p = await ut(
938
+ E(A),
939
+ E(u)
940
+ ), b = _(p);
905
941
  if (await this.checkVaultExists(b))
906
942
  throw new Error(
907
943
  `Vault already exists (ID: ${b}, peginTxHash: ${A}). 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.`
@@ -915,42 +951,42 @@ class Ss {
915
951
  functionName: "getPegInFee",
916
952
  args: [n]
917
953
  });
918
- } catch ($) {
954
+ } catch (O) {
919
955
  throw new Error(
920
956
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
921
- { cause: $ }
957
+ { cause: O }
922
958
  );
923
959
  }
924
- const C = await this.resolveMaxAcceptableCommissionBps(
960
+ const S = await this.resolveMaxAcceptableCommissionBps(
925
961
  n,
926
962
  e.quotedCommissionBps
927
963
  ), g = Q({
928
964
  abi: H,
929
965
  functionName: "submitPeginRequest",
930
966
  args: [
931
- l,
967
+ u,
932
968
  w,
933
969
  P,
934
970
  d,
935
- E,
971
+ B,
936
972
  n,
937
- C,
973
+ S,
938
974
  r,
939
975
  i,
940
976
  f,
941
977
  c
942
978
  ]
943
979
  });
944
- let B;
980
+ let v;
945
981
  try {
946
- B = await h.estimateGas({
982
+ v = await h.estimateGas({
947
983
  to: this.config.vaultContracts.btcVaultRegistry,
948
984
  data: g,
949
985
  value: x,
950
986
  account: this.config.ethWallet.account.address
951
987
  });
952
- } catch ($) {
953
- R($);
988
+ } catch (O) {
989
+ R(O);
954
990
  }
955
991
  let I;
956
992
  try {
@@ -960,23 +996,23 @@ class Ss {
960
996
  value: x,
961
997
  account: this.config.ethWallet.account,
962
998
  chain: this.config.ethChain,
963
- gas: B
999
+ gas: v
964
1000
  });
965
- } catch ($) {
966
- R($);
1001
+ } catch (O) {
1002
+ R(O);
967
1003
  }
968
- const D = await bt({
1004
+ const L = await bt({
969
1005
  publicClient: h,
970
1006
  walletAddress: this.config.ethWallet.account.address,
971
1007
  hash: I,
972
1008
  timeout: Tt
973
1009
  });
974
- return D.status === "reverted" && R(
1010
+ return L.status === "reverted" && R(
975
1011
  new Error(
976
- `Transaction reverted. Hash: ${D.transactionHash}. Check the transaction on block explorer for details.`
1012
+ `Transaction reverted. Hash: ${L.transactionHash}. Check the transaction on block explorer for details.`
977
1013
  )
978
1014
  ), {
979
- ethTxHash: D.transactionHash,
1015
+ ethTxHash: L.transactionHash,
980
1016
  vaultId: b,
981
1017
  peginTxHash: A
982
1018
  };
@@ -998,28 +1034,28 @@ class Ss {
998
1034
  if (!this.config.ethWallet.account)
999
1035
  throw new Error("Ethereum wallet account not found");
1000
1036
  const i = this.config.ethWallet.account.address;
1001
- if (!ct(r.depositorEthAddress, i))
1037
+ if (!lt(r.depositorEthAddress, i))
1002
1038
  throw new Error(
1003
1039
  `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.`
1004
1040
  );
1005
- const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, u = n.map(
1041
+ const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, l = n.map(
1006
1042
  (h) => this.resolvePayoutScriptPubKey(
1007
1043
  a,
1008
1044
  h.depositorPayoutBtcAddress
1009
1045
  )
1010
- ), l = [];
1046
+ ), u = [];
1011
1047
  for (const h of n) {
1012
- const x = S(
1048
+ const x = _(
1013
1049
  h.depositorSignedPeginTx
1014
- ), C = X(x), g = await lt(
1015
- v(C),
1016
- v(i)
1017
- ), B = S(g);
1018
- if (await this.checkVaultExists(B))
1050
+ ), S = X(x), g = await ut(
1051
+ E(S),
1052
+ E(i)
1053
+ ), v = _(g);
1054
+ if (await this.checkVaultExists(v))
1019
1055
  throw new Error(
1020
- `Vault already exists (ID: ${B}, peginTxHash: ${C}). To create a new vault, use different UTXOs or a different amount.`
1056
+ `Vault already exists (ID: ${v}, peginTxHash: ${S}). To create a new vault, use different UTXOs or a different amount.`
1021
1057
  );
1022
- l.push({ vaultId: B, peginTxHash: C });
1058
+ u.push({ vaultId: v, peginTxHash: S });
1023
1059
  }
1024
1060
  const m = this.config.publicClient;
1025
1061
  let P;
@@ -1039,19 +1075,19 @@ class Ss {
1039
1075
  const w = P * BigInt(n.length), d = await this.resolveMaxAcceptableCommissionBps(
1040
1076
  t,
1041
1077
  e.quotedCommissionBps
1042
- ), E = S(
1078
+ ), B = _(
1043
1079
  r.depositorBtcPubkey
1044
- ), k = S(o), f = n.map((h, x) => ({
1045
- depositorBtcPubKey: E,
1080
+ ), k = _(o), f = n.map((h, x) => ({
1081
+ depositorBtcPubKey: B,
1046
1082
  btcPopSignature: c,
1047
1083
  unsignedPrePeginTx: k,
1048
- depositorSignedPeginTx: S(
1084
+ depositorSignedPeginTx: _(
1049
1085
  h.depositorSignedPeginTx
1050
1086
  ),
1051
1087
  hashlock: h.hashlock,
1052
1088
  htlcVout: h.htlcVout,
1053
- referralCode: Ut,
1054
- depositorPayoutBtcAddress: u[x],
1089
+ referralCode: Nt,
1090
+ depositorPayoutBtcAddress: l[x],
1055
1091
  depositorWotsPkHash: h.depositorWotsPkHash
1056
1092
  })), A = Q({
1057
1093
  abi: H,
@@ -1099,7 +1135,7 @@ class Ss {
1099
1135
  )
1100
1136
  ), {
1101
1137
  ethTxHash: T.transactionHash,
1102
- vaults: l
1138
+ vaults: u
1103
1139
  };
1104
1140
  }
1105
1141
  // Anchor to quoted+headroom when supplied (refuse if chain drifted past it);
@@ -1111,7 +1147,7 @@ class Ss {
1111
1147
  );
1112
1148
  let o;
1113
1149
  try {
1114
- o = await new pe(
1150
+ o = await new me(
1115
1151
  this.config.publicClient,
1116
1152
  this.config.vaultContracts.btcVaultRegistry
1117
1153
  ).getVaultProviderCommission(e);
@@ -1122,9 +1158,9 @@ class Ss {
1122
1158
  );
1123
1159
  }
1124
1160
  if (t !== void 0) {
1125
- if (o > t + tt)
1161
+ if (o > t + et)
1126
1162
  throw new Error(
1127
- `Vault provider commission changed since quote: quoted ${t} bps, chain currently reports ${o} bps (allowed drift ${tt} bps). Please refresh to see the new commission and try again.`
1163
+ `Vault provider commission changed since quote: quoted ${t} bps, chain currently reports ${o} bps (allowed drift ${et} bps). Please refresh to see the new commission and try again.`
1128
1164
  );
1129
1165
  return z(t);
1130
1166
  }
@@ -1149,7 +1185,7 @@ class Ss {
1149
1185
  abi: H,
1150
1186
  functionName: "getBtcVaultBasicInfo",
1151
1187
  args: [e]
1152
- })).depositor !== Gt;
1188
+ })).depositor !== zt;
1153
1189
  }
1154
1190
  /**
1155
1191
  * Resolve the BTC scriptPubKey to register as the depositor's payout sink.
@@ -1168,19 +1204,19 @@ class Ss {
1168
1204
  * on-chain payout-script registration.
1169
1205
  */
1170
1206
  resolvePayoutScriptPubKey(e, t) {
1171
- if (!dt(
1207
+ if (!gt(
1172
1208
  t,
1173
1209
  e,
1174
1210
  this.config.btcNetwork
1175
1211
  ))
1176
- throw v(e).length === oe && ss(t, this.config.btcNetwork) ? new Error(
1212
+ throw E(e).length === ne && ns(t, this.config.btcNetwork) ? new Error(
1177
1213
  `BTC payout address "${t}" 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.`
1178
1214
  ) : new Error(
1179
1215
  `BTC payout address "${t}" 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.`
1180
1216
  );
1181
1217
  const o = ft(this.config.btcNetwork);
1182
1218
  try {
1183
- return `0x${vt.address.toOutputScript(t, o).toString("hex")}`;
1219
+ return `0x${Et.address.toOutputScript(t, o).toString("hex")}`;
1184
1220
  } catch {
1185
1221
  throw new Error(
1186
1222
  `Invalid BTC payout address: "${t}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
@@ -1196,14 +1232,14 @@ class Ss {
1196
1232
  async signProofOfPossession() {
1197
1233
  if (!this.config.ethWallet.account)
1198
1234
  throw new Error("Ethereum wallet account not found");
1199
- const e = this.config.ethWallet.account.address, t = V(
1235
+ const e = this.config.ethWallet.account.address, t = $(
1200
1236
  await this.config.btcWallet.getPublicKeyHex()
1201
1237
  ), o = this.config.vaultContracts.btcVaultRegistry, n = `${e.toLowerCase()}:${this.config.ethChain.id}:pegin:${o.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
1202
1238
  n,
1203
1239
  "bip322-simple"
1204
1240
  );
1205
1241
  return {
1206
- btcPopSignature: es(r),
1242
+ btcPopSignature: _e(r),
1207
1243
  depositorEthAddress: e,
1208
1244
  depositorBtcPubkey: t
1209
1245
  };
@@ -1217,7 +1253,7 @@ class Ss {
1217
1253
  * substitute the opposite-parity P2WPKH address.
1218
1254
  */
1219
1255
  async assertPopMatchesBtcWallet(e) {
1220
- const t = await this.config.btcWallet.getPublicKeyHex(), o = V(t), n = V(e.depositorBtcPubkey);
1256
+ const t = await this.config.btcWallet.getPublicKeyHex(), o = $(t), n = $(e.depositorBtcPubkey);
1221
1257
  if (o !== n)
1222
1258
  throw new Error(
1223
1259
  `Proof of possession was signed with BTC pubkey ${n} but the BTC wallet is currently connected to ${o}. Reconnect the original wallet or call signProofOfPossession() again.`
@@ -1241,29 +1277,29 @@ class Ss {
1241
1277
  return this.config.vaultContracts.btcVaultRegistry;
1242
1278
  }
1243
1279
  }
1244
- const ns = 80, rs = 250, is = 300, as = 22, Nt = "ab";
1245
- function cs(s, e) {
1246
- const t = Nt.repeat(is), o = v(s).toLowerCase(), n = e.toString(16).padStart(8, "0"), r = `${o}${n}`, i = t.slice(r.length);
1280
+ const is = 80, as = 250, cs = 300, ls = 22, Dt = "ab";
1281
+ function us(s, e) {
1282
+ const t = Dt.repeat(cs), o = E(s).toLowerCase(), n = e.toString(16).padStart(8, "0"), r = `${o}${n}`, i = t.slice(r.length);
1247
1283
  return `0x${r}${i}`;
1248
1284
  }
1249
- function ls(s, e) {
1250
- const t = (o) => `0x${Nt.repeat(o)}`;
1285
+ function hs(s, e) {
1286
+ const t = (o) => `0x${Dt.repeat(o)}`;
1251
1287
  return {
1252
1288
  depositorBtcPubKey: t(32),
1253
- btcPopSignature: t(ns),
1254
- unsignedPrePeginTx: t(rs),
1255
- depositorSignedPeginTx: cs(
1289
+ btcPopSignature: t(is),
1290
+ unsignedPrePeginTx: t(as),
1291
+ depositorSignedPeginTx: us(
1256
1292
  s,
1257
1293
  e
1258
1294
  ),
1259
1295
  hashlock: t(32),
1260
1296
  htlcVout: e,
1261
- referralCode: Ut,
1262
- depositorPayoutBtcAddress: t(as),
1297
+ referralCode: Nt,
1298
+ depositorPayoutBtcAddress: t(ls),
1263
1299
  depositorWotsPkHash: t(32)
1264
1300
  };
1265
1301
  }
1266
- async function Cs(s) {
1302
+ async function Hs(s) {
1267
1303
  const {
1268
1304
  publicClient: e,
1269
1305
  btcVaultRegistry: t,
@@ -1282,29 +1318,30 @@ async function Cs(s) {
1282
1318
  args: [n]
1283
1319
  }) * BigInt(r), c = Array.from(
1284
1320
  { length: r },
1285
- (l, m) => ls(o, m)
1286
- ), u = Q({
1321
+ (u, m) => hs(o, m)
1322
+ ), l = Q({
1287
1323
  abi: H,
1288
1324
  functionName: "submitPeginRequestBatch",
1289
1325
  args: [
1290
1326
  o,
1291
1327
  n,
1292
- Ft,
1328
+ Wt,
1293
1329
  c
1294
1330
  ]
1295
1331
  });
1296
1332
  return e.estimateGas({
1297
1333
  to: t,
1298
- data: u,
1334
+ data: l,
1299
1335
  value: a,
1300
1336
  account: o
1301
1337
  });
1302
1338
  }
1303
1339
  export {
1304
- Ss as P,
1340
+ Is as P,
1341
+ Se as a,
1305
1342
  Be as b,
1306
- je as c,
1307
- Ye as d,
1308
- Cs as e
1343
+ ss as c,
1344
+ es as d,
1345
+ Hs as e
1309
1346
  };
1310
- //# sourceMappingURL=PeginManager-DKyNgvq1.js.map
1347
+ //# sourceMappingURL=PeginManager-C2vPVud-.js.map