@babylonlabs-io/ts-sdk 0.36.0 → 0.36.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/PeginManager-BPXVXu8t.cjs +2 -0
  2. package/dist/{PeginManager-cPQuJTB9.cjs.map → PeginManager-BPXVXu8t.cjs.map} +1 -1
  3. package/dist/{PeginManager-DF1oinIQ.js → PeginManager-CB-dVkT2.js} +387 -369
  4. package/dist/{PeginManager-DF1oinIQ.js.map → PeginManager-CB-dVkT2.js.map} +1 -1
  5. package/dist/buildAndBroadcastRefund-C2VqXiOx.js +893 -0
  6. package/dist/buildAndBroadcastRefund-C2VqXiOx.js.map +1 -0
  7. package/dist/buildAndBroadcastRefund-CBIfcF47.cjs +2 -0
  8. package/dist/buildAndBroadcastRefund-CBIfcF47.cjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +74 -70
  11. package/dist/tbv/core/clients/eth/types.d.ts +1 -0
  12. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  13. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +1 -0
  14. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  15. package/dist/tbv/core/clients/index.cjs +1 -1
  16. package/dist/tbv/core/clients/index.js +1 -1
  17. package/dist/tbv/core/index.cjs +1 -1
  18. package/dist/tbv/core/index.js +67 -63
  19. package/dist/tbv/core/managers/PeginManager.d.ts +22 -4
  20. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  21. package/dist/tbv/core/managers/index.cjs +1 -1
  22. package/dist/tbv/core/managers/index.js +1 -1
  23. package/dist/tbv/core/services/deposit/__tests__/validateOnChainParticipantKeys.test.d.ts +2 -0
  24. package/dist/tbv/core/services/deposit/__tests__/validateOnChainParticipantKeys.test.d.ts.map +1 -0
  25. package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredVaultVersions.test.d.ts +2 -0
  26. package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredVaultVersions.test.d.ts.map +1 -0
  27. package/dist/tbv/core/services/deposit/index.d.ts +8 -12
  28. package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
  29. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
  30. package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts +21 -0
  31. package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -0
  32. package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.d.ts +15 -0
  33. package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.d.ts.map +1 -0
  34. package/dist/tbv/core/services/index.cjs +1 -1
  35. package/dist/tbv/core/services/index.js +23 -19
  36. package/dist/tbv/core/vault-secrets/index.d.ts +1 -0
  37. package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -1
  38. package/dist/tbv/index.cjs +1 -1
  39. package/dist/tbv/index.js +67 -63
  40. package/dist/tbv/integrations/aave/constants.d.ts +15 -2
  41. package/dist/tbv/integrations/aave/constants.d.ts.map +1 -1
  42. package/dist/tbv/integrations/aave/index.cjs +1 -1
  43. package/dist/tbv/integrations/aave/index.cjs.map +1 -1
  44. package/dist/tbv/integrations/aave/index.d.ts +1 -1
  45. package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
  46. package/dist/tbv/integrations/aave/index.js +94 -93
  47. package/dist/tbv/integrations/aave/index.js.map +1 -1
  48. package/dist/{vault-registry-reader-Cufa-ZkW.cjs → vault-registry-reader-CLnhAUN4.cjs} +2 -2
  49. package/dist/{vault-registry-reader-Cufa-ZkW.cjs.map → vault-registry-reader-CLnhAUN4.cjs.map} +1 -1
  50. package/dist/{vault-registry-reader-Bz8uu0dh.js → vault-registry-reader-CrLodprY.js} +220 -190
  51. package/dist/{vault-registry-reader-Bz8uu0dh.js.map → vault-registry-reader-CrLodprY.js.map} +1 -1
  52. package/package.json +1 -1
  53. package/dist/PeginManager-cPQuJTB9.cjs +0 -2
  54. package/dist/buildAndBroadcastRefund-BQ0CaL6Q.cjs +0 -2
  55. package/dist/buildAndBroadcastRefund-BQ0CaL6Q.cjs.map +0 -1
  56. package/dist/buildAndBroadcastRefund-DzX11N9S.js +0 -785
  57. package/dist/buildAndBroadcastRefund-DzX11N9S.js.map +0 -1
@@ -1,46 +1,46 @@
1
- var Wt = Object.defineProperty;
2
- var Lt = (n, t, e) => t in n ? Wt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var y = (n, t, e) => Lt(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { s as tt, c as Tt, H as Ft, r as U, a as F, b as st, u as Mt, d as ot, e as rt, f as it, g as Xt } from "./sha2-BYVxyZzX.js";
5
- import * as _t from "bitcoinjs-lib";
6
- import { Transaction as Kt, Psbt as at } from "bitcoinjs-lib";
7
- import { Buffer as q } from "buffer";
8
- import { isAddressEqual as ct, encodeFunctionData as lt, zeroAddress as Dt } from "viem";
9
- import { B as R } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
1
+ var Mt = Object.defineProperty;
2
+ var Xt = (n, t, e) => t in n ? Mt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
+ var k = (n, t, e) => Xt(n, typeof t != "symbol" ? t + "" : t, e);
4
+ import { s as nt, c as Bt, H as Kt, r as U, a as F, b as rt, u as Dt, d as it, e as at, f as ct, g as zt } from "./sha2-BYVxyZzX.js";
5
+ import * as It from "bitcoinjs-lib";
6
+ import { Transaction as Gt, Psbt as lt } from "bitcoinjs-lib";
7
+ import { Buffer as Q } from "buffer";
8
+ import { isAddressEqual as ut, encodeFunctionData as ht, zeroAddress as jt } from "viem";
9
+ import { B as O } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
10
10
  import { h as A } from "./errors-CznAK5NB.js";
11
- import { expandWotsSeed as zt, expandHashlockSecret as Gt, expandAuthAnchor as jt, deriveVaultId as ut } from "@babylonlabs-io/babylon-tbv-rust-wasm";
12
- import { b as ht, a as qt, c as Zt, e as Qt, f as Yt } from "./peginInput-C2QPvuhR.js";
13
- import { s as T, u as M, h as Z, e as I, p as Jt, g as dt, i as te } from "./bitcoin-B0S8SHCX.js";
14
- import { c as ee } from "./signing-DaLvGwQe.js";
15
- import { M as ft } from "./validation-CxqROCno.js";
16
- import { c as ne } from "./PayoutManager-s_uH8Uuj.js";
17
- import { s as se, c as K, d as oe, w as gt } from "./waitForTransactionReceiptSmartAware-Cj_DKm0G.js";
18
- import { p as re, f as ie } from "./fundPeginTransaction-oV-dNJOU.js";
19
- import { p as ae, f as ce } from "./mempoolApi-CAIge7Nj.js";
20
- const N = /* @__PURE__ */ BigInt(2 ** 32 - 1), pt = /* @__PURE__ */ BigInt(32);
21
- function le(n, t = !1) {
22
- return t ? { h: Number(n & N), l: Number(n >> pt & N) } : { h: Number(n >> pt & N) | 0, l: Number(n & N) | 0 };
11
+ import { expandWotsSeed as qt, expandHashlockSecret as Zt, expandAuthAnchor as Qt, deriveVaultId as dt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
12
+ import { b as gt, a as Yt, c as Jt, e as te, f as ee } from "./peginInput-C2QPvuhR.js";
13
+ import { s as T, u as M, h as Y, e as B, p as ne, i as ft, g as pt } from "./bitcoin-B0S8SHCX.js";
14
+ import { c as se } from "./signing-DaLvGwQe.js";
15
+ import { M as mt } from "./validation-CxqROCno.js";
16
+ import { c as oe } from "./PayoutManager-s_uH8Uuj.js";
17
+ import { s as re, c as z, d as ie, w as wt } from "./waitForTransactionReceiptSmartAware-Cj_DKm0G.js";
18
+ import { p as ae, f as ce } from "./fundPeginTransaction-oV-dNJOU.js";
19
+ import { p as le, f as ue } from "./mempoolApi-CAIge7Nj.js";
20
+ const N = /* @__PURE__ */ BigInt(2 ** 32 - 1), Pt = /* @__PURE__ */ BigInt(32);
21
+ function he(n, t = !1) {
22
+ return t ? { h: Number(n & N), l: Number(n >> Pt & N) } : { h: Number(n >> Pt & N) | 0, l: Number(n & N) | 0 };
23
23
  }
24
- function ue(n, t = !1) {
24
+ function de(n, t = !1) {
25
25
  const e = n.length;
26
26
  let s = new Uint32Array(e), o = new Uint32Array(e);
27
27
  for (let r = 0; r < e; r++) {
28
- const { h: i, l: a } = le(n[r], t);
28
+ const { h: i, l: a } = he(n[r], t);
29
29
  [s[r], o[r]] = [i, a];
30
30
  }
31
31
  return [s, o];
32
32
  }
33
- const he = (n, t, e) => n << e | t >>> 32 - e, de = (n, t, e) => t << e | n >>> 32 - e, fe = (n, t, e) => t << e - 32 | n >>> 64 - e, ge = (n, t, e) => n << e - 32 | t >>> 64 - e, pe = 106, me = 32, mt = 34;
34
- function we(n, t, e) {
35
- const s = T(n), o = _t.Transaction.fromHex(s);
33
+ const ge = (n, t, e) => n << e | t >>> 32 - e, fe = (n, t, e) => t << e | n >>> 32 - e, pe = (n, t, e) => t << e - 32 | n >>> 64 - e, me = (n, t, e) => n << e - 32 | t >>> 64 - e, we = 106, Pe = 32, bt = 34;
34
+ function be(n, t, e) {
35
+ const s = T(n), o = It.Transaction.fromHex(s);
36
36
  if (o.outs.length <= t)
37
37
  throw new Error(
38
38
  `Pre-PegIn auth-anchor OP_RETURN missing: tx has ${o.outs.length} outputs, expected at least ${t + 1} (vault outputs + OP_RETURN)`
39
39
  );
40
40
  const r = o.outs[t], i = r.script;
41
- if (i.length !== mt || i[0] !== pe || i[1] !== me)
41
+ if (i.length !== bt || i[0] !== we || i[1] !== Pe)
42
42
  throw new Error(
43
- `Pre-PegIn auth-anchor OP_RETURN at vout ${t} has unexpected script encoding (got ${i.length}-byte script with prefix 0x${i.slice(0, Math.min(2, i.length)).toString("hex")}; expected ${mt}-byte OP_RETURN + PUSH32 layout)`
43
+ `Pre-PegIn auth-anchor OP_RETURN at vout ${t} has unexpected script encoding (got ${i.length}-byte script with prefix 0x${i.slice(0, Math.min(2, i.length)).toString("hex")}; expected ${bt}-byte OP_RETURN + PUSH32 layout)`
44
44
  );
45
45
  const a = i.slice(2).toString("hex").toLowerCase();
46
46
  if (a !== e.toLowerCase())
@@ -52,70 +52,70 @@ function we(n, t, e) {
52
52
  `Pre-PegIn auth-anchor OP_RETURN at vout ${t} has non-zero value ${r.value}; OP_RETURN outputs must be 0-value`
53
53
  );
54
54
  }
55
- const C = 32, D = 32, Q = 36, vt = 32, X = 4, Pe = X + C + X + vt;
56
- function Y(n, t, e) {
55
+ const C = 32, G = 32, J = 36, St = 32, X = 4, ye = X + C + X + St;
56
+ function tt(n, t, e) {
57
57
  n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = e & 255;
58
58
  }
59
- function be(n) {
60
- if (n.txid.length !== D)
59
+ function xe(n) {
60
+ if (n.txid.length !== G)
61
61
  throw new Error(
62
- `outpoint.txid must be exactly ${D} bytes, got ${n.txid.length}`
62
+ `outpoint.txid must be exactly ${G} bytes, got ${n.txid.length}`
63
63
  );
64
64
  if (!Number.isInteger(n.vout) || n.vout < 0 || n.vout > 4294967295)
65
65
  throw new Error(`outpoint.vout must be a u32, got ${n.vout}`);
66
- const t = new Uint8Array(Q);
67
- return t.set(n.txid, 0), Y(t, D, n.vout), t;
66
+ const t = new Uint8Array(J);
67
+ return t.set(n.txid, 0), tt(t, G, n.vout), t;
68
68
  }
69
- function wt(n, t) {
69
+ function yt(n, t) {
70
70
  const e = Math.min(n.length, t.length);
71
71
  for (let s = 0; s < e; s++)
72
72
  if (n[s] !== t[s]) return n[s] - t[s];
73
73
  return n.length - t.length;
74
74
  }
75
- function xe(n) {
75
+ function ke(n) {
76
76
  if (n.length === 0)
77
77
  throw new Error(
78
78
  "buildFundingOutpointsCommitment: outpoints must be non-empty"
79
79
  );
80
- const t = n.map(be);
81
- t.sort(wt);
80
+ const t = n.map(xe);
81
+ t.sort(yt);
82
82
  for (let s = 1; s < t.length; s++)
83
- if (wt(t[s - 1], t[s]) === 0)
83
+ if (yt(t[s - 1], t[s]) === 0)
84
84
  throw new Error(
85
85
  "buildFundingOutpointsCommitment: duplicate outpoint detected"
86
86
  );
87
- const e = new Uint8Array(t.length * Q);
87
+ const e = new Uint8Array(t.length * J);
88
88
  for (let s = 0; s < t.length; s++)
89
- e.set(t[s], s * Q);
90
- return tt(e);
89
+ e.set(t[s], s * J);
90
+ return nt(e);
91
91
  }
92
- function ye(n) {
92
+ function Ee(n) {
93
93
  if (n.depositorBtcPubkey.length !== C)
94
94
  throw new Error(
95
95
  `vaultContext: depositorBtcPubkey must be exactly ${C} bytes, got ${n.depositorBtcPubkey.length}`
96
96
  );
97
- const t = xe(n.fundingOutpoints), e = new Uint8Array(Pe);
97
+ const t = ke(n.fundingOutpoints), e = new Uint8Array(ye);
98
98
  let s = 0;
99
- return Y(e, s, C), s += X, e.set(n.depositorBtcPubkey, s), s += C, Y(e, s, vt), s += X, e.set(t, s), e;
99
+ return tt(e, s, C), s += X, e.set(n.depositorBtcPubkey, s), s += C, tt(e, s, St), s += X, e.set(t, s), e;
100
100
  }
101
- const ke = "babylon-btc-vault", It = 32, Pt = It * 2, Ee = /^[0-9a-f]+$/;
102
- async function Te(n, t) {
103
- const e = ye(t), s = M(e), o = await n.deriveContextHash(ke, s);
101
+ const Te = "babylon-btc-vault", At = 32, xt = At * 2, _e = /^[0-9a-f]+$/;
102
+ async function ve(n, t) {
103
+ const e = Ee(t), s = M(e), o = await n.deriveContextHash(Te, s);
104
104
  if (typeof o != "string")
105
105
  throw new Error(
106
106
  `deriveVaultRoot: wallet must return a string, got ${typeof o}`
107
107
  );
108
- if (o.length !== Pt)
108
+ if (o.length !== xt)
109
109
  throw new Error(
110
- `deriveVaultRoot: wallet must return a ${Pt}-character hex string (${It} bytes), got length ${o.length}`
110
+ `deriveVaultRoot: wallet must return a ${xt}-character hex string (${At} bytes), got length ${o.length}`
111
111
  );
112
- if (!Ee.test(o))
112
+ if (!_e.test(o))
113
113
  throw new Error(
114
114
  "deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
115
115
  );
116
- return Z(o);
116
+ return Y(o);
117
117
  }
118
- const _e = /* @__PURE__ */ Uint8Array.from([
118
+ const Be = /* @__PURE__ */ Uint8Array.from([
119
119
  7,
120
120
  4,
121
121
  13,
@@ -132,43 +132,43 @@ const _e = /* @__PURE__ */ Uint8Array.from([
132
132
  14,
133
133
  11,
134
134
  8
135
- ]), St = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), ve = St.map((n) => (9 * n + 5) % 16), Bt = /* @__PURE__ */ (() => {
136
- const e = [[St], [ve]];
135
+ ]), Rt = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), Ie = Rt.map((n) => (9 * n + 5) % 16), Ot = /* @__PURE__ */ (() => {
136
+ const e = [[Rt], [Ie]];
137
137
  for (let s = 0; s < 4; s++)
138
138
  for (let o of e)
139
- o.push(o[s].map((r) => _e[r]));
139
+ o.push(o[s].map((r) => Be[r]));
140
140
  return e;
141
- })(), At = Bt[0], Ot = Bt[1], Rt = /* @__PURE__ */ [
141
+ })(), $t = Ot[0], Ht = Ot[1], Ct = /* @__PURE__ */ [
142
142
  [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
143
143
  [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
144
144
  [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
145
145
  [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
146
146
  [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
147
- ].map((n) => Uint8Array.from(n)), Ie = /* @__PURE__ */ At.map((n, t) => n.map((e) => Rt[t][e])), Se = /* @__PURE__ */ Ot.map((n, t) => n.map((e) => Rt[t][e])), Be = /* @__PURE__ */ Uint32Array.from([
147
+ ].map((n) => Uint8Array.from(n)), Se = /* @__PURE__ */ $t.map((n, t) => n.map((e) => Ct[t][e])), Ae = /* @__PURE__ */ Ht.map((n, t) => n.map((e) => Ct[t][e])), Re = /* @__PURE__ */ Uint32Array.from([
148
148
  0,
149
149
  1518500249,
150
150
  1859775393,
151
151
  2400959708,
152
152
  2840853838
153
- ]), Ae = /* @__PURE__ */ Uint32Array.from([
153
+ ]), Oe = /* @__PURE__ */ Uint32Array.from([
154
154
  1352829926,
155
155
  1548603684,
156
156
  1836072691,
157
157
  2053994217,
158
158
  0
159
159
  ]);
160
- function bt(n, t, e, s) {
160
+ function kt(n, t, e, s) {
161
161
  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);
162
162
  }
163
163
  const V = /* @__PURE__ */ new Uint32Array(16);
164
- class Oe extends Ft {
164
+ class $e extends Kt {
165
165
  constructor() {
166
166
  super(64, 20, 8, !0);
167
- y(this, "h0", 1732584193);
168
- y(this, "h1", -271733879);
169
- y(this, "h2", -1732584194);
170
- y(this, "h3", 271733878);
171
- y(this, "h4", -1009589776);
167
+ k(this, "h0", 1732584193);
168
+ k(this, "h1", -271733879);
169
+ k(this, "h2", -1732584194);
170
+ k(this, "h3", 271733878);
171
+ k(this, "h4", -1009589776);
172
172
  }
173
173
  get() {
174
174
  const { h0: e, h1: s, h2: o, h3: r, h4: i } = this;
@@ -178,18 +178,18 @@ class Oe extends Ft {
178
178
  this.h0 = e | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
179
179
  }
180
180
  process(e, s) {
181
- for (let h = 0; h < 16; h++, s += 4)
182
- V[h] = e.getUint32(s, !0);
181
+ for (let d = 0; d < 16; d++, s += 4)
182
+ V[d] = e.getUint32(s, !0);
183
183
  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, w = this.h4 | 0, P = w;
184
- for (let h = 0; h < 5; h++) {
185
- const g = 4 - h, E = Be[h], S = Ae[h], f = At[h], x = Ot[h], d = Ie[h], k = Se[h];
184
+ for (let d = 0; d < 5; d++) {
185
+ const g = 4 - d, E = Re[d], I = Oe[d], f = $t[d], y = Ht[d], x = Se[d], p = Ae[d];
186
186
  for (let b = 0; b < 16; b++) {
187
- const p = U(o + bt(h, i, c, l) + V[f[b]] + E, d[b]) + w | 0;
188
- o = w, w = l, l = U(c, 10) | 0, c = i, i = p;
187
+ const h = U(o + kt(d, i, c, l) + V[f[b]] + E, x[b]) + w | 0;
188
+ o = w, w = l, l = U(c, 10) | 0, c = i, i = h;
189
189
  }
190
190
  for (let b = 0; b < 16; b++) {
191
- const p = U(r + bt(g, a, u, m) + V[x[b]] + S, k[b]) + P | 0;
192
- r = P, P = m, m = U(u, 10) | 0, u = a, a = p;
191
+ const h = U(r + kt(g, a, u, m) + V[y[b]] + I, p[b]) + P | 0;
192
+ r = P, P = m, m = U(u, 10) | 0, u = a, a = h;
193
193
  }
194
194
  }
195
195
  this.set(this.h1 + c + m | 0, this.h2 + l + P | 0, this.h3 + w + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
@@ -201,28 +201,28 @@ class Oe extends Ft {
201
201
  this.destroyed = !0, F(this.buffer), this.set(0, 0, 0, 0, 0);
202
202
  }
203
203
  }
204
- const Re = /* @__PURE__ */ Tt(() => new Oe()), He = BigInt(0), H = BigInt(1), $e = BigInt(2), Ce = BigInt(7), Ue = BigInt(256), Ne = BigInt(113), Ht = [], $t = [], Ct = [];
205
- for (let n = 0, t = H, e = 1, s = 0; n < 24; n++) {
206
- [e, s] = [s, (2 * e + 3 * s) % 5], Ht.push(2 * (5 * s + e)), $t.push((n + 1) * (n + 2) / 2 % 64);
207
- let o = He;
204
+ const He = /* @__PURE__ */ Bt(() => new $e()), Ce = BigInt(0), $ = BigInt(1), Ue = BigInt(2), Ne = BigInt(7), Ve = BigInt(256), Le = BigInt(113), Ut = [], Nt = [], Vt = [];
205
+ for (let n = 0, t = $, e = 1, s = 0; n < 24; n++) {
206
+ [e, s] = [s, (2 * e + 3 * s) % 5], Ut.push(2 * (5 * s + e)), Nt.push((n + 1) * (n + 2) / 2 % 64);
207
+ let o = Ce;
208
208
  for (let r = 0; r < 7; r++)
209
- t = (t << H ^ (t >> Ce) * Ne) % Ue, t & $e && (o ^= H << (H << BigInt(r)) - H);
210
- Ct.push(o);
209
+ t = (t << $ ^ (t >> Ne) * Le) % Ve, t & Ue && (o ^= $ << ($ << BigInt(r)) - $);
210
+ Vt.push(o);
211
211
  }
212
- const Ut = ue(Ct, !0), Ve = Ut[0], We = Ut[1], xt = (n, t, e) => e > 32 ? fe(n, t, e) : he(n, t, e), yt = (n, t, e) => e > 32 ? ge(n, t, e) : de(n, t, e);
213
- function Le(n, t = 24) {
212
+ const Lt = de(Vt, !0), We = Lt[0], Fe = Lt[1], Et = (n, t, e) => e > 32 ? pe(n, t, e) : ge(n, t, e), Tt = (n, t, e) => e > 32 ? me(n, t, e) : fe(n, t, e);
213
+ function Me(n, t = 24) {
214
214
  const e = new Uint32Array(10);
215
215
  for (let s = 24 - t; s < 24; s++) {
216
216
  for (let i = 0; i < 10; i++)
217
217
  e[i] = n[i] ^ n[i + 10] ^ n[i + 20] ^ n[i + 30] ^ n[i + 40];
218
218
  for (let i = 0; i < 10; i += 2) {
219
- const a = (i + 8) % 10, c = (i + 2) % 10, u = e[c], l = e[c + 1], m = xt(u, l, 1) ^ e[a], w = yt(u, l, 1) ^ e[a + 1];
219
+ const a = (i + 8) % 10, c = (i + 2) % 10, u = e[c], l = e[c + 1], m = Et(u, l, 1) ^ e[a], w = Tt(u, l, 1) ^ e[a + 1];
220
220
  for (let P = 0; P < 50; P += 10)
221
221
  n[i + P] ^= m, n[i + P + 1] ^= w;
222
222
  }
223
223
  let o = n[2], r = n[3];
224
224
  for (let i = 0; i < 24; i++) {
225
- const a = $t[i], c = xt(o, r, a), u = yt(o, r, a), l = Ht[i];
225
+ const a = Nt[i], c = Et(o, r, a), u = Tt(o, r, a), l = Ut[i];
226
226
  o = n[l], r = n[l + 1], n[l] = c, n[l + 1] = u;
227
227
  }
228
228
  for (let i = 0; i < 50; i += 10) {
@@ -231,36 +231,36 @@ function Le(n, t = 24) {
231
231
  for (let a = 0; a < 10; a++)
232
232
  n[i + a] ^= ~e[(a + 2) % 10] & e[(a + 4) % 10];
233
233
  }
234
- n[0] ^= Ve[s], n[1] ^= We[s];
234
+ n[0] ^= We[s], n[1] ^= Fe[s];
235
235
  }
236
236
  F(e);
237
237
  }
238
- class et {
238
+ class st {
239
239
  // NOTE: we accept arguments in bytes instead of bits here.
240
240
  constructor(t, e, s, o = !1, r = 24) {
241
- y(this, "state");
242
- y(this, "pos", 0);
243
- y(this, "posOut", 0);
244
- y(this, "finished", !1);
245
- y(this, "state32");
246
- y(this, "destroyed", !1);
247
- y(this, "blockLen");
248
- y(this, "suffix");
249
- y(this, "outputLen");
250
- y(this, "enableXOF", !1);
251
- y(this, "rounds");
252
- if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r, st(s, "outputLen"), !(0 < t && t < 200))
241
+ k(this, "state");
242
+ k(this, "pos", 0);
243
+ k(this, "posOut", 0);
244
+ k(this, "finished", !1);
245
+ k(this, "state32");
246
+ k(this, "destroyed", !1);
247
+ k(this, "blockLen");
248
+ k(this, "suffix");
249
+ k(this, "outputLen");
250
+ k(this, "enableXOF", !1);
251
+ k(this, "rounds");
252
+ if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r, rt(s, "outputLen"), !(0 < t && t < 200))
253
253
  throw new Error("only keccak-f1600 function is supported");
254
- this.state = new Uint8Array(200), this.state32 = Mt(this.state);
254
+ this.state = new Uint8Array(200), this.state32 = Dt(this.state);
255
255
  }
256
256
  clone() {
257
257
  return this._cloneInto();
258
258
  }
259
259
  keccak() {
260
- ot(this.state32), Le(this.state32, this.rounds), ot(this.state32), this.posOut = 0, this.pos = 0;
260
+ it(this.state32), Me(this.state32, this.rounds), it(this.state32), this.posOut = 0, this.pos = 0;
261
261
  }
262
262
  update(t) {
263
- rt(this), it(t);
263
+ at(this), ct(t);
264
264
  const { blockLen: e, state: s } = this, o = t.length;
265
265
  for (let r = 0; r < o; ) {
266
266
  const i = Math.min(e - this.pos, o - r);
@@ -278,7 +278,7 @@ class et {
278
278
  t[s] ^= e, (e & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
279
279
  }
280
280
  writeInto(t) {
281
- rt(this, !1), it(t), this.finish();
281
+ at(this, !1), ct(t), this.finish();
282
282
  const e = this.state, { blockLen: s } = this;
283
283
  for (let o = 0, r = t.length; o < r; ) {
284
284
  this.posOut >= s && this.keccak();
@@ -293,10 +293,10 @@ class et {
293
293
  return this.writeInto(t);
294
294
  }
295
295
  xof(t) {
296
- return st(t), this.xofInto(new Uint8Array(t));
296
+ return rt(t), this.xofInto(new Uint8Array(t));
297
297
  }
298
298
  digestInto(t) {
299
- if (Xt(t, this), this.finished)
299
+ if (zt(t, this), this.finished)
300
300
  throw new Error("digest() was already called");
301
301
  return this.writeInto(t), this.destroy(), t;
302
302
  }
@@ -308,26 +308,26 @@ class et {
308
308
  }
309
309
  _cloneInto(t) {
310
310
  const { blockLen: e, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
311
- return t || (t = new et(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;
311
+ return t || (t = new st(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;
312
312
  }
313
313
  }
314
- const Fe = (n, t, e, s = {}) => Tt(() => new et(t, n, e), s), Me = /* @__PURE__ */ Fe(1, 136, 32), kt = 64, _ = 20, J = 4, Nt = 2, Xe = 0, Ke = 1, W = [64, 64], De = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
315
- function nt(n) {
316
- return Re(tt(n));
314
+ const Xe = (n, t, e, s = {}) => Bt(() => new st(t, n, e), s), Ke = /* @__PURE__ */ Xe(1, 136, 32), _t = 64, _ = 20, et = 4, Wt = 2, De = 0, ze = 1, L = [64, 64], Ge = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
315
+ function ot(n) {
316
+ return He(nt(n));
317
317
  }
318
- function Vt(n) {
318
+ function Ft(n) {
319
319
  return (1 << n) - 1;
320
320
  }
321
- function ze(n) {
321
+ function je(n) {
322
322
  let t = 1;
323
323
  for (; t * t < n + 1; ) t++;
324
324
  return Math.max(t, 2);
325
325
  }
326
- function Ge(n) {
327
- const t = J, e = n * Vt(t);
328
- return { d: t, n, checksum_radix: ze(e) };
326
+ function qe(n) {
327
+ const t = et, e = n * Ft(t);
328
+ return { d: t, n, checksum_radix: je(e) };
329
329
  }
330
- function z(n, t) {
330
+ function j(n, t) {
331
331
  const e = [];
332
332
  let s = t;
333
333
  for (; s > 0; )
@@ -336,30 +336,30 @@ function z(n, t) {
336
336
  o.set(n);
337
337
  for (let r = 0; r < e.length; r++)
338
338
  o[n.length + r] = e[r];
339
- return nt(o);
339
+ return ot(o);
340
340
  }
341
- function G(n, t) {
341
+ function q(n, t) {
342
342
  let e = n;
343
343
  for (let s = 0; s < t; s++)
344
- e = nt(e);
344
+ e = ot(e);
345
345
  return e;
346
346
  }
347
- function je(n, t) {
348
- const e = Vt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * e / t.checksum_radix), r = [];
347
+ function Ze(n, t) {
348
+ const e = Ft(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * e / t.checksum_radix), r = [];
349
349
  for (let l = 0; l < t.n; l++) {
350
- const m = z(n, l + Nt), w = G(m, e);
350
+ const m = j(n, l + Wt), w = q(m, e);
351
351
  r.push(Array.from(w));
352
352
  }
353
- const i = z(
353
+ const i = j(
354
354
  n,
355
- Xe
356
- ), a = G(
355
+ De
356
+ ), a = q(
357
357
  i,
358
358
  s
359
- ), c = z(
359
+ ), c = j(
360
360
  n,
361
- Ke
362
- ), u = G(
361
+ ze
362
+ ), u = q(
363
363
  c,
364
364
  o
365
365
  );
@@ -370,22 +370,22 @@ function je(n, t) {
370
370
  checksum_minor_terminal: Array.from(a)
371
371
  };
372
372
  }
373
- async function qe(n) {
373
+ async function Qe(n) {
374
374
  try {
375
- if (n.length !== kt)
375
+ if (n.length !== _t)
376
376
  throw new Error(
377
- `WOTS seed must be exactly ${kt} bytes, got ${n.length}`
377
+ `WOTS seed must be exactly ${_t} bytes, got ${n.length}`
378
378
  );
379
379
  const t = [];
380
- for (let e = 0; e < W.length; e++) {
381
- const s = W[e], o = Ge(s), r = new Uint8Array(n.length + 1);
380
+ for (let e = 0; e < L.length; e++) {
381
+ const s = L[e], o = qe(s), r = new Uint8Array(n.length + 1);
382
382
  r.set(n), r[n.length] = e;
383
- const i = nt(r);
383
+ const i = ot(r);
384
384
  try {
385
- const a = je(i, o);
386
- if (a.config.d !== J)
385
+ const a = Ze(i, o);
386
+ if (a.config.d !== et)
387
387
  throw new Error(
388
- `Block ${e}: expected d=${J}, got d=${a.config.d}`
388
+ `Block ${e}: expected d=${et}, got d=${a.config.d}`
389
389
  );
390
390
  if (a.config.n !== s)
391
391
  throw new Error(
@@ -413,16 +413,16 @@ async function qe(n) {
413
413
  r.fill(0), i.fill(0);
414
414
  }
415
415
  }
416
- if (t.length !== W.length)
416
+ if (t.length !== L.length)
417
417
  throw new Error(
418
- `Expected ${W.length} blocks, got ${t.length}`
418
+ `Expected ${L.length} blocks, got ${t.length}`
419
419
  );
420
420
  return t;
421
421
  } finally {
422
422
  n.fill(0);
423
423
  }
424
424
  }
425
- function j(n, t, e) {
425
+ function Z(n, t, e) {
426
426
  if (n.length !== _)
427
427
  throw new Error(
428
428
  `Block ${t} ${e}: expected ${_} bytes, got ${n.length}`
@@ -435,18 +435,18 @@ function j(n, t, e) {
435
435
  );
436
436
  }
437
437
  }
438
- function Ze(n) {
438
+ function Ye(n) {
439
439
  if (n.length === 0)
440
440
  throw new Error("Public keys array must not be empty");
441
441
  for (let r = 0; r < n.length; r++) {
442
442
  const i = n[r];
443
- j(i.checksum_minor_terminal, r, "checksum_minor_terminal"), j(i.checksum_major_terminal, r, "checksum_major_terminal");
443
+ Z(i.checksum_minor_terminal, r, "checksum_minor_terminal"), Z(i.checksum_major_terminal, r, "checksum_major_terminal");
444
444
  for (let a = 0; a < i.message_terminals.length; a++)
445
- j(i.message_terminals[a], r, `message_terminal[${a}]`);
445
+ Z(i.message_terminals[a], r, `message_terminal[${a}]`);
446
446
  }
447
447
  let t = 0;
448
448
  for (const r of n)
449
- t += Nt + r.message_terminals.length;
449
+ t += Wt + r.message_terminals.length;
450
450
  const e = new Uint8Array(t * _);
451
451
  let s = 0;
452
452
  for (const r of n) {
@@ -454,24 +454,24 @@ function Ze(n) {
454
454
  for (const i of r.message_terminals)
455
455
  e.set(i, s), s += _;
456
456
  }
457
- const o = Me(e);
458
- return `0x${De(o)}`;
457
+ const o = Ke(e);
458
+ return `0x${Ge(o)}`;
459
459
  }
460
- async function Qe(n, t) {
460
+ async function Je(n, t) {
461
461
  const e = [], s = [], o = [], r = [];
462
462
  try {
463
463
  for (let i = 0; i < t; i++) {
464
- const a = await zt(n, i);
464
+ const a = await qt(n, i);
465
465
  try {
466
- const u = await qe(a);
467
- e.push(u), s.push(Ze(u));
466
+ const u = await Qe(a);
467
+ e.push(u), s.push(Ye(u));
468
468
  } finally {
469
469
  a.fill(0);
470
470
  }
471
- const c = await Gt(n, i);
471
+ const c = await Zt(n, i);
472
472
  try {
473
473
  const u = M(c);
474
- o.push(u), r.push(ne(I(u)).slice(2));
474
+ o.push(u), r.push(oe(B(u)).slice(2));
475
475
  } finally {
476
476
  c.fill(0);
477
477
  }
@@ -481,33 +481,33 @@ async function Qe(n, t) {
481
481
  }
482
482
  return { perVaultWotsKeys: e, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
483
483
  }
484
- const Ye = /^0x[0-9a-f]+$/i, Je = /^[0-9a-f]+$/i, tn = /^[A-Za-z0-9+/]+={0,2}$/;
485
- function $(n) {
484
+ const tn = /^0x[0-9a-f]+$/i, en = /^[0-9a-f]+$/i, nn = /^[A-Za-z0-9+/]+={0,2}$/;
485
+ function H(n) {
486
486
  if (typeof n != "string" || n.length === 0)
487
487
  throw new Error("BTC wallet returned empty public key");
488
- return Jt(n).toLowerCase();
488
+ return ne(n).toLowerCase();
489
489
  }
490
- function en(n) {
490
+ function sn(n) {
491
491
  if (typeof n != "string" || n.length === 0)
492
492
  throw new Error("BTC wallet returned empty BIP-322 signature");
493
493
  if (n.startsWith("0x") || n.startsWith("0X")) {
494
- if (!Ye.test(n) || n.length < 4 || n.length % 2 !== 0)
494
+ if (!tn.test(n) || n.length < 4 || n.length % 2 !== 0)
495
495
  throw new Error("BTC wallet returned malformed hex BIP-322 signature");
496
496
  return n.toLowerCase();
497
497
  }
498
- if (Je.test(n)) {
498
+ if (en.test(n)) {
499
499
  if (n.length % 2 !== 0)
500
500
  throw new Error("BTC wallet returned malformed hex BIP-322 signature");
501
501
  return `0x${n.toLowerCase()}`;
502
502
  }
503
- if (!tn.test(n) || n.length % 4 !== 0)
503
+ if (!nn.test(n) || n.length % 4 !== 0)
504
504
  throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
505
- const t = q.from(n, "base64");
505
+ const t = Q.from(n, "base64");
506
506
  if (t.length === 0 || t.toString("base64") !== n)
507
507
  throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
508
508
  return `0x${t.toString("hex")}`;
509
509
  }
510
- async function nn(n, t, e) {
510
+ async function on(n, t, e) {
511
511
  if (typeof n.signPsbts == "function") {
512
512
  const o = await n.signPsbts(t, e);
513
513
  if (o.length !== t.length)
@@ -523,25 +523,25 @@ async function nn(n, t, e) {
523
523
  }
524
524
  return s;
525
525
  }
526
- const sn = 0, L = "00".repeat(32);
527
- function on(n, t, e, s) {
526
+ const rn = 0, W = "00".repeat(32);
527
+ function an(n, t, e, s) {
528
528
  const o = e == null ? void 0 : e[`${n}:${t}`];
529
529
  return o ? Promise.resolve({
530
530
  txid: n,
531
531
  vout: t,
532
532
  value: o.value,
533
533
  scriptPubKey: o.scriptPubKey
534
- }) : ce(n, t, s);
534
+ }) : ue(n, t, s);
535
535
  }
536
- const Et = 12e4;
537
- class kn {
536
+ const vt = 12e4;
537
+ class Tn {
538
538
  /**
539
539
  * Creates a new PeginManager instance.
540
540
  *
541
541
  * @param config - Manager configuration including wallets and contract addresses
542
542
  */
543
543
  constructor(t) {
544
- y(this, "config");
544
+ k(this, "config");
545
545
  this.config = t;
546
546
  }
547
547
  /**
@@ -556,27 +556,36 @@ class kn {
556
556
  async preparePegin(t) {
557
557
  if (t.amounts.length === 0)
558
558
  throw new Error("amounts must contain at least one entry");
559
- const e = await this.config.btcWallet.getPublicKeyHex(), s = $(e), o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
559
+ const e = await this.config.btcWallet.getPublicKeyHex(), s = H(e);
560
+ if (!ft(
561
+ t.changeAddress,
562
+ e,
563
+ this.config.btcNetwork
564
+ ))
565
+ throw new Error(
566
+ `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.`
567
+ );
568
+ const o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
560
569
  (g) => ({
561
- txid: Z(g.txid),
570
+ txid: Y(g.txid),
562
571
  vout: g.vout
563
572
  })
564
- ), i = await Te(this.config.btcWallet, {
565
- depositorBtcPubkey: Z(s),
573
+ ), i = await ve(this.config.btcWallet, {
574
+ depositorBtcPubkey: Y(s),
566
575
  fundingOutpoints: r
567
576
  });
568
577
  let a, c;
569
578
  try {
570
- const g = await jt(i);
579
+ const g = await Qt(i);
571
580
  try {
572
- a = M(g), c = M(tt(g));
581
+ a = M(g), c = M(nt(g));
573
582
  } finally {
574
583
  g.fill(0);
575
584
  }
576
585
  } catch (g) {
577
586
  throw i.fill(0), g;
578
587
  }
579
- const u = await Qe(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: w, hashlocks: P } = u, h = await this.preparePeginCommit({
588
+ const u = await Je(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: w, hashlocks: P } = u, d = await this.preparePeginCommit({
580
589
  depositorBtcPubkeyRaw: e,
581
590
  depositorBtcPubkey: s,
582
591
  hashlocks: P,
@@ -584,18 +593,18 @@ class kn {
584
593
  sizing: o,
585
594
  params: t
586
595
  });
587
- for (let g = 0; g < h.perVault.length; g++)
588
- if (h.perVault[g].htlcVout !== g)
596
+ for (let g = 0; g < d.perVault.length; g++)
597
+ if (d.perVault[g].htlcVout !== g)
589
598
  throw new Error(
590
- `Internal invariant violation: htlcVout/index mismatch at vault ${g} (expected ${g}, got ${h.perVault[g].htlcVout})`
599
+ `Internal invariant violation: htlcVout/index mismatch at vault ${g} (expected ${g}, got ${d.perVault[g].htlcVout})`
591
600
  );
592
- return we(
593
- h.fundedPrePeginTxHex,
601
+ return be(
602
+ d.fundedPrePeginTxHex,
594
603
  t.amounts.length,
595
604
  c
596
605
  ), {
597
606
  transaction: {
598
- ...h,
607
+ ...d,
599
608
  selectedUTXOs: o.selectedUTXOs,
600
609
  fee: o.fee,
601
610
  changeAmount: o.changeAmount
@@ -627,8 +636,8 @@ class kn {
627
636
  */
628
637
  async prepareSizing(t, e) {
629
638
  const s = e.amounts.map(
630
- () => L
631
- ), o = e.vaultKeeperBtcPubkeys.length, r = await ht({
639
+ () => W
640
+ ), o = e.vaultKeeperBtcPubkeys.length, r = await gt({
632
641
  depositorPubkey: t,
633
642
  vaultProviderPubkey: T(e.vaultProviderBtcPubkey),
634
643
  vaultKeeperPubkeys: e.vaultKeeperBtcPubkeys.map(T),
@@ -641,14 +650,14 @@ class kn {
641
650
  councilQuorum: e.councilQuorum,
642
651
  councilSize: e.councilSize,
643
652
  network: this.config.btcNetwork,
644
- authAnchorHash: L
645
- }), i = se(
653
+ authAnchorHash: W
654
+ }), i = re(
646
655
  [...e.availableUTXOs],
647
656
  r.totalOutputValue,
648
657
  e.mempoolFeeRate,
649
- re(
658
+ ae(
650
659
  r.htlcValues.length,
651
- L
660
+ W
652
661
  )
653
662
  );
654
663
  return {
@@ -666,11 +675,11 @@ class kn {
666
675
  authAnchorHash: r,
667
676
  sizing: i,
668
677
  params: a
669
- } = t, c = L.toLowerCase();
670
- for (let p = 0; p < o.length; p++)
671
- if (o[p].toLowerCase() === c)
678
+ } = t, c = W.toLowerCase();
679
+ for (let h = 0; h < o.length; h++)
680
+ if (o[h].toLowerCase() === c)
672
681
  throw new Error(
673
- `preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${p} — internal substitution bug`
682
+ `preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${h} — internal substitution bug`
674
683
  );
675
684
  if (r.toLowerCase() === c)
676
685
  throw new Error(
@@ -690,56 +699,56 @@ class kn {
690
699
  councilSize: a.councilSize,
691
700
  network: this.config.btcNetwork,
692
701
  authAnchorHash: r
693
- }, h = await ht(P), g = dt(this.config.btcNetwork), E = ie({
694
- unfundedTxHex: h.psbtHex,
702
+ }, d = await gt(P), g = pt(this.config.btcNetwork), E = ce({
703
+ unfundedTxHex: d.psbtHex,
695
704
  selectedUTXOs: i.selectedUTXOs,
696
705
  changeAddress: a.changeAddress,
697
706
  changeAmount: i.changeAmount,
698
707
  network: g
699
- }), S = T(K(E)), f = [], x = [], d = [];
700
- for (let p = 0; p < o.length; p++) {
701
- const v = await qt({
708
+ }), I = T(z(E)), f = [], y = [], x = [];
709
+ for (let h = 0; h < o.length; h++) {
710
+ const S = await Yt({
702
711
  prePeginParams: P,
703
712
  timelockPegin: a.timelockPegin,
704
713
  fundedPrePeginTxHex: E,
705
- htlcVout: p
706
- }), B = await Zt({
707
- peginTxHex: v.txHex,
714
+ htlcVout: h
715
+ }), v = await Jt({
716
+ peginTxHex: S.txHex,
708
717
  fundedPrePeginTxHex: E,
709
718
  depositorPubkey: s,
710
719
  vaultProviderPubkey: u,
711
720
  vaultKeeperPubkeys: l,
712
721
  universalChallengerPubkeys: m,
713
- hashlock: o[p],
722
+ hashlock: o[h],
714
723
  timelockRefund: a.timelockRefund,
715
724
  network: this.config.btcNetwork
716
725
  });
717
- f.push(v), x.push(B.psbtHex), d.push(
718
- ee(e, 1)
726
+ f.push(S), y.push(v.psbtHex), x.push(
727
+ se(e, 1)
719
728
  );
720
729
  }
721
- const k = await nn(
730
+ const p = await on(
722
731
  this.config.btcWallet,
723
- x,
724
- d
732
+ y,
733
+ x
725
734
  ), b = [];
726
- for (let p = 0; p < k.length; p++) {
727
- const v = Qt(
728
- k[p],
735
+ for (let h = 0; h < p.length; h++) {
736
+ const S = te(
737
+ p[h],
729
738
  s
730
- ), B = Yt(k[p]);
739
+ ), v = ee(p[h]);
731
740
  b.push({
732
- htlcVout: p,
733
- htlcValue: h.htlcValues[p],
734
- peginTxHex: B,
735
- peginTxid: f[p].txid,
736
- peginInputSignature: v,
737
- vaultScriptPubKey: f[p].vaultScriptPubKey
741
+ htlcVout: h,
742
+ htlcValue: d.htlcValues[h],
743
+ peginTxHex: v,
744
+ peginTxid: f[h].txid,
745
+ peginInputSignature: S,
746
+ vaultScriptPubKey: f[h].vaultScriptPubKey
738
747
  });
739
748
  }
740
749
  return {
741
750
  fundedPrePeginTxHex: E,
742
- prePeginTxid: S,
751
+ prePeginTxid: I,
743
752
  perVault: b
744
753
  };
745
754
  }
@@ -759,24 +768,24 @@ class kn {
759
768
  * @throws Error if signing or broadcasting fails
760
769
  */
761
770
  async signAndBroadcast(t) {
762
- const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = Kt.fromHex(o);
771
+ const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = Gt.fromHex(o);
763
772
  if (r.ins.length === 0)
764
773
  throw new Error("Transaction has no inputs");
765
- const i = new at();
774
+ const i = new lt();
766
775
  i.setVersion(r.version), i.setLocktime(r.locktime);
767
- const a = q.from(
768
- $(s),
776
+ const a = Q.from(
777
+ H(s),
769
778
  "hex"
770
779
  ), c = this.config.mempoolApiUrl, u = r.ins.map((f) => {
771
- const x = q.from(f.hash).reverse().toString("hex"), d = f.index;
772
- return on(x, d, t.localPrevouts, c).then(
773
- (k) => ({ input: f, utxoData: k, txid: x, vout: d })
780
+ const y = Q.from(f.hash).reverse().toString("hex"), x = f.index;
781
+ return an(y, x, t.localPrevouts, c).then(
782
+ (p) => ({ input: f, utxoData: p, txid: y, vout: x })
774
783
  );
775
784
  }), l = await Promise.all(u), m = l.reduce(
776
- (f, x) => f + BigInt(x.utxoData.value),
785
+ (f, y) => f + BigInt(y.utxoData.value),
777
786
  0n
778
787
  ), w = r.outs.reduce(
779
- (f, x) => f + BigInt(x.value),
788
+ (f, y) => f + BigInt(y.value),
780
789
  0n
781
790
  );
782
791
  if (m < w)
@@ -784,15 +793,15 @@ class kn {
784
793
  `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.`
785
794
  );
786
795
  const P = m - w;
787
- if (P > ft)
796
+ if (P > mt)
788
797
  throw new Error(
789
- `Implied transaction fee (${P} sat) exceeds maximum reasonable fee (${ft} sat). This may indicate manipulated UTXO data.`
798
+ `Implied transaction fee (${P} sat) exceeds maximum reasonable fee (${mt} sat). This may indicate manipulated UTXO data.`
790
799
  );
791
- for (const { input: f, utxoData: x, txid: d, vout: k } of l) {
792
- const b = oe(
800
+ for (const { input: f, utxoData: y, txid: x, vout: p } of l) {
801
+ const b = ie(
793
802
  {
794
- value: x.value,
795
- scriptPubKey: x.scriptPubKey
803
+ value: y.value,
804
+ scriptPubKey: y.scriptPubKey
796
805
  },
797
806
  a
798
807
  );
@@ -808,19 +817,19 @@ class kn {
808
817
  script: f.script,
809
818
  value: f.value
810
819
  });
811
- const h = await this.config.btcWallet.signPsbt(i.toHex()), g = at.fromHex(h);
820
+ const d = await this.config.btcWallet.signPsbt(i.toHex()), g = lt.fromHex(d);
812
821
  try {
813
822
  g.finalizeAllInputs();
814
823
  } catch (f) {
815
824
  if (!g.data.inputs.every(
816
- (d) => d.finalScriptWitness || d.finalScriptSig
825
+ (x) => x.finalScriptWitness || x.finalScriptSig
817
826
  ))
818
827
  throw new Error(
819
828
  `PSBT finalization failed and wallet did not auto-finalize: ${f}`
820
829
  );
821
830
  }
822
831
  const E = g.extractTransaction().toHex();
823
- return await ae(E, c);
832
+ return await le(E, c);
824
833
  }
825
834
  /**
826
835
  * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
@@ -860,90 +869,90 @@ class kn {
860
869
  if (!this.config.ethWallet.account)
861
870
  throw new Error("Ethereum wallet account not found");
862
871
  const l = this.config.ethWallet.account.address;
863
- if (!ct(u.depositorEthAddress, l))
872
+ if (!ut(u.depositorEthAddress, l))
864
873
  throw new Error(
865
874
  `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.`
866
875
  );
867
- await this.assertPopMatchesBtcWallet(u);
868
- const m = u.btcPopSignature, w = I(u.depositorBtcPubkey), P = I(e), h = I(s), g = await this.resolvePayoutScriptPubKey(
869
- a
870
- ), E = K(h), S = await ut(
871
- T(E),
876
+ const m = await this.assertPopMatchesBtcWallet(u), w = u.btcPopSignature, P = B(u.depositorBtcPubkey), d = B(e), g = B(s), E = a ?? await this.config.btcWallet.getAddress(), I = this.resolvePayoutScriptPubKey(
877
+ m,
878
+ E
879
+ ), f = z(g), y = await dt(
880
+ T(f),
872
881
  T(l)
873
- ), f = I(S);
874
- if (await this.checkVaultExists(f))
882
+ ), x = B(y);
883
+ if (await this.checkVaultExists(x))
875
884
  throw new Error(
876
- `Vault already exists (ID: ${f}, 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.`
885
+ `Vault already exists (ID: ${x}, peginTxHash: ${f}). 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.`
877
886
  );
878
- const d = this.config.publicClient;
879
- let k;
887
+ const b = this.config.publicClient;
888
+ let h;
880
889
  try {
881
- k = await d.readContract({
890
+ h = await b.readContract({
882
891
  address: this.config.vaultContracts.btcVaultRegistry,
883
- abi: R,
892
+ abi: O,
884
893
  functionName: "getPegInFee",
885
894
  args: [o]
886
895
  });
887
- } catch (O) {
896
+ } catch (R) {
888
897
  throw new Error(
889
898
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
890
- { cause: O }
899
+ { cause: R }
891
900
  );
892
901
  }
893
- const b = lt({
894
- abi: R,
902
+ const S = ht({
903
+ abi: O,
895
904
  functionName: "submitPeginRequest",
896
905
  args: [
897
906
  l,
898
- w,
899
- m,
900
907
  P,
901
- h,
908
+ w,
909
+ d,
910
+ g,
902
911
  o,
903
912
  r,
904
913
  i,
905
- g,
914
+ I,
906
915
  c
907
916
  ]
908
917
  });
909
- let p;
918
+ let v;
910
919
  try {
911
- p = await d.estimateGas({
920
+ v = await b.estimateGas({
912
921
  to: this.config.vaultContracts.btcVaultRegistry,
913
- data: b,
914
- value: k,
922
+ data: S,
923
+ value: h,
915
924
  account: this.config.ethWallet.account.address
916
925
  });
917
- } catch (O) {
918
- A(O);
926
+ } catch (R) {
927
+ A(R);
919
928
  }
920
- let v;
929
+ let K;
921
930
  try {
922
- v = await this.config.ethWallet.sendTransaction({
931
+ K = await this.config.ethWallet.sendTransaction({
923
932
  to: this.config.vaultContracts.btcVaultRegistry,
924
- data: b,
925
- value: k,
933
+ data: S,
934
+ value: h,
926
935
  account: this.config.ethWallet.account,
927
936
  chain: this.config.ethChain,
928
- gas: p
937
+ gas: v
929
938
  });
930
- } catch (O) {
931
- A(O);
939
+ } catch (R) {
940
+ A(R);
932
941
  }
933
- const B = await gt({
934
- publicClient: d,
942
+ const D = await wt({
943
+ publicClient: b,
935
944
  walletAddress: this.config.ethWallet.account.address,
936
- hash: v,
937
- timeout: Et
945
+ hash: K,
946
+ timeout: vt
938
947
  });
939
- return B.status === "reverted" && A(
948
+ return D.status === "reverted" && A(
940
949
  new Error(
941
- `Transaction reverted. Hash: ${B.transactionHash}. Check the transaction on block explorer for details.`
950
+ `Transaction reverted. Hash: ${D.transactionHash}. Check the transaction on block explorer for details.`
942
951
  )
943
952
  ), {
944
- ethTxHash: B.transactionHash,
945
- vaultId: f,
946
- peginTxHash: E
953
+ ethTxHash: D.transactionHash,
954
+ vaultId: x,
955
+ peginTxHash: f
947
956
  };
948
957
  }
949
958
  /**
@@ -963,93 +972,92 @@ class kn {
963
972
  if (!this.config.ethWallet.account)
964
973
  throw new Error("Ethereum wallet account not found");
965
974
  const i = this.config.ethWallet.account.address;
966
- if (!ct(r.depositorEthAddress, i))
975
+ if (!ut(r.depositorEthAddress, i))
967
976
  throw new Error(
968
977
  `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.`
969
978
  );
970
- await this.assertPopMatchesBtcWallet(r);
971
- const a = r.btcPopSignature, c = [];
972
- for (const d of o)
973
- c.push(
974
- await this.resolvePayoutScriptPubKey(d.depositorPayoutBtcAddress)
975
- );
976
- const u = [];
977
- for (const d of o) {
978
- const k = I(
979
- d.depositorSignedPeginTx
980
- ), b = K(k), p = await ut(
981
- T(b),
979
+ const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, u = o.map(
980
+ (p) => this.resolvePayoutScriptPubKey(
981
+ a,
982
+ p.depositorPayoutBtcAddress
983
+ )
984
+ ), l = [];
985
+ for (const p of o) {
986
+ const b = B(
987
+ p.depositorSignedPeginTx
988
+ ), h = z(b), S = await dt(
989
+ T(h),
982
990
  T(i)
983
- ), v = I(p);
991
+ ), v = B(S);
984
992
  if (await this.checkVaultExists(v))
985
993
  throw new Error(
986
- `Vault already exists (ID: ${v}, peginTxHash: ${b}). To create a new vault, use different UTXOs or a different amount.`
994
+ `Vault already exists (ID: ${v}, peginTxHash: ${h}). To create a new vault, use different UTXOs or a different amount.`
987
995
  );
988
- u.push({ vaultId: v, peginTxHash: b });
996
+ l.push({ vaultId: v, peginTxHash: h });
989
997
  }
990
- const l = this.config.publicClient;
991
- let m;
998
+ const m = this.config.publicClient;
999
+ let w;
992
1000
  try {
993
- m = await l.readContract({
1001
+ w = await m.readContract({
994
1002
  address: this.config.vaultContracts.btcVaultRegistry,
995
- abi: R,
1003
+ abi: O,
996
1004
  functionName: "getPegInFee",
997
1005
  args: [e]
998
1006
  });
999
- } catch (d) {
1007
+ } catch (p) {
1000
1008
  throw new Error(
1001
1009
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
1002
- { cause: d }
1010
+ { cause: p }
1003
1011
  );
1004
1012
  }
1005
- const w = m * BigInt(o.length), P = I(
1013
+ const P = w * BigInt(o.length), d = B(
1006
1014
  r.depositorBtcPubkey
1007
- ), h = I(s), g = o.map((d, k) => ({
1008
- depositorBtcPubKey: P,
1009
- btcPopSignature: a,
1010
- unsignedPrePeginTx: h,
1011
- depositorSignedPeginTx: I(
1012
- d.depositorSignedPeginTx
1015
+ ), g = B(s), E = o.map((p, b) => ({
1016
+ depositorBtcPubKey: d,
1017
+ btcPopSignature: c,
1018
+ unsignedPrePeginTx: g,
1019
+ depositorSignedPeginTx: B(
1020
+ p.depositorSignedPeginTx
1013
1021
  ),
1014
- hashlock: d.hashlock,
1015
- htlcVout: d.htlcVout,
1016
- referralCode: sn,
1017
- depositorPayoutBtcAddress: c[k],
1018
- depositorWotsPkHash: d.depositorWotsPkHash
1019
- })), E = lt({
1020
- abi: R,
1022
+ hashlock: p.hashlock,
1023
+ htlcVout: p.htlcVout,
1024
+ referralCode: rn,
1025
+ depositorPayoutBtcAddress: u[b],
1026
+ depositorWotsPkHash: p.depositorWotsPkHash
1027
+ })), I = ht({
1028
+ abi: O,
1021
1029
  functionName: "submitPeginRequestBatch",
1022
- args: [i, e, g]
1030
+ args: [i, e, E]
1023
1031
  });
1024
- let S;
1032
+ let f;
1025
1033
  try {
1026
- S = await l.estimateGas({
1034
+ f = await m.estimateGas({
1027
1035
  to: this.config.vaultContracts.btcVaultRegistry,
1028
- data: E,
1029
- value: w,
1036
+ data: I,
1037
+ value: P,
1030
1038
  account: this.config.ethWallet.account.address
1031
1039
  });
1032
- } catch (d) {
1033
- A(d);
1040
+ } catch (p) {
1041
+ A(p);
1034
1042
  }
1035
- let f;
1043
+ let y;
1036
1044
  try {
1037
- f = await this.config.ethWallet.sendTransaction({
1045
+ y = await this.config.ethWallet.sendTransaction({
1038
1046
  to: this.config.vaultContracts.btcVaultRegistry,
1039
- data: E,
1040
- value: w,
1047
+ data: I,
1048
+ value: P,
1041
1049
  account: this.config.ethWallet.account,
1042
1050
  chain: this.config.ethChain,
1043
- gas: S
1051
+ gas: f
1044
1052
  });
1045
- } catch (d) {
1046
- A(d);
1053
+ } catch (p) {
1054
+ A(p);
1047
1055
  }
1048
- const x = await gt({
1049
- publicClient: l,
1056
+ const x = await wt({
1057
+ publicClient: m,
1050
1058
  walletAddress: this.config.ethWallet.account.address,
1051
- hash: f,
1052
- timeout: Et
1059
+ hash: y,
1060
+ timeout: vt
1053
1061
  });
1054
1062
  return x.status === "reverted" && A(
1055
1063
  new Error(
@@ -1057,7 +1065,7 @@ class kn {
1057
1065
  )
1058
1066
  ), {
1059
1067
  ethTxHash: x.transactionHash,
1060
- vaults: u
1068
+ vaults: l
1061
1069
  };
1062
1070
  }
1063
1071
  /**
@@ -1076,37 +1084,40 @@ class kn {
1076
1084
  async checkVaultExists(t) {
1077
1085
  return (await this.config.publicClient.readContract({
1078
1086
  address: this.config.vaultContracts.btcVaultRegistry,
1079
- abi: R,
1087
+ abi: O,
1080
1088
  functionName: "getBtcVaultBasicInfo",
1081
1089
  args: [t]
1082
- })).depositor !== Dt;
1090
+ })).depositor !== jt;
1083
1091
  }
1084
1092
  /**
1085
- * Resolve the BTC payout address to a scriptPubKey hex for the contract.
1093
+ * Resolve the BTC scriptPubKey to register as the depositor's payout sink.
1094
+ *
1095
+ * `address` is validated against the verified depositor pubkey, which MUST
1096
+ * be the *raw* (parity-preserving) form returned by the wallet adapter —
1097
+ * the caller should source it from `assertPopMatchesBtcWallet`'s return
1098
+ * value, not from `popSignature.depositorBtcPubkey` (x-only, parity
1099
+ * stripped). P2WPKH addresses are derived from a parity-bearing compressed
1100
+ * key; passing the x-only form here would let `isAddressFromPublicKey`
1101
+ * try both `02|x` and `03|x` and accept an opposite-parity P2WPKH
1102
+ * address the wallet does not actually control.
1086
1103
  *
1087
- * If a payout address is provided, converts it directly.
1088
- * If omitted, uses the wallet's address and validates it against the
1089
- * wallet's public key to guard against a compromised wallet provider.
1104
+ * The helper does not call into the wallet so the batch path can resolve
1105
+ * many requests without any extra adapter reads. Threat closed: a
1106
+ * state-race or stale FE state that lets a non-wallet address reach the
1107
+ * on-chain payout-script registration.
1090
1108
  */
1091
- async resolvePayoutScriptPubKey(t) {
1092
- let e;
1093
- if (t)
1094
- e = t;
1095
- else {
1096
- e = await this.config.btcWallet.getAddress();
1097
- const o = await this.config.btcWallet.getPublicKeyHex();
1098
- if (!te(
1099
- e,
1100
- o,
1101
- this.config.btcNetwork
1102
- ))
1103
- throw new Error(
1104
- "The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
1105
- );
1106
- }
1107
- const s = dt(this.config.btcNetwork);
1109
+ resolvePayoutScriptPubKey(t, e) {
1110
+ if (!ft(
1111
+ e,
1112
+ t,
1113
+ this.config.btcNetwork
1114
+ ))
1115
+ throw new Error(
1116
+ `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.`
1117
+ );
1118
+ const s = pt(this.config.btcNetwork);
1108
1119
  try {
1109
- return `0x${_t.address.toOutputScript(e, s).toString("hex")}`;
1120
+ return `0x${It.address.toOutputScript(e, s).toString("hex")}`;
1110
1121
  } catch {
1111
1122
  throw new Error(
1112
1123
  `Invalid BTC payout address: "${e}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
@@ -1122,26 +1133,33 @@ class kn {
1122
1133
  async signProofOfPossession() {
1123
1134
  if (!this.config.ethWallet.account)
1124
1135
  throw new Error("Ethereum wallet account not found");
1125
- const t = this.config.ethWallet.account.address, e = $(
1136
+ const t = this.config.ethWallet.account.address, e = H(
1126
1137
  await this.config.btcWallet.getPublicKeyHex()
1127
1138
  ), s = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
1128
1139
  o,
1129
1140
  "bip322-simple"
1130
1141
  );
1131
1142
  return {
1132
- btcPopSignature: en(r),
1143
+ btcPopSignature: sn(r),
1133
1144
  depositorEthAddress: t,
1134
1145
  depositorBtcPubkey: e
1135
1146
  };
1136
1147
  }
1148
+ /**
1149
+ * Confirm the connected BTC wallet still matches the PoP it produced, and
1150
+ * return the wallet's *raw* pubkey hex (parity-preserving form, as the
1151
+ * wallet adapter returns it). The raw form is required by callers that
1152
+ * validate Native SegWit / P2WPKH addresses, since P2WPKH is derived from
1153
+ * a parity-bearing compressed key — an x-only form would let an attacker
1154
+ * substitute the opposite-parity P2WPKH address.
1155
+ */
1137
1156
  async assertPopMatchesBtcWallet(t) {
1138
- const e = $(
1139
- await this.config.btcWallet.getPublicKeyHex()
1140
- ), s = $(t.depositorBtcPubkey);
1141
- if (e !== s)
1157
+ const e = await this.config.btcWallet.getPublicKeyHex(), s = H(e), o = H(t.depositorBtcPubkey);
1158
+ if (s !== o)
1142
1159
  throw new Error(
1143
- `Proof of possession was signed with BTC pubkey ${s} but the BTC wallet is currently connected to ${e}. Reconnect the original wallet or call signProofOfPossession() again.`
1160
+ `Proof of possession was signed with BTC pubkey ${o} but the BTC wallet is currently connected to ${s}. Reconnect the original wallet or call signProofOfPossession() again.`
1144
1161
  );
1162
+ return e;
1145
1163
  }
1146
1164
  /**
1147
1165
  * Gets the configured Bitcoin network.
@@ -1161,12 +1179,12 @@ class kn {
1161
1179
  }
1162
1180
  }
1163
1181
  export {
1164
- kn as P,
1165
- ke as V,
1166
- ye as a,
1167
- xe as b,
1168
- Ze as c,
1169
- qe as d,
1170
- Te as e
1182
+ Tn as P,
1183
+ Te as V,
1184
+ Ee as a,
1185
+ ke as b,
1186
+ Ye as c,
1187
+ Qe as d,
1188
+ ve as e
1171
1189
  };
1172
- //# sourceMappingURL=PeginManager-DF1oinIQ.js.map
1190
+ //# sourceMappingURL=PeginManager-CB-dVkT2.js.map