@babylonlabs-io/ts-sdk 0.20.0 → 0.21.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.
- package/README.md +14 -6
- package/dist/errors-Cbyg_QQf.cjs +2 -0
- package/dist/errors-Cbyg_QQf.cjs.map +1 -0
- package/dist/{errors-CHY4WNi-.js → errors-DvIudLXV.js} +344 -338
- package/dist/errors-DvIudLXV.js.map +1 -0
- package/dist/{index-CFwoGJNQ.js → index-BORWfdUU.js} +140 -115
- package/dist/index-BORWfdUU.js.map +1 -0
- package/dist/index-DNSV--0P.cjs +2 -0
- package/dist/index-DNSV--0P.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +126 -120
- package/dist/index.js.map +1 -1
- package/dist/psbtInputFields-05ZrwRzf.cjs +2 -0
- package/dist/psbtInputFields-05ZrwRzf.cjs.map +1 -0
- package/dist/{psbtInputFields-Dx41_IoI.js → psbtInputFields-r1ss6WLU.js} +93 -85
- package/dist/psbtInputFields-r1ss6WLU.js.map +1 -0
- package/dist/shared/wallets/index.d.ts +8 -0
- package/dist/shared/wallets/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.d.ts +3 -2
- package/dist/tbv/core/clients/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.js +1 -1
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +122 -116
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.d.ts +15 -62
- package/dist/tbv/core/managers/index.d.ts.map +1 -1
- package/dist/tbv/core/services/index.d.ts +2 -4
- package/dist/tbv/core/services/index.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.d.ts +2 -7
- package/dist/tbv/core/utils/index.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.js +37 -31
- package/dist/tbv/core/utils/index.js.map +1 -1
- package/dist/tbv/core/utils/utxo/reservation.d.ts +27 -1
- package/dist/tbv/core/utils/utxo/reservation.d.ts.map +1 -1
- package/dist/tbv/core/utils/validation.d.ts +35 -0
- package/dist/tbv/core/utils/validation.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +122 -116
- package/dist/tbv/index.js.map +1 -1
- package/dist/validation-CxqROCno.js +15 -0
- package/dist/validation-CxqROCno.js.map +1 -0
- package/dist/validation-u8W7Lp2x.cjs +2 -0
- package/dist/validation-u8W7Lp2x.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/errors-BZON3Wmn.cjs +0 -2
- package/dist/errors-BZON3Wmn.cjs.map +0 -1
- package/dist/errors-CHY4WNi-.js.map +0 -1
- package/dist/index-BpXpESWu.cjs +0 -2
- package/dist/index-BpXpESWu.cjs.map +0 -1
- package/dist/index-CFwoGJNQ.js.map +0 -1
- package/dist/psbtInputFields-C-zYR1z7.cjs +0 -2
- package/dist/psbtInputFields-C-zYR1z7.cjs.map +0 -1
- package/dist/psbtInputFields-Dx41_IoI.js.map +0 -1
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import * as
|
|
5
|
-
import { Transaction as
|
|
1
|
+
var Gt = Object.defineProperty;
|
|
2
|
+
var zt = (e, t, n) => t in e ? Gt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var P = (e, t, n) => zt(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as Zt from "bitcoinjs-lib";
|
|
5
|
+
import { Transaction as Jt, Psbt as mt } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as q } from "buffer";
|
|
7
|
-
import { createPublicClient as G, http as z, encodeFunctionData as yt, zeroAddress as
|
|
8
|
-
import { c as
|
|
7
|
+
import { createPublicClient as G, http as z, encodeFunctionData as yt, zeroAddress as Yt } from "viem";
|
|
8
|
+
import { c as Qt } from "./signing-DeWVBl7m.js";
|
|
9
9
|
import { deriveVaultId as wt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
-
import { b as
|
|
11
|
-
import { s as E, g as bt, e as H, i as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { p as
|
|
10
|
+
import { b as te, a as ee, d as ne, e as se, f as oe } from "./challengeAssert-D1lpvuMv.js";
|
|
11
|
+
import { s as E, g as bt, e as H, i as re } from "./bitcoin-nOOgeRyl.js";
|
|
12
|
+
import { M as xt } from "./validation-CxqROCno.js";
|
|
13
|
+
import { b as ie, f as Z, i as ae } from "./psbtInputFields-r1ss6WLU.js";
|
|
14
|
+
import { p as ce, f as le } from "./fundPeginTransaction-BLYXxLBv.js";
|
|
15
|
+
import { p as he, f as ue } from "./index-BORWfdUU.js";
|
|
15
16
|
import { B as $ } from "./types-DWjaqVfP.js";
|
|
16
|
-
import { n as
|
|
17
|
+
import { n as Bt, o as K, q as S, r as M, t as Ct, H as fe, u as U, x as de, y as L, z as ge, A as Pt, D as pe, E as me, F as ye, G as we, I as be, J as xe, K as Pe, L as kt, M as ut, N as At } from "./buildAndBroadcastRefund-DnTQkCgG.js";
|
|
17
18
|
const B = {
|
|
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.",
|
|
@@ -63,14 +64,14 @@ function ft(e) {
|
|
|
63
64
|
if (i)
|
|
64
65
|
return i[1];
|
|
65
66
|
}
|
|
66
|
-
function
|
|
67
|
+
function xn(e) {
|
|
67
68
|
const t = ft(e);
|
|
68
69
|
if (t) {
|
|
69
70
|
const n = t.substring(0, 10);
|
|
70
71
|
return B[t] ?? B[n];
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
|
-
function
|
|
74
|
+
function Pn(e) {
|
|
74
75
|
const t = ft(e);
|
|
75
76
|
if (t === void 0) return !1;
|
|
76
77
|
const n = t.substring(0, 10);
|
|
@@ -98,25 +99,25 @@ function _(e) {
|
|
|
98
99
|
}
|
|
99
100
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
100
101
|
}
|
|
101
|
-
const
|
|
102
|
-
function
|
|
102
|
+
const ke = 0;
|
|
103
|
+
function Te(e, t, n, s) {
|
|
103
104
|
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
104
105
|
return o ? Promise.resolve({
|
|
105
106
|
txid: e,
|
|
106
107
|
vout: t,
|
|
107
108
|
value: o.value,
|
|
108
109
|
scriptPubKey: o.scriptPubKey
|
|
109
|
-
}) :
|
|
110
|
+
}) : ue(e, t, s);
|
|
110
111
|
}
|
|
111
|
-
const
|
|
112
|
-
class
|
|
112
|
+
const Tt = 12e4;
|
|
113
|
+
class kn {
|
|
113
114
|
/**
|
|
114
115
|
* Creates a new PeginManager instance.
|
|
115
116
|
*
|
|
116
117
|
* @param config - Manager configuration including wallets and contract addresses
|
|
117
118
|
*/
|
|
118
119
|
constructor(t) {
|
|
119
|
-
|
|
120
|
+
P(this, "config");
|
|
120
121
|
this.config = t;
|
|
121
122
|
}
|
|
122
123
|
/**
|
|
@@ -160,65 +161,65 @@ class xn {
|
|
|
160
161
|
councilQuorum: t.councilQuorum,
|
|
161
162
|
councilSize: t.councilSize,
|
|
162
163
|
network: this.config.btcNetwork
|
|
163
|
-
}, u = await
|
|
164
|
+
}, u = await te(d), l = ie(
|
|
164
165
|
[...t.availableUTXOs],
|
|
165
166
|
u.totalOutputValue,
|
|
166
167
|
t.mempoolFeeRate,
|
|
167
|
-
|
|
168
|
-
),
|
|
168
|
+
ce(u.htlcValues.length)
|
|
169
|
+
), y = bt(this.config.btcNetwork), c = le({
|
|
169
170
|
unfundedTxHex: u.psbtHex,
|
|
170
|
-
selectedUTXOs:
|
|
171
|
+
selectedUTXOs: l.selectedUTXOs,
|
|
171
172
|
changeAddress: t.changeAddress,
|
|
172
|
-
changeAmount:
|
|
173
|
-
network:
|
|
174
|
-
}),
|
|
175
|
-
for (let
|
|
176
|
-
const
|
|
173
|
+
changeAmount: l.changeAmount,
|
|
174
|
+
network: y
|
|
175
|
+
}), m = E(Z(c)), g = [], b = [], x = [];
|
|
176
|
+
for (let h = 0; h < t.hashlocks.length; h++) {
|
|
177
|
+
const w = await ee({
|
|
177
178
|
prePeginParams: d,
|
|
178
179
|
timelockPegin: t.timelockPegin,
|
|
179
|
-
fundedPrePeginTxHex:
|
|
180
|
-
htlcVout:
|
|
181
|
-
}), T = await
|
|
182
|
-
peginTxHex:
|
|
183
|
-
fundedPrePeginTxHex:
|
|
180
|
+
fundedPrePeginTxHex: c,
|
|
181
|
+
htlcVout: h
|
|
182
|
+
}), T = await ne({
|
|
183
|
+
peginTxHex: w.txHex,
|
|
184
|
+
fundedPrePeginTxHex: c,
|
|
184
185
|
depositorPubkey: s,
|
|
185
186
|
vaultProviderPubkey: o,
|
|
186
187
|
vaultKeeperPubkeys: r,
|
|
187
188
|
universalChallengerPubkeys: i,
|
|
188
|
-
hashlock: t.hashlocks[
|
|
189
|
+
hashlock: t.hashlocks[h],
|
|
189
190
|
timelockRefund: t.timelockRefund,
|
|
190
191
|
network: this.config.btcNetwork
|
|
191
192
|
});
|
|
192
|
-
|
|
193
|
-
|
|
193
|
+
g.push(w), b.push(T.psbtHex), x.push(
|
|
194
|
+
Qt(n, 1)
|
|
194
195
|
);
|
|
195
196
|
}
|
|
196
197
|
const f = await this.signPsbtsWithFallback(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
),
|
|
200
|
-
for (let
|
|
201
|
-
const
|
|
202
|
-
f[
|
|
198
|
+
b,
|
|
199
|
+
x
|
|
200
|
+
), p = [];
|
|
201
|
+
for (let h = 0; h < f.length; h++) {
|
|
202
|
+
const w = se(
|
|
203
|
+
f[h],
|
|
203
204
|
s
|
|
204
|
-
), T =
|
|
205
|
-
|
|
206
|
-
htlcVout:
|
|
207
|
-
htlcValue: u.htlcValues[
|
|
205
|
+
), T = oe(f[h]);
|
|
206
|
+
p.push({
|
|
207
|
+
htlcVout: h,
|
|
208
|
+
htlcValue: u.htlcValues[h],
|
|
208
209
|
peginTxHex: T,
|
|
209
|
-
peginTxid:
|
|
210
|
-
peginInputSignature:
|
|
211
|
-
vaultScriptPubKey:
|
|
210
|
+
peginTxid: g[h].txid,
|
|
211
|
+
peginInputSignature: w,
|
|
212
|
+
vaultScriptPubKey: g[h].vaultScriptPubKey
|
|
212
213
|
});
|
|
213
214
|
}
|
|
214
215
|
return {
|
|
215
|
-
fundedPrePeginTxHex:
|
|
216
|
-
prePeginTxid:
|
|
216
|
+
fundedPrePeginTxHex: c,
|
|
217
|
+
prePeginTxid: m,
|
|
217
218
|
unsignedPrePeginTxHex: u.psbtHex,
|
|
218
|
-
perVault:
|
|
219
|
-
selectedUTXOs:
|
|
220
|
-
fee:
|
|
221
|
-
changeAmount:
|
|
219
|
+
perVault: p,
|
|
220
|
+
selectedUTXOs: l.selectedUTXOs,
|
|
221
|
+
fee: l.fee,
|
|
222
|
+
changeAmount: l.changeAmount
|
|
222
223
|
};
|
|
223
224
|
}
|
|
224
225
|
/**
|
|
@@ -266,7 +267,7 @@ class xn {
|
|
|
266
267
|
* @throws Error if signing or broadcasting fails
|
|
267
268
|
*/
|
|
268
269
|
async signAndBroadcast(t) {
|
|
269
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r =
|
|
270
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = Jt.fromHex(o);
|
|
270
271
|
if (r.ins.length === 0)
|
|
271
272
|
throw new Error("Transaction has no inputs");
|
|
272
273
|
const i = new mt();
|
|
@@ -281,55 +282,60 @@ class xn {
|
|
|
281
282
|
throw new Error(
|
|
282
283
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${d.length}`
|
|
283
284
|
);
|
|
284
|
-
const u = this.config.mempoolApiUrl,
|
|
285
|
-
const
|
|
286
|
-
return
|
|
287
|
-
(
|
|
285
|
+
const u = this.config.mempoolApiUrl, l = r.ins.map((h) => {
|
|
286
|
+
const w = q.from(h.hash).reverse().toString("hex"), T = h.index;
|
|
287
|
+
return Te(w, T, t.localPrevouts, u).then(
|
|
288
|
+
(k) => ({ input: h, utxoData: k, txid: w, vout: T })
|
|
288
289
|
);
|
|
289
|
-
}),
|
|
290
|
-
(
|
|
290
|
+
}), y = await Promise.all(l), c = y.reduce(
|
|
291
|
+
(h, w) => h + BigInt(w.utxoData.value),
|
|
291
292
|
0n
|
|
292
|
-
),
|
|
293
|
-
(
|
|
293
|
+
), m = r.outs.reduce(
|
|
294
|
+
(h, w) => h + BigInt(w.value),
|
|
294
295
|
0n
|
|
295
296
|
);
|
|
296
|
-
if (
|
|
297
|
+
if (c < m)
|
|
298
|
+
throw new Error(
|
|
299
|
+
`UTXO value mismatch: total input value (${c} sat) is less than total output value (${m} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
300
|
+
);
|
|
301
|
+
const g = c - m;
|
|
302
|
+
if (g > xt)
|
|
297
303
|
throw new Error(
|
|
298
|
-
`
|
|
304
|
+
`Implied transaction fee (${g} sat) exceeds maximum reasonable fee (${xt} sat). This may indicate manipulated UTXO data.`
|
|
299
305
|
);
|
|
300
|
-
for (const { input:
|
|
301
|
-
const
|
|
306
|
+
for (const { input: h, utxoData: w, txid: T, vout: k } of y) {
|
|
307
|
+
const I = ae(
|
|
302
308
|
{
|
|
303
|
-
value:
|
|
304
|
-
scriptPubKey:
|
|
309
|
+
value: w.value,
|
|
310
|
+
scriptPubKey: w.scriptPubKey
|
|
305
311
|
},
|
|
306
312
|
d
|
|
307
313
|
);
|
|
308
314
|
i.addInput({
|
|
309
|
-
hash:
|
|
310
|
-
index:
|
|
311
|
-
sequence:
|
|
312
|
-
...
|
|
315
|
+
hash: h.hash,
|
|
316
|
+
index: h.index,
|
|
317
|
+
sequence: h.sequence,
|
|
318
|
+
...I
|
|
313
319
|
});
|
|
314
320
|
}
|
|
315
|
-
for (const
|
|
321
|
+
for (const h of r.outs)
|
|
316
322
|
i.addOutput({
|
|
317
|
-
script:
|
|
318
|
-
value:
|
|
323
|
+
script: h.script,
|
|
324
|
+
value: h.value
|
|
319
325
|
});
|
|
320
|
-
const
|
|
326
|
+
const b = await this.config.btcWallet.signPsbt(i.toHex()), x = mt.fromHex(b);
|
|
321
327
|
try {
|
|
322
|
-
|
|
323
|
-
} catch (
|
|
324
|
-
if (!
|
|
325
|
-
(
|
|
328
|
+
x.finalizeAllInputs();
|
|
329
|
+
} catch (h) {
|
|
330
|
+
if (!x.data.inputs.every(
|
|
331
|
+
(T) => T.finalScriptWitness || T.finalScriptSig
|
|
326
332
|
))
|
|
327
333
|
throw new Error(
|
|
328
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
334
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${h}`
|
|
329
335
|
);
|
|
330
336
|
}
|
|
331
|
-
const
|
|
332
|
-
return await
|
|
337
|
+
const f = x.extractTransaction().toHex();
|
|
338
|
+
return await he(f, u);
|
|
333
339
|
}
|
|
334
340
|
/**
|
|
335
341
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -358,33 +364,33 @@ class xn {
|
|
|
358
364
|
htlcVout: a,
|
|
359
365
|
onPopSigned: d,
|
|
360
366
|
depositorPayoutBtcAddress: u,
|
|
361
|
-
depositorWotsPkHash:
|
|
362
|
-
preSignedBtcPopSignature:
|
|
367
|
+
depositorWotsPkHash: l,
|
|
368
|
+
preSignedBtcPopSignature: y
|
|
363
369
|
} = t;
|
|
364
370
|
if (!this.config.ethWallet.account)
|
|
365
371
|
throw new Error("Ethereum wallet account not found");
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
372
|
+
const c = this.config.ethWallet.account.address, m = await this.resolvePopSignature(
|
|
373
|
+
c,
|
|
374
|
+
y
|
|
369
375
|
);
|
|
370
376
|
d && await d();
|
|
371
|
-
const
|
|
377
|
+
const g = H(n), b = H(s), x = H(o), f = await this.resolvePayoutScriptPubKey(
|
|
372
378
|
u
|
|
373
|
-
),
|
|
374
|
-
E(
|
|
375
|
-
E(
|
|
376
|
-
),
|
|
377
|
-
if (await this.checkVaultExists(
|
|
379
|
+
), p = Z(x), h = await wt(
|
|
380
|
+
E(p),
|
|
381
|
+
E(c)
|
|
382
|
+
), w = H(h);
|
|
383
|
+
if (await this.checkVaultExists(w))
|
|
378
384
|
throw new Error(
|
|
379
|
-
`Vault already exists (ID: ${
|
|
385
|
+
`Vault already exists (ID: ${w}, 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.`
|
|
380
386
|
);
|
|
381
387
|
const k = G({
|
|
382
388
|
chain: this.config.ethChain,
|
|
383
389
|
transport: z()
|
|
384
390
|
});
|
|
385
|
-
let
|
|
391
|
+
let I;
|
|
386
392
|
try {
|
|
387
|
-
|
|
393
|
+
I = await k.readContract({
|
|
388
394
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
389
395
|
abi: $,
|
|
390
396
|
functionName: "getPegInFee",
|
|
@@ -399,16 +405,16 @@ class xn {
|
|
|
399
405
|
abi: $,
|
|
400
406
|
functionName: "submitPeginRequest",
|
|
401
407
|
args: [
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
408
|
+
c,
|
|
409
|
+
g,
|
|
410
|
+
m,
|
|
411
|
+
b,
|
|
412
|
+
x,
|
|
407
413
|
r,
|
|
408
414
|
i,
|
|
409
415
|
a,
|
|
410
416
|
f,
|
|
411
|
-
|
|
417
|
+
l
|
|
412
418
|
]
|
|
413
419
|
});
|
|
414
420
|
let A;
|
|
@@ -416,7 +422,7 @@ class xn {
|
|
|
416
422
|
A = await k.estimateGas({
|
|
417
423
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
418
424
|
data: C,
|
|
419
|
-
value:
|
|
425
|
+
value: I,
|
|
420
426
|
account: this.config.ethWallet.account.address
|
|
421
427
|
});
|
|
422
428
|
} catch (j) {
|
|
@@ -427,7 +433,7 @@ class xn {
|
|
|
427
433
|
X = await this.config.ethWallet.sendTransaction({
|
|
428
434
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
429
435
|
data: C,
|
|
430
|
-
value:
|
|
436
|
+
value: I,
|
|
431
437
|
account: this.config.ethWallet.account,
|
|
432
438
|
chain: this.config.ethChain,
|
|
433
439
|
gas: A
|
|
@@ -437,7 +443,7 @@ class xn {
|
|
|
437
443
|
}
|
|
438
444
|
const pt = await k.waitForTransactionReceipt({
|
|
439
445
|
hash: X,
|
|
440
|
-
timeout:
|
|
446
|
+
timeout: Tt
|
|
441
447
|
});
|
|
442
448
|
return pt.status === "reverted" && _(
|
|
443
449
|
new Error(
|
|
@@ -445,9 +451,9 @@ class xn {
|
|
|
445
451
|
)
|
|
446
452
|
), {
|
|
447
453
|
ethTxHash: pt.transactionHash,
|
|
448
|
-
vaultId:
|
|
449
|
-
peginTxHash:
|
|
450
|
-
btcPopSignature:
|
|
454
|
+
vaultId: w,
|
|
455
|
+
peginTxHash: p,
|
|
456
|
+
btcPopSignature: m
|
|
451
457
|
};
|
|
452
458
|
}
|
|
453
459
|
/**
|
|
@@ -472,31 +478,31 @@ class xn {
|
|
|
472
478
|
);
|
|
473
479
|
r && await r();
|
|
474
480
|
const d = [];
|
|
475
|
-
for (const
|
|
481
|
+
for (const p of s)
|
|
476
482
|
d.push(
|
|
477
|
-
await this.resolvePayoutScriptPubKey(
|
|
483
|
+
await this.resolvePayoutScriptPubKey(p.depositorPayoutBtcAddress)
|
|
478
484
|
);
|
|
479
485
|
const u = [];
|
|
480
|
-
for (const
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
),
|
|
484
|
-
E(
|
|
486
|
+
for (const p of s) {
|
|
487
|
+
const h = H(
|
|
488
|
+
p.depositorSignedPeginTx
|
|
489
|
+
), w = Z(h), T = await wt(
|
|
490
|
+
E(w),
|
|
485
491
|
E(i)
|
|
486
492
|
), k = H(T);
|
|
487
493
|
if (await this.checkVaultExists(k))
|
|
488
494
|
throw new Error(
|
|
489
|
-
`Vault already exists (ID: ${k}, peginTxHash: ${
|
|
495
|
+
`Vault already exists (ID: ${k}, peginTxHash: ${w}). To create a new vault, use different UTXOs or a different amount.`
|
|
490
496
|
);
|
|
491
|
-
u.push({ vaultId: k, peginTxHash:
|
|
497
|
+
u.push({ vaultId: k, peginTxHash: w });
|
|
492
498
|
}
|
|
493
|
-
const
|
|
499
|
+
const l = G({
|
|
494
500
|
chain: this.config.ethChain,
|
|
495
501
|
transport: z()
|
|
496
502
|
});
|
|
497
|
-
let
|
|
503
|
+
let y;
|
|
498
504
|
try {
|
|
499
|
-
|
|
505
|
+
y = await l.readContract({
|
|
500
506
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
501
507
|
abi: $,
|
|
502
508
|
functionName: "getPegInFee",
|
|
@@ -507,54 +513,54 @@ class xn {
|
|
|
507
513
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
508
514
|
);
|
|
509
515
|
}
|
|
510
|
-
const
|
|
511
|
-
depositorBtcPubKey: H(
|
|
516
|
+
const c = y * BigInt(s.length), m = s.map((p, h) => ({
|
|
517
|
+
depositorBtcPubKey: H(p.depositorBtcPubkey),
|
|
512
518
|
btcPopSignature: a,
|
|
513
|
-
unsignedPrePeginTx: H(
|
|
519
|
+
unsignedPrePeginTx: H(p.unsignedPrePeginTx),
|
|
514
520
|
depositorSignedPeginTx: H(
|
|
515
|
-
|
|
521
|
+
p.depositorSignedPeginTx
|
|
516
522
|
),
|
|
517
|
-
hashlock:
|
|
518
|
-
htlcVout:
|
|
519
|
-
referralCode:
|
|
520
|
-
depositorPayoutBtcAddress: d[
|
|
521
|
-
depositorWotsPkHash:
|
|
522
|
-
})),
|
|
523
|
+
hashlock: p.hashlock,
|
|
524
|
+
htlcVout: p.htlcVout,
|
|
525
|
+
referralCode: ke,
|
|
526
|
+
depositorPayoutBtcAddress: d[h],
|
|
527
|
+
depositorWotsPkHash: p.depositorWotsPkHash
|
|
528
|
+
})), g = yt({
|
|
523
529
|
abi: $,
|
|
524
530
|
functionName: "submitPeginRequestBatch",
|
|
525
|
-
args: [i, n,
|
|
531
|
+
args: [i, n, m]
|
|
526
532
|
});
|
|
527
|
-
let
|
|
533
|
+
let b;
|
|
528
534
|
try {
|
|
529
|
-
|
|
535
|
+
b = await l.estimateGas({
|
|
530
536
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
531
|
-
data:
|
|
532
|
-
value:
|
|
537
|
+
data: g,
|
|
538
|
+
value: c,
|
|
533
539
|
account: this.config.ethWallet.account.address
|
|
534
540
|
});
|
|
535
|
-
} catch (
|
|
536
|
-
_(
|
|
541
|
+
} catch (p) {
|
|
542
|
+
_(p);
|
|
537
543
|
}
|
|
538
|
-
let
|
|
544
|
+
let x;
|
|
539
545
|
try {
|
|
540
|
-
|
|
546
|
+
x = await this.config.ethWallet.sendTransaction({
|
|
541
547
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
542
|
-
data:
|
|
543
|
-
value:
|
|
548
|
+
data: g,
|
|
549
|
+
value: c,
|
|
544
550
|
account: this.config.ethWallet.account,
|
|
545
551
|
chain: this.config.ethChain,
|
|
546
|
-
gas:
|
|
552
|
+
gas: b
|
|
547
553
|
});
|
|
548
|
-
} catch (
|
|
549
|
-
_(
|
|
554
|
+
} catch (p) {
|
|
555
|
+
_(p);
|
|
550
556
|
}
|
|
551
|
-
const f = await
|
|
552
|
-
hash:
|
|
553
|
-
timeout:
|
|
557
|
+
const f = await l.waitForTransactionReceipt({
|
|
558
|
+
hash: x,
|
|
559
|
+
timeout: Tt
|
|
554
560
|
});
|
|
555
561
|
return f.status === "reverted" && _(
|
|
556
562
|
new Error(
|
|
557
|
-
`Batch transaction reverted. Hash: ${
|
|
563
|
+
`Batch transaction reverted. Hash: ${x}. Check the transaction on block explorer for details.`
|
|
558
564
|
)
|
|
559
565
|
), {
|
|
560
566
|
ethTxHash: f.transactionHash,
|
|
@@ -578,7 +584,7 @@ class xn {
|
|
|
578
584
|
abi: $,
|
|
579
585
|
functionName: "getBtcVaultBasicInfo",
|
|
580
586
|
args: [t]
|
|
581
|
-
}))[0] !==
|
|
587
|
+
}))[0] !== Yt;
|
|
582
588
|
} catch {
|
|
583
589
|
return !1;
|
|
584
590
|
}
|
|
@@ -597,7 +603,7 @@ class xn {
|
|
|
597
603
|
else {
|
|
598
604
|
n = await this.config.btcWallet.getAddress();
|
|
599
605
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
600
|
-
if (!
|
|
606
|
+
if (!re(
|
|
601
607
|
n,
|
|
602
608
|
o,
|
|
603
609
|
this.config.btcNetwork
|
|
@@ -608,7 +614,7 @@ class xn {
|
|
|
608
614
|
}
|
|
609
615
|
const s = bt(this.config.btcNetwork);
|
|
610
616
|
try {
|
|
611
|
-
return `0x${
|
|
617
|
+
return `0x${Zt.address.toOutputScript(n, s).toString("hex")}`;
|
|
612
618
|
} catch {
|
|
613
619
|
throw new Error(
|
|
614
620
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -647,15 +653,15 @@ class xn {
|
|
|
647
653
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
648
654
|
}
|
|
649
655
|
}
|
|
650
|
-
class
|
|
656
|
+
class $t {
|
|
651
657
|
constructor(t, n) {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
if (
|
|
658
|
+
P(this, "oHash");
|
|
659
|
+
P(this, "iHash");
|
|
660
|
+
P(this, "blockLen");
|
|
661
|
+
P(this, "outputLen");
|
|
662
|
+
P(this, "finished", !1);
|
|
663
|
+
P(this, "destroyed", !1);
|
|
664
|
+
if (Bt(t), K(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
659
665
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
660
666
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
661
667
|
const s = this.blockLen, o = new Uint8Array(s);
|
|
@@ -689,9 +695,9 @@ class At {
|
|
|
689
695
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
690
696
|
}
|
|
691
697
|
}
|
|
692
|
-
const N = (e, t, n) => new
|
|
693
|
-
N.create = (e, t) => new
|
|
694
|
-
const
|
|
698
|
+
const N = (e, t, n) => new $t(e, t).update(n).digest();
|
|
699
|
+
N.create = (e, t) => new $t(e, t);
|
|
700
|
+
const Ie = /* @__PURE__ */ Uint8Array.from([
|
|
695
701
|
7,
|
|
696
702
|
4,
|
|
697
703
|
13,
|
|
@@ -708,43 +714,43 @@ const Te = /* @__PURE__ */ Uint8Array.from([
|
|
|
708
714
|
14,
|
|
709
715
|
11,
|
|
710
716
|
8
|
|
711
|
-
]),
|
|
712
|
-
const n = [[
|
|
717
|
+
]), Ot = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), ve = Ot.map((e) => (9 * e + 5) % 16), Rt = /* @__PURE__ */ (() => {
|
|
718
|
+
const n = [[Ot], [ve]];
|
|
713
719
|
for (let s = 0; s < 4; s++)
|
|
714
720
|
for (let o of n)
|
|
715
|
-
o.push(o[s].map((r) =>
|
|
721
|
+
o.push(o[s].map((r) => Ie[r]));
|
|
716
722
|
return n;
|
|
717
|
-
})(),
|
|
723
|
+
})(), Lt = Rt[0], Ut = Rt[1], Wt = /* @__PURE__ */ [
|
|
718
724
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
719
725
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
720
726
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
721
727
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
722
728
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
723
|
-
].map((e) => Uint8Array.from(e)),
|
|
729
|
+
].map((e) => Uint8Array.from(e)), Ee = /* @__PURE__ */ Lt.map((e, t) => e.map((n) => Wt[t][n])), He = /* @__PURE__ */ Ut.map((e, t) => e.map((n) => Wt[t][n])), _e = /* @__PURE__ */ Uint32Array.from([
|
|
724
730
|
0,
|
|
725
731
|
1518500249,
|
|
726
732
|
1859775393,
|
|
727
733
|
2400959708,
|
|
728
734
|
2840853838
|
|
729
|
-
]),
|
|
735
|
+
]), Se = /* @__PURE__ */ Uint32Array.from([
|
|
730
736
|
1352829926,
|
|
731
737
|
1548603684,
|
|
732
738
|
1836072691,
|
|
733
739
|
2053994217,
|
|
734
740
|
0
|
|
735
741
|
]);
|
|
736
|
-
function
|
|
742
|
+
function It(e, t, n, s) {
|
|
737
743
|
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);
|
|
738
744
|
}
|
|
739
745
|
const W = /* @__PURE__ */ new Uint32Array(16);
|
|
740
|
-
class
|
|
746
|
+
class Be extends fe {
|
|
741
747
|
constructor() {
|
|
742
748
|
super(64, 20, 8, !0);
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
749
|
+
P(this, "h0", 1732584193);
|
|
750
|
+
P(this, "h1", -271733879);
|
|
751
|
+
P(this, "h2", -1732584194);
|
|
752
|
+
P(this, "h3", 271733878);
|
|
753
|
+
P(this, "h4", -1009589776);
|
|
748
754
|
}
|
|
749
755
|
get() {
|
|
750
756
|
const { h0: n, h1: s, h2: o, h3: r, h4: i } = this;
|
|
@@ -754,21 +760,21 @@ class Se extends ue {
|
|
|
754
760
|
this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
755
761
|
}
|
|
756
762
|
process(n, s) {
|
|
757
|
-
for (let
|
|
758
|
-
W[
|
|
759
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, d = this.h2 | 0, u = d,
|
|
760
|
-
for (let
|
|
761
|
-
const
|
|
763
|
+
for (let g = 0; g < 16; g++, s += 4)
|
|
764
|
+
W[g] = n.getUint32(s, !0);
|
|
765
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, d = this.h2 | 0, u = d, l = this.h3 | 0, y = l, c = this.h4 | 0, m = c;
|
|
766
|
+
for (let g = 0; g < 5; g++) {
|
|
767
|
+
const b = 4 - g, x = _e[g], f = Se[g], p = Lt[g], h = Ut[g], w = Ee[g], T = He[g];
|
|
762
768
|
for (let k = 0; k < 16; k++) {
|
|
763
|
-
const
|
|
764
|
-
o =
|
|
769
|
+
const I = U(o + It(g, i, d, l) + W[p[k]] + x, w[k]) + c | 0;
|
|
770
|
+
o = c, c = l, l = U(d, 10) | 0, d = i, i = I;
|
|
765
771
|
}
|
|
766
772
|
for (let k = 0; k < 16; k++) {
|
|
767
|
-
const
|
|
768
|
-
r =
|
|
773
|
+
const I = U(r + It(b, a, u, y) + W[h[k]] + f, T[k]) + m | 0;
|
|
774
|
+
r = m, m = y, y = U(u, 10) | 0, u = a, a = I;
|
|
769
775
|
}
|
|
770
776
|
}
|
|
771
|
-
this.set(this.h1 + d +
|
|
777
|
+
this.set(this.h1 + d + y | 0, this.h2 + l + m | 0, this.h3 + c + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
|
|
772
778
|
}
|
|
773
779
|
roundClean() {
|
|
774
780
|
S(W);
|
|
@@ -777,29 +783,29 @@ class Se extends ue {
|
|
|
777
783
|
this.destroyed = !0, S(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
778
784
|
}
|
|
779
785
|
}
|
|
780
|
-
const
|
|
786
|
+
const Ft = /* @__PURE__ */ Ct(() => new Be()), Ce = BigInt(0), O = BigInt(1), Ae = BigInt(2), $e = BigInt(7), Oe = BigInt(256), Re = BigInt(113), Vt = [], Dt = [], Kt = [];
|
|
781
787
|
for (let e = 0, t = O, n = 1, s = 0; e < 24; e++) {
|
|
782
|
-
[n, s] = [s, (2 * n + 3 * s) % 5], Vt.push(2 * (5 * s + n)),
|
|
783
|
-
let o =
|
|
788
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], Vt.push(2 * (5 * s + n)), Dt.push((e + 1) * (e + 2) / 2 % 64);
|
|
789
|
+
let o = Ce;
|
|
784
790
|
for (let r = 0; r < 7; r++)
|
|
785
|
-
t = (t << O ^ (t >>
|
|
786
|
-
|
|
791
|
+
t = (t << O ^ (t >> $e) * Re) % Oe, t & Ae && (o ^= O << (O << BigInt(r)) - O);
|
|
792
|
+
Kt.push(o);
|
|
787
793
|
}
|
|
788
|
-
const
|
|
789
|
-
function
|
|
794
|
+
const Mt = de(Kt, !0), Le = Mt[0], Ue = Mt[1], vt = (e, t, n) => n > 32 ? we(e, t, n) : me(e, t, n), Et = (e, t, n) => n > 32 ? be(e, t, n) : ye(e, t, n);
|
|
795
|
+
function We(e, t = 24) {
|
|
790
796
|
const n = new Uint32Array(10);
|
|
791
797
|
for (let s = 24 - t; s < 24; s++) {
|
|
792
798
|
for (let i = 0; i < 10; i++)
|
|
793
799
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
794
800
|
for (let i = 0; i < 10; i += 2) {
|
|
795
|
-
const a = (i + 8) % 10, d = (i + 2) % 10, u = n[d],
|
|
796
|
-
for (let
|
|
797
|
-
e[i +
|
|
801
|
+
const a = (i + 8) % 10, d = (i + 2) % 10, u = n[d], l = n[d + 1], y = vt(u, l, 1) ^ n[a], c = Et(u, l, 1) ^ n[a + 1];
|
|
802
|
+
for (let m = 0; m < 50; m += 10)
|
|
803
|
+
e[i + m] ^= y, e[i + m + 1] ^= c;
|
|
798
804
|
}
|
|
799
805
|
let o = e[2], r = e[3];
|
|
800
806
|
for (let i = 0; i < 24; i++) {
|
|
801
|
-
const a =
|
|
802
|
-
o = e[
|
|
807
|
+
const a = Dt[i], d = vt(o, r, a), u = Et(o, r, a), l = Vt[i];
|
|
808
|
+
o = e[l], r = e[l + 1], e[l] = d, e[l + 1] = u;
|
|
803
809
|
}
|
|
804
810
|
for (let i = 0; i < 50; i += 10) {
|
|
805
811
|
for (let a = 0; a < 10; a++)
|
|
@@ -807,33 +813,33 @@ function Ue(e, t = 24) {
|
|
|
807
813
|
for (let a = 0; a < 10; a++)
|
|
808
814
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
809
815
|
}
|
|
810
|
-
e[0] ^=
|
|
816
|
+
e[0] ^= Le[s], e[1] ^= Ue[s];
|
|
811
817
|
}
|
|
812
818
|
S(n);
|
|
813
819
|
}
|
|
814
820
|
class dt {
|
|
815
821
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
816
822
|
constructor(t, n, s, o = !1, r = 24) {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
823
|
+
P(this, "state");
|
|
824
|
+
P(this, "pos", 0);
|
|
825
|
+
P(this, "posOut", 0);
|
|
826
|
+
P(this, "finished", !1);
|
|
827
|
+
P(this, "state32");
|
|
828
|
+
P(this, "destroyed", !1);
|
|
829
|
+
P(this, "blockLen");
|
|
830
|
+
P(this, "suffix");
|
|
831
|
+
P(this, "outputLen");
|
|
832
|
+
P(this, "enableXOF", !1);
|
|
833
|
+
P(this, "rounds");
|
|
828
834
|
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, L(s, "outputLen"), !(0 < t && t < 200))
|
|
829
835
|
throw new Error("only keccak-f1600 function is supported");
|
|
830
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
836
|
+
this.state = new Uint8Array(200), this.state32 = ge(this.state);
|
|
831
837
|
}
|
|
832
838
|
clone() {
|
|
833
839
|
return this._cloneInto();
|
|
834
840
|
}
|
|
835
841
|
keccak() {
|
|
836
|
-
|
|
842
|
+
Pt(this.state32), We(this.state32, this.rounds), Pt(this.state32), this.posOut = 0, this.pos = 0;
|
|
837
843
|
}
|
|
838
844
|
update(t) {
|
|
839
845
|
M(this), K(t);
|
|
@@ -872,7 +878,7 @@ class dt {
|
|
|
872
878
|
return L(t), this.xofInto(new Uint8Array(t));
|
|
873
879
|
}
|
|
874
880
|
digestInto(t) {
|
|
875
|
-
if (
|
|
881
|
+
if (pe(t, this), this.finished)
|
|
876
882
|
throw new Error("digest() was already called");
|
|
877
883
|
return this.writeInto(t), this.destroy(), t;
|
|
878
884
|
}
|
|
@@ -887,49 +893,49 @@ class dt {
|
|
|
887
893
|
return t || (t = new dt(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;
|
|
888
894
|
}
|
|
889
895
|
}
|
|
890
|
-
const
|
|
896
|
+
const Fe = (e, t, n, s = {}) => Ct(() => new dt(t, e, n), s), Nt = /* @__PURE__ */ Fe(1, 136, 32);
|
|
891
897
|
function Ve(e, t, n, s) {
|
|
892
|
-
|
|
893
|
-
const o =
|
|
898
|
+
Bt(e);
|
|
899
|
+
const o = Pe({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
|
|
894
900
|
if (L(r, "c"), L(i, "dkLen"), L(a, "asyncTick"), r < 1)
|
|
895
901
|
throw new Error("iterations (c) must be >= 1");
|
|
896
|
-
const d =
|
|
897
|
-
return { c: r, dkLen: i, asyncTick: a, DK:
|
|
902
|
+
const d = kt(t, "password"), u = kt(n, "salt"), l = new Uint8Array(i), y = N.create(e, d), c = y._cloneInto().update(u);
|
|
903
|
+
return { c: r, dkLen: i, asyncTick: a, DK: l, PRF: y, PRFSalt: c };
|
|
898
904
|
}
|
|
899
|
-
function
|
|
905
|
+
function De(e, t, n, s, o) {
|
|
900
906
|
return e.destroy(), t.destroy(), s && s.destroy(), S(o), n;
|
|
901
907
|
}
|
|
902
|
-
function
|
|
908
|
+
function Ke(e, t, n, s) {
|
|
903
909
|
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: d } = Ve(e, t, n, s);
|
|
904
910
|
let u;
|
|
905
|
-
const
|
|
906
|
-
for (let
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
for (let
|
|
910
|
-
a._cloneInto(u).update(
|
|
911
|
-
for (let f = 0; f <
|
|
912
|
-
|
|
911
|
+
const l = new Uint8Array(4), y = xe(l), c = new Uint8Array(a.outputLen);
|
|
912
|
+
for (let m = 1, g = 0; g < r; m++, g += a.outputLen) {
|
|
913
|
+
const b = i.subarray(g, g + a.outputLen);
|
|
914
|
+
y.setInt32(0, m, !1), (u = d._cloneInto(u)).update(l).digestInto(c), b.set(c.subarray(0, b.length));
|
|
915
|
+
for (let x = 1; x < o; x++) {
|
|
916
|
+
a._cloneInto(u).update(c).digestInto(c);
|
|
917
|
+
for (let f = 0; f < b.length; f++)
|
|
918
|
+
b[f] ^= c[f];
|
|
913
919
|
}
|
|
914
920
|
}
|
|
915
|
-
return
|
|
921
|
+
return De(a, d, i, u, c);
|
|
916
922
|
}
|
|
917
|
-
function
|
|
923
|
+
function Xt(e) {
|
|
918
924
|
if (typeof e != "string")
|
|
919
925
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
920
926
|
return e.normalize("NFKD");
|
|
921
927
|
}
|
|
922
|
-
function
|
|
923
|
-
const t =
|
|
928
|
+
function Me(e) {
|
|
929
|
+
const t = Xt(e), n = t.split(" ");
|
|
924
930
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
925
931
|
throw new Error("Invalid mnemonic");
|
|
926
932
|
return { nfkd: t, words: n };
|
|
927
933
|
}
|
|
928
|
-
const
|
|
929
|
-
function
|
|
930
|
-
return
|
|
934
|
+
const Ne = (e) => Xt("mnemonic" + e);
|
|
935
|
+
function Xe(e, t = "") {
|
|
936
|
+
return Ke(ut, Me(e).nfkd, Ne(t), { c: 2048, dkLen: 64 });
|
|
931
937
|
}
|
|
932
|
-
const
|
|
938
|
+
const je = 508, Ht = 16, F = 32, V = 64, _t = 5, qe = 4;
|
|
933
939
|
function R(...e) {
|
|
934
940
|
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
935
941
|
let s = 0;
|
|
@@ -941,27 +947,27 @@ function J(e) {
|
|
|
941
947
|
return new TextEncoder().encode(e);
|
|
942
948
|
}
|
|
943
949
|
function Y(e) {
|
|
944
|
-
const t = new Uint8Array(
|
|
950
|
+
const t = new Uint8Array(qe);
|
|
945
951
|
return new DataView(t.buffer).setUint32(0, e.length, !1), R(t, e);
|
|
946
952
|
}
|
|
947
953
|
function Q(e, t) {
|
|
948
954
|
return N(ut, e, t);
|
|
949
955
|
}
|
|
950
|
-
function
|
|
951
|
-
return
|
|
956
|
+
function St(e) {
|
|
957
|
+
return Ft(At(e));
|
|
952
958
|
}
|
|
953
959
|
const ct = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
954
|
-
function
|
|
955
|
-
const t =
|
|
960
|
+
function Ge(e) {
|
|
961
|
+
const t = Xe(e), n = new Uint8Array(t);
|
|
956
962
|
return t.fill(0), n;
|
|
957
963
|
}
|
|
958
|
-
async function
|
|
959
|
-
if (e.length !==
|
|
964
|
+
async function ze(e, t, n, s) {
|
|
965
|
+
if (e.length !== V)
|
|
960
966
|
throw new Error(
|
|
961
|
-
`WOTS seed must be ${
|
|
967
|
+
`WOTS seed must be ${V} bytes, got ${e.length}`
|
|
962
968
|
);
|
|
963
969
|
t = E(t), n = E(n);
|
|
964
|
-
const o = e.slice(
|
|
970
|
+
const o = e.slice(F, V), r = e.slice(0, F), i = [o, r];
|
|
965
971
|
try {
|
|
966
972
|
const a = R(
|
|
967
973
|
Y(J(t)),
|
|
@@ -971,29 +977,29 @@ async function Ge(e, t, n, s) {
|
|
|
971
977
|
i.push(d);
|
|
972
978
|
const u = Q(o, d);
|
|
973
979
|
i.push(u);
|
|
974
|
-
const
|
|
975
|
-
i.push(
|
|
976
|
-
const
|
|
977
|
-
let
|
|
980
|
+
const l = u.slice(0, F), y = u.slice(F, V);
|
|
981
|
+
i.push(l, y);
|
|
982
|
+
const c = [], m = [], g = [], b = [];
|
|
983
|
+
let x = !1;
|
|
978
984
|
try {
|
|
979
|
-
for (let f = 0; f <
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
const
|
|
983
|
-
|
|
984
|
-
const
|
|
985
|
+
for (let f = 0; f < je; f++) {
|
|
986
|
+
const p = new Uint8Array(_t);
|
|
987
|
+
p[0] = 0, new DataView(p.buffer).setUint32(1, f, !1);
|
|
988
|
+
const h = new Uint8Array(_t);
|
|
989
|
+
h[0] = 1, new DataView(h.buffer).setUint32(1, f, !1);
|
|
990
|
+
const w = R(l, p), T = R(l, h), k = Q(y, w), I = Q(y, T);
|
|
985
991
|
try {
|
|
986
|
-
const C = k.slice(0,
|
|
987
|
-
|
|
992
|
+
const C = k.slice(0, Ht), A = I.slice(0, Ht);
|
|
993
|
+
c.push(C), m.push(A), g.push(St(C)), b.push(St(A));
|
|
988
994
|
} finally {
|
|
989
|
-
|
|
995
|
+
w.fill(0), T.fill(0), k.fill(0), I.fill(0);
|
|
990
996
|
}
|
|
991
997
|
}
|
|
992
|
-
return
|
|
998
|
+
return x = !0, { falsePreimages: c, truePreimages: m, falseHashes: g, trueHashes: b };
|
|
993
999
|
} finally {
|
|
994
|
-
if (!
|
|
995
|
-
for (const f of
|
|
996
|
-
for (const f of
|
|
1000
|
+
if (!x) {
|
|
1001
|
+
for (const f of c) f.fill(0);
|
|
1002
|
+
for (const f of m) f.fill(0);
|
|
997
1003
|
}
|
|
998
1004
|
}
|
|
999
1005
|
} finally {
|
|
@@ -1001,13 +1007,13 @@ async function Ge(e, t, n, s) {
|
|
|
1001
1007
|
a.fill(0);
|
|
1002
1008
|
}
|
|
1003
1009
|
}
|
|
1004
|
-
function
|
|
1010
|
+
function Tn(e) {
|
|
1005
1011
|
return {
|
|
1006
1012
|
false_list: e.falseHashes.map(ct),
|
|
1007
1013
|
true_list: e.trueHashes.map(ct)
|
|
1008
1014
|
};
|
|
1009
1015
|
}
|
|
1010
|
-
function
|
|
1016
|
+
function Ze(e) {
|
|
1011
1017
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
1012
1018
|
throw new Error(
|
|
1013
1019
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
@@ -1018,10 +1024,10 @@ function ze(e) {
|
|
|
1018
1024
|
s.set(i, o), o += t;
|
|
1019
1025
|
for (const i of e.trueHashes)
|
|
1020
1026
|
s.set(i, o), o += t;
|
|
1021
|
-
const r =
|
|
1027
|
+
const r = Nt(s);
|
|
1022
1028
|
return `0x${ct(r)}`;
|
|
1023
1029
|
}
|
|
1024
|
-
const tt = 32, et = 64,
|
|
1030
|
+
const tt = 32, et = 64, Je = 4, v = 20, lt = 4, jt = 2, Ye = 0, Qe = 1, D = [64, 64];
|
|
1025
1031
|
function ht(...e) {
|
|
1026
1032
|
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
1027
1033
|
let s = 0;
|
|
@@ -1033,30 +1039,30 @@ function nt(e) {
|
|
|
1033
1039
|
return new TextEncoder().encode(e);
|
|
1034
1040
|
}
|
|
1035
1041
|
function st(e) {
|
|
1036
|
-
const t = new Uint8Array(
|
|
1042
|
+
const t = new Uint8Array(Je);
|
|
1037
1043
|
return new DataView(t.buffer).setUint32(0, e.length, !1), ht(t, e);
|
|
1038
1044
|
}
|
|
1039
1045
|
function ot(e) {
|
|
1040
1046
|
return e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
|
|
1041
1047
|
}
|
|
1042
|
-
const
|
|
1043
|
-
function
|
|
1048
|
+
const tn = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
1049
|
+
function en(e, t) {
|
|
1044
1050
|
return N(ut, e, t);
|
|
1045
1051
|
}
|
|
1046
1052
|
function gt(e) {
|
|
1047
|
-
return
|
|
1053
|
+
return Ft(At(e));
|
|
1048
1054
|
}
|
|
1049
|
-
function
|
|
1055
|
+
function qt(e) {
|
|
1050
1056
|
return (1 << e) - 1;
|
|
1051
1057
|
}
|
|
1052
|
-
function
|
|
1058
|
+
function nn(e) {
|
|
1053
1059
|
let t = 1;
|
|
1054
1060
|
for (; t * t < e + 1; ) t++;
|
|
1055
1061
|
return Math.max(t, 2);
|
|
1056
1062
|
}
|
|
1057
|
-
function
|
|
1058
|
-
const t = lt, n =
|
|
1059
|
-
return { d: t, n: e, checksum_radix:
|
|
1063
|
+
function sn(e) {
|
|
1064
|
+
const t = lt, n = qt(t), s = e * n;
|
|
1065
|
+
return { d: t, n: e, checksum_radix: nn(s) };
|
|
1060
1066
|
}
|
|
1061
1067
|
function rt(e, t) {
|
|
1062
1068
|
const n = [];
|
|
@@ -1075,21 +1081,21 @@ function it(e, t) {
|
|
|
1075
1081
|
n = gt(n);
|
|
1076
1082
|
return n;
|
|
1077
1083
|
}
|
|
1078
|
-
function
|
|
1079
|
-
const n =
|
|
1080
|
-
for (let
|
|
1081
|
-
const
|
|
1082
|
-
r.push(Array.from(
|
|
1084
|
+
function on(e, t) {
|
|
1085
|
+
const n = qt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
|
|
1086
|
+
for (let l = 0; l < t.n; l++) {
|
|
1087
|
+
const y = rt(e, l + jt), c = it(y, n);
|
|
1088
|
+
r.push(Array.from(c));
|
|
1083
1089
|
}
|
|
1084
1090
|
const i = rt(
|
|
1085
1091
|
e,
|
|
1086
|
-
|
|
1092
|
+
Ye
|
|
1087
1093
|
), a = it(
|
|
1088
1094
|
i,
|
|
1089
1095
|
s
|
|
1090
1096
|
), d = rt(
|
|
1091
1097
|
e,
|
|
1092
|
-
|
|
1098
|
+
Qe
|
|
1093
1099
|
), u = it(
|
|
1094
1100
|
d,
|
|
1095
1101
|
o
|
|
@@ -1101,7 +1107,7 @@ function sn(e, t) {
|
|
|
1101
1107
|
checksum_minor_terminal: Array.from(a)
|
|
1102
1108
|
};
|
|
1103
1109
|
}
|
|
1104
|
-
async function
|
|
1110
|
+
async function In(e, t, n, s) {
|
|
1105
1111
|
if (e.length !== et)
|
|
1106
1112
|
throw new Error(
|
|
1107
1113
|
`WOTS seed must be exactly ${et} bytes, got ${e.length}`
|
|
@@ -1113,46 +1119,46 @@ async function kn(e, t, n, s) {
|
|
|
1113
1119
|
st(nt(r)),
|
|
1114
1120
|
st(nt(ot(s)))
|
|
1115
1121
|
)
|
|
1116
|
-
), u =
|
|
1122
|
+
), u = en(i, d), l = u.slice(0, tt);
|
|
1117
1123
|
try {
|
|
1118
|
-
const
|
|
1119
|
-
for (let
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1122
|
-
const
|
|
1124
|
+
const y = [];
|
|
1125
|
+
for (let c = 0; c < D.length; c++) {
|
|
1126
|
+
const m = D[c], g = sn(m), b = new Uint8Array(l.length + 1);
|
|
1127
|
+
b.set(l), b[l.length] = c;
|
|
1128
|
+
const x = gt(b);
|
|
1123
1129
|
try {
|
|
1124
|
-
const f =
|
|
1130
|
+
const f = on(x, g);
|
|
1125
1131
|
if (f.config.d !== lt)
|
|
1126
|
-
throw new Error(`Block ${
|
|
1127
|
-
if (f.config.n !==
|
|
1128
|
-
throw new Error(`Block ${
|
|
1129
|
-
if (f.message_terminals.length !==
|
|
1130
|
-
throw new Error(`Block ${
|
|
1131
|
-
for (let
|
|
1132
|
-
if (f.message_terminals[
|
|
1133
|
-
throw new Error(`Block ${
|
|
1134
|
-
if (f.checksum_minor_terminal.length !==
|
|
1135
|
-
throw new Error(`Block ${
|
|
1136
|
-
if (f.checksum_major_terminal.length !==
|
|
1137
|
-
throw new Error(`Block ${
|
|
1138
|
-
|
|
1132
|
+
throw new Error(`Block ${c}: expected d=${lt}, got d=${f.config.d}`);
|
|
1133
|
+
if (f.config.n !== m)
|
|
1134
|
+
throw new Error(`Block ${c}: expected n=${m}, got n=${f.config.n}`);
|
|
1135
|
+
if (f.message_terminals.length !== m)
|
|
1136
|
+
throw new Error(`Block ${c}: expected ${m} message terminals, got ${f.message_terminals.length}`);
|
|
1137
|
+
for (let p = 0; p < f.message_terminals.length; p++)
|
|
1138
|
+
if (f.message_terminals[p].length !== v)
|
|
1139
|
+
throw new Error(`Block ${c} terminal ${p}: expected ${v} bytes, got ${f.message_terminals[p].length}`);
|
|
1140
|
+
if (f.checksum_minor_terminal.length !== v)
|
|
1141
|
+
throw new Error(`Block ${c} checksum_minor: expected ${v} bytes`);
|
|
1142
|
+
if (f.checksum_major_terminal.length !== v)
|
|
1143
|
+
throw new Error(`Block ${c} checksum_major: expected ${v} bytes`);
|
|
1144
|
+
y.push(f);
|
|
1139
1145
|
} finally {
|
|
1140
|
-
|
|
1146
|
+
b.fill(0), x.fill(0);
|
|
1141
1147
|
}
|
|
1142
1148
|
}
|
|
1143
|
-
if (
|
|
1149
|
+
if (y.length !== D.length)
|
|
1144
1150
|
throw new Error(
|
|
1145
|
-
`Expected ${D.length} blocks, got ${
|
|
1151
|
+
`Expected ${D.length} blocks, got ${y.length}`
|
|
1146
1152
|
);
|
|
1147
|
-
return
|
|
1153
|
+
return y;
|
|
1148
1154
|
} finally {
|
|
1149
|
-
d.fill(0), i.fill(0), a.fill(0), u.fill(0),
|
|
1155
|
+
d.fill(0), i.fill(0), a.fill(0), u.fill(0), l.fill(0), e.fill(0);
|
|
1150
1156
|
}
|
|
1151
1157
|
}
|
|
1152
1158
|
function at(e, t, n) {
|
|
1153
|
-
if (e.length !==
|
|
1159
|
+
if (e.length !== v)
|
|
1154
1160
|
throw new Error(
|
|
1155
|
-
`Block ${t} ${n}: expected ${
|
|
1161
|
+
`Block ${t} ${n}: expected ${v} bytes, got ${e.length}`
|
|
1156
1162
|
);
|
|
1157
1163
|
for (let s = 0; s < e.length; s++) {
|
|
1158
1164
|
const o = e[s];
|
|
@@ -1162,7 +1168,7 @@ function at(e, t, n) {
|
|
|
1162
1168
|
);
|
|
1163
1169
|
}
|
|
1164
1170
|
}
|
|
1165
|
-
function
|
|
1171
|
+
function vn(e) {
|
|
1166
1172
|
if (e.length === 0)
|
|
1167
1173
|
throw new Error("Public keys array must not be empty");
|
|
1168
1174
|
for (let r = 0; r < e.length; r++) {
|
|
@@ -1173,28 +1179,28 @@ function Tn(e) {
|
|
|
1173
1179
|
}
|
|
1174
1180
|
let t = 0;
|
|
1175
1181
|
for (const r of e)
|
|
1176
|
-
t +=
|
|
1177
|
-
const n = new Uint8Array(t *
|
|
1182
|
+
t += jt + r.message_terminals.length;
|
|
1183
|
+
const n = new Uint8Array(t * v);
|
|
1178
1184
|
let s = 0;
|
|
1179
1185
|
for (const r of e) {
|
|
1180
|
-
n.set(r.checksum_minor_terminal, s), s +=
|
|
1186
|
+
n.set(r.checksum_minor_terminal, s), s += v, n.set(r.checksum_major_terminal, s), s += v;
|
|
1181
1187
|
for (const i of r.message_terminals)
|
|
1182
|
-
n.set(i, s), s +=
|
|
1188
|
+
n.set(i, s), s += v;
|
|
1183
1189
|
}
|
|
1184
|
-
const o =
|
|
1185
|
-
return `0x${
|
|
1190
|
+
const o = Nt(n);
|
|
1191
|
+
return `0x${tn(o)}`;
|
|
1186
1192
|
}
|
|
1187
|
-
async function
|
|
1188
|
-
const o =
|
|
1193
|
+
async function En(e, t, n, s) {
|
|
1194
|
+
const o = Ge(e);
|
|
1189
1195
|
try {
|
|
1190
|
-
const r = await
|
|
1196
|
+
const r = await ze(
|
|
1191
1197
|
o,
|
|
1192
1198
|
t,
|
|
1193
1199
|
n,
|
|
1194
1200
|
s
|
|
1195
1201
|
);
|
|
1196
1202
|
try {
|
|
1197
|
-
return
|
|
1203
|
+
return Ze(r);
|
|
1198
1204
|
} finally {
|
|
1199
1205
|
for (const i of r.falsePreimages) i.fill(0);
|
|
1200
1206
|
for (const i of r.truePreimages) i.fill(0);
|
|
@@ -1203,24 +1209,24 @@ async function In(e, t, n, s) {
|
|
|
1203
1209
|
o.fill(0);
|
|
1204
1210
|
}
|
|
1205
1211
|
}
|
|
1206
|
-
function
|
|
1212
|
+
function Hn(e) {
|
|
1207
1213
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
1208
1214
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
1209
1215
|
}
|
|
1210
1216
|
export {
|
|
1211
1217
|
B as C,
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1218
|
+
kn as P,
|
|
1219
|
+
In as a,
|
|
1220
|
+
vn as b,
|
|
1221
|
+
Ze as c,
|
|
1222
|
+
ze as d,
|
|
1217
1223
|
ft as e,
|
|
1218
|
-
|
|
1219
|
-
|
|
1224
|
+
En as f,
|
|
1225
|
+
xn as g,
|
|
1220
1226
|
_ as h,
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1227
|
+
Pn as i,
|
|
1228
|
+
Hn as j,
|
|
1229
|
+
Tn as k,
|
|
1230
|
+
Ge as m
|
|
1225
1231
|
};
|
|
1226
|
-
//# sourceMappingURL=errors-
|
|
1232
|
+
//# sourceMappingURL=errors-DvIudLXV.js.map
|