@babylonlabs-io/ts-sdk 0.37.3 → 0.38.1

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