@babylonlabs-io/ts-sdk 0.27.0 → 0.28.0

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