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