@babylonlabs-io/ts-sdk 0.68.0 → 0.68.1
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/{PeginManager--2R3T2S8.js → PeginManager-Bsv6caG3.js} +371 -363
- package/dist/PeginManager-Bsv6caG3.js.map +1 -0
- package/dist/PeginManager-C5NWzGT7.cjs +2 -0
- package/dist/PeginManager-C5NWzGT7.cjs.map +1 -0
- package/dist/{batchPoll-Cjj1du0i.js → batchPoll-Bc_UKaTz.js} +2 -2
- package/dist/{batchPoll-Cjj1du0i.js.map → batchPoll-Bc_UKaTz.js.map} +1 -1
- package/dist/{batchPoll-REVZiE-M.cjs → batchPoll-C9cZ5usJ.cjs} +2 -2
- package/dist/{batchPoll-REVZiE-M.cjs.map → batchPoll-C9cZ5usJ.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -5
- package/dist/{mempoolApi-_D-jvtj_.js → mempoolApi-71R_CNZa.js} +71 -69
- package/dist/mempoolApi-71R_CNZa.js.map +1 -0
- package/dist/mempoolApi-BJN9fGEd.cjs +2 -0
- package/dist/mempoolApi-BJN9fGEd.cjs.map +1 -0
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts +9 -0
- package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +5 -5
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/managers/pegin/verifyPopWitness.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +1 -1
- package/dist/tbv/core/primitives/psbt/verifyKeyPathSchnorrSignature.d.ts +6 -5
- package/dist/tbv/core/primitives/psbt/verifyKeyPathSchnorrSignature.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +5 -5
- package/dist/testing/MockBitcoinWallet.d.ts +1 -1
- package/dist/testing/MockBitcoinWallet.d.ts.map +1 -1
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js +66 -62
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/signBip322P2wpkhWitness.d.ts +5 -0
- package/dist/testing/signBip322P2wpkhWitness.d.ts.map +1 -1
- package/dist/{toRefundInputs-9hv_6k0E.js → toRefundInputs-4UJfSVEz.js} +2 -2
- package/dist/{toRefundInputs-9hv_6k0E.js.map → toRefundInputs-4UJfSVEz.js.map} +1 -1
- package/dist/{toRefundInputs-D8sFs44p.cjs → toRefundInputs-DgDhx_Ut.cjs} +2 -2
- package/dist/{toRefundInputs-D8sFs44p.cjs.map → toRefundInputs-DgDhx_Ut.cjs.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-oGCUbjjZ.js → verifyKeyPathSchnorrSignature-C6Cmk0R1.js} +137 -128
- package/dist/verifyKeyPathSchnorrSignature-C6Cmk0R1.js.map +1 -0
- package/dist/verifyKeyPathSchnorrSignature-Cr5T4Aym.cjs +2 -0
- package/dist/verifyKeyPathSchnorrSignature-Cr5T4Aym.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/PeginManager--2R3T2S8.js.map +0 -1
- package/dist/PeginManager-CKWq8ouZ.cjs +0 -2
- package/dist/PeginManager-CKWq8ouZ.cjs.map +0 -1
- package/dist/mempoolApi-EU1La9wk.cjs +0 -2
- package/dist/mempoolApi-EU1La9wk.cjs.map +0 -1
- package/dist/mempoolApi-_D-jvtj_.js.map +0 -1
- package/dist/verifyKeyPathSchnorrSignature-DCOzQkDf.cjs +0 -2
- package/dist/verifyKeyPathSchnorrSignature-DCOzQkDf.cjs.map +0 -1
- package/dist/verifyKeyPathSchnorrSignature-oGCUbjjZ.js.map +0 -1
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { c as
|
|
1
|
+
var Gt = Object.defineProperty;
|
|
2
|
+
var qt = (s, t, e) => t in s ? Gt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var x = (s, t, e) => qt(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { c as _t, H as Yt, r as W, a as K, b as at, u as zt, d as ct, e as lt, f as ut, g as jt, s as Bt } from "./sha2-BYVxyZzX.js";
|
|
5
5
|
import * as At from "bitcoinjs-lib";
|
|
6
|
-
import { Transaction as Ct, Psbt as
|
|
6
|
+
import { Transaction as Ct, Psbt as ht } from "bitcoinjs-lib";
|
|
7
7
|
import { Buffer as O } from "buffer";
|
|
8
|
-
import { isAddressEqual as
|
|
8
|
+
import { isAddressEqual as dt, encodeFunctionData as tt, zeroAddress as Qt } from "viem";
|
|
9
9
|
import { B as H } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
|
|
10
10
|
import { h as R } from "./errors-Blc-JWnI.js";
|
|
11
|
-
import { expandWotsSeed as Zt, expandHashlockSecret as Jt, expandAuthAnchor as te, deriveVaultId as
|
|
12
|
-
import { a as
|
|
13
|
-
import { d as oe, b as ne, e as re, f as ie, c as ae } from "./verifyKeyPathSchnorrSignature-
|
|
14
|
-
import { p as ce, h as
|
|
11
|
+
import { expandWotsSeed as Zt, expandHashlockSecret as Jt, expandAuthAnchor as te, deriveVaultId as ft } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
+
import { a as pt, b as ee, f as gt, g as se } from "./verifyScriptPathSchnorrSignature-Dy9gF5RF.js";
|
|
13
|
+
import { d as oe, b as ne, e as re, f as ie, c as ae } from "./verifyKeyPathSchnorrSignature-C6Cmk0R1.js";
|
|
14
|
+
import { p as ce, h as et, u as st, e as C, i as mt, s as S, k as wt, X as le } from "./bitcoin-Ch_jxnDa.js";
|
|
15
15
|
import { c as ue } from "./signing-DaLvGwQe.js";
|
|
16
16
|
import { M as bt } from "./validation-Dj3dqYtl.js";
|
|
17
17
|
import { p as he, d as It } from "./parseFundingOutpoints-CO-f6IHK.js";
|
|
18
18
|
import { c as de, s as U, r as fe, b as pe, d as ge } from "./signPsbtsWithFallback-Bv79gLFe.js";
|
|
19
|
-
import { s as me, f as
|
|
20
|
-
import { p as
|
|
21
|
-
import { M as X, B as
|
|
22
|
-
import { l as
|
|
19
|
+
import { s as me, f as q, i as we, w as Pt } from "./waitForTransactionReceiptSmartAware-lobLm0q0.js";
|
|
20
|
+
import { p as be, f as Pe } from "./fundPeginTransaction-B2wyjqp0.js";
|
|
21
|
+
import { M as X, B as ye } from "./constants-GjWXdaqV.js";
|
|
22
|
+
import { l as xe, P as ke, m as Ee, n as Te, p as ve, V as Se, i as _e } from "./mempoolApi-71R_CNZa.js";
|
|
23
23
|
import * as Be from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
24
|
-
const
|
|
25
|
-
function
|
|
26
|
-
return t ? { h: Number(s &
|
|
24
|
+
const N = /* @__PURE__ */ BigInt(2 ** 32 - 1), yt = /* @__PURE__ */ BigInt(32);
|
|
25
|
+
function Ae(s, t = !1) {
|
|
26
|
+
return t ? { h: Number(s & N), l: Number(s >> yt & N) } : { h: Number(s >> yt & N) | 0, l: Number(s & N) | 0 };
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function Ce(s, t = !1) {
|
|
29
29
|
const e = s.length;
|
|
30
30
|
let o = new Uint32Array(e), i = new Uint32Array(e);
|
|
31
|
-
for (let
|
|
32
|
-
const { h:
|
|
33
|
-
[o[
|
|
31
|
+
for (let n = 0; n < e; n++) {
|
|
32
|
+
const { h: r, l: a } = Ae(s[n], t);
|
|
33
|
+
[o[n], i[n]] = [r, a];
|
|
34
34
|
}
|
|
35
35
|
return [o, i];
|
|
36
36
|
}
|
|
37
|
-
const
|
|
38
|
-
function
|
|
37
|
+
const Ie = (s, t, e) => s << e | t >>> 32 - e, He = (s, t, e) => t << e | s >>> 32 - e, Re = (s, t, e) => t << e - 32 | s >>> 64 - e, $e = (s, t, e) => s << e - 32 | t >>> 64 - e, Oe = 64;
|
|
38
|
+
function Ve(s) {
|
|
39
39
|
const t = s.prepeginTxid.toLowerCase();
|
|
40
|
-
if (!/^[0-9a-f]+$/.test(t) || t.length !==
|
|
40
|
+
if (!/^[0-9a-f]+$/.test(t) || t.length !== Oe)
|
|
41
41
|
throw new Error(
|
|
42
42
|
`buildDepositTerms: prepeginTxid must be 64 hex chars, got "${s.prepeginTxid}"`
|
|
43
43
|
);
|
|
@@ -49,9 +49,9 @@ function $e(s) {
|
|
|
49
49
|
throw new Error(
|
|
50
50
|
`buildDepositTerms: maxAcceptableCommissionBps must be an integer in [0, ${X}), got ${s.maxAcceptableCommissionBps}`
|
|
51
51
|
);
|
|
52
|
-
const e = BigInt(
|
|
53
|
-
(i,
|
|
54
|
-
htlcVout:
|
|
52
|
+
const e = BigInt(ye), o = s.peginAmounts.map(
|
|
53
|
+
(i, n) => ({
|
|
54
|
+
htlcVout: n,
|
|
55
55
|
vaultProviderBtcPubkey: s.vaultProviderBtcPubkey,
|
|
56
56
|
peginAmount: i,
|
|
57
57
|
// Ceiling, not quote: floor(peginAmount * maxAcceptableBps / 10_000) —
|
|
@@ -76,53 +76,53 @@ function $e(s) {
|
|
|
76
76
|
vaults: o
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
const
|
|
79
|
+
const ot = 25, Ht = 9999;
|
|
80
80
|
function Y(s) {
|
|
81
81
|
if (!Number.isInteger(s) || s < 0 || s >= X)
|
|
82
82
|
throw new Error(
|
|
83
83
|
`Quoted commissionBps must be an integer in [0, ${X}), got ${s}`
|
|
84
84
|
);
|
|
85
85
|
return Math.min(
|
|
86
|
-
s +
|
|
86
|
+
s + ot,
|
|
87
87
|
Ht
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
|
-
const
|
|
90
|
+
const Me = /^0x[0-9a-f]+$/i, We = /^[0-9a-f]+$/i, Ue = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
91
91
|
function $(s) {
|
|
92
92
|
if (typeof s != "string" || s.length === 0)
|
|
93
93
|
throw new Error("BTC wallet returned empty public key");
|
|
94
94
|
return ce(s).toLowerCase();
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function Ne(s) {
|
|
97
97
|
if (typeof s != "string" || s.length === 0)
|
|
98
98
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
99
99
|
if (s.startsWith("0x") || s.startsWith("0X")) {
|
|
100
|
-
if (!
|
|
100
|
+
if (!Me.test(s) || s.length < 4 || s.length % 2 !== 0)
|
|
101
101
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
102
102
|
return s.toLowerCase();
|
|
103
103
|
}
|
|
104
|
-
if (
|
|
104
|
+
if (We.test(s)) {
|
|
105
105
|
if (s.length % 2 !== 0)
|
|
106
106
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
107
107
|
return `0x${s.toLowerCase()}`;
|
|
108
108
|
}
|
|
109
|
-
if (!
|
|
109
|
+
if (!Ue.test(s) || s.length % 4 !== 0)
|
|
110
110
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
111
111
|
const t = O.from(s, "base64");
|
|
112
112
|
if (t.length === 0 || t.toString("base64") !== s)
|
|
113
113
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
114
114
|
return `0x${t.toString("hex")}`;
|
|
115
115
|
}
|
|
116
|
-
async function
|
|
117
|
-
const { wallet: t, depositTerms: e, fundedPrePeginTxHex: o, depositorBtcPubkey: i } = s,
|
|
118
|
-
if (!
|
|
116
|
+
async function Fe(s) {
|
|
117
|
+
const { wallet: t, depositTerms: e, fundedPrePeginTxHex: o, depositorBtcPubkey: i } = s, n = typeof t.approveDepositTerms == "function" ? t.approveDepositTerms : void 0;
|
|
118
|
+
if (!n && !e)
|
|
119
119
|
return;
|
|
120
|
-
const
|
|
120
|
+
const r = o.startsWith("0x") ? o.slice(2) : o, c = Ct.fromHex(r).getId();
|
|
121
121
|
if (e && e.prepeginTxid.replace(/^0x/, "").toLowerCase() !== c)
|
|
122
122
|
throw new Error(
|
|
123
123
|
`Deposit terms do not match the transaction being broadcast: terms are for prepeginTxid ${e.prepeginTxid}, but this transaction is ${c}.`
|
|
124
124
|
);
|
|
125
|
-
if (!
|
|
125
|
+
if (!n)
|
|
126
126
|
return;
|
|
127
127
|
if (!e)
|
|
128
128
|
throw new Error(
|
|
@@ -145,14 +145,14 @@ async function Ue(s) {
|
|
|
145
145
|
(await It(
|
|
146
146
|
{ deriveContextHash: t.deriveContextHash.bind(t) },
|
|
147
147
|
{
|
|
148
|
-
depositorBtcPubkey:
|
|
148
|
+
depositorBtcPubkey: et(
|
|
149
149
|
$(i)
|
|
150
150
|
),
|
|
151
151
|
fundingOutpoints: u
|
|
152
152
|
}
|
|
153
|
-
)).fill(0), await
|
|
153
|
+
)).fill(0), await n.call(t, e);
|
|
154
154
|
}
|
|
155
|
-
const
|
|
155
|
+
const De = /* @__PURE__ */ Uint8Array.from([
|
|
156
156
|
7,
|
|
157
157
|
4,
|
|
158
158
|
13,
|
|
@@ -169,11 +169,11 @@ const Fe = /* @__PURE__ */ Uint8Array.from([
|
|
|
169
169
|
14,
|
|
170
170
|
11,
|
|
171
171
|
8
|
|
172
|
-
]), Rt = Uint8Array.from(new Array(16).fill(0).map((s, t) => t)),
|
|
173
|
-
const e = [[Rt], [
|
|
172
|
+
]), Rt = Uint8Array.from(new Array(16).fill(0).map((s, t) => t)), Le = Rt.map((s) => (9 * s + 5) % 16), $t = /* @__PURE__ */ (() => {
|
|
173
|
+
const e = [[Rt], [Le]];
|
|
174
174
|
for (let o = 0; o < 4; o++)
|
|
175
175
|
for (let i of e)
|
|
176
|
-
i.push(i[o].map((
|
|
176
|
+
i.push(i[o].map((n) => De[n]));
|
|
177
177
|
return e;
|
|
178
178
|
})(), Ot = $t[0], Vt = $t[1], Mt = /* @__PURE__ */ [
|
|
179
179
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
@@ -181,13 +181,13 @@ const Fe = /* @__PURE__ */ Uint8Array.from([
|
|
|
181
181
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
182
182
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
183
183
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
184
|
-
].map((s) => Uint8Array.from(s)),
|
|
184
|
+
].map((s) => Uint8Array.from(s)), Ke = /* @__PURE__ */ Ot.map((s, t) => s.map((e) => Mt[t][e])), Xe = /* @__PURE__ */ Vt.map((s, t) => s.map((e) => Mt[t][e])), Ge = /* @__PURE__ */ Uint32Array.from([
|
|
185
185
|
0,
|
|
186
186
|
1518500249,
|
|
187
187
|
1859775393,
|
|
188
188
|
2400959708,
|
|
189
189
|
2840853838
|
|
190
|
-
]),
|
|
190
|
+
]), qe = /* @__PURE__ */ Uint32Array.from([
|
|
191
191
|
1352829926,
|
|
192
192
|
1548603684,
|
|
193
193
|
1836072691,
|
|
@@ -197,96 +197,96 @@ const Fe = /* @__PURE__ */ Uint8Array.from([
|
|
|
197
197
|
function xt(s, t, e, o) {
|
|
198
198
|
return s === 0 ? t ^ e ^ o : s === 1 ? t & e | ~t & o : s === 2 ? (t | ~e) ^ o : s === 3 ? t & o | e & ~o : t ^ (e | ~o);
|
|
199
199
|
}
|
|
200
|
-
const
|
|
201
|
-
class
|
|
200
|
+
const F = /* @__PURE__ */ new Uint32Array(16);
|
|
201
|
+
class Ye extends Yt {
|
|
202
202
|
constructor() {
|
|
203
203
|
super(64, 20, 8, !0);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
x(this, "h0", 1732584193);
|
|
205
|
+
x(this, "h1", -271733879);
|
|
206
|
+
x(this, "h2", -1732584194);
|
|
207
|
+
x(this, "h3", 271733878);
|
|
208
|
+
x(this, "h4", -1009589776);
|
|
209
209
|
}
|
|
210
210
|
get() {
|
|
211
|
-
const { h0: e, h1: o, h2: i, h3:
|
|
212
|
-
return [e, o, i,
|
|
211
|
+
const { h0: e, h1: o, h2: i, h3: n, h4: r } = this;
|
|
212
|
+
return [e, o, i, n, r];
|
|
213
213
|
}
|
|
214
|
-
set(e, o, i,
|
|
215
|
-
this.h0 = e | 0, this.h1 = o | 0, this.h2 = i | 0, this.h3 =
|
|
214
|
+
set(e, o, i, n, r) {
|
|
215
|
+
this.h0 = e | 0, this.h1 = o | 0, this.h2 = i | 0, this.h3 = n | 0, this.h4 = r | 0;
|
|
216
216
|
}
|
|
217
217
|
process(e, o) {
|
|
218
218
|
for (let d = 0; d < 16; d++, o += 4)
|
|
219
|
-
|
|
220
|
-
let i = this.h0 | 0,
|
|
219
|
+
F[d] = e.getUint32(o, !0);
|
|
220
|
+
let i = this.h0 | 0, n = i, r = this.h1 | 0, a = r, c = this.h2 | 0, u = c, h = this.h3 | 0, g = h, w = this.h4 | 0, b = w;
|
|
221
221
|
for (let d = 0; d < 5; d++) {
|
|
222
|
-
const E = 4 - d, k =
|
|
222
|
+
const E = 4 - d, k = Ge[d], f = qe[d], v = Ot[d], B = Vt[d], p = Ke[d], P = Xe[d];
|
|
223
223
|
for (let l = 0; l < 16; l++) {
|
|
224
|
-
const
|
|
225
|
-
i =
|
|
224
|
+
const y = W(i + xt(d, r, c, h) + F[v[l]] + k, p[l]) + w | 0;
|
|
225
|
+
i = w, w = h, h = W(c, 10) | 0, c = r, r = y;
|
|
226
226
|
}
|
|
227
227
|
for (let l = 0; l < 16; l++) {
|
|
228
|
-
const
|
|
229
|
-
|
|
228
|
+
const y = W(n + xt(E, a, u, g) + F[B[l]] + f, P[l]) + b | 0;
|
|
229
|
+
n = b, b = g, g = W(u, 10) | 0, u = a, a = y;
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
this.set(this.h1 + c + g | 0, this.h2 + h +
|
|
232
|
+
this.set(this.h1 + c + g | 0, this.h2 + h + b | 0, this.h3 + w + n | 0, this.h4 + i + a | 0, this.h0 + r + u | 0);
|
|
233
233
|
}
|
|
234
234
|
roundClean() {
|
|
235
|
-
K(
|
|
235
|
+
K(F);
|
|
236
236
|
}
|
|
237
237
|
destroy() {
|
|
238
238
|
this.destroyed = !0, K(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
const
|
|
241
|
+
const ze = /* @__PURE__ */ _t(() => new Ye()), je = BigInt(0), M = BigInt(1), Qe = BigInt(2), Ze = BigInt(7), Je = BigInt(256), ts = BigInt(113), Wt = [], Ut = [], Nt = [];
|
|
242
242
|
for (let s = 0, t = M, e = 1, o = 0; s < 24; s++) {
|
|
243
243
|
[e, o] = [o, (2 * e + 3 * o) % 5], Wt.push(2 * (5 * o + e)), Ut.push((s + 1) * (s + 2) / 2 % 64);
|
|
244
|
-
let i =
|
|
245
|
-
for (let
|
|
246
|
-
t = (t << M ^ (t >>
|
|
247
|
-
|
|
244
|
+
let i = je;
|
|
245
|
+
for (let n = 0; n < 7; n++)
|
|
246
|
+
t = (t << M ^ (t >> Ze) * ts) % Je, t & Qe && (i ^= M << (M << BigInt(n)) - M);
|
|
247
|
+
Nt.push(i);
|
|
248
248
|
}
|
|
249
|
-
const
|
|
250
|
-
function
|
|
249
|
+
const Ft = Ce(Nt, !0), es = Ft[0], ss = Ft[1], kt = (s, t, e) => e > 32 ? Re(s, t, e) : Ie(s, t, e), Et = (s, t, e) => e > 32 ? $e(s, t, e) : He(s, t, e);
|
|
250
|
+
function os(s, t = 24) {
|
|
251
251
|
const e = new Uint32Array(10);
|
|
252
252
|
for (let o = 24 - t; o < 24; o++) {
|
|
253
|
-
for (let
|
|
254
|
-
e[
|
|
255
|
-
for (let
|
|
256
|
-
const a = (
|
|
257
|
-
for (let
|
|
258
|
-
s[
|
|
253
|
+
for (let r = 0; r < 10; r++)
|
|
254
|
+
e[r] = s[r] ^ s[r + 10] ^ s[r + 20] ^ s[r + 30] ^ s[r + 40];
|
|
255
|
+
for (let r = 0; r < 10; r += 2) {
|
|
256
|
+
const a = (r + 8) % 10, c = (r + 2) % 10, u = e[c], h = e[c + 1], g = kt(u, h, 1) ^ e[a], w = Et(u, h, 1) ^ e[a + 1];
|
|
257
|
+
for (let b = 0; b < 50; b += 10)
|
|
258
|
+
s[r + b] ^= g, s[r + b + 1] ^= w;
|
|
259
259
|
}
|
|
260
|
-
let i = s[2],
|
|
261
|
-
for (let
|
|
262
|
-
const a = Ut[
|
|
263
|
-
i = s[h],
|
|
260
|
+
let i = s[2], n = s[3];
|
|
261
|
+
for (let r = 0; r < 24; r++) {
|
|
262
|
+
const a = Ut[r], c = kt(i, n, a), u = Et(i, n, a), h = Wt[r];
|
|
263
|
+
i = s[h], n = s[h + 1], s[h] = c, s[h + 1] = u;
|
|
264
264
|
}
|
|
265
|
-
for (let
|
|
265
|
+
for (let r = 0; r < 50; r += 10) {
|
|
266
266
|
for (let a = 0; a < 10; a++)
|
|
267
|
-
e[a] = s[
|
|
267
|
+
e[a] = s[r + a];
|
|
268
268
|
for (let a = 0; a < 10; a++)
|
|
269
|
-
s[
|
|
269
|
+
s[r + a] ^= ~e[(a + 2) % 10] & e[(a + 4) % 10];
|
|
270
270
|
}
|
|
271
|
-
s[0] ^=
|
|
271
|
+
s[0] ^= es[o], s[1] ^= ss[o];
|
|
272
272
|
}
|
|
273
273
|
K(e);
|
|
274
274
|
}
|
|
275
|
-
class
|
|
275
|
+
class rt {
|
|
276
276
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
277
|
-
constructor(t, e, o, i = !1,
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if (this.blockLen = t, this.suffix = e, this.outputLen = o, this.enableXOF = i, this.rounds =
|
|
277
|
+
constructor(t, e, o, i = !1, n = 24) {
|
|
278
|
+
x(this, "state");
|
|
279
|
+
x(this, "pos", 0);
|
|
280
|
+
x(this, "posOut", 0);
|
|
281
|
+
x(this, "finished", !1);
|
|
282
|
+
x(this, "state32");
|
|
283
|
+
x(this, "destroyed", !1);
|
|
284
|
+
x(this, "blockLen");
|
|
285
|
+
x(this, "suffix");
|
|
286
|
+
x(this, "outputLen");
|
|
287
|
+
x(this, "enableXOF", !1);
|
|
288
|
+
x(this, "rounds");
|
|
289
|
+
if (this.blockLen = t, this.suffix = e, this.outputLen = o, this.enableXOF = i, this.rounds = n, at(o, "outputLen"), !(0 < t && t < 200))
|
|
290
290
|
throw new Error("only keccak-f1600 function is supported");
|
|
291
291
|
this.state = new Uint8Array(200), this.state32 = zt(this.state);
|
|
292
292
|
}
|
|
@@ -294,15 +294,15 @@ class nt {
|
|
|
294
294
|
return this._cloneInto();
|
|
295
295
|
}
|
|
296
296
|
keccak() {
|
|
297
|
-
|
|
297
|
+
ct(this.state32), os(this.state32, this.rounds), ct(this.state32), this.posOut = 0, this.pos = 0;
|
|
298
298
|
}
|
|
299
299
|
update(t) {
|
|
300
|
-
|
|
300
|
+
lt(this), ut(t);
|
|
301
301
|
const { blockLen: e, state: o } = this, i = t.length;
|
|
302
|
-
for (let
|
|
303
|
-
const
|
|
304
|
-
for (let a = 0; a <
|
|
305
|
-
o[this.pos++] ^= t[
|
|
302
|
+
for (let n = 0; n < i; ) {
|
|
303
|
+
const r = Math.min(e - this.pos, i - n);
|
|
304
|
+
for (let a = 0; a < r; a++)
|
|
305
|
+
o[this.pos++] ^= t[n++];
|
|
306
306
|
this.pos === e && this.keccak();
|
|
307
307
|
}
|
|
308
308
|
return this;
|
|
@@ -315,12 +315,12 @@ class nt {
|
|
|
315
315
|
t[o] ^= e, (e & 128) !== 0 && o === i - 1 && this.keccak(), t[i - 1] ^= 128, this.keccak();
|
|
316
316
|
}
|
|
317
317
|
writeInto(t) {
|
|
318
|
-
|
|
318
|
+
lt(this, !1), ut(t), this.finish();
|
|
319
319
|
const e = this.state, { blockLen: o } = this;
|
|
320
|
-
for (let i = 0,
|
|
320
|
+
for (let i = 0, n = t.length; i < n; ) {
|
|
321
321
|
this.posOut >= o && this.keccak();
|
|
322
|
-
const
|
|
323
|
-
t.set(e.subarray(this.posOut, this.posOut +
|
|
322
|
+
const r = Math.min(o - this.posOut, n - i);
|
|
323
|
+
t.set(e.subarray(this.posOut, this.posOut + r), i), this.posOut += r, i += r;
|
|
324
324
|
}
|
|
325
325
|
return t;
|
|
326
326
|
}
|
|
@@ -330,7 +330,7 @@ class nt {
|
|
|
330
330
|
return this.writeInto(t);
|
|
331
331
|
}
|
|
332
332
|
xof(t) {
|
|
333
|
-
return
|
|
333
|
+
return at(t), this.xofInto(new Uint8Array(t));
|
|
334
334
|
}
|
|
335
335
|
digestInto(t) {
|
|
336
336
|
if (jt(t, this), this.finished)
|
|
@@ -344,25 +344,25 @@ class nt {
|
|
|
344
344
|
this.destroyed = !0, K(this.state);
|
|
345
345
|
}
|
|
346
346
|
_cloneInto(t) {
|
|
347
|
-
const { blockLen: e, suffix: o, outputLen: i, rounds:
|
|
348
|
-
return t || (t = new
|
|
347
|
+
const { blockLen: e, suffix: o, outputLen: i, rounds: n, enableXOF: r } = this;
|
|
348
|
+
return t || (t = new rt(e, o, i, r, n)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = n, t.suffix = o, t.outputLen = i, t.enableXOF = r, t.destroyed = this.destroyed, t;
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
-
const
|
|
352
|
-
function
|
|
353
|
-
return
|
|
351
|
+
const ns = (s, t, e, o = {}) => _t(() => new rt(t, s, e), o), rs = /* @__PURE__ */ ns(1, 136, 32), Tt = 64, _ = 20, nt = 4, Dt = 2, is = 0, as = 1, D = [64, 64], cs = (s) => Array.from(s).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
352
|
+
function it(s) {
|
|
353
|
+
return ze(Bt(s));
|
|
354
354
|
}
|
|
355
355
|
function Lt(s) {
|
|
356
356
|
return (1 << s) - 1;
|
|
357
357
|
}
|
|
358
|
-
function
|
|
358
|
+
function ls(s) {
|
|
359
359
|
let t = 1;
|
|
360
360
|
for (; t * t < s + 1; ) t++;
|
|
361
361
|
return Math.max(t, 2);
|
|
362
362
|
}
|
|
363
|
-
function
|
|
364
|
-
const t =
|
|
365
|
-
return { d: t, n: s, checksum_radix:
|
|
363
|
+
function us(s) {
|
|
364
|
+
const t = nt, e = s * Lt(t);
|
|
365
|
+
return { d: t, n: s, checksum_radix: ls(e) };
|
|
366
366
|
}
|
|
367
367
|
function z(s, t) {
|
|
368
368
|
const e = [];
|
|
@@ -371,58 +371,58 @@ function z(s, t) {
|
|
|
371
371
|
e.push(o & 255), o >>>= 8;
|
|
372
372
|
const i = new Uint8Array(s.length + e.length);
|
|
373
373
|
i.set(s);
|
|
374
|
-
for (let
|
|
375
|
-
i[s.length +
|
|
376
|
-
return
|
|
374
|
+
for (let n = 0; n < e.length; n++)
|
|
375
|
+
i[s.length + n] = e[n];
|
|
376
|
+
return it(i);
|
|
377
377
|
}
|
|
378
378
|
function j(s, t) {
|
|
379
379
|
let e = s;
|
|
380
380
|
for (let o = 0; o < t; o++)
|
|
381
|
-
e =
|
|
381
|
+
e = it(e);
|
|
382
382
|
return e;
|
|
383
383
|
}
|
|
384
|
-
function
|
|
385
|
-
const e = Lt(t.d), o = t.checksum_radix - 1, i = Math.floor(t.n * e / t.checksum_radix),
|
|
384
|
+
function hs(s, t) {
|
|
385
|
+
const e = Lt(t.d), o = t.checksum_radix - 1, i = Math.floor(t.n * e / t.checksum_radix), n = [];
|
|
386
386
|
for (let h = 0; h < t.n; h++) {
|
|
387
|
-
const g = z(s, h + Dt),
|
|
388
|
-
|
|
387
|
+
const g = z(s, h + Dt), w = j(g, e);
|
|
388
|
+
n.push(Array.from(w));
|
|
389
389
|
}
|
|
390
|
-
const
|
|
390
|
+
const r = z(
|
|
391
391
|
s,
|
|
392
|
-
|
|
392
|
+
is
|
|
393
393
|
), a = j(
|
|
394
|
-
|
|
394
|
+
r,
|
|
395
395
|
o
|
|
396
396
|
), c = z(
|
|
397
397
|
s,
|
|
398
|
-
|
|
398
|
+
as
|
|
399
399
|
), u = j(
|
|
400
400
|
c,
|
|
401
401
|
i
|
|
402
402
|
);
|
|
403
403
|
return {
|
|
404
404
|
config: t,
|
|
405
|
-
message_terminals:
|
|
405
|
+
message_terminals: n,
|
|
406
406
|
checksum_major_terminal: Array.from(u),
|
|
407
407
|
checksum_minor_terminal: Array.from(a)
|
|
408
408
|
};
|
|
409
409
|
}
|
|
410
|
-
async function
|
|
410
|
+
async function ds(s) {
|
|
411
411
|
try {
|
|
412
|
-
if (s.length !==
|
|
412
|
+
if (s.length !== Tt)
|
|
413
413
|
throw new Error(
|
|
414
|
-
`WOTS seed must be exactly ${
|
|
414
|
+
`WOTS seed must be exactly ${Tt} bytes, got ${s.length}`
|
|
415
415
|
);
|
|
416
416
|
const t = [];
|
|
417
417
|
for (let e = 0; e < D.length; e++) {
|
|
418
|
-
const o = D[e], i =
|
|
419
|
-
|
|
420
|
-
const
|
|
418
|
+
const o = D[e], i = us(o), n = new Uint8Array(s.length + 1);
|
|
419
|
+
n.set(s), n[s.length] = e;
|
|
420
|
+
const r = it(n);
|
|
421
421
|
try {
|
|
422
|
-
const a =
|
|
423
|
-
if (a.config.d !==
|
|
422
|
+
const a = hs(r, i);
|
|
423
|
+
if (a.config.d !== nt)
|
|
424
424
|
throw new Error(
|
|
425
|
-
`Block ${e}: expected d=${
|
|
425
|
+
`Block ${e}: expected d=${nt}, got d=${a.config.d}`
|
|
426
426
|
);
|
|
427
427
|
if (a.config.n !== o)
|
|
428
428
|
throw new Error(
|
|
@@ -433,21 +433,21 @@ async function us(s) {
|
|
|
433
433
|
`Block ${e}: expected ${o} message terminals, got ${a.message_terminals.length}`
|
|
434
434
|
);
|
|
435
435
|
for (let c = 0; c < a.message_terminals.length; c++)
|
|
436
|
-
if (a.message_terminals[c].length !==
|
|
436
|
+
if (a.message_terminals[c].length !== _)
|
|
437
437
|
throw new Error(
|
|
438
|
-
`Block ${e} terminal ${c}: expected ${
|
|
438
|
+
`Block ${e} terminal ${c}: expected ${_} bytes, got ${a.message_terminals[c].length}`
|
|
439
439
|
);
|
|
440
|
-
if (a.checksum_minor_terminal.length !==
|
|
440
|
+
if (a.checksum_minor_terminal.length !== _)
|
|
441
441
|
throw new Error(
|
|
442
|
-
`Block ${e} checksum_minor: expected ${
|
|
442
|
+
`Block ${e} checksum_minor: expected ${_} bytes`
|
|
443
443
|
);
|
|
444
|
-
if (a.checksum_major_terminal.length !==
|
|
444
|
+
if (a.checksum_major_terminal.length !== _)
|
|
445
445
|
throw new Error(
|
|
446
|
-
`Block ${e} checksum_major: expected ${
|
|
446
|
+
`Block ${e} checksum_major: expected ${_} bytes`
|
|
447
447
|
);
|
|
448
448
|
t.push(a);
|
|
449
449
|
} finally {
|
|
450
|
-
|
|
450
|
+
n.fill(0), r.fill(0);
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
453
|
if (t.length !== D.length)
|
|
@@ -460,9 +460,9 @@ async function us(s) {
|
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
462
|
function Q(s, t, e) {
|
|
463
|
-
if (s.length !==
|
|
463
|
+
if (s.length !== _)
|
|
464
464
|
throw new Error(
|
|
465
|
-
`Block ${t} ${e}: expected ${
|
|
465
|
+
`Block ${t} ${e}: expected ${_} bytes, got ${s.length}`
|
|
466
466
|
);
|
|
467
467
|
for (let o = 0; o < s.length; o++) {
|
|
468
468
|
const i = s[o];
|
|
@@ -472,43 +472,43 @@ function Q(s, t, e) {
|
|
|
472
472
|
);
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
|
-
function
|
|
475
|
+
function fs(s) {
|
|
476
476
|
if (s.length === 0)
|
|
477
477
|
throw new Error("Public keys array must not be empty");
|
|
478
|
-
for (let
|
|
479
|
-
const
|
|
480
|
-
Q(
|
|
481
|
-
for (let a = 0; a <
|
|
482
|
-
Q(
|
|
478
|
+
for (let n = 0; n < s.length; n++) {
|
|
479
|
+
const r = s[n];
|
|
480
|
+
Q(r.checksum_minor_terminal, n, "checksum_minor_terminal"), Q(r.checksum_major_terminal, n, "checksum_major_terminal");
|
|
481
|
+
for (let a = 0; a < r.message_terminals.length; a++)
|
|
482
|
+
Q(r.message_terminals[a], n, `message_terminal[${a}]`);
|
|
483
483
|
}
|
|
484
484
|
let t = 0;
|
|
485
|
-
for (const
|
|
486
|
-
t += Dt +
|
|
487
|
-
const e = new Uint8Array(t *
|
|
485
|
+
for (const n of s)
|
|
486
|
+
t += Dt + n.message_terminals.length;
|
|
487
|
+
const e = new Uint8Array(t * _);
|
|
488
488
|
let o = 0;
|
|
489
|
-
for (const
|
|
490
|
-
e.set(
|
|
491
|
-
for (const
|
|
492
|
-
e.set(
|
|
489
|
+
for (const n of s) {
|
|
490
|
+
e.set(n.checksum_minor_terminal, o), o += _, e.set(n.checksum_major_terminal, o), o += _;
|
|
491
|
+
for (const r of n.message_terminals)
|
|
492
|
+
e.set(r, o), o += _;
|
|
493
493
|
}
|
|
494
|
-
const i =
|
|
495
|
-
return `0x${
|
|
494
|
+
const i = rs(e);
|
|
495
|
+
return `0x${cs(i)}`;
|
|
496
496
|
}
|
|
497
|
-
async function
|
|
498
|
-
const e = [], o = [], i = [],
|
|
497
|
+
async function ps(s, t) {
|
|
498
|
+
const e = [], o = [], i = [], n = [];
|
|
499
499
|
try {
|
|
500
|
-
for (let
|
|
501
|
-
const a = await Zt(s,
|
|
500
|
+
for (let r = 0; r < t; r++) {
|
|
501
|
+
const a = await Zt(s, r);
|
|
502
502
|
try {
|
|
503
|
-
const u = await
|
|
504
|
-
e.push(u), o.push(
|
|
503
|
+
const u = await ds(a);
|
|
504
|
+
e.push(u), o.push(fs(u));
|
|
505
505
|
} finally {
|
|
506
506
|
a.fill(0);
|
|
507
507
|
}
|
|
508
|
-
const c = await Jt(s,
|
|
508
|
+
const c = await Jt(s, r);
|
|
509
509
|
try {
|
|
510
|
-
const u =
|
|
511
|
-
i.push(u),
|
|
510
|
+
const u = st(c);
|
|
511
|
+
i.push(u), n.push(de(C(u)).slice(2));
|
|
512
512
|
} finally {
|
|
513
513
|
c.fill(0);
|
|
514
514
|
}
|
|
@@ -516,12 +516,12 @@ async function ds(s, t) {
|
|
|
516
516
|
} finally {
|
|
517
517
|
s.fill(0);
|
|
518
518
|
}
|
|
519
|
-
return { perVaultWotsKeys: e, wotsPkHashes: o, htlcSecretHexes: i, hashlocks:
|
|
519
|
+
return { perVaultWotsKeys: e, wotsPkHashes: o, htlcSecretHexes: i, hashlocks: n };
|
|
520
520
|
}
|
|
521
|
-
const
|
|
522
|
-
function
|
|
521
|
+
const gs = 1, ms = 2, ws = 33, bs = 2, Ps = 3, ys = 1, L = 64, xs = 0, Z = 1, vt = /^[0-9a-f]{64}$/i, ks = /^(?:[0-9a-f]{2})+$/;
|
|
522
|
+
function Es(s) {
|
|
523
523
|
const t = s.slice(2);
|
|
524
|
-
if (!
|
|
524
|
+
if (!ks.test(t))
|
|
525
525
|
throw new Error(
|
|
526
526
|
"proof of possession witness is not even-length lowercase hex"
|
|
527
527
|
);
|
|
@@ -530,16 +530,16 @@ function ys(s) {
|
|
|
530
530
|
"proof of possession witness"
|
|
531
531
|
);
|
|
532
532
|
}
|
|
533
|
-
function
|
|
533
|
+
function Ts(s, t, e) {
|
|
534
534
|
var i;
|
|
535
|
-
const o =
|
|
536
|
-
if (o.length ===
|
|
537
|
-
const [
|
|
538
|
-
let
|
|
539
|
-
if (
|
|
540
|
-
|
|
541
|
-
else if (
|
|
542
|
-
|
|
535
|
+
const o = Es(e);
|
|
536
|
+
if (o.length === gs) {
|
|
537
|
+
const [n] = o;
|
|
538
|
+
let r, a;
|
|
539
|
+
if (n.length === L)
|
|
540
|
+
r = n, a = xs;
|
|
541
|
+
else if (n.length === L + 1 && n[L] === Z)
|
|
542
|
+
r = n.subarray(0, L), a = Z;
|
|
543
543
|
else
|
|
544
544
|
throw new Error(
|
|
545
545
|
"proof of possession witness item must be a 64-byte Schnorr signature (or 65 bytes ending in 0x01)"
|
|
@@ -549,34 +549,42 @@ function ks(s, t, e) {
|
|
|
549
549
|
`depositor public key must be bare 64-char x-only hex, got "${t}"`
|
|
550
550
|
);
|
|
551
551
|
const c = Uint8Array.from(O.from(t, "hex"));
|
|
552
|
-
if (!
|
|
552
|
+
if (!xe(s, c, r, a))
|
|
553
553
|
throw new Error(
|
|
554
554
|
"proof of possession signature does not verify against the depositor key"
|
|
555
555
|
);
|
|
556
556
|
return { kind: "p2tr-verified" };
|
|
557
557
|
}
|
|
558
|
-
if (o.length ===
|
|
558
|
+
if (o.length === ms) {
|
|
559
559
|
if (!vt.test(t))
|
|
560
560
|
throw new Error(
|
|
561
561
|
`depositor public key must be bare 64-char x-only hex, got "${t}"`
|
|
562
562
|
);
|
|
563
|
-
const [
|
|
564
|
-
if (
|
|
563
|
+
const [n, r] = o;
|
|
564
|
+
if (r.length !== ws || r[0] !== bs && r[0] !== Ps)
|
|
565
565
|
throw new Error(
|
|
566
|
-
`proof of possession P2WPKH witness item 1 is not a compressed public key (${
|
|
566
|
+
`proof of possession P2WPKH witness item 1 is not a compressed public key (${r.length} bytes, prefix 0x${((i = r[0]) == null ? void 0 : i.toString(16)) ?? "none"})`
|
|
567
567
|
);
|
|
568
|
-
if (!Be.isPointCompressed(
|
|
568
|
+
if (!Be.isPointCompressed(r))
|
|
569
569
|
throw new Error(
|
|
570
570
|
"proof of possession P2WPKH witness pubkey is not a valid secp256k1 point"
|
|
571
571
|
);
|
|
572
572
|
const a = O.from(
|
|
573
|
-
|
|
573
|
+
r.subarray(ys)
|
|
574
574
|
).toString("hex");
|
|
575
575
|
if (a !== t.toLowerCase())
|
|
576
576
|
throw new Error(
|
|
577
577
|
`proof of possession witness pubkey does not match the depositor key: witness carries ${a}, expected ${t}`
|
|
578
578
|
);
|
|
579
|
-
if (
|
|
579
|
+
if (n.length < ke || n.length > Ee)
|
|
580
|
+
throw new Error(
|
|
581
|
+
`proof of possession signature is ${n.length} bytes; vault ingestion accepts only 71/72-byte DER signatures with a sighash byte — try a different account or a Taproot address`
|
|
582
|
+
);
|
|
583
|
+
if (n[n.length - 1] !== Z)
|
|
584
|
+
throw new Error(
|
|
585
|
+
`proof of possession P2WPKH signature must end in a SIGHASH_ALL (0x01) byte, got 0x${n[n.length - 1].toString(16)}`
|
|
586
|
+
);
|
|
587
|
+
if (!Te(s, r, n))
|
|
580
588
|
throw new Error(
|
|
581
589
|
"proof of possession signature does not verify against the depositor key"
|
|
582
590
|
);
|
|
@@ -586,8 +594,8 @@ function ks(s, t, e) {
|
|
|
586
594
|
`proof of possession witness has ${o.length} items; expected 1 (P2TR) or 2 (P2WPKH)`
|
|
587
595
|
);
|
|
588
596
|
}
|
|
589
|
-
const Kt = 0,
|
|
590
|
-
function
|
|
597
|
+
const Kt = 0, J = "00".repeat(32);
|
|
598
|
+
function vs(s, t) {
|
|
591
599
|
const e = {
|
|
592
600
|
bitcoin: "bc",
|
|
593
601
|
testnet: "tb",
|
|
@@ -601,24 +609,24 @@ function Es(s, t) {
|
|
|
601
609
|
return !1;
|
|
602
610
|
}
|
|
603
611
|
}
|
|
604
|
-
function
|
|
612
|
+
function Ss(s, t, e, o) {
|
|
605
613
|
const i = e == null ? void 0 : e[`${s}:${t}`];
|
|
606
614
|
return i ? Promise.resolve({
|
|
607
615
|
txid: s,
|
|
608
616
|
vout: t,
|
|
609
617
|
value: i.value,
|
|
610
618
|
scriptPubKey: i.scriptPubKey
|
|
611
|
-
}) :
|
|
619
|
+
}) : _e(s, t, o);
|
|
612
620
|
}
|
|
613
|
-
const
|
|
614
|
-
class
|
|
621
|
+
const St = 12e4;
|
|
622
|
+
class Zs {
|
|
615
623
|
/**
|
|
616
624
|
* Creates a new PeginManager instance.
|
|
617
625
|
*
|
|
618
626
|
* @param config - Manager configuration including wallets and contract addresses
|
|
619
627
|
*/
|
|
620
628
|
constructor(t) {
|
|
621
|
-
|
|
629
|
+
x(this, "config");
|
|
622
630
|
this.config = t;
|
|
623
631
|
}
|
|
624
632
|
/**
|
|
@@ -641,7 +649,7 @@ class js {
|
|
|
641
649
|
throw new Error(
|
|
642
650
|
`Pre-PegIn changeAddress "${t.changeAddress}" is not the approval wallet's change address ("${f}"). Refusing to build a tx the signing device would reject.`
|
|
643
651
|
);
|
|
644
|
-
} else if (!
|
|
652
|
+
} else if (!mt(
|
|
645
653
|
t.changeAddress,
|
|
646
654
|
e,
|
|
647
655
|
this.config.btcNetwork
|
|
@@ -649,30 +657,30 @@ class js {
|
|
|
649
657
|
throw new Error(
|
|
650
658
|
`Pre-PegIn changeAddress "${t.changeAddress}" is not derived from the connected wallet's public key. Refusing to build a tx that would send change to an address the signing key doesn't control.`
|
|
651
659
|
);
|
|
652
|
-
const i = await this.prepareSizing(o, t),
|
|
660
|
+
const i = await this.prepareSizing(o, t), n = i.selectedUTXOs.map(
|
|
653
661
|
(f) => ({
|
|
654
|
-
txid:
|
|
662
|
+
txid: et(f.txid),
|
|
655
663
|
vout: f.vout
|
|
656
664
|
})
|
|
657
|
-
),
|
|
658
|
-
depositorBtcPubkey:
|
|
659
|
-
fundingOutpoints:
|
|
665
|
+
), r = await It(this.config.btcWallet, {
|
|
666
|
+
depositorBtcPubkey: et(o),
|
|
667
|
+
fundingOutpoints: n
|
|
660
668
|
});
|
|
661
669
|
let a, c;
|
|
662
670
|
try {
|
|
663
|
-
const f = await te(
|
|
671
|
+
const f = await te(r);
|
|
664
672
|
try {
|
|
665
|
-
a =
|
|
673
|
+
a = st(f), c = st(Bt(f));
|
|
666
674
|
} finally {
|
|
667
675
|
f.fill(0);
|
|
668
676
|
}
|
|
669
677
|
} catch (f) {
|
|
670
|
-
throw
|
|
678
|
+
throw r.fill(0), f;
|
|
671
679
|
}
|
|
672
|
-
const u = await
|
|
680
|
+
const u = await ps(r, t.amounts.length), { perVaultWotsKeys: h, wotsPkHashes: g, htlcSecretHexes: w, hashlocks: b } = u, d = await this.preparePeginCommit({
|
|
673
681
|
depositorBtcPubkeyRaw: e,
|
|
674
682
|
depositorBtcPubkey: o,
|
|
675
|
-
hashlocks:
|
|
683
|
+
hashlocks: b,
|
|
676
684
|
authAnchorHash: c,
|
|
677
685
|
sizing: i,
|
|
678
686
|
params: t
|
|
@@ -699,7 +707,7 @@ class js {
|
|
|
699
707
|
derivedSecrets: {
|
|
700
708
|
perVaultWotsKeys: h,
|
|
701
709
|
wotsPkHashes: g,
|
|
702
|
-
htlcSecretHexes:
|
|
710
|
+
htlcSecretHexes: w,
|
|
703
711
|
authAnchorHex: a
|
|
704
712
|
},
|
|
705
713
|
depositTerms: E
|
|
@@ -723,13 +731,13 @@ class js {
|
|
|
723
731
|
*/
|
|
724
732
|
async prepareSizing(t, e) {
|
|
725
733
|
const o = e.amounts.map(
|
|
726
|
-
() =>
|
|
727
|
-
), i = e.vaultKeeperBtcPubkeys.length,
|
|
734
|
+
() => J
|
|
735
|
+
), i = e.vaultKeeperBtcPubkeys.length, n = await pt({
|
|
728
736
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
729
737
|
depositorPubkey: t,
|
|
730
|
-
vaultProviderPubkey:
|
|
731
|
-
vaultKeeperPubkeys: e.vaultKeeperBtcPubkeys.map(
|
|
732
|
-
universalChallengerPubkeys: e.universalChallengerBtcPubkeys.map(
|
|
738
|
+
vaultProviderPubkey: S(e.vaultProviderBtcPubkey),
|
|
739
|
+
vaultKeeperPubkeys: e.vaultKeeperBtcPubkeys.map(S),
|
|
740
|
+
universalChallengerPubkeys: e.universalChallengerBtcPubkeys.map(S),
|
|
733
741
|
hashlocks: o,
|
|
734
742
|
timelockRefund: e.timelockRefund,
|
|
735
743
|
pegInAmounts: e.amounts,
|
|
@@ -739,17 +747,17 @@ class js {
|
|
|
739
747
|
councilQuorum: e.councilQuorum,
|
|
740
748
|
councilSize: e.councilSize,
|
|
741
749
|
network: this.config.btcNetwork,
|
|
742
|
-
authAnchorHash:
|
|
743
|
-
}),
|
|
750
|
+
authAnchorHash: J
|
|
751
|
+
}), r = me(
|
|
744
752
|
[...e.availableUTXOs],
|
|
745
|
-
|
|
753
|
+
n.totalOutputValue,
|
|
746
754
|
e.mempoolFeeRate,
|
|
747
|
-
|
|
755
|
+
be(n.htlcValues.length, !0)
|
|
748
756
|
);
|
|
749
757
|
return {
|
|
750
|
-
selectedUTXOs:
|
|
751
|
-
fee:
|
|
752
|
-
changeAmount:
|
|
758
|
+
selectedUTXOs: r.selectedUTXOs,
|
|
759
|
+
fee: r.fee,
|
|
760
|
+
changeAmount: r.changeAmount
|
|
753
761
|
};
|
|
754
762
|
}
|
|
755
763
|
/** Build PegIn txs and batch-sign their inputs with real hashlocks. */
|
|
@@ -758,22 +766,22 @@ class js {
|
|
|
758
766
|
depositorBtcPubkeyRaw: e,
|
|
759
767
|
depositorBtcPubkey: o,
|
|
760
768
|
hashlocks: i,
|
|
761
|
-
authAnchorHash:
|
|
762
|
-
sizing:
|
|
769
|
+
authAnchorHash: n,
|
|
770
|
+
sizing: r,
|
|
763
771
|
params: a
|
|
764
|
-
} = t, c =
|
|
772
|
+
} = t, c = J.toLowerCase();
|
|
765
773
|
for (let m = 0; m < i.length; m++)
|
|
766
774
|
if (i[m].toLowerCase() === c)
|
|
767
775
|
throw new Error(
|
|
768
776
|
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${m} — internal substitution bug`
|
|
769
777
|
);
|
|
770
|
-
if (
|
|
778
|
+
if (n.toLowerCase() === c)
|
|
771
779
|
throw new Error(
|
|
772
780
|
"preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
|
|
773
781
|
);
|
|
774
|
-
const u =
|
|
782
|
+
const u = S(
|
|
775
783
|
a.vaultProviderBtcPubkey
|
|
776
|
-
), h = a.vaultKeeperBtcPubkeys.map(
|
|
784
|
+
), h = a.vaultKeeperBtcPubkeys.map(S), g = a.universalChallengerBtcPubkeys.map(S), w = h.length, b = {
|
|
777
785
|
vaultCoreVersion: a.vaultCoreVersion,
|
|
778
786
|
depositorPubkey: o,
|
|
779
787
|
vaultProviderPubkey: u,
|
|
@@ -784,28 +792,28 @@ class js {
|
|
|
784
792
|
pegInAmounts: a.amounts,
|
|
785
793
|
feeRate: a.protocolFeeRate,
|
|
786
794
|
minPeginFeeRate: a.minPeginFeeRate,
|
|
787
|
-
numLocalChallengers:
|
|
795
|
+
numLocalChallengers: w,
|
|
788
796
|
councilQuorum: a.councilQuorum,
|
|
789
797
|
councilSize: a.councilSize,
|
|
790
798
|
network: this.config.btcNetwork,
|
|
791
|
-
authAnchorHash:
|
|
792
|
-
}, d = await
|
|
799
|
+
authAnchorHash: n
|
|
800
|
+
}, d = await pt(b), E = wt(this.config.btcNetwork), k = Pe({
|
|
793
801
|
unfundedTxHex: d.psbtHex,
|
|
794
|
-
selectedUTXOs:
|
|
802
|
+
selectedUTXOs: r.selectedUTXOs,
|
|
795
803
|
changeAddress: a.changeAddress,
|
|
796
|
-
changeAmount:
|
|
804
|
+
changeAmount: r.changeAmount,
|
|
797
805
|
network: E
|
|
798
|
-
}), f =
|
|
799
|
-
if (f !==
|
|
806
|
+
}), f = r.selectedUTXOs.reduce((m, T) => m + BigInt(T.value), 0n) - d.totalOutputValue - r.changeAmount;
|
|
807
|
+
if (f !== r.fee)
|
|
800
808
|
throw new Error(
|
|
801
|
-
`Pre-PegIn funded fee ${f} does not match the sizing-pass fee ${
|
|
809
|
+
`Pre-PegIn funded fee ${f} does not match the sizing-pass fee ${r.fee}; refusing to publish a deposit-terms fee bound the funded transaction does not pay.`
|
|
802
810
|
);
|
|
803
|
-
const v =
|
|
804
|
-
|
|
805
|
-
),
|
|
811
|
+
const v = S(
|
|
812
|
+
q(k)
|
|
813
|
+
), B = [], p = [], P = [];
|
|
806
814
|
for (let m = 0; m < i.length; m++) {
|
|
807
815
|
const T = await ee({
|
|
808
|
-
prePeginParams:
|
|
816
|
+
prePeginParams: b,
|
|
809
817
|
timelockPegin: a.timelockPegin,
|
|
810
818
|
fundedPrePeginTxHex: k,
|
|
811
819
|
htlcVout: m
|
|
@@ -821,18 +829,18 @@ class js {
|
|
|
821
829
|
timelockRefund: a.timelockRefund,
|
|
822
830
|
network: this.config.btcNetwork
|
|
823
831
|
});
|
|
824
|
-
|
|
832
|
+
B.push(T), p.push(I.psbtHex), P.push(
|
|
825
833
|
ue(e, 1)
|
|
826
834
|
);
|
|
827
835
|
}
|
|
828
|
-
const l =
|
|
836
|
+
const l = Ve({
|
|
829
837
|
vaultCoreVersion: a.vaultCoreVersion,
|
|
830
838
|
protocolFeeRate: a.protocolFeeRate,
|
|
831
839
|
timelockPegin: a.timelockPegin,
|
|
832
840
|
timelockAssert: a.timelockAssert,
|
|
833
841
|
timelockRefund: a.timelockRefund,
|
|
834
842
|
prepeginTxid: v,
|
|
835
|
-
prepeginMaxFee:
|
|
843
|
+
prepeginMaxFee: r.fee,
|
|
836
844
|
vaultProviderBtcPubkey: u,
|
|
837
845
|
vaultKeeperBtcPubkeys: h,
|
|
838
846
|
universalChallengerBtcPubkeys: g,
|
|
@@ -844,18 +852,18 @@ class js {
|
|
|
844
852
|
peginMaxFee: d.minPeginFee
|
|
845
853
|
});
|
|
846
854
|
U(this.config.btcWallet) && await this.config.btcWallet.approveDepositTerms(l);
|
|
847
|
-
const
|
|
855
|
+
const y = await ge(
|
|
848
856
|
this.config.btcWallet,
|
|
849
857
|
p,
|
|
850
858
|
P
|
|
851
859
|
), A = [];
|
|
852
|
-
for (let m = 0; m <
|
|
853
|
-
|
|
860
|
+
for (let m = 0; m < y.length; m++) {
|
|
861
|
+
gt({
|
|
854
862
|
requestedPsbtHex: p[m],
|
|
855
|
-
returnedPsbtHex:
|
|
863
|
+
returnedPsbtHex: y[m]
|
|
856
864
|
});
|
|
857
865
|
const T = re(
|
|
858
|
-
|
|
866
|
+
y[m],
|
|
859
867
|
o
|
|
860
868
|
);
|
|
861
869
|
se({
|
|
@@ -864,14 +872,14 @@ class js {
|
|
|
864
872
|
signerXOnlyPubkeyHex: o,
|
|
865
873
|
inputIndex: 0
|
|
866
874
|
});
|
|
867
|
-
const I = ie(
|
|
875
|
+
const I = ie(y[m]);
|
|
868
876
|
A.push({
|
|
869
877
|
htlcVout: m,
|
|
870
878
|
htlcValue: d.htlcValues[m],
|
|
871
879
|
peginTxHex: I,
|
|
872
|
-
peginTxid:
|
|
880
|
+
peginTxid: B[m].txid,
|
|
873
881
|
peginInputSignature: T,
|
|
874
|
-
vaultScriptPubKey:
|
|
882
|
+
vaultScriptPubKey: B[m].vaultScriptPubKey
|
|
875
883
|
});
|
|
876
884
|
}
|
|
877
885
|
return {
|
|
@@ -905,63 +913,63 @@ class js {
|
|
|
905
913
|
* @throws Error if signing or broadcasting fails
|
|
906
914
|
*/
|
|
907
915
|
async signAndBroadcast(t) {
|
|
908
|
-
const { fundedPrePeginTxHex: e, depositorBtcPubkey: o } = t, i = e.startsWith("0x") ? e.slice(2) : e,
|
|
909
|
-
if (
|
|
916
|
+
const { fundedPrePeginTxHex: e, depositorBtcPubkey: o } = t, i = e.startsWith("0x") ? e.slice(2) : e, n = Ct.fromHex(i);
|
|
917
|
+
if (n.ins.length === 0)
|
|
910
918
|
throw new Error("Transaction has no inputs");
|
|
911
|
-
const
|
|
912
|
-
|
|
919
|
+
const r = new ht();
|
|
920
|
+
r.setVersion(n.version), r.setLocktime(n.locktime);
|
|
913
921
|
const a = O.from(
|
|
914
922
|
$(o),
|
|
915
923
|
"hex"
|
|
916
|
-
), c = this.config.mempoolApiUrl, u =
|
|
924
|
+
), c = this.config.mempoolApiUrl, u = n.ins.map((p) => {
|
|
917
925
|
const P = O.from(p.hash).reverse().toString("hex"), l = p.index;
|
|
918
|
-
return
|
|
919
|
-
(
|
|
926
|
+
return Ss(P, l, t.localPrevouts, c).then(
|
|
927
|
+
(y) => ({ input: p, utxoData: y, txid: P, vout: l })
|
|
920
928
|
);
|
|
921
929
|
}), h = await Promise.all(u), g = h.reduce(
|
|
922
930
|
(p, P) => p + BigInt(P.utxoData.value),
|
|
923
931
|
0n
|
|
924
|
-
),
|
|
932
|
+
), w = n.outs.reduce(
|
|
925
933
|
(p, P) => p + BigInt(P.value),
|
|
926
934
|
0n
|
|
927
935
|
);
|
|
928
|
-
if (g <
|
|
936
|
+
if (g < w)
|
|
929
937
|
throw new Error(
|
|
930
|
-
`UTXO value mismatch: total input value (${g} sat) is less than total output value (${
|
|
938
|
+
`UTXO value mismatch: total input value (${g} sat) is less than total output value (${w} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
931
939
|
);
|
|
932
|
-
const
|
|
933
|
-
if (
|
|
940
|
+
const b = g - w;
|
|
941
|
+
if (b > bt)
|
|
934
942
|
throw new Error(
|
|
935
|
-
`Implied transaction fee (${
|
|
943
|
+
`Implied transaction fee (${b} sat) exceeds maximum reasonable fee (${bt} sat). This may indicate manipulated UTXO data.`
|
|
936
944
|
);
|
|
937
|
-
for (const { input: p, utxoData: P, txid: l, vout:
|
|
938
|
-
const A =
|
|
945
|
+
for (const { input: p, utxoData: P, txid: l, vout: y } of h) {
|
|
946
|
+
const A = we(
|
|
939
947
|
{
|
|
940
948
|
value: P.value,
|
|
941
949
|
scriptPubKey: P.scriptPubKey
|
|
942
950
|
},
|
|
943
951
|
a
|
|
944
952
|
);
|
|
945
|
-
|
|
953
|
+
r.addInput({
|
|
946
954
|
hash: p.hash,
|
|
947
955
|
index: p.index,
|
|
948
956
|
sequence: p.sequence,
|
|
949
957
|
...A
|
|
950
958
|
});
|
|
951
959
|
}
|
|
952
|
-
for (const p of
|
|
953
|
-
|
|
960
|
+
for (const p of n.outs)
|
|
961
|
+
r.addOutput({
|
|
954
962
|
script: p.script,
|
|
955
963
|
value: p.value
|
|
956
964
|
});
|
|
957
|
-
await
|
|
965
|
+
await Fe({
|
|
958
966
|
wallet: this.config.btcWallet,
|
|
959
967
|
depositTerms: t.depositTerms,
|
|
960
968
|
fundedPrePeginTxHex: e,
|
|
961
969
|
depositorBtcPubkey: o
|
|
962
970
|
});
|
|
963
|
-
const d =
|
|
964
|
-
|
|
971
|
+
const d = r.toHex(), E = await this.config.btcWallet.signPsbt(d);
|
|
972
|
+
gt({
|
|
965
973
|
requestedPsbtHex: d,
|
|
966
974
|
returnedPsbtHex: E
|
|
967
975
|
});
|
|
@@ -969,11 +977,11 @@ class js {
|
|
|
969
977
|
requestedPsbtHex: d,
|
|
970
978
|
returnedPsbtHex: E
|
|
971
979
|
});
|
|
972
|
-
if (U(this.config.btcWallet) && k !==
|
|
980
|
+
if (U(this.config.btcWallet) && k !== r.data.inputs.length)
|
|
973
981
|
throw new Error(
|
|
974
|
-
`Key-path verification covered ${k} of ${
|
|
982
|
+
`Key-path verification covered ${k} of ${r.data.inputs.length} Pre-PegIn inputs; an approval wallet signs every input key-path, so the unverified ones must not be broadcast.`
|
|
975
983
|
);
|
|
976
|
-
const f =
|
|
984
|
+
const f = ht.fromHex(E);
|
|
977
985
|
try {
|
|
978
986
|
f.finalizeAllInputs();
|
|
979
987
|
} catch (p) {
|
|
@@ -985,7 +993,7 @@ class js {
|
|
|
985
993
|
);
|
|
986
994
|
}
|
|
987
995
|
const v = f.extractTransaction().toHex();
|
|
988
|
-
return await
|
|
996
|
+
return await ve(v, c);
|
|
989
997
|
}
|
|
990
998
|
/**
|
|
991
999
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -1016,8 +1024,8 @@ class js {
|
|
|
1016
1024
|
unsignedPrePeginTx: e,
|
|
1017
1025
|
depositorSignedPeginTx: o,
|
|
1018
1026
|
vaultProvider: i,
|
|
1019
|
-
hashlock:
|
|
1020
|
-
htlcVout:
|
|
1027
|
+
hashlock: n,
|
|
1028
|
+
htlcVout: r,
|
|
1021
1029
|
depositorPayoutBtcAddress: a,
|
|
1022
1030
|
depositorWotsPkHash: c,
|
|
1023
1031
|
popSignature: u
|
|
@@ -1025,27 +1033,27 @@ class js {
|
|
|
1025
1033
|
if (!this.config.ethWallet.account)
|
|
1026
1034
|
throw new Error("Ethereum wallet account not found");
|
|
1027
1035
|
const h = this.config.ethWallet.account.address;
|
|
1028
|
-
if (!
|
|
1036
|
+
if (!dt(u.depositorEthAddress, h))
|
|
1029
1037
|
throw new Error(
|
|
1030
1038
|
`Proof of possession was signed for ${u.depositorEthAddress} but the Ethereum wallet is currently connected to ${h}. Reconnect the original account or call signProofOfPossession() again.`
|
|
1031
1039
|
);
|
|
1032
|
-
const g = await this.assertPopMatchesBtcWallet(u),
|
|
1040
|
+
const g = await this.assertPopMatchesBtcWallet(u), w = u.btcPopSignature, b = C(
|
|
1033
1041
|
u.depositorBtcPubkey
|
|
1034
1042
|
), d = C(e), E = C(o), k = a ?? await this.config.btcWallet.getAddress(), f = this.resolvePayoutScriptPubKey(
|
|
1035
1043
|
g,
|
|
1036
1044
|
k
|
|
1037
|
-
), v =
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
), p = C(
|
|
1045
|
+
), v = q(E), B = await ft(
|
|
1046
|
+
S(v),
|
|
1047
|
+
S(h)
|
|
1048
|
+
), p = C(B);
|
|
1041
1049
|
if (await this.checkVaultExists(p))
|
|
1042
1050
|
throw new Error(
|
|
1043
1051
|
`Vault already exists (ID: ${p}, peginTxHash: ${v}). 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.`
|
|
1044
1052
|
);
|
|
1045
1053
|
const l = this.config.publicClient;
|
|
1046
|
-
let
|
|
1054
|
+
let y;
|
|
1047
1055
|
try {
|
|
1048
|
-
|
|
1056
|
+
y = await l.readContract({
|
|
1049
1057
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1050
1058
|
abi: H,
|
|
1051
1059
|
functionName: "getPegInFee",
|
|
@@ -1060,19 +1068,19 @@ class js {
|
|
|
1060
1068
|
const A = await this.resolveMaxAcceptableCommissionBps(
|
|
1061
1069
|
i,
|
|
1062
1070
|
t.quotedCommissionBps
|
|
1063
|
-
), m =
|
|
1071
|
+
), m = tt({
|
|
1064
1072
|
abi: H,
|
|
1065
1073
|
functionName: "submitPeginRequest",
|
|
1066
1074
|
args: [
|
|
1067
1075
|
h,
|
|
1068
|
-
w,
|
|
1069
1076
|
b,
|
|
1077
|
+
w,
|
|
1070
1078
|
d,
|
|
1071
1079
|
E,
|
|
1072
1080
|
i,
|
|
1073
1081
|
A,
|
|
1074
|
-
r,
|
|
1075
1082
|
n,
|
|
1083
|
+
r,
|
|
1076
1084
|
f,
|
|
1077
1085
|
c
|
|
1078
1086
|
]
|
|
@@ -1082,7 +1090,7 @@ class js {
|
|
|
1082
1090
|
T = await l.estimateGas({
|
|
1083
1091
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1084
1092
|
data: m,
|
|
1085
|
-
value:
|
|
1093
|
+
value: y,
|
|
1086
1094
|
account: this.config.ethWallet.account.address
|
|
1087
1095
|
});
|
|
1088
1096
|
} catch (V) {
|
|
@@ -1093,7 +1101,7 @@ class js {
|
|
|
1093
1101
|
I = await this.config.ethWallet.sendTransaction({
|
|
1094
1102
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1095
1103
|
data: m,
|
|
1096
|
-
value:
|
|
1104
|
+
value: y,
|
|
1097
1105
|
account: this.config.ethWallet.account,
|
|
1098
1106
|
chain: this.config.ethChain,
|
|
1099
1107
|
gas: T
|
|
@@ -1101,18 +1109,18 @@ class js {
|
|
|
1101
1109
|
} catch (V) {
|
|
1102
1110
|
R(V);
|
|
1103
1111
|
}
|
|
1104
|
-
const
|
|
1112
|
+
const G = await Pt({
|
|
1105
1113
|
publicClient: l,
|
|
1106
1114
|
walletAddress: this.config.ethWallet.account.address,
|
|
1107
1115
|
hash: I,
|
|
1108
|
-
timeout:
|
|
1116
|
+
timeout: St
|
|
1109
1117
|
});
|
|
1110
|
-
return
|
|
1118
|
+
return G.status === "reverted" && R(
|
|
1111
1119
|
new Error(
|
|
1112
|
-
`Transaction reverted. Hash: ${
|
|
1120
|
+
`Transaction reverted. Hash: ${G.transactionHash}. Check the transaction on block explorer for details.`
|
|
1113
1121
|
)
|
|
1114
1122
|
), {
|
|
1115
|
-
ethTxHash:
|
|
1123
|
+
ethTxHash: G.transactionHash,
|
|
1116
1124
|
vaultId: p,
|
|
1117
1125
|
peginTxHash: v
|
|
1118
1126
|
};
|
|
@@ -1128,28 +1136,28 @@ class js {
|
|
|
1128
1136
|
* @returns Batch result with per-vault IDs and single ETH tx hash
|
|
1129
1137
|
*/
|
|
1130
1138
|
async registerPeginBatchOnChain(t) {
|
|
1131
|
-
const { vaultProvider: e, unsignedPrePeginTx: o, requests: i, popSignature:
|
|
1139
|
+
const { vaultProvider: e, unsignedPrePeginTx: o, requests: i, popSignature: n } = t;
|
|
1132
1140
|
if (i.length === 0)
|
|
1133
1141
|
throw new Error("Batch pegin requires at least one request");
|
|
1134
1142
|
if (!this.config.ethWallet.account)
|
|
1135
1143
|
throw new Error("Ethereum wallet account not found");
|
|
1136
|
-
const
|
|
1137
|
-
if (!
|
|
1144
|
+
const r = this.config.ethWallet.account.address;
|
|
1145
|
+
if (!dt(n.depositorEthAddress, r))
|
|
1138
1146
|
throw new Error(
|
|
1139
|
-
`Proof of possession was signed for ${
|
|
1147
|
+
`Proof of possession was signed for ${n.depositorEthAddress} but the Ethereum wallet is currently connected to ${r}. Reconnect the original account or call signProofOfPossession() again.`
|
|
1140
1148
|
);
|
|
1141
|
-
const a = await this.assertPopMatchesBtcWallet(
|
|
1149
|
+
const a = await this.assertPopMatchesBtcWallet(n), c = n.btcPopSignature, u = i.map(
|
|
1142
1150
|
(l) => this.resolvePayoutScriptPubKey(
|
|
1143
1151
|
a,
|
|
1144
1152
|
l.depositorPayoutBtcAddress
|
|
1145
1153
|
)
|
|
1146
1154
|
), h = [];
|
|
1147
1155
|
for (const l of i) {
|
|
1148
|
-
const
|
|
1156
|
+
const y = C(
|
|
1149
1157
|
l.depositorSignedPeginTx
|
|
1150
|
-
), A =
|
|
1151
|
-
|
|
1152
|
-
|
|
1158
|
+
), A = q(y), m = await ft(
|
|
1159
|
+
S(A),
|
|
1160
|
+
S(r)
|
|
1153
1161
|
), T = C(m);
|
|
1154
1162
|
if (await this.checkVaultExists(T))
|
|
1155
1163
|
throw new Error(
|
|
@@ -1158,9 +1166,9 @@ class js {
|
|
|
1158
1166
|
h.push({ vaultId: T, peginTxHash: A });
|
|
1159
1167
|
}
|
|
1160
1168
|
const g = this.config.publicClient;
|
|
1161
|
-
let
|
|
1169
|
+
let w;
|
|
1162
1170
|
try {
|
|
1163
|
-
|
|
1171
|
+
w = await g.readContract({
|
|
1164
1172
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1165
1173
|
abi: H,
|
|
1166
1174
|
functionName: "getPegInFee",
|
|
@@ -1172,12 +1180,12 @@ class js {
|
|
|
1172
1180
|
{ cause: l }
|
|
1173
1181
|
);
|
|
1174
1182
|
}
|
|
1175
|
-
const
|
|
1183
|
+
const b = w * BigInt(i.length), d = await this.resolveMaxAcceptableCommissionBps(
|
|
1176
1184
|
e,
|
|
1177
1185
|
t.quotedCommissionBps
|
|
1178
1186
|
), E = C(
|
|
1179
|
-
|
|
1180
|
-
), k = C(o), f = i.map((l,
|
|
1187
|
+
n.depositorBtcPubkey
|
|
1188
|
+
), k = C(o), f = i.map((l, y) => ({
|
|
1181
1189
|
depositorBtcPubKey: E,
|
|
1182
1190
|
btcPopSignature: c,
|
|
1183
1191
|
unsignedPrePeginTx: k,
|
|
@@ -1187,24 +1195,24 @@ class js {
|
|
|
1187
1195
|
hashlock: l.hashlock,
|
|
1188
1196
|
htlcVout: l.htlcVout,
|
|
1189
1197
|
referralCode: Kt,
|
|
1190
|
-
depositorPayoutBtcAddress: u[
|
|
1198
|
+
depositorPayoutBtcAddress: u[y],
|
|
1191
1199
|
depositorWotsPkHash: l.depositorWotsPkHash
|
|
1192
|
-
})), v =
|
|
1200
|
+
})), v = tt({
|
|
1193
1201
|
abi: H,
|
|
1194
1202
|
functionName: "submitPeginRequestBatch",
|
|
1195
1203
|
args: [
|
|
1196
|
-
|
|
1204
|
+
r,
|
|
1197
1205
|
e,
|
|
1198
1206
|
d,
|
|
1199
1207
|
f
|
|
1200
1208
|
]
|
|
1201
1209
|
});
|
|
1202
|
-
let
|
|
1210
|
+
let B;
|
|
1203
1211
|
try {
|
|
1204
|
-
|
|
1212
|
+
B = await g.estimateGas({
|
|
1205
1213
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1206
1214
|
data: v,
|
|
1207
|
-
value:
|
|
1215
|
+
value: b,
|
|
1208
1216
|
account: this.config.ethWallet.account.address
|
|
1209
1217
|
});
|
|
1210
1218
|
} catch (l) {
|
|
@@ -1215,19 +1223,19 @@ class js {
|
|
|
1215
1223
|
p = await this.config.ethWallet.sendTransaction({
|
|
1216
1224
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1217
1225
|
data: v,
|
|
1218
|
-
value:
|
|
1226
|
+
value: b,
|
|
1219
1227
|
account: this.config.ethWallet.account,
|
|
1220
1228
|
chain: this.config.ethChain,
|
|
1221
|
-
gas:
|
|
1229
|
+
gas: B
|
|
1222
1230
|
});
|
|
1223
1231
|
} catch (l) {
|
|
1224
1232
|
R(l);
|
|
1225
1233
|
}
|
|
1226
|
-
const P = await
|
|
1234
|
+
const P = await Pt({
|
|
1227
1235
|
publicClient: g,
|
|
1228
1236
|
walletAddress: this.config.ethWallet.account.address,
|
|
1229
1237
|
hash: p,
|
|
1230
|
-
timeout:
|
|
1238
|
+
timeout: St
|
|
1231
1239
|
});
|
|
1232
1240
|
return P.status === "reverted" && R(
|
|
1233
1241
|
new Error(
|
|
@@ -1247,7 +1255,7 @@ class js {
|
|
|
1247
1255
|
);
|
|
1248
1256
|
let o;
|
|
1249
1257
|
try {
|
|
1250
|
-
o = await new
|
|
1258
|
+
o = await new Se(
|
|
1251
1259
|
this.config.publicClient,
|
|
1252
1260
|
this.config.vaultContracts.btcVaultRegistry
|
|
1253
1261
|
).getVaultProviderCommission(t);
|
|
@@ -1258,9 +1266,9 @@ class js {
|
|
|
1258
1266
|
);
|
|
1259
1267
|
}
|
|
1260
1268
|
if (e !== void 0) {
|
|
1261
|
-
if (o > e +
|
|
1269
|
+
if (o > e + ot)
|
|
1262
1270
|
throw new Error(
|
|
1263
|
-
`Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${o} bps (allowed drift ${
|
|
1271
|
+
`Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${o} bps (allowed drift ${ot} bps). Please refresh to see the new commission and try again.`
|
|
1264
1272
|
);
|
|
1265
1273
|
return Y(e);
|
|
1266
1274
|
}
|
|
@@ -1304,17 +1312,17 @@ class js {
|
|
|
1304
1312
|
* on-chain payout-script registration.
|
|
1305
1313
|
*/
|
|
1306
1314
|
resolvePayoutScriptPubKey(t, e) {
|
|
1307
|
-
if (!
|
|
1315
|
+
if (!mt(
|
|
1308
1316
|
e,
|
|
1309
1317
|
t,
|
|
1310
1318
|
this.config.btcNetwork
|
|
1311
1319
|
))
|
|
1312
|
-
throw
|
|
1320
|
+
throw S(t).length === le && vs(e, this.config.btcNetwork) ? new Error(
|
|
1313
1321
|
`BTC payout address "${e}" is a P2WPKH (Native SegWit) address, but the connected wallet only exposes an x-only public key. P2WPKH validation requires a compressed key with known y-parity. Use a P2TR (Taproot) payout address instead.`
|
|
1314
1322
|
) : new Error(
|
|
1315
1323
|
`BTC payout address "${e}" is not derived from the connected wallet's public key. The payout sink must be controlled by the same key that signs the pegin; refusing to register a mismatched address.`
|
|
1316
1324
|
);
|
|
1317
|
-
const o =
|
|
1325
|
+
const o = wt(this.config.btcNetwork);
|
|
1318
1326
|
try {
|
|
1319
1327
|
return `0x${At.address.toOutputScript(e, o).toString("hex")}`;
|
|
1320
1328
|
} catch {
|
|
@@ -1341,15 +1349,15 @@ class js {
|
|
|
1341
1349
|
throw new Error("Ethereum wallet account not found");
|
|
1342
1350
|
const t = this.config.ethWallet.account.address, e = $(
|
|
1343
1351
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1344
|
-
), o = this.config.vaultContracts.btcVaultRegistry, i = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${o.toLowerCase()}`,
|
|
1352
|
+
), o = this.config.vaultContracts.btcVaultRegistry, i = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${o.toLowerCase()}`, n = await this.config.btcWallet.signMessage(
|
|
1345
1353
|
i,
|
|
1346
1354
|
"bip322-simple"
|
|
1347
|
-
),
|
|
1348
|
-
return
|
|
1355
|
+
), r = Ne(n);
|
|
1356
|
+
return Ts(
|
|
1349
1357
|
new TextEncoder().encode(i),
|
|
1350
1358
|
e,
|
|
1351
|
-
|
|
1352
|
-
), { btcPopSignature:
|
|
1359
|
+
r
|
|
1360
|
+
), { btcPopSignature: r, depositorEthAddress: t, depositorBtcPubkey: e };
|
|
1353
1361
|
}
|
|
1354
1362
|
/**
|
|
1355
1363
|
* Confirm the connected BTC wallet still matches the PoP it produced, and
|
|
@@ -1384,49 +1392,49 @@ class js {
|
|
|
1384
1392
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1385
1393
|
}
|
|
1386
1394
|
}
|
|
1387
|
-
const
|
|
1388
|
-
function
|
|
1389
|
-
const e = Xt.repeat(
|
|
1390
|
-
return `0x${
|
|
1395
|
+
const _s = 80, Bs = 250, As = 300, Cs = 22, Xt = "ab";
|
|
1396
|
+
function Is(s, t) {
|
|
1397
|
+
const e = Xt.repeat(As), o = S(s).toLowerCase(), i = t.toString(16).padStart(8, "0"), n = `${o}${i}`, r = e.slice(n.length);
|
|
1398
|
+
return `0x${n}${r}`;
|
|
1391
1399
|
}
|
|
1392
|
-
function
|
|
1400
|
+
function Hs(s, t) {
|
|
1393
1401
|
const e = (o) => `0x${Xt.repeat(o)}`;
|
|
1394
1402
|
return {
|
|
1395
1403
|
depositorBtcPubKey: e(32),
|
|
1396
|
-
btcPopSignature: e(
|
|
1404
|
+
btcPopSignature: e(_s),
|
|
1397
1405
|
unsignedPrePeginTx: e(Bs),
|
|
1398
|
-
depositorSignedPeginTx:
|
|
1406
|
+
depositorSignedPeginTx: Is(
|
|
1399
1407
|
s,
|
|
1400
1408
|
t
|
|
1401
1409
|
),
|
|
1402
1410
|
hashlock: e(32),
|
|
1403
1411
|
htlcVout: t,
|
|
1404
1412
|
referralCode: Kt,
|
|
1405
|
-
depositorPayoutBtcAddress: e(
|
|
1413
|
+
depositorPayoutBtcAddress: e(Cs),
|
|
1406
1414
|
depositorWotsPkHash: e(32)
|
|
1407
1415
|
};
|
|
1408
1416
|
}
|
|
1409
|
-
async function
|
|
1417
|
+
async function Js(s) {
|
|
1410
1418
|
const {
|
|
1411
1419
|
publicClient: t,
|
|
1412
1420
|
btcVaultRegistry: e,
|
|
1413
1421
|
depositorEthAddress: o,
|
|
1414
1422
|
vaultProvider: i,
|
|
1415
|
-
batchSize:
|
|
1423
|
+
batchSize: n
|
|
1416
1424
|
} = s;
|
|
1417
|
-
if (
|
|
1425
|
+
if (n <= 0)
|
|
1418
1426
|
throw new Error(
|
|
1419
|
-
`estimateSubmitPeginRequestBatchGas requires batchSize >= 1 (received ${
|
|
1427
|
+
`estimateSubmitPeginRequestBatchGas requires batchSize >= 1 (received ${n})`
|
|
1420
1428
|
);
|
|
1421
1429
|
const a = await t.readContract({
|
|
1422
1430
|
address: e,
|
|
1423
1431
|
abi: H,
|
|
1424
1432
|
functionName: "getPegInFee",
|
|
1425
1433
|
args: [i]
|
|
1426
|
-
}) * BigInt(
|
|
1427
|
-
{ length:
|
|
1428
|
-
(h, g) =>
|
|
1429
|
-
), u =
|
|
1434
|
+
}) * BigInt(n), c = Array.from(
|
|
1435
|
+
{ length: n },
|
|
1436
|
+
(h, g) => Hs(o, g)
|
|
1437
|
+
), u = tt({
|
|
1430
1438
|
abi: H,
|
|
1431
1439
|
functionName: "submitPeginRequestBatch",
|
|
1432
1440
|
args: [
|
|
@@ -1444,15 +1452,15 @@ async function Qs(s) {
|
|
|
1444
1452
|
});
|
|
1445
1453
|
}
|
|
1446
1454
|
export {
|
|
1447
|
-
|
|
1455
|
+
ot as C,
|
|
1448
1456
|
Ht as M,
|
|
1449
|
-
|
|
1457
|
+
Zs as P,
|
|
1450
1458
|
Y as a,
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1459
|
+
Ve as b,
|
|
1460
|
+
fs as c,
|
|
1461
|
+
ds as d,
|
|
1462
|
+
Js as e,
|
|
1463
|
+
Fe as f,
|
|
1464
|
+
ps as g
|
|
1457
1465
|
};
|
|
1458
|
-
//# sourceMappingURL=PeginManager
|
|
1466
|
+
//# sourceMappingURL=PeginManager-Bsv6caG3.js.map
|