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