@babylonlabs-io/ts-sdk 0.48.1 → 0.48.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/{PayoutManager-BbemBIo9.js → PayoutManager-D02AePm4.js} +78 -65
- package/dist/PayoutManager-D02AePm4.js.map +1 -0
- package/dist/PayoutManager-DD1audlx.cjs +2 -0
- package/dist/PayoutManager-DD1audlx.cjs.map +1 -0
- package/dist/{PeginManager-BMO6R9I9.js → PeginManager-6seoi9mV.js} +217 -198
- package/dist/PeginManager-6seoi9mV.js.map +1 -0
- package/dist/PeginManager-CHZieoEQ.cjs +2 -0
- package/dist/PeginManager-CHZieoEQ.cjs.map +1 -0
- package/dist/buildAndBroadcastRefund-Bi07LxuY.cjs +2 -0
- package/dist/buildAndBroadcastRefund-Bi07LxuY.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-hM9Wo0VZ.js → buildAndBroadcastRefund-DXHs6unL.js} +448 -422
- package/dist/buildAndBroadcastRefund-DXHs6unL.js.map +1 -0
- package/dist/{challengeAssert-1fy_EzAi.js → challengeAssert-ChvLypwc.js} +7 -7
- package/dist/{challengeAssert-1fy_EzAi.js.map → challengeAssert-ChvLypwc.js.map} +1 -1
- package/dist/challengeAssert-Culc7DoS.cjs +2 -0
- package/dist/{challengeAssert-DEw-z3n9.cjs.map → challengeAssert-Culc7DoS.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +170 -169
- package/dist/{noPayout-BwSaoU7w.js → noPayout-CA4-x5vZ.js} +2 -2
- package/dist/{noPayout-BwSaoU7w.js.map → noPayout-CA4-x5vZ.js.map} +1 -1
- package/dist/noPayout-CJ_Acpl_.cjs +2 -0
- package/dist/{noPayout-B2Xd40nk.cjs.map → noPayout-CJ_Acpl_.cjs.map} +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +168 -167
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +2 -2
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +8 -7
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +30 -29
- package/dist/tbv/core/primitives/psbt/__tests__/verifyScriptPathSchnorrSignature.test.d.ts +14 -0
- package/dist/tbv/core/primitives/psbt/__tests__/verifyScriptPathSchnorrSignature.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/verifyScriptPathSchnorrSignature.d.ts +53 -0
- package/dist/tbv/core/primitives/psbt/verifyScriptPathSchnorrSignature.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +2 -2
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +168 -167
- package/dist/verifyScriptPathSchnorrSignature-D43cncKJ.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-D43cncKJ.cjs.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-DFJAEleY.js +563 -0
- package/dist/verifyScriptPathSchnorrSignature-DFJAEleY.js.map +1 -0
- package/package.json +1 -1
- package/dist/PayoutManager-BLpgkfOS.cjs +0 -2
- package/dist/PayoutManager-BLpgkfOS.cjs.map +0 -1
- package/dist/PayoutManager-BbemBIo9.js.map +0 -1
- package/dist/PeginManager-BMO6R9I9.js.map +0 -1
- package/dist/PeginManager-CfkjDMy7.cjs +0 -2
- package/dist/PeginManager-CfkjDMy7.cjs.map +0 -1
- package/dist/assertPsbtUnsignedTxMatches-BHyBdtxs.js +0 -481
- package/dist/assertPsbtUnsignedTxMatches-BHyBdtxs.js.map +0 -1
- package/dist/assertPsbtUnsignedTxMatches-s9H0Qqkl.cjs +0 -2
- package/dist/assertPsbtUnsignedTxMatches-s9H0Qqkl.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-CLvF5ETe.cjs +0 -2
- package/dist/buildAndBroadcastRefund-CLvF5ETe.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-hM9Wo0VZ.js.map +0 -1
- package/dist/challengeAssert-DEw-z3n9.cjs +0 -2
- package/dist/noPayout-B2Xd40nk.cjs +0 -2
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
var qt = Object.defineProperty;
|
|
2
2
|
var zt = (n, t, e) => t in n ? qt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
3
|
var x = (n, t, e) => zt(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { s as it, c as
|
|
4
|
+
import { s as it, c as At, H as Yt, r as V, a as W, b as lt, u as jt, d as ut, e as ht, f as dt, g as Zt } from "./sha2-BYVxyZzX.js";
|
|
5
5
|
import * as Ct from "bitcoinjs-lib";
|
|
6
6
|
import { Transaction as Qt, Psbt as gt } from "bitcoinjs-lib";
|
|
7
7
|
import { Buffer as J } from "buffer";
|
|
8
8
|
import { isAddressEqual as ft, encodeFunctionData as tt, zeroAddress as Jt } from "viem";
|
|
9
|
-
import { B as
|
|
9
|
+
import { B as A } from "./BTCVaultRegistry.abi-Chs4AFBj.js";
|
|
10
10
|
import { h as H } from "./errors-Blc-JWnI.js";
|
|
11
11
|
import { expandWotsSeed as te, expandHashlockSecret as ee, expandAuthAnchor as ne, deriveVaultId as pt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
-
import {
|
|
13
|
-
import { b as
|
|
14
|
-
import { u as X, h as et, e as
|
|
15
|
-
import { c as
|
|
12
|
+
import { a as mt, b as se, d as Pt, f as oe } from "./verifyScriptPathSchnorrSignature-DFJAEleY.js";
|
|
13
|
+
import { b as re, e as ie, f as ae } from "./peginInput-BPRB9tUi.js";
|
|
14
|
+
import { u as X, h as et, e as S, p as ce, i as bt, s as T, j as wt, X as le } from "./bitcoin-B5aNKtsk.js";
|
|
15
|
+
import { c as ue } from "./signing-DaLvGwQe.js";
|
|
16
16
|
import { M as yt } from "./validation-CxqROCno.js";
|
|
17
|
-
import { c as
|
|
18
|
-
import { s as
|
|
19
|
-
import { p as
|
|
20
|
-
import { p as
|
|
17
|
+
import { c as he, a as de } from "./PayoutManager-D02AePm4.js";
|
|
18
|
+
import { s as ge, f as q, i as fe, w as xt } from "./waitForTransactionReceiptSmartAware-Ckg_oZAo.js";
|
|
19
|
+
import { p as pe, f as me } from "./fundPeginTransaction-96FxwYYJ.js";
|
|
20
|
+
import { p as Pe, V as be, h as we } from "./mempoolApi-BxT89SAq.js";
|
|
21
21
|
const M = /* @__PURE__ */ BigInt(2 ** 32 - 1), kt = /* @__PURE__ */ BigInt(32);
|
|
22
|
-
function
|
|
22
|
+
function ye(n, t = !1) {
|
|
23
23
|
return t ? { h: Number(n & M), l: Number(n >> kt & M) } : { h: Number(n >> kt & M) | 0, l: Number(n & M) | 0 };
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function xe(n, t = !1) {
|
|
26
26
|
const e = n.length;
|
|
27
27
|
let s = new Uint32Array(e), o = new Uint32Array(e);
|
|
28
28
|
for (let r = 0; r < e; r++) {
|
|
29
|
-
const { h: i, l: a } =
|
|
29
|
+
const { h: i, l: a } = ye(n[r], t);
|
|
30
30
|
[s[r], o[r]] = [i, a];
|
|
31
31
|
}
|
|
32
32
|
return [s, o];
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const ke = (n, t, e) => n << e | t >>> 32 - e, Ee = (n, t, e) => t << e | n >>> 32 - e, Te = (n, t, e) => t << e - 32 | n >>> 64 - e, _e = (n, t, e) => n << e - 32 | t >>> 64 - e, U = 32, z = 32, nt = 36, Ht = 32, K = 4, Be = K + U + K + Ht;
|
|
35
35
|
function st(n, t, e) {
|
|
36
36
|
n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = e & 255;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function Se(n) {
|
|
39
39
|
if (n.txid.length !== z)
|
|
40
40
|
throw new Error(
|
|
41
41
|
`outpoint.txid must be exactly ${z} bytes, got ${n.txid.length}`
|
|
@@ -56,7 +56,7 @@ function ve(n) {
|
|
|
56
56
|
throw new Error(
|
|
57
57
|
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
58
58
|
);
|
|
59
|
-
const t = n.map(
|
|
59
|
+
const t = n.map(Se);
|
|
60
60
|
t.sort(Et);
|
|
61
61
|
for (let s = 1; s < t.length; s++)
|
|
62
62
|
if (Et(t[s - 1], t[s]) === 0)
|
|
@@ -68,18 +68,18 @@ function ve(n) {
|
|
|
68
68
|
e.set(t[s], s * nt);
|
|
69
69
|
return it(e);
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function Ie(n) {
|
|
72
72
|
if (n.depositorBtcPubkey.length !== U)
|
|
73
73
|
throw new Error(
|
|
74
74
|
`vaultContext: depositorBtcPubkey must be exactly ${U} bytes, got ${n.depositorBtcPubkey.length}`
|
|
75
75
|
);
|
|
76
|
-
const t = ve(n.fundingOutpoints), e = new Uint8Array(
|
|
76
|
+
const t = ve(n.fundingOutpoints), e = new Uint8Array(Be);
|
|
77
77
|
let s = 0;
|
|
78
78
|
return st(e, s, U), s += K, e.set(n.depositorBtcPubkey, s), s += U, st(e, s, Ht), s += K, e.set(t, s), e;
|
|
79
79
|
}
|
|
80
|
-
const Ae = "babylon-btc-vault", Ot = 32, Tt = Ot * 2,
|
|
81
|
-
async function
|
|
82
|
-
const e =
|
|
80
|
+
const Ae = "babylon-btc-vault", Ot = 32, Tt = Ot * 2, Ce = /^[0-9a-f]+$/;
|
|
81
|
+
async function He(n, t) {
|
|
82
|
+
const e = Ie(t), s = X(e), o = await n.deriveContextHash(Ae, s);
|
|
83
83
|
if (typeof o != "string")
|
|
84
84
|
throw new Error(
|
|
85
85
|
`deriveVaultRoot: wallet must return a string, got ${typeof o}`
|
|
@@ -88,13 +88,13 @@ async function Ce(n, t) {
|
|
|
88
88
|
throw new Error(
|
|
89
89
|
`deriveVaultRoot: wallet must return a ${Tt}-character hex string (${Ot} bytes), got length ${o.length}`
|
|
90
90
|
);
|
|
91
|
-
if (!
|
|
91
|
+
if (!Ce.test(o))
|
|
92
92
|
throw new Error(
|
|
93
93
|
"deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
|
|
94
94
|
);
|
|
95
95
|
return et(o);
|
|
96
96
|
}
|
|
97
|
-
const
|
|
97
|
+
const Oe = /* @__PURE__ */ Uint8Array.from([
|
|
98
98
|
7,
|
|
99
99
|
4,
|
|
100
100
|
13,
|
|
@@ -111,11 +111,11 @@ const He = /* @__PURE__ */ Uint8Array.from([
|
|
|
111
111
|
14,
|
|
112
112
|
11,
|
|
113
113
|
8
|
|
114
|
-
]), Rt = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)),
|
|
115
|
-
const e = [[Rt], [
|
|
114
|
+
]), Rt = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), Re = Rt.map((n) => (9 * n + 5) % 16), $t = /* @__PURE__ */ (() => {
|
|
115
|
+
const e = [[Rt], [Re]];
|
|
116
116
|
for (let s = 0; s < 4; s++)
|
|
117
117
|
for (let o of e)
|
|
118
|
-
o.push(o[s].map((r) =>
|
|
118
|
+
o.push(o[s].map((r) => Oe[r]));
|
|
119
119
|
return e;
|
|
120
120
|
})(), Ut = $t[0], Vt = $t[1], Mt = /* @__PURE__ */ [
|
|
121
121
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
@@ -123,13 +123,13 @@ const He = /* @__PURE__ */ Uint8Array.from([
|
|
|
123
123
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
124
124
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
125
125
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
126
|
-
].map((n) => Uint8Array.from(n)),
|
|
126
|
+
].map((n) => Uint8Array.from(n)), $e = /* @__PURE__ */ Ut.map((n, t) => n.map((e) => Mt[t][e])), Ue = /* @__PURE__ */ Vt.map((n, t) => n.map((e) => Mt[t][e])), Ve = /* @__PURE__ */ Uint32Array.from([
|
|
127
127
|
0,
|
|
128
128
|
1518500249,
|
|
129
129
|
1859775393,
|
|
130
130
|
2400959708,
|
|
131
131
|
2840853838
|
|
132
|
-
]),
|
|
132
|
+
]), Me = /* @__PURE__ */ Uint32Array.from([
|
|
133
133
|
1352829926,
|
|
134
134
|
1548603684,
|
|
135
135
|
1836072691,
|
|
@@ -140,7 +140,7 @@ function _t(n, t, e, s) {
|
|
|
140
140
|
return n === 0 ? t ^ e ^ s : n === 1 ? t & e | ~t & s : n === 2 ? (t | ~e) ^ s : n === 3 ? t & s | e & ~s : t ^ (e | ~s);
|
|
141
141
|
}
|
|
142
142
|
const N = /* @__PURE__ */ new Uint32Array(16);
|
|
143
|
-
class
|
|
143
|
+
class Ne extends Yt {
|
|
144
144
|
constructor() {
|
|
145
145
|
super(64, 20, 8, !0);
|
|
146
146
|
x(this, "h0", 1732584193);
|
|
@@ -159,19 +159,19 @@ class Me extends Yt {
|
|
|
159
159
|
process(e, s) {
|
|
160
160
|
for (let g = 0; g < 16; g++, s += 4)
|
|
161
161
|
N[g] = e.getUint32(s, !0);
|
|
162
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0,
|
|
162
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, h = c, l = this.h3 | 0, m = l, P = this.h4 | 0, b = P;
|
|
163
163
|
for (let g = 0; g < 5; g++) {
|
|
164
|
-
const f = 4 - g, k =
|
|
165
|
-
for (let
|
|
166
|
-
const
|
|
167
|
-
o = P, P = l, l = V(c, 10) | 0, c = i, i =
|
|
164
|
+
const f = 4 - g, k = Ve[g], v = Me[g], E = Ut[g], p = Vt[g], w = $e[g], y = Ue[g];
|
|
165
|
+
for (let d = 0; d < 16; d++) {
|
|
166
|
+
const u = V(o + _t(g, i, c, l) + N[E[d]] + k, w[d]) + P | 0;
|
|
167
|
+
o = P, P = l, l = V(c, 10) | 0, c = i, i = u;
|
|
168
168
|
}
|
|
169
|
-
for (let
|
|
170
|
-
const
|
|
171
|
-
r = b, b = m, m = V(
|
|
169
|
+
for (let d = 0; d < 16; d++) {
|
|
170
|
+
const u = V(r + _t(f, a, h, m) + N[p[d]] + v, y[d]) + b | 0;
|
|
171
|
+
r = b, b = m, m = V(h, 10) | 0, h = a, a = u;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
this.set(this.h1 + c + m | 0, this.h2 + l + b | 0, this.h3 + P + r | 0, this.h4 + o + a | 0, this.h0 + i +
|
|
174
|
+
this.set(this.h1 + c + m | 0, this.h2 + l + b | 0, this.h3 + P + r | 0, this.h4 + o + a | 0, this.h0 + i + h | 0);
|
|
175
175
|
}
|
|
176
176
|
roundClean() {
|
|
177
177
|
W(N);
|
|
@@ -180,29 +180,29 @@ class Me extends Yt {
|
|
|
180
180
|
this.destroyed = !0, W(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
const
|
|
183
|
+
const Fe = /* @__PURE__ */ At(() => new Ne()), Le = BigInt(0), R = BigInt(1), We = BigInt(2), Xe = BigInt(7), Ke = BigInt(256), De = BigInt(113), Nt = [], Ft = [], Lt = [];
|
|
184
184
|
for (let n = 0, t = R, e = 1, s = 0; n < 24; n++) {
|
|
185
185
|
[e, s] = [s, (2 * e + 3 * s) % 5], Nt.push(2 * (5 * s + e)), Ft.push((n + 1) * (n + 2) / 2 % 64);
|
|
186
|
-
let o =
|
|
186
|
+
let o = Le;
|
|
187
187
|
for (let r = 0; r < 7; r++)
|
|
188
|
-
t = (t << R ^ (t >>
|
|
188
|
+
t = (t << R ^ (t >> Xe) * De) % Ke, t & We && (o ^= R << (R << BigInt(r)) - R);
|
|
189
189
|
Lt.push(o);
|
|
190
190
|
}
|
|
191
|
-
const Wt =
|
|
192
|
-
function
|
|
191
|
+
const Wt = xe(Lt, !0), Ge = Wt[0], qe = Wt[1], Bt = (n, t, e) => e > 32 ? Te(n, t, e) : ke(n, t, e), St = (n, t, e) => e > 32 ? _e(n, t, e) : Ee(n, t, e);
|
|
192
|
+
function ze(n, t = 24) {
|
|
193
193
|
const e = new Uint32Array(10);
|
|
194
194
|
for (let s = 24 - t; s < 24; s++) {
|
|
195
195
|
for (let i = 0; i < 10; i++)
|
|
196
196
|
e[i] = n[i] ^ n[i + 10] ^ n[i + 20] ^ n[i + 30] ^ n[i + 40];
|
|
197
197
|
for (let i = 0; i < 10; i += 2) {
|
|
198
|
-
const a = (i + 8) % 10, c = (i + 2) % 10,
|
|
198
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, h = e[c], l = e[c + 1], m = Bt(h, l, 1) ^ e[a], P = St(h, l, 1) ^ e[a + 1];
|
|
199
199
|
for (let b = 0; b < 50; b += 10)
|
|
200
200
|
n[i + b] ^= m, n[i + b + 1] ^= P;
|
|
201
201
|
}
|
|
202
202
|
let o = n[2], r = n[3];
|
|
203
203
|
for (let i = 0; i < 24; i++) {
|
|
204
|
-
const a = Ft[i], c = Bt(o, r, a),
|
|
205
|
-
o = n[l], r = n[l + 1], n[l] = c, n[l + 1] =
|
|
204
|
+
const a = Ft[i], c = Bt(o, r, a), h = St(o, r, a), l = Nt[i];
|
|
205
|
+
o = n[l], r = n[l + 1], n[l] = c, n[l + 1] = h;
|
|
206
206
|
}
|
|
207
207
|
for (let i = 0; i < 50; i += 10) {
|
|
208
208
|
for (let a = 0; a < 10; a++)
|
|
@@ -210,7 +210,7 @@ function qe(n, t = 24) {
|
|
|
210
210
|
for (let a = 0; a < 10; a++)
|
|
211
211
|
n[i + a] ^= ~e[(a + 2) % 10] & e[(a + 4) % 10];
|
|
212
212
|
}
|
|
213
|
-
n[0] ^=
|
|
213
|
+
n[0] ^= Ge[s], n[1] ^= qe[s];
|
|
214
214
|
}
|
|
215
215
|
W(e);
|
|
216
216
|
}
|
|
@@ -236,7 +236,7 @@ class at {
|
|
|
236
236
|
return this._cloneInto();
|
|
237
237
|
}
|
|
238
238
|
keccak() {
|
|
239
|
-
ut(this.state32),
|
|
239
|
+
ut(this.state32), ze(this.state32, this.rounds), ut(this.state32), this.posOut = 0, this.pos = 0;
|
|
240
240
|
}
|
|
241
241
|
update(t) {
|
|
242
242
|
ht(this), dt(t);
|
|
@@ -290,21 +290,21 @@ class at {
|
|
|
290
290
|
return t || (t = new at(e, 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;
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
const
|
|
293
|
+
const Ye = (n, t, e, s = {}) => At(() => new at(t, n, e), s), je = /* @__PURE__ */ Ye(1, 136, 32), vt = 64, _ = 20, ot = 4, Xt = 2, Ze = 0, Qe = 1, F = [64, 64], Je = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
294
294
|
function ct(n) {
|
|
295
|
-
return
|
|
295
|
+
return Fe(it(n));
|
|
296
296
|
}
|
|
297
297
|
function Kt(n) {
|
|
298
298
|
return (1 << n) - 1;
|
|
299
299
|
}
|
|
300
|
-
function
|
|
300
|
+
function tn(n) {
|
|
301
301
|
let t = 1;
|
|
302
302
|
for (; t * t < n + 1; ) t++;
|
|
303
303
|
return Math.max(t, 2);
|
|
304
304
|
}
|
|
305
|
-
function
|
|
305
|
+
function en(n) {
|
|
306
306
|
const t = ot, e = n * Kt(t);
|
|
307
|
-
return { d: t, n, checksum_radix:
|
|
307
|
+
return { d: t, n, checksum_radix: tn(e) };
|
|
308
308
|
}
|
|
309
309
|
function Y(n, t) {
|
|
310
310
|
const e = [];
|
|
@@ -323,7 +323,7 @@ function j(n, t) {
|
|
|
323
323
|
e = ct(e);
|
|
324
324
|
return e;
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function nn(n, t) {
|
|
327
327
|
const e = Kt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * e / t.checksum_radix), r = [];
|
|
328
328
|
for (let l = 0; l < t.n; l++) {
|
|
329
329
|
const m = Y(n, l + Xt), P = j(m, e);
|
|
@@ -331,37 +331,37 @@ function en(n, t) {
|
|
|
331
331
|
}
|
|
332
332
|
const i = Y(
|
|
333
333
|
n,
|
|
334
|
-
|
|
334
|
+
Ze
|
|
335
335
|
), a = j(
|
|
336
336
|
i,
|
|
337
337
|
s
|
|
338
338
|
), c = Y(
|
|
339
339
|
n,
|
|
340
|
-
|
|
341
|
-
),
|
|
340
|
+
Qe
|
|
341
|
+
), h = j(
|
|
342
342
|
c,
|
|
343
343
|
o
|
|
344
344
|
);
|
|
345
345
|
return {
|
|
346
346
|
config: t,
|
|
347
347
|
message_terminals: r,
|
|
348
|
-
checksum_major_terminal: Array.from(
|
|
348
|
+
checksum_major_terminal: Array.from(h),
|
|
349
349
|
checksum_minor_terminal: Array.from(a)
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
async function
|
|
352
|
+
async function sn(n) {
|
|
353
353
|
try {
|
|
354
|
-
if (n.length !==
|
|
354
|
+
if (n.length !== vt)
|
|
355
355
|
throw new Error(
|
|
356
|
-
`WOTS seed must be exactly ${
|
|
356
|
+
`WOTS seed must be exactly ${vt} bytes, got ${n.length}`
|
|
357
357
|
);
|
|
358
358
|
const t = [];
|
|
359
359
|
for (let e = 0; e < F.length; e++) {
|
|
360
|
-
const s = F[e], o =
|
|
360
|
+
const s = F[e], o = en(s), r = new Uint8Array(n.length + 1);
|
|
361
361
|
r.set(n), r[n.length] = e;
|
|
362
362
|
const i = ct(r);
|
|
363
363
|
try {
|
|
364
|
-
const a =
|
|
364
|
+
const a = nn(i, o);
|
|
365
365
|
if (a.config.d !== ot)
|
|
366
366
|
throw new Error(
|
|
367
367
|
`Block ${e}: expected d=${ot}, got d=${a.config.d}`
|
|
@@ -414,7 +414,7 @@ function Z(n, t, e) {
|
|
|
414
414
|
);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
-
function
|
|
417
|
+
function on(n) {
|
|
418
418
|
if (n.length === 0)
|
|
419
419
|
throw new Error("Public keys array must not be empty");
|
|
420
420
|
for (let r = 0; r < n.length; r++) {
|
|
@@ -433,24 +433,24 @@ function sn(n) {
|
|
|
433
433
|
for (const i of r.message_terminals)
|
|
434
434
|
e.set(i, s), s += _;
|
|
435
435
|
}
|
|
436
|
-
const o =
|
|
437
|
-
return `0x${
|
|
436
|
+
const o = je(e);
|
|
437
|
+
return `0x${Je(o)}`;
|
|
438
438
|
}
|
|
439
|
-
async function
|
|
439
|
+
async function rn(n, t) {
|
|
440
440
|
const e = [], s = [], o = [], r = [];
|
|
441
441
|
try {
|
|
442
442
|
for (let i = 0; i < t; i++) {
|
|
443
443
|
const a = await te(n, i);
|
|
444
444
|
try {
|
|
445
|
-
const
|
|
446
|
-
e.push(
|
|
445
|
+
const h = await sn(a);
|
|
446
|
+
e.push(h), s.push(on(h));
|
|
447
447
|
} finally {
|
|
448
448
|
a.fill(0);
|
|
449
449
|
}
|
|
450
450
|
const c = await ee(n, i);
|
|
451
451
|
try {
|
|
452
|
-
const
|
|
453
|
-
o.push(
|
|
452
|
+
const h = X(c);
|
|
453
|
+
o.push(h), r.push(he(S(h)).slice(2));
|
|
454
454
|
} finally {
|
|
455
455
|
c.fill(0);
|
|
456
456
|
}
|
|
@@ -460,33 +460,33 @@ async function on(n, t) {
|
|
|
460
460
|
}
|
|
461
461
|
return { perVaultWotsKeys: e, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
|
|
462
462
|
}
|
|
463
|
-
const
|
|
463
|
+
const an = /^0x[0-9a-f]+$/i, cn = /^[0-9a-f]+$/i, ln = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
464
464
|
function $(n) {
|
|
465
465
|
if (typeof n != "string" || n.length === 0)
|
|
466
466
|
throw new Error("BTC wallet returned empty public key");
|
|
467
|
-
return
|
|
467
|
+
return ce(n).toLowerCase();
|
|
468
468
|
}
|
|
469
|
-
function
|
|
469
|
+
function un(n) {
|
|
470
470
|
if (typeof n != "string" || n.length === 0)
|
|
471
471
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
472
472
|
if (n.startsWith("0x") || n.startsWith("0X")) {
|
|
473
|
-
if (!
|
|
473
|
+
if (!an.test(n) || n.length < 4 || n.length % 2 !== 0)
|
|
474
474
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
475
475
|
return n.toLowerCase();
|
|
476
476
|
}
|
|
477
|
-
if (
|
|
477
|
+
if (cn.test(n)) {
|
|
478
478
|
if (n.length % 2 !== 0)
|
|
479
479
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
480
480
|
return `0x${n.toLowerCase()}`;
|
|
481
481
|
}
|
|
482
|
-
if (!
|
|
482
|
+
if (!ln.test(n) || n.length % 4 !== 0)
|
|
483
483
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
484
484
|
const t = J.from(n, "base64");
|
|
485
485
|
if (t.length === 0 || t.toString("base64") !== n)
|
|
486
486
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
487
487
|
return `0x${t.toString("hex")}`;
|
|
488
488
|
}
|
|
489
|
-
async function
|
|
489
|
+
async function hn(n, t, e) {
|
|
490
490
|
if (typeof n.signPsbts == "function") {
|
|
491
491
|
const o = await n.signPsbts(t, e);
|
|
492
492
|
if (o.length !== t.length)
|
|
@@ -503,7 +503,7 @@ async function un(n, t, e) {
|
|
|
503
503
|
return s;
|
|
504
504
|
}
|
|
505
505
|
const Dt = 0, L = 25, rt = 9999, Q = "00".repeat(32);
|
|
506
|
-
function
|
|
506
|
+
function dn(n, t) {
|
|
507
507
|
const e = {
|
|
508
508
|
bitcoin: "bc",
|
|
509
509
|
testnet: "tb",
|
|
@@ -517,17 +517,17 @@ function hn(n, t) {
|
|
|
517
517
|
return !1;
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
|
-
function
|
|
520
|
+
function gn(n, t, e, s) {
|
|
521
521
|
const o = e == null ? void 0 : e[`${n}:${t}`];
|
|
522
522
|
return o ? Promise.resolve({
|
|
523
523
|
txid: n,
|
|
524
524
|
vout: t,
|
|
525
525
|
value: o.value,
|
|
526
526
|
scriptPubKey: o.scriptPubKey
|
|
527
|
-
}) :
|
|
527
|
+
}) : we(n, t, s);
|
|
528
528
|
}
|
|
529
|
-
const
|
|
530
|
-
class
|
|
529
|
+
const It = 12e4;
|
|
530
|
+
class Vn {
|
|
531
531
|
/**
|
|
532
532
|
* Creates a new PeginManager instance.
|
|
533
533
|
*
|
|
@@ -563,7 +563,7 @@ class Un {
|
|
|
563
563
|
txid: et(f.txid),
|
|
564
564
|
vout: f.vout
|
|
565
565
|
})
|
|
566
|
-
), i = await
|
|
566
|
+
), i = await He(this.config.btcWallet, {
|
|
567
567
|
depositorBtcPubkey: et(s),
|
|
568
568
|
fundingOutpoints: r
|
|
569
569
|
});
|
|
@@ -578,7 +578,7 @@ class Un {
|
|
|
578
578
|
} catch (f) {
|
|
579
579
|
throw i.fill(0), f;
|
|
580
580
|
}
|
|
581
|
-
const
|
|
581
|
+
const h = await rn(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: P, hashlocks: b } = h, g = await this.preparePeginCommit({
|
|
582
582
|
depositorBtcPubkeyRaw: e,
|
|
583
583
|
depositorBtcPubkey: s,
|
|
584
584
|
hashlocks: b,
|
|
@@ -591,7 +591,7 @@ class Un {
|
|
|
591
591
|
throw new Error(
|
|
592
592
|
`Internal invariant violation: htlcVout/index mismatch at vault ${f} (expected ${f}, got ${g.perVault[f].htlcVout})`
|
|
593
593
|
);
|
|
594
|
-
return
|
|
594
|
+
return de(
|
|
595
595
|
g.fundedPrePeginTxHex,
|
|
596
596
|
t.amounts.length,
|
|
597
597
|
c
|
|
@@ -645,11 +645,11 @@ class Un {
|
|
|
645
645
|
councilSize: e.councilSize,
|
|
646
646
|
network: this.config.btcNetwork,
|
|
647
647
|
authAnchorHash: Q
|
|
648
|
-
}), i =
|
|
648
|
+
}), i = ge(
|
|
649
649
|
[...e.availableUTXOs],
|
|
650
650
|
r.totalOutputValue,
|
|
651
651
|
e.mempoolFeeRate,
|
|
652
|
-
|
|
652
|
+
pe(r.htlcValues.length, !0)
|
|
653
653
|
);
|
|
654
654
|
return {
|
|
655
655
|
selectedUTXOs: i.selectedUTXOs,
|
|
@@ -667,18 +667,20 @@ class Un {
|
|
|
667
667
|
sizing: i,
|
|
668
668
|
params: a
|
|
669
669
|
} = t, c = Q.toLowerCase();
|
|
670
|
-
for (let
|
|
671
|
-
if (o[
|
|
670
|
+
for (let u = 0; u < o.length; u++)
|
|
671
|
+
if (o[u].toLowerCase() === c)
|
|
672
672
|
throw new Error(
|
|
673
|
-
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${
|
|
673
|
+
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${u} — internal substitution bug`
|
|
674
674
|
);
|
|
675
675
|
if (r.toLowerCase() === c)
|
|
676
676
|
throw new Error(
|
|
677
677
|
"preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
|
|
678
678
|
);
|
|
679
|
-
const
|
|
679
|
+
const h = T(
|
|
680
|
+
a.vaultProviderBtcPubkey
|
|
681
|
+
), l = a.vaultKeeperBtcPubkeys.map(T), m = a.universalChallengerBtcPubkeys.map(T), P = l.length, b = {
|
|
680
682
|
depositorPubkey: s,
|
|
681
|
-
vaultProviderPubkey:
|
|
683
|
+
vaultProviderPubkey: h,
|
|
682
684
|
vaultKeeperPubkeys: l,
|
|
683
685
|
universalChallengerPubkeys: m,
|
|
684
686
|
hashlocks: o,
|
|
@@ -691,61 +693,70 @@ class Un {
|
|
|
691
693
|
councilSize: a.councilSize,
|
|
692
694
|
network: this.config.btcNetwork,
|
|
693
695
|
authAnchorHash: r
|
|
694
|
-
}, g = await mt(b), f = wt(this.config.btcNetwork), k =
|
|
696
|
+
}, g = await mt(b), f = wt(this.config.btcNetwork), k = me({
|
|
695
697
|
unfundedTxHex: g.psbtHex,
|
|
696
698
|
selectedUTXOs: i.selectedUTXOs,
|
|
697
699
|
changeAddress: a.changeAddress,
|
|
698
700
|
changeAmount: i.changeAmount,
|
|
699
701
|
network: f
|
|
700
|
-
}),
|
|
701
|
-
|
|
702
|
+
}), v = T(
|
|
703
|
+
q(k)
|
|
704
|
+
), E = [], p = [], w = [];
|
|
705
|
+
for (let u = 0; u < o.length; u++) {
|
|
702
706
|
const B = await se({
|
|
703
707
|
prePeginParams: b,
|
|
704
708
|
timelockPegin: a.timelockPegin,
|
|
705
709
|
fundedPrePeginTxHex: k,
|
|
706
|
-
htlcVout:
|
|
707
|
-
}),
|
|
710
|
+
htlcVout: u
|
|
711
|
+
}), I = await re({
|
|
708
712
|
peginTxHex: B.txHex,
|
|
709
713
|
fundedPrePeginTxHex: k,
|
|
710
714
|
depositorPubkey: s,
|
|
711
|
-
vaultProviderPubkey:
|
|
715
|
+
vaultProviderPubkey: h,
|
|
712
716
|
vaultKeeperPubkeys: l,
|
|
713
717
|
universalChallengerPubkeys: m,
|
|
714
|
-
hashlock: o[
|
|
718
|
+
hashlock: o[u],
|
|
715
719
|
timelockRefund: a.timelockRefund,
|
|
716
720
|
network: this.config.btcNetwork
|
|
717
721
|
});
|
|
718
|
-
E.push(B), p.push(
|
|
719
|
-
|
|
722
|
+
E.push(B), p.push(I.psbtHex), w.push(
|
|
723
|
+
ue(e, 1)
|
|
720
724
|
);
|
|
721
725
|
}
|
|
722
|
-
const y = await
|
|
726
|
+
const y = await hn(
|
|
723
727
|
this.config.btcWallet,
|
|
724
728
|
p,
|
|
725
729
|
w
|
|
726
|
-
),
|
|
727
|
-
for (let
|
|
730
|
+
), d = [];
|
|
731
|
+
for (let u = 0; u < y.length; u++) {
|
|
728
732
|
Pt({
|
|
729
|
-
requestedPsbtHex: p[
|
|
730
|
-
returnedPsbtHex: y[
|
|
733
|
+
requestedPsbtHex: p[u],
|
|
734
|
+
returnedPsbtHex: y[u]
|
|
731
735
|
});
|
|
732
|
-
const B =
|
|
733
|
-
y[
|
|
736
|
+
const B = ie(
|
|
737
|
+
y[u],
|
|
734
738
|
s
|
|
735
|
-
)
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
739
|
+
);
|
|
740
|
+
oe({
|
|
741
|
+
requestedPsbtHex: p[u],
|
|
742
|
+
signatureHex: B,
|
|
743
|
+
signerXOnlyPubkeyHex: s,
|
|
744
|
+
inputIndex: 0
|
|
745
|
+
});
|
|
746
|
+
const I = ae(y[u]);
|
|
747
|
+
d.push({
|
|
748
|
+
htlcVout: u,
|
|
749
|
+
htlcValue: g.htlcValues[u],
|
|
750
|
+
peginTxHex: I,
|
|
751
|
+
peginTxid: E[u].txid,
|
|
741
752
|
peginInputSignature: B,
|
|
742
|
-
vaultScriptPubKey: E[
|
|
753
|
+
vaultScriptPubKey: E[u].vaultScriptPubKey
|
|
743
754
|
});
|
|
744
755
|
}
|
|
745
756
|
return {
|
|
746
757
|
fundedPrePeginTxHex: k,
|
|
747
|
-
prePeginTxid:
|
|
748
|
-
perVault:
|
|
758
|
+
prePeginTxid: v,
|
|
759
|
+
perVault: d
|
|
749
760
|
};
|
|
750
761
|
}
|
|
751
762
|
/**
|
|
@@ -772,12 +783,12 @@ class Un {
|
|
|
772
783
|
const a = J.from(
|
|
773
784
|
$(s),
|
|
774
785
|
"hex"
|
|
775
|
-
), c = this.config.mempoolApiUrl,
|
|
786
|
+
), c = this.config.mempoolApiUrl, h = r.ins.map((p) => {
|
|
776
787
|
const w = J.from(p.hash).reverse().toString("hex"), y = p.index;
|
|
777
|
-
return
|
|
778
|
-
(
|
|
788
|
+
return gn(w, y, t.localPrevouts, c).then(
|
|
789
|
+
(d) => ({ input: p, utxoData: d, txid: w, vout: y })
|
|
779
790
|
);
|
|
780
|
-
}), l = await Promise.all(
|
|
791
|
+
}), l = await Promise.all(h), m = l.reduce(
|
|
781
792
|
(p, w) => p + BigInt(w.utxoData.value),
|
|
782
793
|
0n
|
|
783
794
|
), P = r.outs.reduce(
|
|
@@ -793,8 +804,8 @@ class Un {
|
|
|
793
804
|
throw new Error(
|
|
794
805
|
`Implied transaction fee (${b} sat) exceeds maximum reasonable fee (${yt} sat). This may indicate manipulated UTXO data.`
|
|
795
806
|
);
|
|
796
|
-
for (const { input: p, utxoData: w, txid: y, vout:
|
|
797
|
-
const
|
|
807
|
+
for (const { input: p, utxoData: w, txid: y, vout: d } of l) {
|
|
808
|
+
const u = fe(
|
|
798
809
|
{
|
|
799
810
|
value: w.value,
|
|
800
811
|
scriptPubKey: w.scriptPubKey
|
|
@@ -805,7 +816,7 @@ class Un {
|
|
|
805
816
|
hash: p.hash,
|
|
806
817
|
index: p.index,
|
|
807
818
|
sequence: p.sequence,
|
|
808
|
-
...
|
|
819
|
+
...u
|
|
809
820
|
});
|
|
810
821
|
}
|
|
811
822
|
for (const p of r.outs)
|
|
@@ -829,8 +840,8 @@ class Un {
|
|
|
829
840
|
`PSBT finalization failed and wallet did not auto-finalize: ${p}`
|
|
830
841
|
);
|
|
831
842
|
}
|
|
832
|
-
const
|
|
833
|
-
return await
|
|
843
|
+
const v = k.extractTransaction().toHex();
|
|
844
|
+
return await Pe(v, c);
|
|
834
845
|
}
|
|
835
846
|
/**
|
|
836
847
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -865,32 +876,34 @@ class Un {
|
|
|
865
876
|
htlcVout: i,
|
|
866
877
|
depositorPayoutBtcAddress: a,
|
|
867
878
|
depositorWotsPkHash: c,
|
|
868
|
-
popSignature:
|
|
879
|
+
popSignature: h
|
|
869
880
|
} = t;
|
|
870
881
|
if (!this.config.ethWallet.account)
|
|
871
882
|
throw new Error("Ethereum wallet account not found");
|
|
872
883
|
const l = this.config.ethWallet.account.address;
|
|
873
|
-
if (!ft(
|
|
884
|
+
if (!ft(h.depositorEthAddress, l))
|
|
874
885
|
throw new Error(
|
|
875
|
-
`Proof of possession was signed for ${
|
|
886
|
+
`Proof of possession was signed for ${h.depositorEthAddress} but the Ethereum wallet is currently connected to ${l}. Reconnect the original account or call signProofOfPossession() again.`
|
|
876
887
|
);
|
|
877
|
-
const m = await this.assertPopMatchesBtcWallet(
|
|
888
|
+
const m = await this.assertPopMatchesBtcWallet(h), P = h.btcPopSignature, b = S(
|
|
889
|
+
h.depositorBtcPubkey
|
|
890
|
+
), g = S(e), f = S(s), k = a ?? await this.config.btcWallet.getAddress(), v = this.resolvePayoutScriptPubKey(
|
|
878
891
|
m,
|
|
879
892
|
k
|
|
880
893
|
), E = q(f), p = await pt(
|
|
881
894
|
T(E),
|
|
882
895
|
T(l)
|
|
883
|
-
), w =
|
|
896
|
+
), w = S(p);
|
|
884
897
|
if (await this.checkVaultExists(w))
|
|
885
898
|
throw new Error(
|
|
886
899
|
`Vault already exists (ID: ${w}, peginTxHash: ${E}). 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.`
|
|
887
900
|
);
|
|
888
|
-
const
|
|
889
|
-
let
|
|
901
|
+
const d = this.config.publicClient;
|
|
902
|
+
let u;
|
|
890
903
|
try {
|
|
891
|
-
|
|
904
|
+
u = await d.readContract({
|
|
892
905
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
893
|
-
abi:
|
|
906
|
+
abi: A,
|
|
894
907
|
functionName: "getPegInFee",
|
|
895
908
|
args: [o]
|
|
896
909
|
});
|
|
@@ -903,8 +916,8 @@ class Un {
|
|
|
903
916
|
const B = await this.resolveMaxAcceptableCommissionBps(
|
|
904
917
|
o,
|
|
905
918
|
t.quotedCommissionBps
|
|
906
|
-
),
|
|
907
|
-
abi:
|
|
919
|
+
), I = tt({
|
|
920
|
+
abi: A,
|
|
908
921
|
functionName: "submitPeginRequest",
|
|
909
922
|
args: [
|
|
910
923
|
l,
|
|
@@ -916,16 +929,16 @@ class Un {
|
|
|
916
929
|
B,
|
|
917
930
|
r,
|
|
918
931
|
i,
|
|
919
|
-
|
|
932
|
+
v,
|
|
920
933
|
c
|
|
921
934
|
]
|
|
922
935
|
});
|
|
923
936
|
let C;
|
|
924
937
|
try {
|
|
925
|
-
C = await
|
|
938
|
+
C = await d.estimateGas({
|
|
926
939
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
927
|
-
data:
|
|
928
|
-
value:
|
|
940
|
+
data: I,
|
|
941
|
+
value: u,
|
|
929
942
|
account: this.config.ethWallet.account.address
|
|
930
943
|
});
|
|
931
944
|
} catch (O) {
|
|
@@ -935,8 +948,8 @@ class Un {
|
|
|
935
948
|
try {
|
|
936
949
|
D = await this.config.ethWallet.sendTransaction({
|
|
937
950
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
938
|
-
data:
|
|
939
|
-
value:
|
|
951
|
+
data: I,
|
|
952
|
+
value: u,
|
|
940
953
|
account: this.config.ethWallet.account,
|
|
941
954
|
chain: this.config.ethChain,
|
|
942
955
|
gas: C
|
|
@@ -945,10 +958,10 @@ class Un {
|
|
|
945
958
|
H(O);
|
|
946
959
|
}
|
|
947
960
|
const G = await xt({
|
|
948
|
-
publicClient:
|
|
961
|
+
publicClient: d,
|
|
949
962
|
walletAddress: this.config.ethWallet.account.address,
|
|
950
963
|
hash: D,
|
|
951
|
-
timeout:
|
|
964
|
+
timeout: It
|
|
952
965
|
});
|
|
953
966
|
return G.status === "reverted" && H(
|
|
954
967
|
new Error(
|
|
@@ -981,19 +994,19 @@ class Un {
|
|
|
981
994
|
throw new Error(
|
|
982
995
|
`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.`
|
|
983
996
|
);
|
|
984
|
-
const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature,
|
|
985
|
-
(
|
|
997
|
+
const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, h = o.map(
|
|
998
|
+
(d) => this.resolvePayoutScriptPubKey(
|
|
986
999
|
a,
|
|
987
|
-
|
|
1000
|
+
d.depositorPayoutBtcAddress
|
|
988
1001
|
)
|
|
989
1002
|
), l = [];
|
|
990
|
-
for (const
|
|
991
|
-
const
|
|
992
|
-
|
|
993
|
-
), B = q(
|
|
1003
|
+
for (const d of o) {
|
|
1004
|
+
const u = S(
|
|
1005
|
+
d.depositorSignedPeginTx
|
|
1006
|
+
), B = q(u), I = await pt(
|
|
994
1007
|
T(B),
|
|
995
1008
|
T(i)
|
|
996
|
-
), C =
|
|
1009
|
+
), C = S(I);
|
|
997
1010
|
if (await this.checkVaultExists(C))
|
|
998
1011
|
throw new Error(
|
|
999
1012
|
`Vault already exists (ID: ${C}, peginTxHash: ${B}). To create a new vault, use different UTXOs or a different amount.`
|
|
@@ -1005,41 +1018,41 @@ class Un {
|
|
|
1005
1018
|
try {
|
|
1006
1019
|
P = await m.readContract({
|
|
1007
1020
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1008
|
-
abi:
|
|
1021
|
+
abi: A,
|
|
1009
1022
|
functionName: "getPegInFee",
|
|
1010
1023
|
args: [e]
|
|
1011
1024
|
});
|
|
1012
|
-
} catch (
|
|
1025
|
+
} catch (d) {
|
|
1013
1026
|
throw new Error(
|
|
1014
1027
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
1015
|
-
{ cause:
|
|
1028
|
+
{ cause: d }
|
|
1016
1029
|
);
|
|
1017
1030
|
}
|
|
1018
1031
|
const b = P * BigInt(o.length), g = await this.resolveMaxAcceptableCommissionBps(
|
|
1019
1032
|
e,
|
|
1020
1033
|
t.quotedCommissionBps
|
|
1021
|
-
), f =
|
|
1034
|
+
), f = S(
|
|
1022
1035
|
r.depositorBtcPubkey
|
|
1023
|
-
), k =
|
|
1036
|
+
), k = S(s), v = o.map((d, u) => ({
|
|
1024
1037
|
depositorBtcPubKey: f,
|
|
1025
1038
|
btcPopSignature: c,
|
|
1026
1039
|
unsignedPrePeginTx: k,
|
|
1027
|
-
depositorSignedPeginTx:
|
|
1028
|
-
|
|
1040
|
+
depositorSignedPeginTx: S(
|
|
1041
|
+
d.depositorSignedPeginTx
|
|
1029
1042
|
),
|
|
1030
|
-
hashlock:
|
|
1031
|
-
htlcVout:
|
|
1043
|
+
hashlock: d.hashlock,
|
|
1044
|
+
htlcVout: d.htlcVout,
|
|
1032
1045
|
referralCode: Dt,
|
|
1033
|
-
depositorPayoutBtcAddress: u
|
|
1034
|
-
depositorWotsPkHash:
|
|
1046
|
+
depositorPayoutBtcAddress: h[u],
|
|
1047
|
+
depositorWotsPkHash: d.depositorWotsPkHash
|
|
1035
1048
|
})), E = tt({
|
|
1036
|
-
abi:
|
|
1049
|
+
abi: A,
|
|
1037
1050
|
functionName: "submitPeginRequestBatch",
|
|
1038
1051
|
args: [
|
|
1039
1052
|
i,
|
|
1040
1053
|
e,
|
|
1041
1054
|
g,
|
|
1042
|
-
|
|
1055
|
+
v
|
|
1043
1056
|
]
|
|
1044
1057
|
});
|
|
1045
1058
|
let p;
|
|
@@ -1050,8 +1063,8 @@ class Un {
|
|
|
1050
1063
|
value: b,
|
|
1051
1064
|
account: this.config.ethWallet.account.address
|
|
1052
1065
|
});
|
|
1053
|
-
} catch (
|
|
1054
|
-
H(
|
|
1066
|
+
} catch (d) {
|
|
1067
|
+
H(d);
|
|
1055
1068
|
}
|
|
1056
1069
|
let w;
|
|
1057
1070
|
try {
|
|
@@ -1063,14 +1076,14 @@ class Un {
|
|
|
1063
1076
|
chain: this.config.ethChain,
|
|
1064
1077
|
gas: p
|
|
1065
1078
|
});
|
|
1066
|
-
} catch (
|
|
1067
|
-
H(
|
|
1079
|
+
} catch (d) {
|
|
1080
|
+
H(d);
|
|
1068
1081
|
}
|
|
1069
1082
|
const y = await xt({
|
|
1070
1083
|
publicClient: m,
|
|
1071
1084
|
walletAddress: this.config.ethWallet.account.address,
|
|
1072
1085
|
hash: w,
|
|
1073
|
-
timeout:
|
|
1086
|
+
timeout: It
|
|
1074
1087
|
});
|
|
1075
1088
|
return y.status === "reverted" && H(
|
|
1076
1089
|
new Error(
|
|
@@ -1086,7 +1099,7 @@ class Un {
|
|
|
1086
1099
|
async resolveMaxAcceptableCommissionBps(t, e) {
|
|
1087
1100
|
let s;
|
|
1088
1101
|
try {
|
|
1089
|
-
s = await new
|
|
1102
|
+
s = await new be(
|
|
1090
1103
|
this.config.publicClient,
|
|
1091
1104
|
this.config.vaultContracts.btcVaultRegistry
|
|
1092
1105
|
).getVaultProviderCommission(t);
|
|
@@ -1127,7 +1140,7 @@ class Un {
|
|
|
1127
1140
|
async checkVaultExists(t) {
|
|
1128
1141
|
return (await this.config.publicClient.readContract({
|
|
1129
1142
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1130
|
-
abi:
|
|
1143
|
+
abi: A,
|
|
1131
1144
|
functionName: "getBtcVaultBasicInfo",
|
|
1132
1145
|
args: [t]
|
|
1133
1146
|
})).depositor !== Jt;
|
|
@@ -1154,7 +1167,7 @@ class Un {
|
|
|
1154
1167
|
t,
|
|
1155
1168
|
this.config.btcNetwork
|
|
1156
1169
|
))
|
|
1157
|
-
throw T(t).length ===
|
|
1170
|
+
throw T(t).length === le && dn(e, this.config.btcNetwork) ? new Error(
|
|
1158
1171
|
`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.`
|
|
1159
1172
|
) : new Error(
|
|
1160
1173
|
`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.`
|
|
@@ -1184,7 +1197,7 @@ class Un {
|
|
|
1184
1197
|
"bip322-simple"
|
|
1185
1198
|
);
|
|
1186
1199
|
return {
|
|
1187
|
-
btcPopSignature:
|
|
1200
|
+
btcPopSignature: un(r),
|
|
1188
1201
|
depositorEthAddress: t,
|
|
1189
1202
|
depositorBtcPubkey: e
|
|
1190
1203
|
};
|
|
@@ -1222,44 +1235,50 @@ class Un {
|
|
|
1222
1235
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1223
1236
|
}
|
|
1224
1237
|
}
|
|
1225
|
-
const
|
|
1226
|
-
function
|
|
1227
|
-
const e = Gt.repeat(
|
|
1238
|
+
const fn = 80, pn = 250, mn = 300, Pn = 22, Gt = "ab";
|
|
1239
|
+
function bn(n, t) {
|
|
1240
|
+
const e = Gt.repeat(mn), s = T(n).toLowerCase(), o = t.toString(16).padStart(8, "0"), r = `${s}${o}`, i = e.slice(r.length);
|
|
1228
1241
|
return `0x${r}${i}`;
|
|
1229
1242
|
}
|
|
1230
|
-
function
|
|
1243
|
+
function wn(n, t) {
|
|
1231
1244
|
const e = (s) => `0x${Gt.repeat(s)}`;
|
|
1232
1245
|
return {
|
|
1233
1246
|
depositorBtcPubKey: e(32),
|
|
1234
|
-
btcPopSignature: e(
|
|
1235
|
-
unsignedPrePeginTx: e(
|
|
1236
|
-
depositorSignedPeginTx:
|
|
1247
|
+
btcPopSignature: e(fn),
|
|
1248
|
+
unsignedPrePeginTx: e(pn),
|
|
1249
|
+
depositorSignedPeginTx: bn(
|
|
1237
1250
|
n,
|
|
1238
1251
|
t
|
|
1239
1252
|
),
|
|
1240
1253
|
hashlock: e(32),
|
|
1241
1254
|
htlcVout: t,
|
|
1242
1255
|
referralCode: Dt,
|
|
1243
|
-
depositorPayoutBtcAddress: e(
|
|
1256
|
+
depositorPayoutBtcAddress: e(Pn),
|
|
1244
1257
|
depositorWotsPkHash: e(32)
|
|
1245
1258
|
};
|
|
1246
1259
|
}
|
|
1247
|
-
async function
|
|
1248
|
-
const {
|
|
1260
|
+
async function Mn(n) {
|
|
1261
|
+
const {
|
|
1262
|
+
publicClient: t,
|
|
1263
|
+
btcVaultRegistry: e,
|
|
1264
|
+
depositorEthAddress: s,
|
|
1265
|
+
vaultProvider: o,
|
|
1266
|
+
batchSize: r
|
|
1267
|
+
} = n;
|
|
1249
1268
|
if (r <= 0)
|
|
1250
1269
|
throw new Error(
|
|
1251
1270
|
`estimateSubmitPeginRequestBatchGas requires batchSize >= 1 (received ${r})`
|
|
1252
1271
|
);
|
|
1253
1272
|
const a = await t.readContract({
|
|
1254
1273
|
address: e,
|
|
1255
|
-
abi:
|
|
1274
|
+
abi: A,
|
|
1256
1275
|
functionName: "getPegInFee",
|
|
1257
1276
|
args: [o]
|
|
1258
1277
|
}) * BigInt(r), c = Array.from(
|
|
1259
1278
|
{ length: r },
|
|
1260
|
-
(l, m) =>
|
|
1261
|
-
),
|
|
1262
|
-
abi:
|
|
1279
|
+
(l, m) => wn(s, m)
|
|
1280
|
+
), h = tt({
|
|
1281
|
+
abi: A,
|
|
1263
1282
|
functionName: "submitPeginRequestBatch",
|
|
1264
1283
|
args: [
|
|
1265
1284
|
s,
|
|
@@ -1270,19 +1289,19 @@ async function Vn(n) {
|
|
|
1270
1289
|
});
|
|
1271
1290
|
return t.estimateGas({
|
|
1272
1291
|
to: e,
|
|
1273
|
-
data:
|
|
1292
|
+
data: h,
|
|
1274
1293
|
value: a,
|
|
1275
1294
|
account: s
|
|
1276
1295
|
});
|
|
1277
1296
|
}
|
|
1278
1297
|
export {
|
|
1279
|
-
|
|
1298
|
+
Vn as P,
|
|
1280
1299
|
Ae as V,
|
|
1281
|
-
|
|
1300
|
+
Ie as a,
|
|
1282
1301
|
ve as b,
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1302
|
+
on as c,
|
|
1303
|
+
sn as d,
|
|
1304
|
+
Mn as e,
|
|
1305
|
+
He as f
|
|
1287
1306
|
};
|
|
1288
|
-
//# sourceMappingURL=PeginManager-
|
|
1307
|
+
//# sourceMappingURL=PeginManager-6seoi9mV.js.map
|