@babylonlabs-io/ts-sdk 0.26.3 → 0.27.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 (132) hide show
  1. package/dist/{bitcoin-nOOgeRyl.js → bitcoin-B-Y0DlqR.js} +63 -60
  2. package/dist/bitcoin-B-Y0DlqR.js.map +1 -0
  3. package/dist/bitcoin-DIN0OupO.cjs +2 -0
  4. package/dist/bitcoin-DIN0OupO.cjs.map +1 -0
  5. package/dist/buildAndBroadcastRefund-BEASMFsz.cjs +2 -0
  6. package/dist/buildAndBroadcastRefund-BEASMFsz.cjs.map +1 -0
  7. package/dist/buildAndBroadcastRefund-BzYJv-Fv.js +862 -0
  8. package/dist/buildAndBroadcastRefund-BzYJv-Fv.js.map +1 -0
  9. package/dist/challengeAssert-BM8m9gPM.cjs +2 -0
  10. package/dist/challengeAssert-BM8m9gPM.cjs.map +1 -0
  11. package/dist/{challengeAssert-CH32j5cZ.js → challengeAssert-j2Vwqo0-.js} +135 -120
  12. package/dist/challengeAssert-j2Vwqo0-.js.map +1 -0
  13. package/dist/context-B4fYDTxy.cjs +2 -0
  14. package/dist/context-B4fYDTxy.cjs.map +1 -0
  15. package/dist/{errors-kc6XZy1U.js → context-ktqanzXE.js} +442 -324
  16. package/dist/context-ktqanzXE.js.map +1 -0
  17. package/dist/fundPeginTransaction-DaWoYCgO.cjs +2 -0
  18. package/dist/fundPeginTransaction-DaWoYCgO.cjs.map +1 -0
  19. package/dist/fundPeginTransaction-oV-dNJOU.js +76 -0
  20. package/dist/fundPeginTransaction-oV-dNJOU.js.map +1 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +100 -91
  23. package/dist/{payout-DzGsAnhf.js → payout-B_fvQU3q.js} +2 -2
  24. package/dist/{payout-DzGsAnhf.js.map → payout-B_fvQU3q.js.map} +1 -1
  25. package/dist/{payout-RFIh7GLN.cjs → payout-DP6KMFP1.cjs} +2 -2
  26. package/dist/{payout-RFIh7GLN.cjs.map → payout-DP6KMFP1.cjs.map} +1 -1
  27. package/dist/psbtInputFields-CB8hqjQ5.cjs +2 -0
  28. package/dist/psbtInputFields-CB8hqjQ5.cjs.map +1 -0
  29. package/dist/{psbtInputFields-B_cRzwBi.js → psbtInputFields-DeTFSJOq.js} +71 -65
  30. package/dist/psbtInputFields-DeTFSJOq.js.map +1 -0
  31. package/dist/sha2-1XZuToHP.cjs +2 -0
  32. package/dist/sha2-1XZuToHP.cjs.map +1 -0
  33. package/dist/sha2-ZzfZqQSw.js +1123 -0
  34. package/dist/sha2-ZzfZqQSw.js.map +1 -0
  35. package/dist/tbv/core/clients/index.cjs +1 -1
  36. package/dist/tbv/core/clients/index.js +27 -24
  37. package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322Verify.test.d.ts +17 -0
  38. package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322Verify.test.d.ts.map +1 -0
  39. package/dist/tbv/core/clients/vault-provider/auth/__tests__/cbor.test.d.ts +15 -0
  40. package/dist/tbv/core/clients/vault-provider/auth/__tests__/cbor.test.d.ts.map +1 -0
  41. package/dist/tbv/core/clients/vault-provider/auth/__tests__/goldenVectors.d.ts +44 -0
  42. package/dist/tbv/core/clients/vault-provider/auth/__tests__/goldenVectors.d.ts.map +1 -0
  43. package/dist/tbv/core/clients/vault-provider/auth/__tests__/serverIdentity.test.d.ts +2 -0
  44. package/dist/tbv/core/clients/vault-provider/auth/__tests__/serverIdentity.test.d.ts.map +1 -0
  45. package/dist/tbv/core/clients/vault-provider/auth/__tests__/tokenProvider.test.d.ts +2 -0
  46. package/dist/tbv/core/clients/vault-provider/auth/__tests__/tokenProvider.test.d.ts.map +1 -0
  47. package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts +56 -0
  48. package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts.map +1 -0
  49. package/dist/tbv/core/clients/vault-provider/auth/cbor.d.ts +44 -0
  50. package/dist/tbv/core/clients/vault-provider/auth/cbor.d.ts.map +1 -0
  51. package/dist/tbv/core/clients/vault-provider/auth/index.d.ts +10 -0
  52. package/dist/tbv/core/clients/vault-provider/auth/index.d.ts.map +1 -0
  53. package/dist/tbv/core/clients/vault-provider/auth/serverIdentity.d.ts +68 -0
  54. package/dist/tbv/core/clients/vault-provider/auth/serverIdentity.d.ts.map +1 -0
  55. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts +81 -0
  56. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts.map +1 -0
  57. package/dist/tbv/core/clients/vault-provider/index.d.ts +2 -1
  58. package/dist/tbv/core/clients/vault-provider/index.d.ts.map +1 -1
  59. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +66 -1
  60. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
  61. package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
  62. package/dist/tbv/core/index.cjs +1 -1
  63. package/dist/tbv/core/index.d.ts +3 -0
  64. package/dist/tbv/core/index.d.ts.map +1 -1
  65. package/dist/tbv/core/index.js +96 -87
  66. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  67. package/dist/tbv/core/primitives/index.cjs +1 -1
  68. package/dist/tbv/core/primitives/index.js +3 -3
  69. package/dist/tbv/core/primitives/psbt/pegin.d.ts +17 -2
  70. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  71. package/dist/tbv/core/primitives/utils/bitcoin.d.ts +19 -0
  72. package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
  73. package/dist/tbv/core/services/index.cjs +1 -1
  74. package/dist/tbv/core/services/index.js +1 -1
  75. package/dist/tbv/core/utils/fee/__tests__/constants.test.d.ts +2 -0
  76. package/dist/tbv/core/utils/fee/__tests__/constants.test.d.ts.map +1 -0
  77. package/dist/tbv/core/utils/fee/constants.d.ts +30 -9
  78. package/dist/tbv/core/utils/fee/constants.d.ts.map +1 -1
  79. package/dist/tbv/core/utils/index.cjs +1 -1
  80. package/dist/tbv/core/utils/index.js +28 -27
  81. package/dist/tbv/core/utils/utxo/reservation.d.ts +5 -0
  82. package/dist/tbv/core/utils/utxo/reservation.d.ts.map +1 -1
  83. package/dist/tbv/core/vault-secrets/__tests__/context.golden.test.d.ts +34 -0
  84. package/dist/tbv/core/vault-secrets/__tests__/context.golden.test.d.ts.map +1 -0
  85. package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts +6 -0
  86. package/dist/tbv/core/vault-secrets/__tests__/context.test.d.ts.map +1 -0
  87. package/dist/tbv/core/vault-secrets/__tests__/expand.test.d.ts +10 -0
  88. package/dist/tbv/core/vault-secrets/__tests__/expand.test.d.ts.map +1 -0
  89. package/dist/tbv/core/vault-secrets/__tests__/info.test.d.ts +8 -0
  90. package/dist/tbv/core/vault-secrets/__tests__/info.test.d.ts.map +1 -0
  91. package/dist/tbv/core/vault-secrets/context.d.ts +52 -0
  92. package/dist/tbv/core/vault-secrets/context.d.ts.map +1 -0
  93. package/dist/tbv/core/vault-secrets/expand.d.ts +43 -0
  94. package/dist/tbv/core/vault-secrets/expand.d.ts.map +1 -0
  95. package/dist/tbv/core/vault-secrets/index.d.ts +16 -0
  96. package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -0
  97. package/dist/tbv/core/vault-secrets/info.d.ts +55 -0
  98. package/dist/tbv/core/vault-secrets/info.d.ts.map +1 -0
  99. package/dist/tbv/index.cjs +1 -1
  100. package/dist/tbv/index.js +96 -87
  101. package/dist/vault-registry-reader-BizmBSBV.cjs +2 -0
  102. package/dist/vault-registry-reader-BizmBSBV.cjs.map +1 -0
  103. package/dist/{index-D7s2ilf8.js → vault-registry-reader-CpCOte7w.js} +522 -268
  104. package/dist/vault-registry-reader-CpCOte7w.js.map +1 -0
  105. package/package.json +6 -1
  106. package/dist/bitcoin-CNnPFU6Y.cjs +0 -2
  107. package/dist/bitcoin-CNnPFU6Y.cjs.map +0 -1
  108. package/dist/bitcoin-nOOgeRyl.js.map +0 -1
  109. package/dist/buildAndBroadcastRefund-Ccp-2GWW.js +0 -1334
  110. package/dist/buildAndBroadcastRefund-Ccp-2GWW.js.map +0 -1
  111. package/dist/buildAndBroadcastRefund-Mr3ck5ek.cjs +0 -2
  112. package/dist/buildAndBroadcastRefund-Mr3ck5ek.cjs.map +0 -1
  113. package/dist/challengeAssert-CH32j5cZ.js.map +0 -1
  114. package/dist/challengeAssert-X7V3Ik_Q.cjs +0 -2
  115. package/dist/challengeAssert-X7V3Ik_Q.cjs.map +0 -1
  116. package/dist/errors-DJkMz2Gt.cjs +0 -2
  117. package/dist/errors-DJkMz2Gt.cjs.map +0 -1
  118. package/dist/errors-kc6XZy1U.js.map +0 -1
  119. package/dist/fundPeginTransaction-BLYXxLBv.js +0 -70
  120. package/dist/fundPeginTransaction-BLYXxLBv.js.map +0 -1
  121. package/dist/fundPeginTransaction-DxNOeyNI.cjs +0 -2
  122. package/dist/fundPeginTransaction-DxNOeyNI.cjs.map +0 -1
  123. package/dist/index-CIuXb72l.cjs +0 -2
  124. package/dist/index-CIuXb72l.cjs.map +0 -1
  125. package/dist/index-D7s2ilf8.js.map +0 -1
  126. package/dist/psbtInputFields-B_cRzwBi.js.map +0 -1
  127. package/dist/psbtInputFields-DFwuqxdh.cjs +0 -2
  128. package/dist/psbtInputFields-DFwuqxdh.cjs.map +0 -1
  129. package/dist/types-WrGfwlJd.js +0 -608
  130. package/dist/types-WrGfwlJd.js.map +0 -1
  131. package/dist/types-xU3SBcpH.cjs +0 -2
  132. package/dist/types-xU3SBcpH.cjs.map +0 -1
@@ -1,21 +1,20 @@
1
- var Rt = Object.defineProperty;
2
- var Lt = (e, t, n) => t in e ? Rt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var b = (e, t, n) => Lt(e, typeof t != "symbol" ? t + "" : t, n);
4
- import * as Ut from "bitcoinjs-lib";
5
- import { Transaction as Wt, Psbt as it } from "bitcoinjs-lib";
6
- import { Buffer as Y } from "buffer";
7
- import { isAddressEqual as at, createPublicClient as D, http as N, encodeFunctionData as ct, zeroAddress as Ft } from "viem";
8
- import { c as Vt } from "./signing-BZigafm0.js";
9
- import { deriveVaultId as lt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
10
- import { b as Kt, a as Mt, d as Dt, e as Nt, f as Xt } from "./challengeAssert-CH32j5cZ.js";
11
- import { s as B, g as ht, e as I, i as jt, p as qt } from "./bitcoin-nOOgeRyl.js";
12
- import { M as ut } from "./validation-CxqROCno.js";
13
- import { b as Gt, f as X, i as zt } from "./psbtInputFields-B_cRzwBi.js";
14
- import { p as Zt, f as Jt } from "./fundPeginTransaction-BLYXxLBv.js";
15
- import { p as Qt, f as Yt } from "./index-D7s2ilf8.js";
16
- import { B as A } from "./types-WrGfwlJd.js";
17
- import { n as bt, o as F, q as H, r as V, t as xt, H as te, u as L, x as ee, y as R, z as ne, A as dt, D as se, E as oe, F as re, G as ie, I as ae, J as ce, K as le, L as ft, M as Pt, N as he } from "./buildAndBroadcastRefund-Ccp-2GWW.js";
18
- const S = {
1
+ var te = Object.defineProperty;
2
+ var ee = (e, t, n) => t in e ? te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var b = (e, t, n) => ee(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import * as ne from "bitcoinjs-lib";
5
+ import { Transaction as se, Psbt as yt } from "bitcoinjs-lib";
6
+ import { Buffer as it } from "buffer";
7
+ import { isAddressEqual as bt, createPublicClient as q, http as Z, encodeFunctionData as xt, zeroAddress as oe } from "viem";
8
+ import { c as re } from "./signing-BZigafm0.js";
9
+ import { deriveVaultId as Pt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
10
+ import { b as ie, a as ae, d as ce, e as le, f as ue } from "./challengeAssert-j2Vwqo0-.js";
11
+ import { s as v, g as kt, e as I, i as he, p as de } from "./bitcoin-B-Y0DlqR.js";
12
+ import { M as Et } from "./validation-CxqROCno.js";
13
+ import { b as fe, f as G, i as ge } from "./psbtInputFields-DeTFSJOq.js";
14
+ import { p as pe, f as me } from "./fundPeginTransaction-oV-dNJOU.js";
15
+ import { p as we, f as ye } from "./vault-registry-reader-CpCOte7w.js";
16
+ import { B as O, e as ht, f as U, g as S, h as V, i as Ut, H as be, r as F, j as xe, k as C, u as Pe, l as Tt, m as ke, n as Ee, o as Te, p as Ie, q as _e, t as ve, v as Be, w as It, x as Wt, s as W } from "./sha2-ZzfZqQSw.js";
17
+ const H = {
19
18
  // VaultAlreadyExists()
20
19
  "0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
21
20
  // ScriptPubKeyMismatch() - taproot output doesn't match expected script
@@ -49,7 +48,7 @@ const S = {
49
48
  // PeginTransactionAlreadyUsed()
50
49
  "0x7ed061c9": "This pegin transaction has already been used to activate another vault."
51
50
  };
52
- function nt(e) {
51
+ function dt(e) {
53
52
  if (!e || typeof e != "object") return;
54
53
  const t = e;
55
54
  if (typeof t.data == "string" && t.data.startsWith("0x"))
@@ -68,24 +67,24 @@ function nt(e) {
68
67
  if (i)
69
68
  return i[1];
70
69
  }
71
- function fn(e) {
72
- const t = nt(e);
70
+ function Fn(e) {
71
+ const t = dt(e);
73
72
  if (t) {
74
73
  const n = t.substring(0, 10);
75
- return S[t] ?? S[n];
74
+ return H[t] ?? H[n];
76
75
  }
77
76
  }
78
- function gn(e) {
79
- const t = nt(e);
77
+ function Mn(e) {
78
+ const t = dt(e);
80
79
  if (t === void 0) return !1;
81
80
  const n = t.substring(0, 10);
82
- return t in S || n in S;
81
+ return t in H || n in H;
83
82
  }
84
- function C(e) {
83
+ function A(e) {
85
84
  console.error("[Contract Error] Raw error:", e);
86
- const t = nt(e);
85
+ const t = dt(e);
87
86
  if (console.error("[Contract Error] Extracted error data:", t), t) {
88
- const s = t.substring(0, 10), o = S[t] ?? S[s];
87
+ const s = t.substring(0, 10), o = H[t] ?? H[s];
89
88
  if (o)
90
89
  throw console.error("[Contract Error] Known error:", o), new Error(o);
91
90
  }
@@ -103,43 +102,43 @@ function C(e) {
103
102
  }
104
103
  throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
105
104
  }
106
- const ue = 0, de = /^0x[0-9a-f]+$/i, fe = /^[0-9a-f]+$/i, ge = /^[A-Za-z0-9+/]+={0,2}$/;
105
+ const Se = 0, Ae = /^0x[0-9a-f]+$/i, Ce = /^[0-9a-f]+$/i, He = /^[A-Za-z0-9+/]+={0,2}$/;
107
106
  function $(e) {
108
107
  if (typeof e != "string" || e.length === 0)
109
108
  throw new Error("BTC wallet returned empty public key");
110
- return qt(e).toLowerCase();
109
+ return de(e).toLowerCase();
111
110
  }
112
- function pe(e) {
111
+ function Oe(e) {
113
112
  if (typeof e != "string" || e.length === 0)
114
113
  throw new Error("BTC wallet returned empty BIP-322 signature");
115
114
  if (e.startsWith("0x") || e.startsWith("0X")) {
116
- if (!de.test(e) || e.length < 4 || e.length % 2 !== 0)
115
+ if (!Ae.test(e) || e.length < 4 || e.length % 2 !== 0)
117
116
  throw new Error("BTC wallet returned malformed hex BIP-322 signature");
118
117
  return e.toLowerCase();
119
118
  }
120
- if (fe.test(e)) {
119
+ if (Ce.test(e)) {
121
120
  if (e.length % 2 !== 0)
122
121
  throw new Error("BTC wallet returned malformed hex BIP-322 signature");
123
122
  return `0x${e.toLowerCase()}`;
124
123
  }
125
- if (!ge.test(e) || e.length % 4 !== 0)
124
+ if (!He.test(e) || e.length % 4 !== 0)
126
125
  throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
127
- const t = Y.from(e, "base64");
126
+ const t = it.from(e, "base64");
128
127
  if (t.length === 0 || t.toString("base64") !== e)
129
128
  throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
130
129
  return `0x${t.toString("hex")}`;
131
130
  }
132
- function me(e, t, n, s) {
131
+ function $e(e, t, n, s) {
133
132
  const o = n == null ? void 0 : n[`${e}:${t}`];
134
133
  return o ? Promise.resolve({
135
134
  txid: e,
136
135
  vout: t,
137
136
  value: o.value,
138
137
  scriptPubKey: o.scriptPubKey
139
- }) : Yt(e, t, s);
138
+ }) : ye(e, t, s);
140
139
  }
141
- const gt = 12e4;
142
- class pn {
140
+ const _t = 12e4;
141
+ class Nn {
143
142
  /**
144
143
  * Creates a new PeginManager instance.
145
144
  *
@@ -170,14 +169,14 @@ class pn {
170
169
  * @throws Error if wallet operations fail or insufficient funds
171
170
  */
172
171
  async preparePegin(t) {
173
- const n = await this.config.btcWallet.getPublicKeyHex(), s = $(n), o = B(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(B), i = t.universalChallengerBtcPubkeys.map(B);
172
+ const n = await this.config.btcWallet.getPublicKeyHex(), s = $(n), o = v(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(v), i = t.universalChallengerBtcPubkeys.map(v);
174
173
  if (t.hashlocks.length !== t.amounts.length)
175
174
  throw new Error(
176
175
  `hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
177
176
  );
178
177
  if (t.hashlocks.length === 0)
179
178
  throw new Error("hashlocks must contain at least one entry");
180
- const a = r.length, f = {
179
+ const a = r.length, h = {
181
180
  depositorPubkey: s,
182
181
  vaultProviderPubkey: o,
183
182
  vaultKeeperPubkeys: r,
@@ -190,25 +189,28 @@ class pn {
190
189
  councilQuorum: t.councilQuorum,
191
190
  councilSize: t.councilSize,
192
191
  network: this.config.btcNetwork
193
- }, h = await Kt(f), c = Gt(
192
+ }, u = await ie(h), c = fe(
194
193
  [...t.availableUTXOs],
195
- h.totalOutputValue,
194
+ u.totalOutputValue,
196
195
  t.mempoolFeeRate,
197
- Zt(h.htlcValues.length)
198
- ), m = ht(this.config.btcNetwork), l = Jt({
199
- unfundedTxHex: h.psbtHex,
196
+ pe(
197
+ u.htlcValues.length,
198
+ h.authAnchorHash
199
+ )
200
+ ), m = kt(this.config.btcNetwork), l = me({
201
+ unfundedTxHex: u.psbtHex,
200
202
  selectedUTXOs: c.selectedUTXOs,
201
203
  changeAddress: t.changeAddress,
202
204
  changeAmount: c.changeAmount,
203
205
  network: m
204
- }), y = B(X(l)), d = [], x = [], P = [];
206
+ }), y = v(G(l)), f = [], x = [], P = [];
205
207
  for (let g = 0; g < t.hashlocks.length; g++) {
206
- const p = await Mt({
207
- prePeginParams: f,
208
+ const p = await ae({
209
+ prePeginParams: h,
208
210
  timelockPegin: t.timelockPegin,
209
211
  fundedPrePeginTxHex: l,
210
212
  htlcVout: g
211
- }), T = await Dt({
213
+ }), E = await ce({
212
214
  peginTxHex: p.txHex,
213
215
  fundedPrePeginTxHex: l,
214
216
  depositorPubkey: s,
@@ -219,32 +221,32 @@ class pn {
219
221
  timelockRefund: t.timelockRefund,
220
222
  network: this.config.btcNetwork
221
223
  });
222
- d.push(p), x.push(T.psbtHex), P.push(
223
- Vt(n, 1)
224
+ f.push(p), x.push(E.psbtHex), P.push(
225
+ re(n, 1)
224
226
  );
225
227
  }
226
228
  const w = await this.signPsbtsWithFallback(
227
229
  x,
228
230
  P
229
- ), u = [];
231
+ ), d = [];
230
232
  for (let g = 0; g < w.length; g++) {
231
- const p = Nt(
233
+ const p = le(
232
234
  w[g],
233
235
  s
234
- ), T = Xt(w[g]);
235
- u.push({
236
+ ), E = ue(w[g]);
237
+ d.push({
236
238
  htlcVout: g,
237
- htlcValue: h.htlcValues[g],
238
- peginTxHex: T,
239
- peginTxid: d[g].txid,
239
+ htlcValue: u.htlcValues[g],
240
+ peginTxHex: E,
241
+ peginTxid: f[g].txid,
240
242
  peginInputSignature: p,
241
- vaultScriptPubKey: d[g].vaultScriptPubKey
243
+ vaultScriptPubKey: f[g].vaultScriptPubKey
242
244
  });
243
245
  }
244
246
  return {
245
247
  fundedPrePeginTxHex: l,
246
248
  prePeginTxid: y,
247
- perVault: u,
249
+ perVault: d,
248
250
  selectedUTXOs: c.selectedUTXOs,
249
251
  fee: c.fee,
250
252
  changeAmount: c.changeAmount
@@ -295,24 +297,24 @@ class pn {
295
297
  * @throws Error if signing or broadcasting fails
296
298
  */
297
299
  async signAndBroadcast(t) {
298
- const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = Wt.fromHex(o);
300
+ const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = se.fromHex(o);
299
301
  if (r.ins.length === 0)
300
302
  throw new Error("Transaction has no inputs");
301
- const i = new it();
303
+ const i = new yt();
302
304
  i.setVersion(r.version), i.setLocktime(r.locktime);
303
- const a = Y.from(
305
+ const a = it.from(
304
306
  $(s),
305
307
  "hex"
306
- ), f = this.config.mempoolApiUrl, h = r.ins.map((u) => {
307
- const g = Y.from(u.hash).reverse().toString("hex"), p = u.index;
308
- return me(g, p, t.localPrevouts, f).then(
309
- (T) => ({ input: u, utxoData: T, txid: g, vout: p })
308
+ ), h = this.config.mempoolApiUrl, u = r.ins.map((d) => {
309
+ const g = it.from(d.hash).reverse().toString("hex"), p = d.index;
310
+ return $e(g, p, t.localPrevouts, h).then(
311
+ (E) => ({ input: d, utxoData: E, txid: g, vout: p })
310
312
  );
311
- }), c = await Promise.all(h), m = c.reduce(
312
- (u, g) => u + BigInt(g.utxoData.value),
313
+ }), c = await Promise.all(u), m = c.reduce(
314
+ (d, g) => d + BigInt(g.utxoData.value),
313
315
  0n
314
316
  ), l = r.outs.reduce(
315
- (u, g) => u + BigInt(g.value),
317
+ (d, g) => d + BigInt(g.value),
316
318
  0n
317
319
  );
318
320
  if (m < l)
@@ -320,12 +322,12 @@ class pn {
320
322
  `UTXO value mismatch: total input value (${m} sat) is less than total output value (${l} sat). This may indicate the mempool API returned manipulated UTXO data.`
321
323
  );
322
324
  const y = m - l;
323
- if (y > ut)
325
+ if (y > Et)
324
326
  throw new Error(
325
- `Implied transaction fee (${y} sat) exceeds maximum reasonable fee (${ut} sat). This may indicate manipulated UTXO data.`
327
+ `Implied transaction fee (${y} sat) exceeds maximum reasonable fee (${Et} sat). This may indicate manipulated UTXO data.`
326
328
  );
327
- for (const { input: u, utxoData: g, txid: p, vout: T } of c) {
328
- const k = zt(
329
+ for (const { input: d, utxoData: g, txid: p, vout: E } of c) {
330
+ const k = ge(
329
331
  {
330
332
  value: g.value,
331
333
  scriptPubKey: g.scriptPubKey
@@ -333,30 +335,30 @@ class pn {
333
335
  a
334
336
  );
335
337
  i.addInput({
336
- hash: u.hash,
337
- index: u.index,
338
- sequence: u.sequence,
338
+ hash: d.hash,
339
+ index: d.index,
340
+ sequence: d.sequence,
339
341
  ...k
340
342
  });
341
343
  }
342
- for (const u of r.outs)
344
+ for (const d of r.outs)
343
345
  i.addOutput({
344
- script: u.script,
345
- value: u.value
346
+ script: d.script,
347
+ value: d.value
346
348
  });
347
- const d = await this.config.btcWallet.signPsbt(i.toHex()), x = it.fromHex(d);
349
+ const f = await this.config.btcWallet.signPsbt(i.toHex()), x = yt.fromHex(f);
348
350
  try {
349
351
  x.finalizeAllInputs();
350
- } catch (u) {
352
+ } catch (d) {
351
353
  if (!x.data.inputs.every(
352
354
  (p) => p.finalScriptWitness || p.finalScriptSig
353
355
  ))
354
356
  throw new Error(
355
- `PSBT finalization failed and wallet did not auto-finalize: ${u}`
357
+ `PSBT finalization failed and wallet did not auto-finalize: ${d}`
356
358
  );
357
359
  }
358
360
  const P = x.extractTransaction().toHex();
359
- return await Qt(P, f);
361
+ return await we(P, h);
360
362
  }
361
363
  /**
362
364
  * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
@@ -390,36 +392,36 @@ class pn {
390
392
  hashlock: r,
391
393
  htlcVout: i,
392
394
  depositorPayoutBtcAddress: a,
393
- depositorWotsPkHash: f,
394
- popSignature: h
395
+ depositorWotsPkHash: h,
396
+ popSignature: u
395
397
  } = t;
396
398
  if (!this.config.ethWallet.account)
397
399
  throw new Error("Ethereum wallet account not found");
398
400
  const c = this.config.ethWallet.account.address;
399
- if (!at(h.depositorEthAddress, c))
401
+ if (!bt(u.depositorEthAddress, c))
400
402
  throw new Error(
401
- `Proof of possession was signed for ${h.depositorEthAddress} but the Ethereum wallet is currently connected to ${c}. Reconnect the original account or call signProofOfPossession() again.`
403
+ `Proof of possession was signed for ${u.depositorEthAddress} but the Ethereum wallet is currently connected to ${c}. Reconnect the original account or call signProofOfPossession() again.`
402
404
  );
403
- await this.assertPopMatchesBtcWallet(h);
404
- const m = h.btcPopSignature, l = I(h.depositorBtcPubkey), y = I(n), d = I(s), x = await this.resolvePayoutScriptPubKey(
405
+ await this.assertPopMatchesBtcWallet(u);
406
+ const m = u.btcPopSignature, l = I(u.depositorBtcPubkey), y = I(n), f = I(s), x = await this.resolvePayoutScriptPubKey(
405
407
  a
406
- ), P = X(d), w = await lt(
407
- B(P),
408
- B(c)
409
- ), u = I(w);
410
- if (await this.checkVaultExists(u))
408
+ ), P = G(f), w = await Pt(
409
+ v(P),
410
+ v(c)
411
+ ), d = I(w);
412
+ if (await this.checkVaultExists(d))
411
413
  throw new Error(
412
- `Vault already exists (ID: ${u}, peginTxHash: ${P}). 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.`
414
+ `Vault already exists (ID: ${d}, peginTxHash: ${P}). 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.`
413
415
  );
414
- const p = D({
416
+ const p = q({
415
417
  chain: this.config.ethChain,
416
- transport: N()
418
+ transport: Z()
417
419
  });
418
- let T;
420
+ let E;
419
421
  try {
420
- T = await p.readContract({
422
+ E = await p.readContract({
421
423
  address: this.config.vaultContracts.btcVaultRegistry,
422
- abi: A,
424
+ abi: O,
423
425
  functionName: "getPegInFee",
424
426
  args: [o]
425
427
  });
@@ -428,57 +430,57 @@ class pn {
428
430
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
429
431
  );
430
432
  }
431
- const k = ct({
432
- abi: A,
433
+ const k = xt({
434
+ abi: O,
433
435
  functionName: "submitPeginRequest",
434
436
  args: [
435
437
  c,
436
438
  l,
437
439
  m,
438
440
  y,
439
- d,
441
+ f,
440
442
  o,
441
443
  r,
442
444
  i,
443
445
  x,
444
- f
446
+ h
445
447
  ]
446
448
  });
447
- let v;
449
+ let _;
448
450
  try {
449
- v = await p.estimateGas({
451
+ _ = await p.estimateGas({
450
452
  to: this.config.vaultContracts.btcVaultRegistry,
451
453
  data: k,
452
- value: T,
454
+ value: E,
453
455
  account: this.config.ethWallet.account.address
454
456
  });
455
- } catch (M) {
456
- C(M);
457
+ } catch (j) {
458
+ A(j);
457
459
  }
458
- let _;
460
+ let B;
459
461
  try {
460
- _ = await this.config.ethWallet.sendTransaction({
462
+ B = await this.config.ethWallet.sendTransaction({
461
463
  to: this.config.vaultContracts.btcVaultRegistry,
462
464
  data: k,
463
- value: T,
465
+ value: E,
464
466
  account: this.config.ethWallet.account,
465
467
  chain: this.config.ethChain,
466
- gas: v
468
+ gas: _
467
469
  });
468
- } catch (M) {
469
- C(M);
470
+ } catch (j) {
471
+ A(j);
470
472
  }
471
- const K = await p.waitForTransactionReceipt({
472
- hash: _,
473
- timeout: gt
473
+ const X = await p.waitForTransactionReceipt({
474
+ hash: B,
475
+ timeout: _t
474
476
  });
475
- return K.status === "reverted" && C(
477
+ return X.status === "reverted" && A(
476
478
  new Error(
477
- `Transaction reverted. Hash: ${_}. Check the transaction on block explorer for details.`
479
+ `Transaction reverted. Hash: ${B}. Check the transaction on block explorer for details.`
478
480
  )
479
481
  ), {
480
- ethTxHash: K.transactionHash,
481
- vaultId: u,
482
+ ethTxHash: X.transactionHash,
483
+ vaultId: d,
482
484
  peginTxHash: P
483
485
  };
484
486
  }
@@ -499,39 +501,39 @@ class pn {
499
501
  if (!this.config.ethWallet.account)
500
502
  throw new Error("Ethereum wallet account not found");
501
503
  const i = this.config.ethWallet.account.address;
502
- if (!at(r.depositorEthAddress, i))
504
+ if (!bt(r.depositorEthAddress, i))
503
505
  throw new Error(
504
506
  `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.`
505
507
  );
506
508
  await this.assertPopMatchesBtcWallet(r);
507
- const a = r.btcPopSignature, f = [];
509
+ const a = r.btcPopSignature, h = [];
508
510
  for (const p of o)
509
- f.push(
511
+ h.push(
510
512
  await this.resolvePayoutScriptPubKey(p.depositorPayoutBtcAddress)
511
513
  );
512
- const h = [];
514
+ const u = [];
513
515
  for (const p of o) {
514
- const T = I(
516
+ const E = I(
515
517
  p.depositorSignedPeginTx
516
- ), k = X(T), v = await lt(
517
- B(k),
518
- B(i)
519
- ), _ = I(v);
520
- if (await this.checkVaultExists(_))
518
+ ), k = G(E), _ = await Pt(
519
+ v(k),
520
+ v(i)
521
+ ), B = I(_);
522
+ if (await this.checkVaultExists(B))
521
523
  throw new Error(
522
- `Vault already exists (ID: ${_}, peginTxHash: ${k}). To create a new vault, use different UTXOs or a different amount.`
524
+ `Vault already exists (ID: ${B}, peginTxHash: ${k}). To create a new vault, use different UTXOs or a different amount.`
523
525
  );
524
- h.push({ vaultId: _, peginTxHash: k });
526
+ u.push({ vaultId: B, peginTxHash: k });
525
527
  }
526
- const c = D({
528
+ const c = q({
527
529
  chain: this.config.ethChain,
528
- transport: N()
530
+ transport: Z()
529
531
  });
530
532
  let m;
531
533
  try {
532
534
  m = await c.readContract({
533
535
  address: this.config.vaultContracts.btcVaultRegistry,
534
- abi: A,
536
+ abi: O,
535
537
  functionName: "getPegInFee",
536
538
  args: [n]
537
539
  });
@@ -542,20 +544,20 @@ class pn {
542
544
  }
543
545
  const l = m * BigInt(o.length), y = I(
544
546
  r.depositorBtcPubkey
545
- ), d = I(s), x = o.map((p, T) => ({
547
+ ), f = I(s), x = o.map((p, E) => ({
546
548
  depositorBtcPubKey: y,
547
549
  btcPopSignature: a,
548
- unsignedPrePeginTx: d,
550
+ unsignedPrePeginTx: f,
549
551
  depositorSignedPeginTx: I(
550
552
  p.depositorSignedPeginTx
551
553
  ),
552
554
  hashlock: p.hashlock,
553
555
  htlcVout: p.htlcVout,
554
- referralCode: ue,
555
- depositorPayoutBtcAddress: f[T],
556
+ referralCode: Se,
557
+ depositorPayoutBtcAddress: h[E],
556
558
  depositorWotsPkHash: p.depositorWotsPkHash
557
- })), P = ct({
558
- abi: A,
559
+ })), P = xt({
560
+ abi: O,
559
561
  functionName: "submitPeginRequestBatch",
560
562
  args: [i, n, x]
561
563
  });
@@ -568,11 +570,11 @@ class pn {
568
570
  account: this.config.ethWallet.account.address
569
571
  });
570
572
  } catch (p) {
571
- C(p);
573
+ A(p);
572
574
  }
573
- let u;
575
+ let d;
574
576
  try {
575
- u = await this.config.ethWallet.sendTransaction({
577
+ d = await this.config.ethWallet.sendTransaction({
576
578
  to: this.config.vaultContracts.btcVaultRegistry,
577
579
  data: P,
578
580
  value: l,
@@ -581,19 +583,19 @@ class pn {
581
583
  gas: w
582
584
  });
583
585
  } catch (p) {
584
- C(p);
586
+ A(p);
585
587
  }
586
588
  const g = await c.waitForTransactionReceipt({
587
- hash: u,
588
- timeout: gt
589
+ hash: d,
590
+ timeout: _t
589
591
  });
590
- return g.status === "reverted" && C(
592
+ return g.status === "reverted" && A(
591
593
  new Error(
592
- `Batch transaction reverted. Hash: ${u}. Check the transaction on block explorer for details.`
594
+ `Batch transaction reverted. Hash: ${d}. Check the transaction on block explorer for details.`
593
595
  )
594
596
  ), {
595
597
  ethTxHash: g.transactionHash,
596
- vaults: h
598
+ vaults: u
597
599
  };
598
600
  }
599
601
  /**
@@ -604,15 +606,15 @@ class pn {
604
606
  */
605
607
  async checkVaultExists(t) {
606
608
  try {
607
- return (await D({
609
+ return (await q({
608
610
  chain: this.config.ethChain,
609
- transport: N()
611
+ transport: Z()
610
612
  }).readContract({
611
613
  address: this.config.vaultContracts.btcVaultRegistry,
612
- abi: A,
614
+ abi: O,
613
615
  functionName: "getBtcVaultBasicInfo",
614
616
  args: [t]
615
- }))[0] !== Ft;
617
+ }))[0] !== oe;
616
618
  } catch {
617
619
  return !1;
618
620
  }
@@ -631,7 +633,7 @@ class pn {
631
633
  else {
632
634
  n = await this.config.btcWallet.getAddress();
633
635
  const o = await this.config.btcWallet.getPublicKeyHex();
634
- if (!jt(
636
+ if (!he(
635
637
  n,
636
638
  o,
637
639
  this.config.btcNetwork
@@ -640,9 +642,9 @@ class pn {
640
642
  "The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
641
643
  );
642
644
  }
643
- const s = ht(this.config.btcNetwork);
645
+ const s = kt(this.config.btcNetwork);
644
646
  try {
645
- return `0x${Ut.address.toOutputScript(n, s).toString("hex")}`;
647
+ return `0x${ne.address.toOutputScript(n, s).toString("hex")}`;
646
648
  } catch {
647
649
  throw new Error(
648
650
  `Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
@@ -665,7 +667,7 @@ class pn {
665
667
  "bip322-simple"
666
668
  );
667
669
  return {
668
- btcPopSignature: pe(r),
670
+ btcPopSignature: Oe(r),
669
671
  depositorEthAddress: t,
670
672
  depositorBtcPubkey: n
671
673
  };
@@ -696,7 +698,7 @@ class pn {
696
698
  return this.config.vaultContracts.btcVaultRegistry;
697
699
  }
698
700
  }
699
- class kt {
701
+ class Ft {
700
702
  constructor(t, n) {
701
703
  b(this, "oHash");
702
704
  b(this, "iHash");
@@ -704,7 +706,7 @@ class kt {
704
706
  b(this, "outputLen");
705
707
  b(this, "finished", !1);
706
708
  b(this, "destroyed", !1);
707
- if (bt(t), F(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
709
+ if (ht(t), U(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
708
710
  throw new Error("Expected instance of class which extends utils.Hash");
709
711
  this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
710
712
  const s = this.blockLen, o = new Uint8Array(s);
@@ -714,13 +716,13 @@ class kt {
714
716
  this.iHash.update(o), this.oHash = t.create();
715
717
  for (let r = 0; r < o.length; r++)
716
718
  o[r] ^= 106;
717
- this.oHash.update(o), H(o);
719
+ this.oHash.update(o), S(o);
718
720
  }
719
721
  update(t) {
720
722
  return V(this), this.iHash.update(t), this;
721
723
  }
722
724
  digestInto(t) {
723
- V(this), F(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
725
+ V(this), U(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
724
726
  }
725
727
  digest() {
726
728
  const t = new Uint8Array(this.oHash.outputLen);
@@ -738,9 +740,9 @@ class kt {
738
740
  this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
739
741
  }
740
742
  }
741
- const st = (e, t, n) => new kt(e, t).update(n).digest();
742
- st.create = (e, t) => new kt(e, t);
743
- const we = /* @__PURE__ */ Uint8Array.from([
743
+ const K = (e, t, n) => new Ft(e, t).update(n).digest();
744
+ K.create = (e, t) => new Ft(e, t);
745
+ const Le = /* @__PURE__ */ Uint8Array.from([
744
746
  7,
745
747
  4,
746
748
  13,
@@ -757,36 +759,36 @@ const we = /* @__PURE__ */ Uint8Array.from([
757
759
  14,
758
760
  11,
759
761
  8
760
- ]), Tt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), ye = Tt.map((e) => (9 * e + 5) % 16), Et = /* @__PURE__ */ (() => {
761
- const n = [[Tt], [ye]];
762
+ ]), Mt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Re = Mt.map((e) => (9 * e + 5) % 16), Nt = /* @__PURE__ */ (() => {
763
+ const n = [[Mt], [Re]];
762
764
  for (let s = 0; s < 4; s++)
763
765
  for (let o of n)
764
- o.push(o[s].map((r) => we[r]));
766
+ o.push(o[s].map((r) => Le[r]));
765
767
  return n;
766
- })(), It = Et[0], vt = Et[1], Bt = /* @__PURE__ */ [
768
+ })(), Vt = Nt[0], Dt = Nt[1], Kt = /* @__PURE__ */ [
767
769
  [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
768
770
  [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
769
771
  [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
770
772
  [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
771
773
  [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
772
- ].map((e) => Uint8Array.from(e)), be = /* @__PURE__ */ It.map((e, t) => e.map((n) => Bt[t][n])), xe = /* @__PURE__ */ vt.map((e, t) => e.map((n) => Bt[t][n])), Pe = /* @__PURE__ */ Uint32Array.from([
774
+ ].map((e) => Uint8Array.from(e)), Ue = /* @__PURE__ */ Vt.map((e, t) => e.map((n) => Kt[t][n])), We = /* @__PURE__ */ Dt.map((e, t) => e.map((n) => Kt[t][n])), Fe = /* @__PURE__ */ Uint32Array.from([
773
775
  0,
774
776
  1518500249,
775
777
  1859775393,
776
778
  2400959708,
777
779
  2840853838
778
- ]), ke = /* @__PURE__ */ Uint32Array.from([
780
+ ]), Me = /* @__PURE__ */ Uint32Array.from([
779
781
  1352829926,
780
782
  1548603684,
781
783
  1836072691,
782
784
  2053994217,
783
785
  0
784
786
  ]);
785
- function pt(e, t, n, s) {
787
+ function vt(e, t, n, s) {
786
788
  return e === 0 ? t ^ n ^ s : e === 1 ? t & n | ~t & s : e === 2 ? (t | ~n) ^ s : e === 3 ? t & s | n & ~s : t ^ (n | ~s);
787
789
  }
788
- const U = /* @__PURE__ */ new Uint32Array(16);
789
- class Te extends te {
790
+ const M = /* @__PURE__ */ new Uint32Array(16);
791
+ class Ne extends be {
790
792
  constructor() {
791
793
  super(64, 20, 8, !0);
792
794
  b(this, "h0", 1732584193);
@@ -803,52 +805,52 @@ class Te extends te {
803
805
  this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
804
806
  }
805
807
  process(n, s) {
806
- for (let d = 0; d < 16; d++, s += 4)
807
- U[d] = n.getUint32(s, !0);
808
- let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, f = this.h2 | 0, h = f, c = this.h3 | 0, m = c, l = this.h4 | 0, y = l;
809
- for (let d = 0; d < 5; d++) {
810
- const x = 4 - d, P = Pe[d], w = ke[d], u = It[d], g = vt[d], p = be[d], T = xe[d];
808
+ for (let f = 0; f < 16; f++, s += 4)
809
+ M[f] = n.getUint32(s, !0);
810
+ let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, h = this.h2 | 0, u = h, c = this.h3 | 0, m = c, l = this.h4 | 0, y = l;
811
+ for (let f = 0; f < 5; f++) {
812
+ const x = 4 - f, P = Fe[f], w = Me[f], d = Vt[f], g = Dt[f], p = Ue[f], E = We[f];
811
813
  for (let k = 0; k < 16; k++) {
812
- const v = L(o + pt(d, i, f, c) + U[u[k]] + P, p[k]) + l | 0;
813
- o = l, l = c, c = L(f, 10) | 0, f = i, i = v;
814
+ const _ = F(o + vt(f, i, h, c) + M[d[k]] + P, p[k]) + l | 0;
815
+ o = l, l = c, c = F(h, 10) | 0, h = i, i = _;
814
816
  }
815
817
  for (let k = 0; k < 16; k++) {
816
- const v = L(r + pt(x, a, h, m) + U[g[k]] + w, T[k]) + y | 0;
817
- r = y, y = m, m = L(h, 10) | 0, h = a, a = v;
818
+ const _ = F(r + vt(x, a, u, m) + M[g[k]] + w, E[k]) + y | 0;
819
+ r = y, y = m, m = F(u, 10) | 0, u = a, a = _;
818
820
  }
819
821
  }
820
- this.set(this.h1 + f + m | 0, this.h2 + c + y | 0, this.h3 + l + r | 0, this.h4 + o + a | 0, this.h0 + i + h | 0);
822
+ this.set(this.h1 + h + m | 0, this.h2 + c + y | 0, this.h3 + l + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
821
823
  }
822
824
  roundClean() {
823
- H(U);
825
+ S(M);
824
826
  }
825
827
  destroy() {
826
- this.destroyed = !0, H(this.buffer), this.set(0, 0, 0, 0, 0);
828
+ this.destroyed = !0, S(this.buffer), this.set(0, 0, 0, 0, 0);
827
829
  }
828
830
  }
829
- const Ee = /* @__PURE__ */ xt(() => new Te()), Ie = BigInt(0), O = BigInt(1), ve = BigInt(2), Be = BigInt(7), _e = BigInt(256), Ce = BigInt(113), _t = [], Ct = [], Ht = [];
830
- for (let e = 0, t = O, n = 1, s = 0; e < 24; e++) {
831
- [n, s] = [s, (2 * n + 3 * s) % 5], _t.push(2 * (5 * s + n)), Ct.push((e + 1) * (e + 2) / 2 % 64);
832
- let o = Ie;
831
+ const Ve = /* @__PURE__ */ Ut(() => new Ne()), De = BigInt(0), L = BigInt(1), Ke = BigInt(2), Xe = BigInt(7), je = BigInt(256), qe = BigInt(113), Xt = [], jt = [], qt = [];
832
+ for (let e = 0, t = L, n = 1, s = 0; e < 24; e++) {
833
+ [n, s] = [s, (2 * n + 3 * s) % 5], Xt.push(2 * (5 * s + n)), jt.push((e + 1) * (e + 2) / 2 % 64);
834
+ let o = De;
833
835
  for (let r = 0; r < 7; r++)
834
- t = (t << O ^ (t >> Be) * Ce) % _e, t & ve && (o ^= O << (O << BigInt(r)) - O);
835
- Ht.push(o);
836
+ t = (t << L ^ (t >> Xe) * qe) % je, t & Ke && (o ^= L << (L << BigInt(r)) - L);
837
+ qt.push(o);
836
838
  }
837
- const St = ee(Ht, !0), He = St[0], Se = St[1], mt = (e, t, n) => n > 32 ? ie(e, t, n) : oe(e, t, n), wt = (e, t, n) => n > 32 ? ae(e, t, n) : re(e, t, n);
838
- function Ae(e, t = 24) {
839
+ const Zt = xe(qt, !0), Ze = Zt[0], Ge = Zt[1], Bt = (e, t, n) => n > 32 ? Ie(e, t, n) : Ee(e, t, n), St = (e, t, n) => n > 32 ? _e(e, t, n) : Te(e, t, n);
840
+ function ze(e, t = 24) {
839
841
  const n = new Uint32Array(10);
840
842
  for (let s = 24 - t; s < 24; s++) {
841
843
  for (let i = 0; i < 10; i++)
842
844
  n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
843
845
  for (let i = 0; i < 10; i += 2) {
844
- const a = (i + 8) % 10, f = (i + 2) % 10, h = n[f], c = n[f + 1], m = mt(h, c, 1) ^ n[a], l = wt(h, c, 1) ^ n[a + 1];
846
+ const a = (i + 8) % 10, h = (i + 2) % 10, u = n[h], c = n[h + 1], m = Bt(u, c, 1) ^ n[a], l = St(u, c, 1) ^ n[a + 1];
845
847
  for (let y = 0; y < 50; y += 10)
846
848
  e[i + y] ^= m, e[i + y + 1] ^= l;
847
849
  }
848
850
  let o = e[2], r = e[3];
849
851
  for (let i = 0; i < 24; i++) {
850
- const a = Ct[i], f = mt(o, r, a), h = wt(o, r, a), c = _t[i];
851
- o = e[c], r = e[c + 1], e[c] = f, e[c + 1] = h;
852
+ const a = jt[i], h = Bt(o, r, a), u = St(o, r, a), c = Xt[i];
853
+ o = e[c], r = e[c + 1], e[c] = h, e[c + 1] = u;
852
854
  }
853
855
  for (let i = 0; i < 50; i += 10) {
854
856
  for (let a = 0; a < 10; a++)
@@ -856,11 +858,11 @@ function Ae(e, t = 24) {
856
858
  for (let a = 0; a < 10; a++)
857
859
  e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
858
860
  }
859
- e[0] ^= He[s], e[1] ^= Se[s];
861
+ e[0] ^= Ze[s], e[1] ^= Ge[s];
860
862
  }
861
- H(n);
863
+ S(n);
862
864
  }
863
- class ot {
865
+ class ft {
864
866
  // NOTE: we accept arguments in bytes instead of bits here.
865
867
  constructor(t, n, s, o = !1, r = 24) {
866
868
  b(this, "state");
@@ -874,18 +876,18 @@ class ot {
874
876
  b(this, "outputLen");
875
877
  b(this, "enableXOF", !1);
876
878
  b(this, "rounds");
877
- if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, R(s, "outputLen"), !(0 < t && t < 200))
879
+ if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, C(s, "outputLen"), !(0 < t && t < 200))
878
880
  throw new Error("only keccak-f1600 function is supported");
879
- this.state = new Uint8Array(200), this.state32 = ne(this.state);
881
+ this.state = new Uint8Array(200), this.state32 = Pe(this.state);
880
882
  }
881
883
  clone() {
882
884
  return this._cloneInto();
883
885
  }
884
886
  keccak() {
885
- dt(this.state32), Ae(this.state32, this.rounds), dt(this.state32), this.posOut = 0, this.pos = 0;
887
+ Tt(this.state32), ze(this.state32, this.rounds), Tt(this.state32), this.posOut = 0, this.pos = 0;
886
888
  }
887
889
  update(t) {
888
- V(this), F(t);
890
+ V(this), U(t);
889
891
  const { blockLen: n, state: s } = this, o = t.length;
890
892
  for (let r = 0; r < o; ) {
891
893
  const i = Math.min(n - this.pos, o - r);
@@ -903,7 +905,7 @@ class ot {
903
905
  t[s] ^= n, (n & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
904
906
  }
905
907
  writeInto(t) {
906
- V(this, !1), F(t), this.finish();
908
+ V(this, !1), U(t), this.finish();
907
909
  const n = this.state, { blockLen: s } = this;
908
910
  for (let o = 0, r = t.length; o < r; ) {
909
911
  this.posOut >= s && this.keccak();
@@ -918,10 +920,10 @@ class ot {
918
920
  return this.writeInto(t);
919
921
  }
920
922
  xof(t) {
921
- return R(t), this.xofInto(new Uint8Array(t));
923
+ return C(t), this.xofInto(new Uint8Array(t));
922
924
  }
923
925
  digestInto(t) {
924
- if (se(t, this), this.finished)
926
+ if (ke(t, this), this.finished)
925
927
  throw new Error("digest() was already called");
926
928
  return this.writeInto(t), this.destroy(), t;
927
929
  }
@@ -929,93 +931,93 @@ class ot {
929
931
  return this.digestInto(new Uint8Array(this.outputLen));
930
932
  }
931
933
  destroy() {
932
- this.destroyed = !0, H(this.state);
934
+ this.destroyed = !0, S(this.state);
933
935
  }
934
936
  _cloneInto(t) {
935
937
  const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
936
- return t || (t = new ot(n, 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;
938
+ return t || (t = new ft(n, 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;
937
939
  }
938
940
  }
939
- const $e = (e, t, n, s = {}) => xt(() => new ot(t, e, n), s), Oe = /* @__PURE__ */ $e(1, 136, 32);
940
- function Re(e, t, n, s) {
941
- bt(e);
942
- const o = le({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
943
- if (R(r, "c"), R(i, "dkLen"), R(a, "asyncTick"), r < 1)
941
+ const Ye = (e, t, n, s = {}) => Ut(() => new ft(t, e, n), s), Je = /* @__PURE__ */ Ye(1, 136, 32);
942
+ function Qe(e, t, n, s) {
943
+ ht(e);
944
+ const o = Be({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
945
+ if (C(r, "c"), C(i, "dkLen"), C(a, "asyncTick"), r < 1)
944
946
  throw new Error("iterations (c) must be >= 1");
945
- const f = ft(t, "password"), h = ft(n, "salt"), c = new Uint8Array(i), m = st.create(e, f), l = m._cloneInto().update(h);
947
+ const h = It(t, "password"), u = It(n, "salt"), c = new Uint8Array(i), m = K.create(e, h), l = m._cloneInto().update(u);
946
948
  return { c: r, dkLen: i, asyncTick: a, DK: c, PRF: m, PRFSalt: l };
947
949
  }
948
- function Le(e, t, n, s, o) {
949
- return e.destroy(), t.destroy(), s && s.destroy(), H(o), n;
950
+ function tn(e, t, n, s, o) {
951
+ return e.destroy(), t.destroy(), s && s.destroy(), S(o), n;
950
952
  }
951
- function Ue(e, t, n, s) {
952
- const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: f } = Re(e, t, n, s);
953
- let h;
954
- const c = new Uint8Array(4), m = ce(c), l = new Uint8Array(a.outputLen);
955
- for (let y = 1, d = 0; d < r; y++, d += a.outputLen) {
956
- const x = i.subarray(d, d + a.outputLen);
957
- m.setInt32(0, y, !1), (h = f._cloneInto(h)).update(c).digestInto(l), x.set(l.subarray(0, x.length));
953
+ function en(e, t, n, s) {
954
+ const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: h } = Qe(e, t, n, s);
955
+ let u;
956
+ const c = new Uint8Array(4), m = ve(c), l = new Uint8Array(a.outputLen);
957
+ for (let y = 1, f = 0; f < r; y++, f += a.outputLen) {
958
+ const x = i.subarray(f, f + a.outputLen);
959
+ m.setInt32(0, y, !1), (u = h._cloneInto(u)).update(c).digestInto(l), x.set(l.subarray(0, x.length));
958
960
  for (let P = 1; P < o; P++) {
959
- a._cloneInto(h).update(l).digestInto(l);
961
+ a._cloneInto(u).update(l).digestInto(l);
960
962
  for (let w = 0; w < x.length; w++)
961
963
  x[w] ^= l[w];
962
964
  }
963
965
  }
964
- return Le(a, f, i, h, l);
966
+ return tn(a, h, i, u, l);
965
967
  }
966
- function At(e) {
968
+ function Gt(e) {
967
969
  if (typeof e != "string")
968
970
  throw new TypeError("invalid mnemonic type: " + typeof e);
969
971
  return e.normalize("NFKD");
970
972
  }
971
- function We(e) {
972
- const t = At(e), n = t.split(" ");
973
+ function nn(e) {
974
+ const t = Gt(e), n = t.split(" ");
973
975
  if (![12, 15, 18, 21, 24].includes(n.length))
974
976
  throw new Error("Invalid mnemonic");
975
977
  return { nfkd: t, words: n };
976
978
  }
977
- const Fe = (e) => At("mnemonic" + e);
978
- function Ve(e, t = "") {
979
- return Ue(Pt, We(e).nfkd, Fe(t), { c: 2048, dkLen: 64 });
979
+ const sn = (e) => Gt("mnemonic" + e);
980
+ function on(e, t = "") {
981
+ return en(Wt, nn(e).nfkd, sn(t), { c: 2048, dkLen: 64 });
980
982
  }
981
- const j = 32, q = 64, Ke = 4, E = 20, tt = 4, $t = 2, Me = 0, De = 1, W = [64, 64];
982
- function et(...e) {
983
+ const z = 32, Y = 64, rn = 4, T = 20, at = 4, zt = 2, an = 0, cn = 1, N = [64, 64];
984
+ function ct(...e) {
983
985
  const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
984
986
  let s = 0;
985
987
  for (const o of e)
986
988
  n.set(o, s), s += o.length;
987
989
  return n;
988
990
  }
989
- function G(e) {
991
+ function J(e) {
990
992
  return new TextEncoder().encode(e);
991
993
  }
992
- function z(e) {
993
- const t = new Uint8Array(Ke);
994
- return new DataView(t.buffer).setUint32(0, e.length, !1), et(t, e);
994
+ function Q(e) {
995
+ const t = new Uint8Array(rn);
996
+ return new DataView(t.buffer).setUint32(0, e.length, !1), ct(t, e);
995
997
  }
996
- function yt(e) {
998
+ function At(e) {
997
999
  return e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
998
1000
  }
999
- const Ne = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
1000
- function Xe(e, t) {
1001
- return st(Pt, e, t);
1001
+ const ln = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
1002
+ function un(e, t) {
1003
+ return K(Wt, e, t);
1002
1004
  }
1003
- function rt(e) {
1004
- return Ee(he(e));
1005
+ function gt(e) {
1006
+ return Ve(W(e));
1005
1007
  }
1006
- function Ot(e) {
1008
+ function Yt(e) {
1007
1009
  return (1 << e) - 1;
1008
1010
  }
1009
- function je(e) {
1011
+ function hn(e) {
1010
1012
  let t = 1;
1011
1013
  for (; t * t < e + 1; ) t++;
1012
1014
  return Math.max(t, 2);
1013
1015
  }
1014
- function qe(e) {
1015
- const t = tt, n = Ot(t), s = e * n;
1016
- return { d: t, n: e, checksum_radix: je(s) };
1016
+ function dn(e) {
1017
+ const t = at, n = Yt(t), s = e * n;
1018
+ return { d: t, n: e, checksum_radix: hn(s) };
1017
1019
  }
1018
- function Z(e, t) {
1020
+ function tt(e, t) {
1019
1021
  const n = [];
1020
1022
  let s = t;
1021
1023
  for (; s > 0; )
@@ -1024,96 +1026,96 @@ function Z(e, t) {
1024
1026
  o.set(e);
1025
1027
  for (let r = 0; r < n.length; r++)
1026
1028
  o[e.length + r] = n[r];
1027
- return rt(o);
1029
+ return gt(o);
1028
1030
  }
1029
- function J(e, t) {
1031
+ function et(e, t) {
1030
1032
  let n = e;
1031
1033
  for (let s = 0; s < t; s++)
1032
- n = rt(n);
1034
+ n = gt(n);
1033
1035
  return n;
1034
1036
  }
1035
- function Ge(e, t) {
1036
- const n = Ot(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
1037
+ function fn(e, t) {
1038
+ const n = Yt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
1037
1039
  for (let c = 0; c < t.n; c++) {
1038
- const m = Z(e, c + $t), l = J(m, n);
1040
+ const m = tt(e, c + zt), l = et(m, n);
1039
1041
  r.push(Array.from(l));
1040
1042
  }
1041
- const i = Z(
1043
+ const i = tt(
1042
1044
  e,
1043
- Me
1044
- ), a = J(
1045
+ an
1046
+ ), a = et(
1045
1047
  i,
1046
1048
  s
1047
- ), f = Z(
1049
+ ), h = tt(
1048
1050
  e,
1049
- De
1050
- ), h = J(
1051
- f,
1051
+ cn
1052
+ ), u = et(
1053
+ h,
1052
1054
  o
1053
1055
  );
1054
1056
  return {
1055
1057
  config: t,
1056
1058
  message_terminals: r,
1057
- checksum_major_terminal: Array.from(h),
1059
+ checksum_major_terminal: Array.from(u),
1058
1060
  checksum_minor_terminal: Array.from(a)
1059
1061
  };
1060
1062
  }
1061
- function ze(e) {
1062
- const t = Ve(e), n = new Uint8Array(t);
1063
+ function gn(e) {
1064
+ const t = on(e), n = new Uint8Array(t);
1063
1065
  return t.fill(0), n;
1064
1066
  }
1065
- async function Ze(e, t, n, s) {
1066
- if (e.length !== q)
1067
+ async function pn(e, t, n, s) {
1068
+ if (e.length !== Y)
1067
1069
  throw new Error(
1068
- `WOTS seed must be exactly ${q} bytes, got ${e.length}`
1070
+ `WOTS seed must be exactly ${Y} bytes, got ${e.length}`
1069
1071
  );
1070
- const o = yt(t).toLowerCase(), r = yt(n).toLowerCase(), i = e.slice(j, q), a = e.slice(0, j), f = et(
1072
+ const o = At(t).toLowerCase(), r = At(n).toLowerCase(), i = e.slice(z, Y), a = e.slice(0, z), h = ct(
1071
1073
  a,
1072
- et(
1073
- z(G(o)),
1074
- z(G(r)),
1075
- z(G(s.toLowerCase()))
1074
+ ct(
1075
+ Q(J(o)),
1076
+ Q(J(r)),
1077
+ Q(J(s.toLowerCase()))
1076
1078
  )
1077
- ), h = Xe(i, f), c = h.slice(0, j);
1079
+ ), u = un(i, h), c = u.slice(0, z);
1078
1080
  try {
1079
1081
  const m = [];
1080
- for (let l = 0; l < W.length; l++) {
1081
- const y = W[l], d = qe(y), x = new Uint8Array(c.length + 1);
1082
+ for (let l = 0; l < N.length; l++) {
1083
+ const y = N[l], f = dn(y), x = new Uint8Array(c.length + 1);
1082
1084
  x.set(c), x[c.length] = l;
1083
- const P = rt(x);
1085
+ const P = gt(x);
1084
1086
  try {
1085
- const w = Ge(P, d);
1086
- if (w.config.d !== tt)
1087
- throw new Error(`Block ${l}: expected d=${tt}, got d=${w.config.d}`);
1087
+ const w = fn(P, f);
1088
+ if (w.config.d !== at)
1089
+ throw new Error(`Block ${l}: expected d=${at}, got d=${w.config.d}`);
1088
1090
  if (w.config.n !== y)
1089
1091
  throw new Error(`Block ${l}: expected n=${y}, got n=${w.config.n}`);
1090
1092
  if (w.message_terminals.length !== y)
1091
1093
  throw new Error(`Block ${l}: expected ${y} message terminals, got ${w.message_terminals.length}`);
1092
- for (let u = 0; u < w.message_terminals.length; u++)
1093
- if (w.message_terminals[u].length !== E)
1094
- throw new Error(`Block ${l} terminal ${u}: expected ${E} bytes, got ${w.message_terminals[u].length}`);
1095
- if (w.checksum_minor_terminal.length !== E)
1096
- throw new Error(`Block ${l} checksum_minor: expected ${E} bytes`);
1097
- if (w.checksum_major_terminal.length !== E)
1098
- throw new Error(`Block ${l} checksum_major: expected ${E} bytes`);
1094
+ for (let d = 0; d < w.message_terminals.length; d++)
1095
+ if (w.message_terminals[d].length !== T)
1096
+ throw new Error(`Block ${l} terminal ${d}: expected ${T} bytes, got ${w.message_terminals[d].length}`);
1097
+ if (w.checksum_minor_terminal.length !== T)
1098
+ throw new Error(`Block ${l} checksum_minor: expected ${T} bytes`);
1099
+ if (w.checksum_major_terminal.length !== T)
1100
+ throw new Error(`Block ${l} checksum_major: expected ${T} bytes`);
1099
1101
  m.push(w);
1100
1102
  } finally {
1101
1103
  x.fill(0), P.fill(0);
1102
1104
  }
1103
1105
  }
1104
- if (m.length !== W.length)
1106
+ if (m.length !== N.length)
1105
1107
  throw new Error(
1106
- `Expected ${W.length} blocks, got ${m.length}`
1108
+ `Expected ${N.length} blocks, got ${m.length}`
1107
1109
  );
1108
1110
  return m;
1109
1111
  } finally {
1110
- f.fill(0), i.fill(0), a.fill(0), h.fill(0), c.fill(0), e.fill(0);
1112
+ h.fill(0), i.fill(0), a.fill(0), u.fill(0), c.fill(0), e.fill(0);
1111
1113
  }
1112
1114
  }
1113
- function Q(e, t, n) {
1114
- if (e.length !== E)
1115
+ function nt(e, t, n) {
1116
+ if (e.length !== T)
1115
1117
  throw new Error(
1116
- `Block ${t} ${n}: expected ${E} bytes, got ${e.length}`
1118
+ `Block ${t} ${n}: expected ${T} bytes, got ${e.length}`
1117
1119
  );
1118
1120
  for (let s = 0; s < e.length; s++) {
1119
1121
  const o = e[s];
@@ -1123,57 +1125,173 @@ function Q(e, t, n) {
1123
1125
  );
1124
1126
  }
1125
1127
  }
1126
- function Je(e) {
1128
+ function mn(e) {
1127
1129
  if (e.length === 0)
1128
1130
  throw new Error("Public keys array must not be empty");
1129
1131
  for (let r = 0; r < e.length; r++) {
1130
1132
  const i = e[r];
1131
- Q(i.checksum_minor_terminal, r, "checksum_minor_terminal"), Q(i.checksum_major_terminal, r, "checksum_major_terminal");
1133
+ nt(i.checksum_minor_terminal, r, "checksum_minor_terminal"), nt(i.checksum_major_terminal, r, "checksum_major_terminal");
1132
1134
  for (let a = 0; a < i.message_terminals.length; a++)
1133
- Q(i.message_terminals[a], r, `message_terminal[${a}]`);
1135
+ nt(i.message_terminals[a], r, `message_terminal[${a}]`);
1134
1136
  }
1135
1137
  let t = 0;
1136
1138
  for (const r of e)
1137
- t += $t + r.message_terminals.length;
1138
- const n = new Uint8Array(t * E);
1139
+ t += zt + r.message_terminals.length;
1140
+ const n = new Uint8Array(t * T);
1139
1141
  let s = 0;
1140
1142
  for (const r of e) {
1141
- n.set(r.checksum_minor_terminal, s), s += E, n.set(r.checksum_major_terminal, s), s += E;
1143
+ n.set(r.checksum_minor_terminal, s), s += T, n.set(r.checksum_major_terminal, s), s += T;
1142
1144
  for (const i of r.message_terminals)
1143
- n.set(i, s), s += E;
1145
+ n.set(i, s), s += T;
1144
1146
  }
1145
- const o = Oe(n);
1146
- return `0x${Ne(o)}`;
1147
+ const o = Je(n);
1148
+ return `0x${ln(o)}`;
1147
1149
  }
1148
- async function mn(e, t, n, s) {
1149
- const o = ze(e);
1150
+ async function Vn(e, t, n, s) {
1151
+ const o = gn(e);
1150
1152
  try {
1151
- const r = await Ze(
1153
+ const r = await pn(
1152
1154
  o,
1153
1155
  t,
1154
1156
  n,
1155
1157
  s
1156
1158
  );
1157
- return Je(r);
1159
+ return mn(r);
1158
1160
  } finally {
1159
1161
  o.fill(0);
1160
1162
  }
1161
1163
  }
1162
- function wn(e) {
1164
+ function Dn(e) {
1163
1165
  const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
1164
1166
  return t.includes("wots") && t.includes("hash") && t.includes("does not match");
1165
1167
  }
1168
+ const st = /* @__PURE__ */ Uint8Array.of(0), Ct = /* @__PURE__ */ Uint8Array.of();
1169
+ function pt(e, t, n, s = 32) {
1170
+ ht(e), C(s, "length");
1171
+ const o = e.outputLen;
1172
+ if (s > 255 * o)
1173
+ throw new Error("Length must be <= 255*HashLen");
1174
+ const r = Math.ceil(s / o);
1175
+ n === void 0 ? n = Ct : U(n, void 0, "info");
1176
+ const i = new Uint8Array(r * o), a = K.create(e, t), h = a._cloneInto(), u = new Uint8Array(a.outputLen);
1177
+ for (let c = 0; c < r; c++)
1178
+ st[0] = c + 1, h.update(c === 0 ? Ct : u).update(n).update(st).digestInto(u), i.set(u, o * c), a._cloneInto(h);
1179
+ return a.destroy(), h.destroy(), S(u, st), i.slice(0, s);
1180
+ }
1181
+ const ot = new TextEncoder().encode("babylonvault"), Ht = 255, Ot = 65535, $t = 2, wn = "hashlock", yn = "auth-anchor", bn = "wots-seed";
1182
+ function Jt(e) {
1183
+ if (!Number.isInteger(e) || e < 0 || e > 4294967295)
1184
+ throw new Error(`i2osp4: value must be a u32, got ${e}`);
1185
+ const t = new Uint8Array(4);
1186
+ return t[0] = e >>> 24 & 255, t[1] = e >>> 16 & 255, t[2] = e >>> 8 & 255, t[3] = e & 255, t;
1187
+ }
1188
+ function mt(e, t = new Uint8Array(0)) {
1189
+ const n = new TextEncoder().encode(e);
1190
+ if (n.length === 0 || n.length > Ht)
1191
+ throw new Error(
1192
+ `info: label length must be in [1, ${Ht}], got ${n.length}`
1193
+ );
1194
+ if (t.length > Ot)
1195
+ throw new Error(
1196
+ `info: ctx length must be in [0, ${Ot}], got ${t.length}`
1197
+ );
1198
+ const s = ot.length + 1 + n.length + $t + t.length, o = new Uint8Array(s);
1199
+ let r = 0;
1200
+ return o.set(ot, r), r += ot.length, o[r] = n.length, r += 1, o.set(n, r), r += n.length, o[r] = t.length >>> 8 & 255, o[r + 1] = t.length & 255, r += $t, o.set(t, r), o;
1201
+ }
1202
+ const Lt = 32, xn = 32, Pn = 32, kn = 64;
1203
+ function wt(e) {
1204
+ if (e.length !== Lt)
1205
+ throw new Error(
1206
+ `vault-secrets: root must be exactly ${Lt} bytes, got ${e.length}`
1207
+ );
1208
+ }
1209
+ function Kn(e) {
1210
+ return wt(e), pt(
1211
+ W,
1212
+ e,
1213
+ mt(yn),
1214
+ xn
1215
+ );
1216
+ }
1217
+ function Xn(e, t) {
1218
+ return wt(e), pt(
1219
+ W,
1220
+ e,
1221
+ mt(wn, Jt(t)),
1222
+ Pn
1223
+ );
1224
+ }
1225
+ function jn(e, t) {
1226
+ return wt(e), pt(
1227
+ W,
1228
+ e,
1229
+ mt(bn, Jt(t)),
1230
+ kn
1231
+ );
1232
+ }
1233
+ const R = 32, rt = 32, lt = 36, Qt = 32, D = 4, En = D + R + D + Qt;
1234
+ function ut(e, t, n) {
1235
+ e[t] = n >>> 24 & 255, e[t + 1] = n >>> 16 & 255, e[t + 2] = n >>> 8 & 255, e[t + 3] = n & 255;
1236
+ }
1237
+ function Tn(e) {
1238
+ if (e.txid.length !== rt)
1239
+ throw new Error(
1240
+ `outpoint.txid must be exactly ${rt} bytes, got ${e.txid.length}`
1241
+ );
1242
+ if (!Number.isInteger(e.vout) || e.vout < 0 || e.vout > 4294967295)
1243
+ throw new Error(`outpoint.vout must be a u32, got ${e.vout}`);
1244
+ const t = new Uint8Array(lt);
1245
+ return t.set(e.txid, 0), ut(t, rt, e.vout), t;
1246
+ }
1247
+ function Rt(e, t) {
1248
+ const n = Math.min(e.length, t.length);
1249
+ for (let s = 0; s < n; s++)
1250
+ if (e[s] !== t[s]) return e[s] - t[s];
1251
+ return e.length - t.length;
1252
+ }
1253
+ function In(e) {
1254
+ if (e.length === 0)
1255
+ throw new Error(
1256
+ "buildFundingOutpointsCommitment: outpoints must be non-empty"
1257
+ );
1258
+ const t = e.map(Tn);
1259
+ t.sort(Rt);
1260
+ for (let s = 1; s < t.length; s++)
1261
+ if (Rt(t[s - 1], t[s]) === 0)
1262
+ throw new Error(
1263
+ "buildFundingOutpointsCommitment: duplicate outpoint detected"
1264
+ );
1265
+ const n = new Uint8Array(t.length * lt);
1266
+ for (let s = 0; s < t.length; s++)
1267
+ n.set(t[s], s * lt);
1268
+ return W(n);
1269
+ }
1270
+ function qn(e) {
1271
+ if (e.depositorBtcPubkey.length !== R)
1272
+ throw new Error(
1273
+ `vaultContext: depositorBtcPubkey must be exactly ${R} bytes, got ${e.depositorBtcPubkey.length}`
1274
+ );
1275
+ const t = In(e.fundingOutpoints), n = new Uint8Array(En);
1276
+ let s = 0;
1277
+ return ut(n, s, R), s += D, n.set(e.depositorBtcPubkey, s), s += R, ut(n, s, Qt), s += D, n.set(t, s), n;
1278
+ }
1166
1279
  export {
1167
- S as C,
1168
- pn as P,
1169
- mn as a,
1170
- wn as b,
1171
- Je as c,
1172
- Ze as d,
1173
- nt as e,
1174
- fn as g,
1175
- C as h,
1176
- gn as i,
1177
- ze as m
1280
+ H as C,
1281
+ Nn as P,
1282
+ Vn as a,
1283
+ Dn as b,
1284
+ mn as c,
1285
+ pn as d,
1286
+ dt as e,
1287
+ Kn as f,
1288
+ Fn as g,
1289
+ A as h,
1290
+ Mn as i,
1291
+ Xn as j,
1292
+ jn as k,
1293
+ In as l,
1294
+ gn as m,
1295
+ qn as n
1178
1296
  };
1179
- //# sourceMappingURL=errors-kc6XZy1U.js.map
1297
+ //# sourceMappingURL=context-ktqanzXE.js.map