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