@babylonlabs-io/ts-sdk 0.26.0 → 0.26.2

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