@babylonlabs-io/ts-sdk 0.37.2 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BTCVaultRegistry.abi-CHFGevwa.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-CHFGevwa.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-DbJ5lsFJ.js → BTCVaultRegistry.abi-Cq9-JlqT.js} +38 -2
- package/dist/BTCVaultRegistry.abi-Cq9-JlqT.js.map +1 -0
- package/dist/{PayoutManager-BxAY2x0g.cjs → PayoutManager-BfT0V-tm.cjs} +2 -2
- package/dist/{PayoutManager-BxAY2x0g.cjs.map → PayoutManager-BfT0V-tm.cjs.map} +1 -1
- package/dist/{PayoutManager-sfxuOBGq.js → PayoutManager-Cf51DBcu.js} +2 -2
- package/dist/{PayoutManager-sfxuOBGq.js.map → PayoutManager-Cf51DBcu.js.map} +1 -1
- package/dist/PeginManager-BRHJZYmE.cjs +2 -0
- package/dist/PeginManager-BRHJZYmE.cjs.map +1 -0
- package/dist/{PeginManager-B1Mh8dJ3.js → PeginManager-C1en2vwr.js} +431 -371
- package/dist/PeginManager-C1en2vwr.js.map +1 -0
- package/dist/{ProtocolParams.abi-DXu8L0Fn.js → ProtocolParams.abi-C2brDWTI.js} +8 -3
- package/dist/ProtocolParams.abi-C2brDWTI.js.map +1 -0
- package/dist/ProtocolParams.abi-DQhcqsNr.cjs +2 -0
- package/dist/ProtocolParams.abi-DQhcqsNr.cjs.map +1 -0
- package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs +2 -0
- package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs.map +1 -0
- package/dist/{assertPsbtUnsignedTxMatches-D7RxpR4A.js → assertPsbtUnsignedTxMatches-Dry5dTfl.js} +84 -81
- package/dist/assertPsbtUnsignedTxMatches-Dry5dTfl.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CEKwFY8l.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CEKwFY8l.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-Ck_ddlLk.js → buildAndBroadcastRefund-vwfVgJeA.js} +202 -201
- package/dist/buildAndBroadcastRefund-vwfVgJeA.js.map +1 -0
- package/dist/challengeAssert-CMb7r-je.cjs +2 -0
- package/dist/challengeAssert-CMb7r-je.cjs.map +1 -0
- package/dist/{challengeAssert-BXESW00N.js → challengeAssert-D7OCrDIc.js} +29 -29
- package/dist/challengeAssert-D7OCrDIc.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +19 -19
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +12 -1
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +9 -9
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +0 -9
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/types.d.ts +38 -21
- package/dist/tbv/core/clients/vault-provider/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +36 -2
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +6 -2
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +10 -10
- package/dist/tbv/core/managers/PeginManager.d.ts +5 -0
- 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.js +2 -2
- package/dist/tbv/core/primitives/psbt/payout.d.ts +2 -2
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts +4 -2
- package/dist/tbv/core/services/deposit/waitForPeginStatus.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/pegout/state.d.ts +5 -8
- package/dist/tbv/core/services/pegout/state.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +10 -10
- package/dist/tbv/integrations/aave/clients/query.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.js +23 -22
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/tbv/integrations/aave/types.d.ts +6 -0
- package/dist/tbv/integrations/aave/types.d.ts.map +1 -1
- package/dist/types-D2jcXfm7.cjs +2 -0
- package/dist/types-D2jcXfm7.cjs.map +1 -0
- package/dist/types-TOmEvvRy.js +322 -0
- package/dist/types-TOmEvvRy.js.map +1 -0
- package/dist/{vault-registry-reader-Blhu9FW2.js → vault-registry-reader-BrARgFre.js} +207 -202
- package/dist/vault-registry-reader-BrARgFre.js.map +1 -0
- package/dist/vault-registry-reader-CbJHSxVe.cjs +2 -0
- package/dist/vault-registry-reader-CbJHSxVe.cjs.map +1 -0
- package/package.json +3 -3
- package/dist/BTCVaultRegistry.abi-DbJ5lsFJ.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs.map +0 -1
- package/dist/PeginManager-B1Mh8dJ3.js.map +0 -1
- package/dist/PeginManager-BbHPyz-G.cjs +0 -2
- package/dist/PeginManager-BbHPyz-G.cjs.map +0 -1
- package/dist/ProtocolParams.abi-BmvHwQJV.cjs +0 -2
- package/dist/ProtocolParams.abi-BmvHwQJV.cjs.map +0 -1
- package/dist/ProtocolParams.abi-DXu8L0Fn.js.map +0 -1
- package/dist/assertPsbtUnsignedTxMatches-BoHwgW30.cjs +0 -2
- package/dist/assertPsbtUnsignedTxMatches-BoHwgW30.cjs.map +0 -1
- package/dist/assertPsbtUnsignedTxMatches-D7RxpR4A.js.map +0 -1
- package/dist/buildAndBroadcastRefund-Ck_ddlLk.js.map +0 -1
- package/dist/buildAndBroadcastRefund-DyPQyghx.cjs +0 -2
- package/dist/buildAndBroadcastRefund-DyPQyghx.cjs.map +0 -1
- package/dist/challengeAssert-BKDS_ADt.cjs +0 -2
- package/dist/challengeAssert-BKDS_ADt.cjs.map +0 -1
- package/dist/challengeAssert-BXESW00N.js.map +0 -1
- package/dist/types-DnyyBNcC.cjs +0 -2
- package/dist/types-DnyyBNcC.cjs.map +0 -1
- package/dist/types-TiIjyo2b.js +0 -320
- package/dist/types-TiIjyo2b.js.map +0 -1
- package/dist/vault-registry-reader-7gOYnrQD.cjs +0 -2
- package/dist/vault-registry-reader-7gOYnrQD.cjs.map +0 -1
- package/dist/vault-registry-reader-Blhu9FW2.js.map +0 -1
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { s as
|
|
5
|
-
import * as
|
|
6
|
-
import { Transaction as
|
|
7
|
-
import { Buffer as
|
|
8
|
-
import { isAddressEqual as
|
|
9
|
-
import { B as O } from "./BTCVaultRegistry.abi-
|
|
10
|
-
import { h as
|
|
11
|
-
import { expandWotsSeed as
|
|
12
|
-
import { b as
|
|
13
|
-
import { c as
|
|
14
|
-
import { s as T, u as
|
|
15
|
-
import { c as
|
|
16
|
-
import { M as
|
|
17
|
-
import { c as
|
|
18
|
-
import { s as
|
|
19
|
-
import { p as
|
|
20
|
-
import { p as
|
|
21
|
-
const
|
|
22
|
-
function
|
|
23
|
-
return t ? { h: Number(n &
|
|
1
|
+
var zt = Object.defineProperty;
|
|
2
|
+
var qt = (n, t, e) => t in n ? zt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var x = (n, t, e) => qt(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { s as ot, c as Ct, H as Gt, r as N, a as F, b as ct, u as jt, d as lt, e as ut, f as ht, g as Zt } from "./sha2-BYVxyZzX.js";
|
|
5
|
+
import * as rt from "bitcoinjs-lib";
|
|
6
|
+
import { Transaction as Yt, Psbt as dt } from "bitcoinjs-lib";
|
|
7
|
+
import { Buffer as J } from "buffer";
|
|
8
|
+
import { isAddressEqual as gt, encodeFunctionData as ft, zeroAddress as Qt } from "viem";
|
|
9
|
+
import { B as O } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
|
|
10
|
+
import { h as C } from "./errors-CznAK5NB.js";
|
|
11
|
+
import { expandWotsSeed as Jt, expandHashlockSecret as te, expandAuthAnchor as ee, deriveVaultId as pt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
+
import { b as mt, a as ne, c as se, e as oe, f as re } from "./peginInput-CYJzbuwA.js";
|
|
13
|
+
import { c as wt } from "./assertPsbtUnsignedTxMatches-Dry5dTfl.js";
|
|
14
|
+
import { s as T, u as K, h as tt, e as B, p as ie, i as Pt, j as bt, X as ae } from "./bitcoin-B5aNKtsk.js";
|
|
15
|
+
import { c as ce } from "./signing-DaLvGwQe.js";
|
|
16
|
+
import { M as yt } from "./validation-CxqROCno.js";
|
|
17
|
+
import { c as le } from "./PayoutManager-Cf51DBcu.js";
|
|
18
|
+
import { s as ue, f as G, i as he, w as xt } from "./waitForTransactionReceiptSmartAware-CmgFXFza.js";
|
|
19
|
+
import { p as de, f as ge } from "./fundPeginTransaction-t-6TsHAY.js";
|
|
20
|
+
import { p as fe, f as pe } from "./mempoolApi-CAIge7Nj.js";
|
|
21
|
+
const V = /* @__PURE__ */ BigInt(2 ** 32 - 1), kt = /* @__PURE__ */ BigInt(32);
|
|
22
|
+
function me(n, t = !1) {
|
|
23
|
+
return t ? { h: Number(n & V), l: Number(n >> kt & V) } : { h: Number(n >> kt & V) | 0, l: Number(n & V) | 0 };
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function we(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 } = me(n[r], t);
|
|
30
30
|
[s[r], o[r]] = [i, a];
|
|
31
31
|
}
|
|
32
32
|
return [s, o];
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
function
|
|
36
|
-
const s = T(n), o =
|
|
34
|
+
const Pe = (n, t, e) => n << e | t >>> 32 - e, be = (n, t, e) => t << e | n >>> 32 - e, ye = (n, t, e) => t << e - 32 | n >>> 64 - e, xe = (n, t, e) => n << e - 32 | t >>> 64 - e, ke = 106, Ee = 32, Et = 34;
|
|
35
|
+
function Te(n, t, e) {
|
|
36
|
+
const s = T(n), o = rt.Transaction.fromHex(s);
|
|
37
37
|
if (o.outs.length <= t)
|
|
38
38
|
throw new Error(
|
|
39
39
|
`Pre-PegIn auth-anchor OP_RETURN missing: tx has ${o.outs.length} outputs, expected at least ${t + 1} (vault outputs + OP_RETURN)`
|
|
40
40
|
);
|
|
41
41
|
const r = o.outs[t], i = r.script;
|
|
42
|
-
if (i.length !==
|
|
42
|
+
if (i.length !== Et || i[0] !== ke || i[1] !== Ee)
|
|
43
43
|
throw new Error(
|
|
44
|
-
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has unexpected script encoding (got ${i.length}-byte script with prefix 0x${i.slice(0, Math.min(2, i.length)).toString("hex")}; expected ${
|
|
44
|
+
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has unexpected script encoding (got ${i.length}-byte script with prefix 0x${i.slice(0, Math.min(2, i.length)).toString("hex")}; expected ${Et}-byte OP_RETURN + PUSH32 layout)`
|
|
45
45
|
);
|
|
46
46
|
const a = i.slice(2).toString("hex").toLowerCase();
|
|
47
47
|
if (a !== e.toLowerCase())
|
|
@@ -53,70 +53,70 @@ function xe(n, t, e) {
|
|
|
53
53
|
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has non-zero value ${r.value}; OP_RETURN outputs must be 0-value`
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
function
|
|
56
|
+
const U = 32, j = 32, et = 36, Ht = 32, D = 4, _e = D + U + D + Ht;
|
|
57
|
+
function nt(n, t, e) {
|
|
58
58
|
n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = e & 255;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
if (n.txid.length !==
|
|
60
|
+
function ve(n) {
|
|
61
|
+
if (n.txid.length !== j)
|
|
62
62
|
throw new Error(
|
|
63
|
-
`outpoint.txid must be exactly ${
|
|
63
|
+
`outpoint.txid must be exactly ${j} bytes, got ${n.txid.length}`
|
|
64
64
|
);
|
|
65
65
|
if (!Number.isInteger(n.vout) || n.vout < 0 || n.vout > 4294967295)
|
|
66
66
|
throw new Error(`outpoint.vout must be a u32, got ${n.vout}`);
|
|
67
|
-
const t = new Uint8Array(
|
|
68
|
-
return t.set(n.txid, 0),
|
|
67
|
+
const t = new Uint8Array(et);
|
|
68
|
+
return t.set(n.txid, 0), nt(t, j, n.vout), t;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function Tt(n, t) {
|
|
71
71
|
const e = Math.min(n.length, t.length);
|
|
72
72
|
for (let s = 0; s < e; s++)
|
|
73
73
|
if (n[s] !== t[s]) return n[s] - t[s];
|
|
74
74
|
return n.length - t.length;
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function Be(n) {
|
|
77
77
|
if (n.length === 0)
|
|
78
78
|
throw new Error(
|
|
79
79
|
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
80
80
|
);
|
|
81
|
-
const t = n.map(
|
|
82
|
-
t.sort(
|
|
81
|
+
const t = n.map(ve);
|
|
82
|
+
t.sort(Tt);
|
|
83
83
|
for (let s = 1; s < t.length; s++)
|
|
84
|
-
if (
|
|
84
|
+
if (Tt(t[s - 1], t[s]) === 0)
|
|
85
85
|
throw new Error(
|
|
86
86
|
"buildFundingOutpointsCommitment: duplicate outpoint detected"
|
|
87
87
|
);
|
|
88
|
-
const e = new Uint8Array(t.length *
|
|
88
|
+
const e = new Uint8Array(t.length * et);
|
|
89
89
|
for (let s = 0; s < t.length; s++)
|
|
90
|
-
e.set(t[s], s *
|
|
91
|
-
return
|
|
90
|
+
e.set(t[s], s * et);
|
|
91
|
+
return ot(e);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
if (n.depositorBtcPubkey.length !==
|
|
93
|
+
function Se(n) {
|
|
94
|
+
if (n.depositorBtcPubkey.length !== U)
|
|
95
95
|
throw new Error(
|
|
96
|
-
`vaultContext: depositorBtcPubkey must be exactly ${
|
|
96
|
+
`vaultContext: depositorBtcPubkey must be exactly ${U} bytes, got ${n.depositorBtcPubkey.length}`
|
|
97
97
|
);
|
|
98
|
-
const t =
|
|
98
|
+
const t = Be(n.fundingOutpoints), e = new Uint8Array(_e);
|
|
99
99
|
let s = 0;
|
|
100
|
-
return
|
|
100
|
+
return nt(e, s, U), s += D, e.set(n.depositorBtcPubkey, s), s += U, nt(e, s, Ht), s += D, e.set(t, s), e;
|
|
101
101
|
}
|
|
102
|
-
const
|
|
103
|
-
async function
|
|
104
|
-
const e =
|
|
102
|
+
const Ie = "babylon-btc-vault", Rt = 32, _t = Rt * 2, Ae = /^[0-9a-f]+$/;
|
|
103
|
+
async function Oe(n, t) {
|
|
104
|
+
const e = Se(t), s = K(e), o = await n.deriveContextHash(Ie, s);
|
|
105
105
|
if (typeof o != "string")
|
|
106
106
|
throw new Error(
|
|
107
107
|
`deriveVaultRoot: wallet must return a string, got ${typeof o}`
|
|
108
108
|
);
|
|
109
|
-
if (o.length !==
|
|
109
|
+
if (o.length !== _t)
|
|
110
110
|
throw new Error(
|
|
111
|
-
`deriveVaultRoot: wallet must return a ${
|
|
111
|
+
`deriveVaultRoot: wallet must return a ${_t}-character hex string (${Rt} bytes), got length ${o.length}`
|
|
112
112
|
);
|
|
113
|
-
if (!
|
|
113
|
+
if (!Ae.test(o))
|
|
114
114
|
throw new Error(
|
|
115
115
|
"deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
|
|
116
116
|
);
|
|
117
|
-
return
|
|
117
|
+
return tt(o);
|
|
118
118
|
}
|
|
119
|
-
const
|
|
119
|
+
const Ce = /* @__PURE__ */ Uint8Array.from([
|
|
120
120
|
7,
|
|
121
121
|
4,
|
|
122
122
|
13,
|
|
@@ -133,43 +133,43 @@ const Ie = /* @__PURE__ */ Uint8Array.from([
|
|
|
133
133
|
14,
|
|
134
134
|
11,
|
|
135
135
|
8
|
|
136
|
-
]),
|
|
137
|
-
const e = [[
|
|
136
|
+
]), $t = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), He = $t.map((n) => (9 * n + 5) % 16), Ut = /* @__PURE__ */ (() => {
|
|
137
|
+
const e = [[$t], [He]];
|
|
138
138
|
for (let s = 0; s < 4; s++)
|
|
139
139
|
for (let o of e)
|
|
140
|
-
o.push(o[s].map((r) =>
|
|
140
|
+
o.push(o[s].map((r) => Ce[r]));
|
|
141
141
|
return e;
|
|
142
|
-
})(),
|
|
142
|
+
})(), Nt = Ut[0], Vt = Ut[1], Lt = /* @__PURE__ */ [
|
|
143
143
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
144
144
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
145
145
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
146
146
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
147
147
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
148
|
-
].map((n) => Uint8Array.from(n)),
|
|
148
|
+
].map((n) => Uint8Array.from(n)), Re = /* @__PURE__ */ Nt.map((n, t) => n.map((e) => Lt[t][e])), $e = /* @__PURE__ */ Vt.map((n, t) => n.map((e) => Lt[t][e])), Ue = /* @__PURE__ */ Uint32Array.from([
|
|
149
149
|
0,
|
|
150
150
|
1518500249,
|
|
151
151
|
1859775393,
|
|
152
152
|
2400959708,
|
|
153
153
|
2840853838
|
|
154
|
-
]),
|
|
154
|
+
]), Ne = /* @__PURE__ */ Uint32Array.from([
|
|
155
155
|
1352829926,
|
|
156
156
|
1548603684,
|
|
157
157
|
1836072691,
|
|
158
158
|
2053994217,
|
|
159
159
|
0
|
|
160
160
|
]);
|
|
161
|
-
function
|
|
161
|
+
function vt(n, t, e, s) {
|
|
162
162
|
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);
|
|
163
163
|
}
|
|
164
|
-
const
|
|
165
|
-
class
|
|
164
|
+
const L = /* @__PURE__ */ new Uint32Array(16);
|
|
165
|
+
class Ve extends Gt {
|
|
166
166
|
constructor() {
|
|
167
167
|
super(64, 20, 8, !0);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
x(this, "h0", 1732584193);
|
|
169
|
+
x(this, "h1", -271733879);
|
|
170
|
+
x(this, "h2", -1732584194);
|
|
171
|
+
x(this, "h3", 271733878);
|
|
172
|
+
x(this, "h4", -1009589776);
|
|
173
173
|
}
|
|
174
174
|
get() {
|
|
175
175
|
const { h0: e, h1: s, h2: o, h3: r, h4: i } = this;
|
|
@@ -179,52 +179,52 @@ class $e extends Dt {
|
|
|
179
179
|
this.h0 = e | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
180
180
|
}
|
|
181
181
|
process(e, s) {
|
|
182
|
-
for (let
|
|
183
|
-
|
|
184
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0,
|
|
185
|
-
for (let
|
|
186
|
-
const f = 4 -
|
|
187
|
-
for (let
|
|
188
|
-
const
|
|
189
|
-
o =
|
|
182
|
+
for (let g = 0; g < 16; g++, s += 4)
|
|
183
|
+
L[g] = e.getUint32(s, !0);
|
|
184
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, d = c, l = this.h3 | 0, m = l, w = this.h4 | 0, P = w;
|
|
185
|
+
for (let g = 0; g < 5; g++) {
|
|
186
|
+
const f = 4 - g, k = Ue[g], S = Ne[g], E = Nt[g], p = Vt[g], b = Re[g], y = $e[g];
|
|
187
|
+
for (let u = 0; u < 16; u++) {
|
|
188
|
+
const h = N(o + vt(g, i, c, l) + L[E[u]] + k, b[u]) + w | 0;
|
|
189
|
+
o = w, w = l, l = N(c, 10) | 0, c = i, i = h;
|
|
190
190
|
}
|
|
191
|
-
for (let
|
|
192
|
-
const
|
|
193
|
-
r =
|
|
191
|
+
for (let u = 0; u < 16; u++) {
|
|
192
|
+
const h = N(r + vt(f, a, d, m) + L[p[u]] + S, y[u]) + P | 0;
|
|
193
|
+
r = P, P = m, m = N(d, 10) | 0, d = a, a = h;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
this.set(this.h1 + c + m | 0, this.h2 + l +
|
|
196
|
+
this.set(this.h1 + c + m | 0, this.h2 + l + P | 0, this.h3 + w + r | 0, this.h4 + o + a | 0, this.h0 + i + d | 0);
|
|
197
197
|
}
|
|
198
198
|
roundClean() {
|
|
199
|
-
F(
|
|
199
|
+
F(L);
|
|
200
200
|
}
|
|
201
201
|
destroy() {
|
|
202
202
|
this.destroyed = !0, F(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
const
|
|
206
|
-
for (let n = 0, t =
|
|
207
|
-
[e, s] = [s, (2 * e + 3 * s) % 5],
|
|
208
|
-
let o =
|
|
205
|
+
const Le = /* @__PURE__ */ Ct(() => new Ve()), Me = BigInt(0), R = BigInt(1), We = BigInt(2), Xe = BigInt(7), Fe = BigInt(256), Ke = BigInt(113), Mt = [], Wt = [], Xt = [];
|
|
206
|
+
for (let n = 0, t = R, e = 1, s = 0; n < 24; n++) {
|
|
207
|
+
[e, s] = [s, (2 * e + 3 * s) % 5], Mt.push(2 * (5 * s + e)), Wt.push((n + 1) * (n + 2) / 2 % 64);
|
|
208
|
+
let o = Me;
|
|
209
209
|
for (let r = 0; r < 7; r++)
|
|
210
|
-
t = (t <<
|
|
211
|
-
|
|
210
|
+
t = (t << R ^ (t >> Xe) * Ke) % Fe, t & We && (o ^= R << (R << BigInt(r)) - R);
|
|
211
|
+
Xt.push(o);
|
|
212
212
|
}
|
|
213
|
-
const
|
|
214
|
-
function
|
|
213
|
+
const Ft = we(Xt, !0), De = Ft[0], ze = Ft[1], Bt = (n, t, e) => e > 32 ? ye(n, t, e) : Pe(n, t, e), St = (n, t, e) => e > 32 ? xe(n, t, e) : be(n, t, e);
|
|
214
|
+
function qe(n, t = 24) {
|
|
215
215
|
const e = new Uint32Array(10);
|
|
216
216
|
for (let s = 24 - t; s < 24; s++) {
|
|
217
217
|
for (let i = 0; i < 10; i++)
|
|
218
218
|
e[i] = n[i] ^ n[i + 10] ^ n[i + 20] ^ n[i + 30] ^ n[i + 40];
|
|
219
219
|
for (let i = 0; i < 10; i += 2) {
|
|
220
|
-
const a = (i + 8) % 10, c = (i + 2) % 10,
|
|
221
|
-
for (let
|
|
222
|
-
n[i +
|
|
220
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, d = e[c], l = e[c + 1], m = Bt(d, l, 1) ^ e[a], w = St(d, l, 1) ^ e[a + 1];
|
|
221
|
+
for (let P = 0; P < 50; P += 10)
|
|
222
|
+
n[i + P] ^= m, n[i + P + 1] ^= w;
|
|
223
223
|
}
|
|
224
224
|
let o = n[2], r = n[3];
|
|
225
225
|
for (let i = 0; i < 24; i++) {
|
|
226
|
-
const a =
|
|
227
|
-
o = n[l], r = n[l + 1], n[l] = c, n[l + 1] =
|
|
226
|
+
const a = Wt[i], c = Bt(o, r, a), d = St(o, r, a), l = Mt[i];
|
|
227
|
+
o = n[l], r = n[l + 1], n[l] = c, n[l + 1] = d;
|
|
228
228
|
}
|
|
229
229
|
for (let i = 0; i < 50; i += 10) {
|
|
230
230
|
for (let a = 0; a < 10; a++)
|
|
@@ -232,36 +232,36 @@ function Xe(n, t = 24) {
|
|
|
232
232
|
for (let a = 0; a < 10; a++)
|
|
233
233
|
n[i + a] ^= ~e[(a + 2) % 10] & e[(a + 4) % 10];
|
|
234
234
|
}
|
|
235
|
-
n[0] ^=
|
|
235
|
+
n[0] ^= De[s], n[1] ^= ze[s];
|
|
236
236
|
}
|
|
237
237
|
F(e);
|
|
238
238
|
}
|
|
239
|
-
class
|
|
239
|
+
class it {
|
|
240
240
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
241
241
|
constructor(t, e, s, o = !1, r = 24) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r,
|
|
242
|
+
x(this, "state");
|
|
243
|
+
x(this, "pos", 0);
|
|
244
|
+
x(this, "posOut", 0);
|
|
245
|
+
x(this, "finished", !1);
|
|
246
|
+
x(this, "state32");
|
|
247
|
+
x(this, "destroyed", !1);
|
|
248
|
+
x(this, "blockLen");
|
|
249
|
+
x(this, "suffix");
|
|
250
|
+
x(this, "outputLen");
|
|
251
|
+
x(this, "enableXOF", !1);
|
|
252
|
+
x(this, "rounds");
|
|
253
|
+
if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r, ct(s, "outputLen"), !(0 < t && t < 200))
|
|
254
254
|
throw new Error("only keccak-f1600 function is supported");
|
|
255
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
255
|
+
this.state = new Uint8Array(200), this.state32 = jt(this.state);
|
|
256
256
|
}
|
|
257
257
|
clone() {
|
|
258
258
|
return this._cloneInto();
|
|
259
259
|
}
|
|
260
260
|
keccak() {
|
|
261
|
-
|
|
261
|
+
lt(this.state32), qe(this.state32, this.rounds), lt(this.state32), this.posOut = 0, this.pos = 0;
|
|
262
262
|
}
|
|
263
263
|
update(t) {
|
|
264
|
-
|
|
264
|
+
ut(this), ht(t);
|
|
265
265
|
const { blockLen: e, state: s } = this, o = t.length;
|
|
266
266
|
for (let r = 0; r < o; ) {
|
|
267
267
|
const i = Math.min(e - this.pos, o - r);
|
|
@@ -279,7 +279,7 @@ class st {
|
|
|
279
279
|
t[s] ^= e, (e & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
280
280
|
}
|
|
281
281
|
writeInto(t) {
|
|
282
|
-
|
|
282
|
+
ut(this, !1), ht(t), this.finish();
|
|
283
283
|
const e = this.state, { blockLen: s } = this;
|
|
284
284
|
for (let o = 0, r = t.length; o < r; ) {
|
|
285
285
|
this.posOut >= s && this.keccak();
|
|
@@ -294,10 +294,10 @@ class st {
|
|
|
294
294
|
return this.writeInto(t);
|
|
295
295
|
}
|
|
296
296
|
xof(t) {
|
|
297
|
-
return
|
|
297
|
+
return ct(t), this.xofInto(new Uint8Array(t));
|
|
298
298
|
}
|
|
299
299
|
digestInto(t) {
|
|
300
|
-
if (
|
|
300
|
+
if (Zt(t, this), this.finished)
|
|
301
301
|
throw new Error("digest() was already called");
|
|
302
302
|
return this.writeInto(t), this.destroy(), t;
|
|
303
303
|
}
|
|
@@ -309,26 +309,26 @@ class st {
|
|
|
309
309
|
}
|
|
310
310
|
_cloneInto(t) {
|
|
311
311
|
const { blockLen: e, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
312
|
-
return t || (t = new
|
|
312
|
+
return t || (t = new it(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;
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
|
-
const
|
|
316
|
-
function
|
|
317
|
-
return
|
|
315
|
+
const Ge = (n, t, e, s = {}) => Ct(() => new it(t, n, e), s), je = /* @__PURE__ */ Ge(1, 136, 32), It = 64, _ = 20, st = 4, Kt = 2, Ze = 0, Ye = 1, M = [64, 64], Qe = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
316
|
+
function at(n) {
|
|
317
|
+
return Le(ot(n));
|
|
318
318
|
}
|
|
319
|
-
function
|
|
319
|
+
function Dt(n) {
|
|
320
320
|
return (1 << n) - 1;
|
|
321
321
|
}
|
|
322
|
-
function
|
|
322
|
+
function Je(n) {
|
|
323
323
|
let t = 1;
|
|
324
324
|
for (; t * t < n + 1; ) t++;
|
|
325
325
|
return Math.max(t, 2);
|
|
326
326
|
}
|
|
327
|
-
function
|
|
328
|
-
const t =
|
|
329
|
-
return { d: t, n, checksum_radix:
|
|
327
|
+
function tn(n) {
|
|
328
|
+
const t = st, e = n * Dt(t);
|
|
329
|
+
return { d: t, n, checksum_radix: Je(e) };
|
|
330
330
|
}
|
|
331
|
-
function
|
|
331
|
+
function Z(n, t) {
|
|
332
332
|
const e = [];
|
|
333
333
|
let s = t;
|
|
334
334
|
for (; s > 0; )
|
|
@@ -337,56 +337,56 @@ function j(n, t) {
|
|
|
337
337
|
o.set(n);
|
|
338
338
|
for (let r = 0; r < e.length; r++)
|
|
339
339
|
o[n.length + r] = e[r];
|
|
340
|
-
return
|
|
340
|
+
return at(o);
|
|
341
341
|
}
|
|
342
|
-
function
|
|
342
|
+
function Y(n, t) {
|
|
343
343
|
let e = n;
|
|
344
344
|
for (let s = 0; s < t; s++)
|
|
345
|
-
e =
|
|
345
|
+
e = at(e);
|
|
346
346
|
return e;
|
|
347
347
|
}
|
|
348
|
-
function
|
|
349
|
-
const e =
|
|
348
|
+
function en(n, t) {
|
|
349
|
+
const e = Dt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * e / t.checksum_radix), r = [];
|
|
350
350
|
for (let l = 0; l < t.n; l++) {
|
|
351
|
-
const m =
|
|
352
|
-
r.push(Array.from(
|
|
351
|
+
const m = Z(n, l + Kt), w = Y(m, e);
|
|
352
|
+
r.push(Array.from(w));
|
|
353
353
|
}
|
|
354
|
-
const i =
|
|
354
|
+
const i = Z(
|
|
355
355
|
n,
|
|
356
|
-
|
|
357
|
-
), a =
|
|
356
|
+
Ze
|
|
357
|
+
), a = Y(
|
|
358
358
|
i,
|
|
359
359
|
s
|
|
360
|
-
), c =
|
|
360
|
+
), c = Z(
|
|
361
361
|
n,
|
|
362
|
-
|
|
363
|
-
),
|
|
362
|
+
Ye
|
|
363
|
+
), d = Y(
|
|
364
364
|
c,
|
|
365
365
|
o
|
|
366
366
|
);
|
|
367
367
|
return {
|
|
368
368
|
config: t,
|
|
369
369
|
message_terminals: r,
|
|
370
|
-
checksum_major_terminal: Array.from(
|
|
370
|
+
checksum_major_terminal: Array.from(d),
|
|
371
371
|
checksum_minor_terminal: Array.from(a)
|
|
372
372
|
};
|
|
373
373
|
}
|
|
374
|
-
async function
|
|
374
|
+
async function nn(n) {
|
|
375
375
|
try {
|
|
376
|
-
if (n.length !==
|
|
376
|
+
if (n.length !== It)
|
|
377
377
|
throw new Error(
|
|
378
|
-
`WOTS seed must be exactly ${
|
|
378
|
+
`WOTS seed must be exactly ${It} bytes, got ${n.length}`
|
|
379
379
|
);
|
|
380
380
|
const t = [];
|
|
381
|
-
for (let e = 0; e <
|
|
382
|
-
const s =
|
|
381
|
+
for (let e = 0; e < M.length; e++) {
|
|
382
|
+
const s = M[e], o = tn(s), r = new Uint8Array(n.length + 1);
|
|
383
383
|
r.set(n), r[n.length] = e;
|
|
384
|
-
const i =
|
|
384
|
+
const i = at(r);
|
|
385
385
|
try {
|
|
386
|
-
const a =
|
|
387
|
-
if (a.config.d !==
|
|
386
|
+
const a = en(i, o);
|
|
387
|
+
if (a.config.d !== st)
|
|
388
388
|
throw new Error(
|
|
389
|
-
`Block ${e}: expected d=${
|
|
389
|
+
`Block ${e}: expected d=${st}, got d=${a.config.d}`
|
|
390
390
|
);
|
|
391
391
|
if (a.config.n !== s)
|
|
392
392
|
throw new Error(
|
|
@@ -414,16 +414,16 @@ async function Ye(n) {
|
|
|
414
414
|
r.fill(0), i.fill(0);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
-
if (t.length !==
|
|
417
|
+
if (t.length !== M.length)
|
|
418
418
|
throw new Error(
|
|
419
|
-
`Expected ${
|
|
419
|
+
`Expected ${M.length} blocks, got ${t.length}`
|
|
420
420
|
);
|
|
421
421
|
return t;
|
|
422
422
|
} finally {
|
|
423
423
|
n.fill(0);
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
|
-
function
|
|
426
|
+
function Q(n, t, e) {
|
|
427
427
|
if (n.length !== _)
|
|
428
428
|
throw new Error(
|
|
429
429
|
`Block ${t} ${e}: expected ${_} bytes, got ${n.length}`
|
|
@@ -436,18 +436,18 @@ function Z(n, t, e) {
|
|
|
436
436
|
);
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
function
|
|
439
|
+
function sn(n) {
|
|
440
440
|
if (n.length === 0)
|
|
441
441
|
throw new Error("Public keys array must not be empty");
|
|
442
442
|
for (let r = 0; r < n.length; r++) {
|
|
443
443
|
const i = n[r];
|
|
444
|
-
|
|
444
|
+
Q(i.checksum_minor_terminal, r, "checksum_minor_terminal"), Q(i.checksum_major_terminal, r, "checksum_major_terminal");
|
|
445
445
|
for (let a = 0; a < i.message_terminals.length; a++)
|
|
446
|
-
|
|
446
|
+
Q(i.message_terminals[a], r, `message_terminal[${a}]`);
|
|
447
447
|
}
|
|
448
448
|
let t = 0;
|
|
449
449
|
for (const r of n)
|
|
450
|
-
t +=
|
|
450
|
+
t += Kt + r.message_terminals.length;
|
|
451
451
|
const e = new Uint8Array(t * _);
|
|
452
452
|
let s = 0;
|
|
453
453
|
for (const r of n) {
|
|
@@ -455,24 +455,24 @@ function Je(n) {
|
|
|
455
455
|
for (const i of r.message_terminals)
|
|
456
456
|
e.set(i, s), s += _;
|
|
457
457
|
}
|
|
458
|
-
const o =
|
|
459
|
-
return `0x${
|
|
458
|
+
const o = je(e);
|
|
459
|
+
return `0x${Qe(o)}`;
|
|
460
460
|
}
|
|
461
|
-
async function
|
|
461
|
+
async function on(n, t) {
|
|
462
462
|
const e = [], s = [], o = [], r = [];
|
|
463
463
|
try {
|
|
464
464
|
for (let i = 0; i < t; i++) {
|
|
465
|
-
const a = await
|
|
465
|
+
const a = await Jt(n, i);
|
|
466
466
|
try {
|
|
467
|
-
const
|
|
468
|
-
e.push(
|
|
467
|
+
const d = await nn(a);
|
|
468
|
+
e.push(d), s.push(sn(d));
|
|
469
469
|
} finally {
|
|
470
470
|
a.fill(0);
|
|
471
471
|
}
|
|
472
|
-
const c = await
|
|
472
|
+
const c = await te(n, i);
|
|
473
473
|
try {
|
|
474
|
-
const
|
|
475
|
-
o.push(
|
|
474
|
+
const d = K(c);
|
|
475
|
+
o.push(d), r.push(le(B(d)).slice(2));
|
|
476
476
|
} finally {
|
|
477
477
|
c.fill(0);
|
|
478
478
|
}
|
|
@@ -482,33 +482,33 @@ async function tn(n, t) {
|
|
|
482
482
|
}
|
|
483
483
|
return { perVaultWotsKeys: e, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
|
|
484
484
|
}
|
|
485
|
-
const
|
|
485
|
+
const rn = /^0x[0-9a-f]+$/i, an = /^[0-9a-f]+$/i, cn = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
486
486
|
function $(n) {
|
|
487
487
|
if (typeof n != "string" || n.length === 0)
|
|
488
488
|
throw new Error("BTC wallet returned empty public key");
|
|
489
|
-
return
|
|
489
|
+
return ie(n).toLowerCase();
|
|
490
490
|
}
|
|
491
|
-
function
|
|
491
|
+
function ln(n) {
|
|
492
492
|
if (typeof n != "string" || n.length === 0)
|
|
493
493
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
494
494
|
if (n.startsWith("0x") || n.startsWith("0X")) {
|
|
495
|
-
if (!
|
|
495
|
+
if (!rn.test(n) || n.length < 4 || n.length % 2 !== 0)
|
|
496
496
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
497
497
|
return n.toLowerCase();
|
|
498
498
|
}
|
|
499
|
-
if (
|
|
499
|
+
if (an.test(n)) {
|
|
500
500
|
if (n.length % 2 !== 0)
|
|
501
501
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
502
502
|
return `0x${n.toLowerCase()}`;
|
|
503
503
|
}
|
|
504
|
-
if (!
|
|
504
|
+
if (!cn.test(n) || n.length % 4 !== 0)
|
|
505
505
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
506
|
-
const t =
|
|
506
|
+
const t = J.from(n, "base64");
|
|
507
507
|
if (t.length === 0 || t.toString("base64") !== n)
|
|
508
508
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
509
509
|
return `0x${t.toString("hex")}`;
|
|
510
510
|
}
|
|
511
|
-
async function
|
|
511
|
+
async function un(n, t, e) {
|
|
512
512
|
if (typeof n.signPsbts == "function") {
|
|
513
513
|
const o = await n.signPsbts(t, e);
|
|
514
514
|
if (o.length !== t.length)
|
|
@@ -524,25 +524,39 @@ async function rn(n, t, e) {
|
|
|
524
524
|
}
|
|
525
525
|
return s;
|
|
526
526
|
}
|
|
527
|
-
const
|
|
528
|
-
function
|
|
527
|
+
const hn = 0, W = 25, At = 9999, X = "00".repeat(32);
|
|
528
|
+
function dn(n, t) {
|
|
529
|
+
const e = {
|
|
530
|
+
bitcoin: "bc",
|
|
531
|
+
testnet: "tb",
|
|
532
|
+
signet: "tb",
|
|
533
|
+
regtest: "bcrt"
|
|
534
|
+
};
|
|
535
|
+
try {
|
|
536
|
+
const s = rt.address.fromBech32(n);
|
|
537
|
+
return s.prefix === e[t] && s.version === 0 && s.data.length === 20;
|
|
538
|
+
} catch {
|
|
539
|
+
return !1;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function gn(n, t, e, s) {
|
|
529
543
|
const o = e == null ? void 0 : e[`${n}:${t}`];
|
|
530
544
|
return o ? Promise.resolve({
|
|
531
545
|
txid: n,
|
|
532
546
|
vout: t,
|
|
533
547
|
value: o.value,
|
|
534
548
|
scriptPubKey: o.scriptPubKey
|
|
535
|
-
}) :
|
|
549
|
+
}) : pe(n, t, s);
|
|
536
550
|
}
|
|
537
|
-
const
|
|
538
|
-
class
|
|
551
|
+
const Ot = 12e4;
|
|
552
|
+
class On {
|
|
539
553
|
/**
|
|
540
554
|
* Creates a new PeginManager instance.
|
|
541
555
|
*
|
|
542
556
|
* @param config - Manager configuration including wallets and contract addresses
|
|
543
557
|
*/
|
|
544
558
|
constructor(t) {
|
|
545
|
-
|
|
559
|
+
x(this, "config");
|
|
546
560
|
this.config = t;
|
|
547
561
|
}
|
|
548
562
|
/**
|
|
@@ -558,7 +572,7 @@ class vn {
|
|
|
558
572
|
if (t.amounts.length === 0)
|
|
559
573
|
throw new Error("amounts must contain at least one entry");
|
|
560
574
|
const e = await this.config.btcWallet.getPublicKeyHex(), s = $(e);
|
|
561
|
-
if (!
|
|
575
|
+
if (!Pt(
|
|
562
576
|
t.changeAddress,
|
|
563
577
|
e,
|
|
564
578
|
this.config.btcNetwork
|
|
@@ -568,44 +582,44 @@ class vn {
|
|
|
568
582
|
);
|
|
569
583
|
const o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
|
|
570
584
|
(f) => ({
|
|
571
|
-
txid:
|
|
585
|
+
txid: tt(f.txid),
|
|
572
586
|
vout: f.vout
|
|
573
587
|
})
|
|
574
|
-
), i = await
|
|
575
|
-
depositorBtcPubkey:
|
|
588
|
+
), i = await Oe(this.config.btcWallet, {
|
|
589
|
+
depositorBtcPubkey: tt(s),
|
|
576
590
|
fundingOutpoints: r
|
|
577
591
|
});
|
|
578
592
|
let a, c;
|
|
579
593
|
try {
|
|
580
|
-
const f = await
|
|
594
|
+
const f = await ee(i);
|
|
581
595
|
try {
|
|
582
|
-
a =
|
|
596
|
+
a = K(f), c = K(ot(f));
|
|
583
597
|
} finally {
|
|
584
598
|
f.fill(0);
|
|
585
599
|
}
|
|
586
600
|
} catch (f) {
|
|
587
601
|
throw i.fill(0), f;
|
|
588
602
|
}
|
|
589
|
-
const
|
|
603
|
+
const d = await on(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: w, hashlocks: P } = d, g = await this.preparePeginCommit({
|
|
590
604
|
depositorBtcPubkeyRaw: e,
|
|
591
605
|
depositorBtcPubkey: s,
|
|
592
|
-
hashlocks:
|
|
606
|
+
hashlocks: P,
|
|
593
607
|
authAnchorHash: c,
|
|
594
608
|
sizing: o,
|
|
595
609
|
params: t
|
|
596
610
|
});
|
|
597
|
-
for (let f = 0; f <
|
|
598
|
-
if (
|
|
611
|
+
for (let f = 0; f < g.perVault.length; f++)
|
|
612
|
+
if (g.perVault[f].htlcVout !== f)
|
|
599
613
|
throw new Error(
|
|
600
|
-
`Internal invariant violation: htlcVout/index mismatch at vault ${f} (expected ${f}, got ${
|
|
614
|
+
`Internal invariant violation: htlcVout/index mismatch at vault ${f} (expected ${f}, got ${g.perVault[f].htlcVout})`
|
|
601
615
|
);
|
|
602
|
-
return
|
|
603
|
-
|
|
616
|
+
return Te(
|
|
617
|
+
g.fundedPrePeginTxHex,
|
|
604
618
|
t.amounts.length,
|
|
605
619
|
c
|
|
606
620
|
), {
|
|
607
621
|
transaction: {
|
|
608
|
-
...
|
|
622
|
+
...g,
|
|
609
623
|
selectedUTXOs: o.selectedUTXOs,
|
|
610
624
|
fee: o.fee,
|
|
611
625
|
changeAmount: o.changeAmount
|
|
@@ -614,7 +628,7 @@ class vn {
|
|
|
614
628
|
derivedSecrets: {
|
|
615
629
|
perVaultWotsKeys: l,
|
|
616
630
|
wotsPkHashes: m,
|
|
617
|
-
htlcSecretHexes:
|
|
631
|
+
htlcSecretHexes: w,
|
|
618
632
|
authAnchorHex: a
|
|
619
633
|
}
|
|
620
634
|
};
|
|
@@ -637,8 +651,8 @@ class vn {
|
|
|
637
651
|
*/
|
|
638
652
|
async prepareSizing(t, e) {
|
|
639
653
|
const s = e.amounts.map(
|
|
640
|
-
() =>
|
|
641
|
-
), o = e.vaultKeeperBtcPubkeys.length, r = await
|
|
654
|
+
() => X
|
|
655
|
+
), o = e.vaultKeeperBtcPubkeys.length, r = await mt({
|
|
642
656
|
depositorPubkey: t,
|
|
643
657
|
vaultProviderPubkey: T(e.vaultProviderBtcPubkey),
|
|
644
658
|
vaultKeeperPubkeys: e.vaultKeeperBtcPubkeys.map(T),
|
|
@@ -651,14 +665,14 @@ class vn {
|
|
|
651
665
|
councilQuorum: e.councilQuorum,
|
|
652
666
|
councilSize: e.councilSize,
|
|
653
667
|
network: this.config.btcNetwork,
|
|
654
|
-
authAnchorHash:
|
|
655
|
-
}), i =
|
|
668
|
+
authAnchorHash: X
|
|
669
|
+
}), i = ue(
|
|
656
670
|
[...e.availableUTXOs],
|
|
657
671
|
r.totalOutputValue,
|
|
658
672
|
e.mempoolFeeRate,
|
|
659
|
-
|
|
673
|
+
de(
|
|
660
674
|
r.htlcValues.length,
|
|
661
|
-
|
|
675
|
+
X
|
|
662
676
|
)
|
|
663
677
|
);
|
|
664
678
|
return {
|
|
@@ -676,85 +690,85 @@ class vn {
|
|
|
676
690
|
authAnchorHash: r,
|
|
677
691
|
sizing: i,
|
|
678
692
|
params: a
|
|
679
|
-
} = t, c =
|
|
680
|
-
for (let
|
|
681
|
-
if (o[
|
|
693
|
+
} = t, c = X.toLowerCase();
|
|
694
|
+
for (let h = 0; h < o.length; h++)
|
|
695
|
+
if (o[h].toLowerCase() === c)
|
|
682
696
|
throw new Error(
|
|
683
|
-
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${
|
|
697
|
+
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${h} — internal substitution bug`
|
|
684
698
|
);
|
|
685
699
|
if (r.toLowerCase() === c)
|
|
686
700
|
throw new Error(
|
|
687
701
|
"preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
|
|
688
702
|
);
|
|
689
|
-
const
|
|
703
|
+
const d = T(a.vaultProviderBtcPubkey), l = a.vaultKeeperBtcPubkeys.map(T), m = a.universalChallengerBtcPubkeys.map(T), w = l.length, P = {
|
|
690
704
|
depositorPubkey: s,
|
|
691
|
-
vaultProviderPubkey:
|
|
705
|
+
vaultProviderPubkey: d,
|
|
692
706
|
vaultKeeperPubkeys: l,
|
|
693
707
|
universalChallengerPubkeys: m,
|
|
694
708
|
hashlocks: o,
|
|
695
709
|
timelockRefund: a.timelockRefund,
|
|
696
710
|
pegInAmounts: a.amounts,
|
|
697
711
|
feeRate: a.protocolFeeRate,
|
|
698
|
-
numLocalChallengers:
|
|
712
|
+
numLocalChallengers: w,
|
|
699
713
|
councilQuorum: a.councilQuorum,
|
|
700
714
|
councilSize: a.councilSize,
|
|
701
715
|
network: this.config.btcNetwork,
|
|
702
716
|
authAnchorHash: r
|
|
703
|
-
},
|
|
704
|
-
unfundedTxHex:
|
|
717
|
+
}, g = await mt(P), f = bt(this.config.btcNetwork), k = ge({
|
|
718
|
+
unfundedTxHex: g.psbtHex,
|
|
705
719
|
selectedUTXOs: i.selectedUTXOs,
|
|
706
720
|
changeAddress: a.changeAddress,
|
|
707
721
|
changeAmount: i.changeAmount,
|
|
708
722
|
network: f
|
|
709
|
-
}),
|
|
710
|
-
for (let
|
|
711
|
-
const
|
|
712
|
-
prePeginParams:
|
|
723
|
+
}), S = T(G(k)), E = [], p = [], b = [];
|
|
724
|
+
for (let h = 0; h < o.length; h++) {
|
|
725
|
+
const v = await ne({
|
|
726
|
+
prePeginParams: P,
|
|
713
727
|
timelockPegin: a.timelockPegin,
|
|
714
728
|
fundedPrePeginTxHex: k,
|
|
715
|
-
htlcVout:
|
|
716
|
-
}),
|
|
717
|
-
peginTxHex:
|
|
729
|
+
htlcVout: h
|
|
730
|
+
}), I = await se({
|
|
731
|
+
peginTxHex: v.txHex,
|
|
718
732
|
fundedPrePeginTxHex: k,
|
|
719
733
|
depositorPubkey: s,
|
|
720
|
-
vaultProviderPubkey:
|
|
734
|
+
vaultProviderPubkey: d,
|
|
721
735
|
vaultKeeperPubkeys: l,
|
|
722
736
|
universalChallengerPubkeys: m,
|
|
723
|
-
hashlock: o[
|
|
737
|
+
hashlock: o[h],
|
|
724
738
|
timelockRefund: a.timelockRefund,
|
|
725
739
|
network: this.config.btcNetwork
|
|
726
740
|
});
|
|
727
|
-
E.push(
|
|
728
|
-
|
|
741
|
+
E.push(v), p.push(I.psbtHex), b.push(
|
|
742
|
+
ce(e, 1)
|
|
729
743
|
);
|
|
730
744
|
}
|
|
731
|
-
const
|
|
745
|
+
const y = await un(
|
|
732
746
|
this.config.btcWallet,
|
|
733
747
|
p,
|
|
734
|
-
|
|
735
|
-
),
|
|
736
|
-
for (let
|
|
737
|
-
|
|
738
|
-
requestedPsbtHex: p[
|
|
739
|
-
returnedPsbtHex:
|
|
748
|
+
b
|
|
749
|
+
), u = [];
|
|
750
|
+
for (let h = 0; h < y.length; h++) {
|
|
751
|
+
wt({
|
|
752
|
+
requestedPsbtHex: p[h],
|
|
753
|
+
returnedPsbtHex: y[h]
|
|
740
754
|
});
|
|
741
|
-
const
|
|
742
|
-
|
|
755
|
+
const v = oe(
|
|
756
|
+
y[h],
|
|
743
757
|
s
|
|
744
|
-
),
|
|
745
|
-
|
|
746
|
-
htlcVout:
|
|
747
|
-
htlcValue:
|
|
748
|
-
peginTxHex:
|
|
749
|
-
peginTxid: E[
|
|
750
|
-
peginInputSignature:
|
|
751
|
-
vaultScriptPubKey: E[
|
|
758
|
+
), I = re(y[h]);
|
|
759
|
+
u.push({
|
|
760
|
+
htlcVout: h,
|
|
761
|
+
htlcValue: g.htlcValues[h],
|
|
762
|
+
peginTxHex: I,
|
|
763
|
+
peginTxid: E[h].txid,
|
|
764
|
+
peginInputSignature: v,
|
|
765
|
+
vaultScriptPubKey: E[h].vaultScriptPubKey
|
|
752
766
|
});
|
|
753
767
|
}
|
|
754
768
|
return {
|
|
755
769
|
fundedPrePeginTxHex: k,
|
|
756
|
-
prePeginTxid:
|
|
757
|
-
perVault:
|
|
770
|
+
prePeginTxid: S,
|
|
771
|
+
perVault: u
|
|
758
772
|
};
|
|
759
773
|
}
|
|
760
774
|
/**
|
|
@@ -773,40 +787,40 @@ class vn {
|
|
|
773
787
|
* @throws Error if signing or broadcasting fails
|
|
774
788
|
*/
|
|
775
789
|
async signAndBroadcast(t) {
|
|
776
|
-
const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r =
|
|
790
|
+
const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = Yt.fromHex(o);
|
|
777
791
|
if (r.ins.length === 0)
|
|
778
792
|
throw new Error("Transaction has no inputs");
|
|
779
|
-
const i = new
|
|
793
|
+
const i = new dt();
|
|
780
794
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
781
|
-
const a =
|
|
795
|
+
const a = J.from(
|
|
782
796
|
$(s),
|
|
783
797
|
"hex"
|
|
784
|
-
), c = this.config.mempoolApiUrl,
|
|
785
|
-
const
|
|
786
|
-
return
|
|
787
|
-
(
|
|
798
|
+
), c = this.config.mempoolApiUrl, d = r.ins.map((p) => {
|
|
799
|
+
const b = J.from(p.hash).reverse().toString("hex"), y = p.index;
|
|
800
|
+
return gn(b, y, t.localPrevouts, c).then(
|
|
801
|
+
(u) => ({ input: p, utxoData: u, txid: b, vout: y })
|
|
788
802
|
);
|
|
789
|
-
}), l = await Promise.all(
|
|
790
|
-
(p,
|
|
803
|
+
}), l = await Promise.all(d), m = l.reduce(
|
|
804
|
+
(p, b) => p + BigInt(b.utxoData.value),
|
|
791
805
|
0n
|
|
792
|
-
),
|
|
793
|
-
(p,
|
|
806
|
+
), w = r.outs.reduce(
|
|
807
|
+
(p, b) => p + BigInt(b.value),
|
|
794
808
|
0n
|
|
795
809
|
);
|
|
796
|
-
if (m <
|
|
810
|
+
if (m < w)
|
|
797
811
|
throw new Error(
|
|
798
|
-
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${
|
|
812
|
+
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${w} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
799
813
|
);
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
814
|
+
const P = m - w;
|
|
815
|
+
if (P > yt)
|
|
802
816
|
throw new Error(
|
|
803
|
-
`Implied transaction fee (${
|
|
817
|
+
`Implied transaction fee (${P} sat) exceeds maximum reasonable fee (${yt} sat). This may indicate manipulated UTXO data.`
|
|
804
818
|
);
|
|
805
|
-
for (const { input: p, utxoData:
|
|
806
|
-
const
|
|
819
|
+
for (const { input: p, utxoData: b, txid: y, vout: u } of l) {
|
|
820
|
+
const h = he(
|
|
807
821
|
{
|
|
808
|
-
value:
|
|
809
|
-
scriptPubKey:
|
|
822
|
+
value: b.value,
|
|
823
|
+
scriptPubKey: b.scriptPubKey
|
|
810
824
|
},
|
|
811
825
|
a
|
|
812
826
|
);
|
|
@@ -814,7 +828,7 @@ class vn {
|
|
|
814
828
|
hash: p.hash,
|
|
815
829
|
index: p.index,
|
|
816
830
|
sequence: p.sequence,
|
|
817
|
-
...
|
|
831
|
+
...h
|
|
818
832
|
});
|
|
819
833
|
}
|
|
820
834
|
for (const p of r.outs)
|
|
@@ -822,24 +836,24 @@ class vn {
|
|
|
822
836
|
script: p.script,
|
|
823
837
|
value: p.value
|
|
824
838
|
});
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
requestedPsbtHex:
|
|
839
|
+
const g = i.toHex(), f = await this.config.btcWallet.signPsbt(g);
|
|
840
|
+
wt({
|
|
841
|
+
requestedPsbtHex: g,
|
|
828
842
|
returnedPsbtHex: f
|
|
829
843
|
});
|
|
830
|
-
const k =
|
|
844
|
+
const k = dt.fromHex(f);
|
|
831
845
|
try {
|
|
832
846
|
k.finalizeAllInputs();
|
|
833
847
|
} catch (p) {
|
|
834
848
|
if (!k.data.inputs.every(
|
|
835
|
-
(
|
|
849
|
+
(y) => y.finalScriptWitness || y.finalScriptSig
|
|
836
850
|
))
|
|
837
851
|
throw new Error(
|
|
838
852
|
`PSBT finalization failed and wallet did not auto-finalize: ${p}`
|
|
839
853
|
);
|
|
840
854
|
}
|
|
841
|
-
const
|
|
842
|
-
return await
|
|
855
|
+
const S = k.extractTransaction().toHex();
|
|
856
|
+
return await fe(S, c);
|
|
843
857
|
}
|
|
844
858
|
/**
|
|
845
859
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -874,94 +888,98 @@ class vn {
|
|
|
874
888
|
htlcVout: i,
|
|
875
889
|
depositorPayoutBtcAddress: a,
|
|
876
890
|
depositorWotsPkHash: c,
|
|
877
|
-
popSignature:
|
|
891
|
+
popSignature: d
|
|
878
892
|
} = t;
|
|
879
893
|
if (!this.config.ethWallet.account)
|
|
880
894
|
throw new Error("Ethereum wallet account not found");
|
|
881
895
|
const l = this.config.ethWallet.account.address;
|
|
882
|
-
if (!
|
|
896
|
+
if (!gt(d.depositorEthAddress, l))
|
|
883
897
|
throw new Error(
|
|
884
|
-
`Proof of possession was signed for ${
|
|
898
|
+
`Proof of possession was signed for ${d.depositorEthAddress} but the Ethereum wallet is currently connected to ${l}. Reconnect the original account or call signProofOfPossession() again.`
|
|
885
899
|
);
|
|
886
|
-
const m = await this.assertPopMatchesBtcWallet(
|
|
900
|
+
const m = await this.assertPopMatchesBtcWallet(d), w = d.btcPopSignature, P = B(d.depositorBtcPubkey), g = B(e), f = B(s), k = a ?? await this.config.btcWallet.getAddress(), S = this.resolvePayoutScriptPubKey(
|
|
887
901
|
m,
|
|
888
902
|
k
|
|
889
|
-
), E =
|
|
903
|
+
), E = G(f), p = await pt(
|
|
890
904
|
T(E),
|
|
891
905
|
T(l)
|
|
892
|
-
),
|
|
893
|
-
if (await this.checkVaultExists(
|
|
906
|
+
), b = B(p);
|
|
907
|
+
if (await this.checkVaultExists(b))
|
|
894
908
|
throw new Error(
|
|
895
|
-
`Vault already exists (ID: ${
|
|
909
|
+
`Vault already exists (ID: ${b}, 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.`
|
|
896
910
|
);
|
|
897
|
-
const
|
|
898
|
-
let
|
|
911
|
+
const u = this.config.publicClient;
|
|
912
|
+
let h;
|
|
899
913
|
try {
|
|
900
|
-
|
|
914
|
+
h = await u.readContract({
|
|
901
915
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
902
916
|
abi: O,
|
|
903
917
|
functionName: "getPegInFee",
|
|
904
918
|
args: [o]
|
|
905
919
|
});
|
|
906
|
-
} catch (
|
|
920
|
+
} catch (H) {
|
|
907
921
|
throw new Error(
|
|
908
922
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
909
|
-
{ cause:
|
|
923
|
+
{ cause: H }
|
|
910
924
|
);
|
|
911
925
|
}
|
|
912
|
-
const
|
|
926
|
+
const v = await this.resolveMaxAcceptableCommissionBps(
|
|
927
|
+
o,
|
|
928
|
+
t.quotedCommissionBps
|
|
929
|
+
), I = ft({
|
|
913
930
|
abi: O,
|
|
914
931
|
functionName: "submitPeginRequest",
|
|
915
932
|
args: [
|
|
916
933
|
l,
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
934
|
+
P,
|
|
935
|
+
w,
|
|
936
|
+
g,
|
|
920
937
|
f,
|
|
921
938
|
o,
|
|
939
|
+
v,
|
|
922
940
|
r,
|
|
923
941
|
i,
|
|
924
|
-
|
|
942
|
+
S,
|
|
925
943
|
c
|
|
926
944
|
]
|
|
927
945
|
});
|
|
928
|
-
let
|
|
946
|
+
let A;
|
|
929
947
|
try {
|
|
930
|
-
|
|
948
|
+
A = await u.estimateGas({
|
|
931
949
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
932
|
-
data:
|
|
933
|
-
value:
|
|
950
|
+
data: I,
|
|
951
|
+
value: h,
|
|
934
952
|
account: this.config.ethWallet.account.address
|
|
935
953
|
});
|
|
936
|
-
} catch (
|
|
937
|
-
|
|
954
|
+
} catch (H) {
|
|
955
|
+
C(H);
|
|
938
956
|
}
|
|
939
|
-
let
|
|
957
|
+
let z;
|
|
940
958
|
try {
|
|
941
|
-
|
|
959
|
+
z = await this.config.ethWallet.sendTransaction({
|
|
942
960
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
943
|
-
data:
|
|
944
|
-
value:
|
|
961
|
+
data: I,
|
|
962
|
+
value: h,
|
|
945
963
|
account: this.config.ethWallet.account,
|
|
946
964
|
chain: this.config.ethChain,
|
|
947
|
-
gas:
|
|
965
|
+
gas: A
|
|
948
966
|
});
|
|
949
|
-
} catch (
|
|
950
|
-
|
|
967
|
+
} catch (H) {
|
|
968
|
+
C(H);
|
|
951
969
|
}
|
|
952
|
-
const
|
|
953
|
-
publicClient:
|
|
970
|
+
const q = await xt({
|
|
971
|
+
publicClient: u,
|
|
954
972
|
walletAddress: this.config.ethWallet.account.address,
|
|
955
|
-
hash:
|
|
956
|
-
timeout:
|
|
973
|
+
hash: z,
|
|
974
|
+
timeout: Ot
|
|
957
975
|
});
|
|
958
|
-
return
|
|
976
|
+
return q.status === "reverted" && C(
|
|
959
977
|
new Error(
|
|
960
|
-
`Transaction reverted. Hash: ${
|
|
978
|
+
`Transaction reverted. Hash: ${q.transactionHash}. Check the transaction on block explorer for details.`
|
|
961
979
|
)
|
|
962
980
|
), {
|
|
963
|
-
ethTxHash:
|
|
964
|
-
vaultId:
|
|
981
|
+
ethTxHash: q.transactionHash,
|
|
982
|
+
vaultId: b,
|
|
965
983
|
peginTxHash: E
|
|
966
984
|
};
|
|
967
985
|
}
|
|
@@ -982,102 +1000,142 @@ class vn {
|
|
|
982
1000
|
if (!this.config.ethWallet.account)
|
|
983
1001
|
throw new Error("Ethereum wallet account not found");
|
|
984
1002
|
const i = this.config.ethWallet.account.address;
|
|
985
|
-
if (!
|
|
1003
|
+
if (!gt(r.depositorEthAddress, i))
|
|
986
1004
|
throw new Error(
|
|
987
1005
|
`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.`
|
|
988
1006
|
);
|
|
989
|
-
const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature,
|
|
990
|
-
(
|
|
1007
|
+
const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, d = o.map(
|
|
1008
|
+
(u) => this.resolvePayoutScriptPubKey(
|
|
991
1009
|
a,
|
|
992
|
-
|
|
1010
|
+
u.depositorPayoutBtcAddress
|
|
993
1011
|
)
|
|
994
1012
|
), l = [];
|
|
995
|
-
for (const
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
),
|
|
999
|
-
T(
|
|
1013
|
+
for (const u of o) {
|
|
1014
|
+
const h = B(
|
|
1015
|
+
u.depositorSignedPeginTx
|
|
1016
|
+
), v = G(h), I = await pt(
|
|
1017
|
+
T(v),
|
|
1000
1018
|
T(i)
|
|
1001
|
-
),
|
|
1002
|
-
if (await this.checkVaultExists(
|
|
1019
|
+
), A = B(I);
|
|
1020
|
+
if (await this.checkVaultExists(A))
|
|
1003
1021
|
throw new Error(
|
|
1004
|
-
`Vault already exists (ID: ${
|
|
1022
|
+
`Vault already exists (ID: ${A}, peginTxHash: ${v}). To create a new vault, use different UTXOs or a different amount.`
|
|
1005
1023
|
);
|
|
1006
|
-
l.push({ vaultId:
|
|
1024
|
+
l.push({ vaultId: A, peginTxHash: v });
|
|
1007
1025
|
}
|
|
1008
1026
|
const m = this.config.publicClient;
|
|
1009
|
-
let
|
|
1027
|
+
let w;
|
|
1010
1028
|
try {
|
|
1011
|
-
|
|
1029
|
+
w = await m.readContract({
|
|
1012
1030
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1013
1031
|
abi: O,
|
|
1014
1032
|
functionName: "getPegInFee",
|
|
1015
1033
|
args: [e]
|
|
1016
1034
|
});
|
|
1017
|
-
} catch (
|
|
1035
|
+
} catch (u) {
|
|
1018
1036
|
throw new Error(
|
|
1019
1037
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
1020
|
-
{ cause:
|
|
1038
|
+
{ cause: u }
|
|
1021
1039
|
);
|
|
1022
1040
|
}
|
|
1023
|
-
const
|
|
1041
|
+
const P = w * BigInt(o.length), g = await this.resolveMaxAcceptableCommissionBps(
|
|
1042
|
+
e,
|
|
1043
|
+
t.quotedCommissionBps
|
|
1044
|
+
), f = B(
|
|
1024
1045
|
r.depositorBtcPubkey
|
|
1025
|
-
),
|
|
1026
|
-
depositorBtcPubKey:
|
|
1046
|
+
), k = B(s), S = o.map((u, h) => ({
|
|
1047
|
+
depositorBtcPubKey: f,
|
|
1027
1048
|
btcPopSignature: c,
|
|
1028
|
-
unsignedPrePeginTx:
|
|
1029
|
-
depositorSignedPeginTx:
|
|
1030
|
-
|
|
1049
|
+
unsignedPrePeginTx: k,
|
|
1050
|
+
depositorSignedPeginTx: B(
|
|
1051
|
+
u.depositorSignedPeginTx
|
|
1031
1052
|
),
|
|
1032
|
-
hashlock:
|
|
1033
|
-
htlcVout:
|
|
1034
|
-
referralCode:
|
|
1035
|
-
depositorPayoutBtcAddress: h
|
|
1036
|
-
depositorWotsPkHash:
|
|
1037
|
-
})),
|
|
1053
|
+
hashlock: u.hashlock,
|
|
1054
|
+
htlcVout: u.htlcVout,
|
|
1055
|
+
referralCode: hn,
|
|
1056
|
+
depositorPayoutBtcAddress: d[h],
|
|
1057
|
+
depositorWotsPkHash: u.depositorWotsPkHash
|
|
1058
|
+
})), E = ft({
|
|
1038
1059
|
abi: O,
|
|
1039
1060
|
functionName: "submitPeginRequestBatch",
|
|
1040
|
-
args: [
|
|
1061
|
+
args: [
|
|
1062
|
+
i,
|
|
1063
|
+
e,
|
|
1064
|
+
g,
|
|
1065
|
+
S
|
|
1066
|
+
]
|
|
1041
1067
|
});
|
|
1042
|
-
let
|
|
1068
|
+
let p;
|
|
1043
1069
|
try {
|
|
1044
|
-
|
|
1070
|
+
p = await m.estimateGas({
|
|
1045
1071
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1046
|
-
data:
|
|
1047
|
-
value:
|
|
1072
|
+
data: E,
|
|
1073
|
+
value: P,
|
|
1048
1074
|
account: this.config.ethWallet.account.address
|
|
1049
1075
|
});
|
|
1050
|
-
} catch (
|
|
1051
|
-
|
|
1076
|
+
} catch (u) {
|
|
1077
|
+
C(u);
|
|
1052
1078
|
}
|
|
1053
|
-
let
|
|
1079
|
+
let b;
|
|
1054
1080
|
try {
|
|
1055
|
-
|
|
1081
|
+
b = await this.config.ethWallet.sendTransaction({
|
|
1056
1082
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1057
|
-
data:
|
|
1058
|
-
value:
|
|
1083
|
+
data: E,
|
|
1084
|
+
value: P,
|
|
1059
1085
|
account: this.config.ethWallet.account,
|
|
1060
1086
|
chain: this.config.ethChain,
|
|
1061
|
-
gas:
|
|
1087
|
+
gas: p
|
|
1062
1088
|
});
|
|
1063
|
-
} catch (
|
|
1064
|
-
|
|
1089
|
+
} catch (u) {
|
|
1090
|
+
C(u);
|
|
1065
1091
|
}
|
|
1066
|
-
const
|
|
1092
|
+
const y = await xt({
|
|
1067
1093
|
publicClient: m,
|
|
1068
1094
|
walletAddress: this.config.ethWallet.account.address,
|
|
1069
|
-
hash:
|
|
1070
|
-
timeout:
|
|
1095
|
+
hash: b,
|
|
1096
|
+
timeout: Ot
|
|
1071
1097
|
});
|
|
1072
|
-
return
|
|
1098
|
+
return y.status === "reverted" && C(
|
|
1073
1099
|
new Error(
|
|
1074
|
-
`Batch transaction reverted. Hash: ${
|
|
1100
|
+
`Batch transaction reverted. Hash: ${y.transactionHash}. Check the transaction on block explorer for details.`
|
|
1075
1101
|
)
|
|
1076
1102
|
), {
|
|
1077
|
-
ethTxHash:
|
|
1103
|
+
ethTxHash: y.transactionHash,
|
|
1078
1104
|
vaults: l
|
|
1079
1105
|
};
|
|
1080
1106
|
}
|
|
1107
|
+
// Anchor to quoted+headroom when supplied (refuse if chain drifted past it);
|
|
1108
|
+
// otherwise fall back to chain-current+headroom — see #1691.
|
|
1109
|
+
async resolveMaxAcceptableCommissionBps(t, e) {
|
|
1110
|
+
let s;
|
|
1111
|
+
try {
|
|
1112
|
+
s = await this.config.publicClient.readContract({
|
|
1113
|
+
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1114
|
+
abi: O,
|
|
1115
|
+
functionName: "getVaultProviderCommission",
|
|
1116
|
+
args: [t]
|
|
1117
|
+
});
|
|
1118
|
+
} catch (o) {
|
|
1119
|
+
throw new Error(
|
|
1120
|
+
"Failed to query vault provider commission from the contract. Please check your network connection and that the contract address is correct.",
|
|
1121
|
+
{ cause: o }
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
if (e !== void 0) {
|
|
1125
|
+
if (s > e + W)
|
|
1126
|
+
throw new Error(
|
|
1127
|
+
`Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${s} bps (allowed drift ${W} bps). Please refresh to see the new commission and try again.`
|
|
1128
|
+
);
|
|
1129
|
+
return Math.min(
|
|
1130
|
+
e + W,
|
|
1131
|
+
At
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
return Math.min(
|
|
1135
|
+
s + W,
|
|
1136
|
+
At
|
|
1137
|
+
);
|
|
1138
|
+
}
|
|
1081
1139
|
/**
|
|
1082
1140
|
* Check if a vault already exists for a given vault ID.
|
|
1083
1141
|
*
|
|
@@ -1097,7 +1155,7 @@ class vn {
|
|
|
1097
1155
|
abi: O,
|
|
1098
1156
|
functionName: "getBtcVaultBasicInfo",
|
|
1099
1157
|
args: [t]
|
|
1100
|
-
})).depositor !==
|
|
1158
|
+
})).depositor !== Qt;
|
|
1101
1159
|
}
|
|
1102
1160
|
/**
|
|
1103
1161
|
* Resolve the BTC scriptPubKey to register as the depositor's payout sink.
|
|
@@ -1116,17 +1174,19 @@ class vn {
|
|
|
1116
1174
|
* on-chain payout-script registration.
|
|
1117
1175
|
*/
|
|
1118
1176
|
resolvePayoutScriptPubKey(t, e) {
|
|
1119
|
-
if (!
|
|
1177
|
+
if (!Pt(
|
|
1120
1178
|
e,
|
|
1121
1179
|
t,
|
|
1122
1180
|
this.config.btcNetwork
|
|
1123
1181
|
))
|
|
1124
|
-
throw new Error(
|
|
1182
|
+
throw T(t).length === ae && dn(e, this.config.btcNetwork) ? new Error(
|
|
1183
|
+
`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.`
|
|
1184
|
+
) : new Error(
|
|
1125
1185
|
`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.`
|
|
1126
1186
|
);
|
|
1127
|
-
const s =
|
|
1187
|
+
const s = bt(this.config.btcNetwork);
|
|
1128
1188
|
try {
|
|
1129
|
-
return `0x${
|
|
1189
|
+
return `0x${rt.address.toOutputScript(e, s).toString("hex")}`;
|
|
1130
1190
|
} catch {
|
|
1131
1191
|
throw new Error(
|
|
1132
1192
|
`Invalid BTC payout address: "${e}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1149,7 +1209,7 @@ class vn {
|
|
|
1149
1209
|
"bip322-simple"
|
|
1150
1210
|
);
|
|
1151
1211
|
return {
|
|
1152
|
-
btcPopSignature:
|
|
1212
|
+
btcPopSignature: ln(r),
|
|
1153
1213
|
depositorEthAddress: t,
|
|
1154
1214
|
depositorBtcPubkey: e
|
|
1155
1215
|
};
|
|
@@ -1188,12 +1248,12 @@ class vn {
|
|
|
1188
1248
|
}
|
|
1189
1249
|
}
|
|
1190
1250
|
export {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1251
|
+
On as P,
|
|
1252
|
+
Ie as V,
|
|
1253
|
+
Se as a,
|
|
1254
|
+
Be as b,
|
|
1255
|
+
sn as c,
|
|
1256
|
+
nn as d,
|
|
1257
|
+
Oe as e
|
|
1198
1258
|
};
|
|
1199
|
-
//# sourceMappingURL=PeginManager-
|
|
1259
|
+
//# sourceMappingURL=PeginManager-C1en2vwr.js.map
|