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