@babylonlabs-io/ts-sdk 0.78.0 → 0.79.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BTCVaultRegistry.abi-BT3eo60h.js → BTCVaultRegistry.abi-B0x9_Bza.js} +43 -1
- package/dist/BTCVaultRegistry.abi-B0x9_Bza.js.map +1 -0
- package/dist/BTCVaultRegistry.abi-BQ5tFNSu.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-BQ5tFNSu.cjs.map +1 -0
- package/dist/{BTCVaultRegistryKeyEpochs.abi-D8cIbMtH.js → BTCVaultRegistryKeyEpochs.abi-BWoxwPQv.js} +57 -20
- package/dist/BTCVaultRegistryKeyEpochs.abi-BWoxwPQv.js.map +1 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-DCJnzKer.cjs +2 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-DCJnzKer.cjs.map +1 -0
- package/dist/{PeginManager-Cz0Ytdwo.js → PeginManager-BXlh3ar0.js} +289 -348
- package/dist/PeginManager-BXlh3ar0.js.map +1 -0
- package/dist/PeginManager-BuVSknB0.cjs +2 -0
- package/dist/PeginManager-BuVSknB0.cjs.map +1 -0
- package/dist/ProtocolParams.abi-Db2USqQm.cjs +2 -0
- package/dist/ProtocolParams.abi-Db2USqQm.cjs.map +1 -0
- package/dist/ProtocolParams.abi-q0AidvYX.js +526 -0
- package/dist/ProtocolParams.abi-q0AidvYX.js.map +1 -0
- package/dist/buildAndBroadcastReclaim-N9dXH9dm.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-N9dXH9dm.cjs.map +1 -0
- package/dist/{buildAndBroadcastReclaim-DD50pVB1.js → buildAndBroadcastReclaim-O6z9kvc4.js} +502 -468
- package/dist/buildAndBroadcastReclaim-O6z9kvc4.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +227 -222
- package/dist/pegin-registration-client-CZgcU2_0.cjs +2 -0
- package/dist/pegin-registration-client-CZgcU2_0.cjs.map +1 -0
- package/dist/{pegin-registration-client-7Vbtdypu.js → pegin-registration-client-pcczkzMg.js} +184 -143
- package/dist/pegin-registration-client-pcczkzMg.js.map +1 -0
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.js +2 -2
- package/dist/tbv/core/clients/eth/pegin-registration-client.d.ts +17 -0
- package/dist/tbv/core/clients/eth/pegin-registration-client.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/signer-set-reader.d.ts +2 -0
- package/dist/tbv/core/clients/eth/signer-set-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +28 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +12 -0
- 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 +2 -2
- package/dist/tbv/core/contracts/__tests__/peginFingerprintAbi.test.d.ts +24 -0
- package/dist/tbv/core/contracts/__tests__/peginFingerprintAbi.test.d.ts.map +1 -0
- package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts +14 -0
- package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +38 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +10 -0
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/errors.d.ts +41 -4
- package/dist/tbv/core/contracts/errors.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.cjs.map +1 -1
- package/dist/tbv/core/contracts/index.d.ts +1 -1
- package/dist/tbv/core/contracts/index.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.js +15 -492
- package/dist/tbv/core/contracts/index.js.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +222 -217
- package/dist/tbv/core/managers/PeginManager.d.ts +13 -25
- 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.d.ts +2 -2
- package/dist/tbv/core/managers/index.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.js +4 -5
- package/dist/tbv/core/pegin-fingerprint/index.d.ts +1 -1
- package/dist/tbv/core/pegin-fingerprint/index.d.ts.map +1 -1
- package/dist/tbv/core/pegin-fingerprint/peginFingerprint.d.ts +10 -0
- package/dist/tbv/core/pegin-fingerprint/peginFingerprint.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/index.d.ts +1 -1
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts +50 -3
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +56 -54
- package/dist/tbv/core/services/participants/__tests__/fixtures/rotation.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +222 -217
- package/dist/tbv/integrations/aave/clients/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/clients/spoke.d.ts +13 -0
- package/dist/tbv/integrations/aave/clients/spoke.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +137 -125
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/{toRefundInputs-D708M8MA.js → toRefundInputs-9inv4Ai4.js} +96 -92
- package/dist/toRefundInputs-9inv4Ai4.js.map +1 -0
- package/dist/toRefundInputs-DitGWAnz.cjs +2 -0
- package/dist/toRefundInputs-DitGWAnz.cjs.map +1 -0
- package/dist/{types-BwqkOoJ6.js → types-B9YhlXe8.js} +109 -83
- package/dist/types-B9YhlXe8.js.map +1 -0
- package/dist/types-C1tpDycc.cjs +2 -0
- package/dist/types-C1tpDycc.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/BTCVaultRegistry.abi-BJnjzEWD.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-BJnjzEWD.cjs.map +0 -1
- package/dist/BTCVaultRegistry.abi-BT3eo60h.js.map +0 -1
- package/dist/BTCVaultRegistryKeyEpochs.abi-CrQiTLfA.cjs +0 -2
- package/dist/BTCVaultRegistryKeyEpochs.abi-CrQiTLfA.cjs.map +0 -1
- package/dist/BTCVaultRegistryKeyEpochs.abi-D8cIbMtH.js.map +0 -1
- package/dist/PeginManager-Cz0Ytdwo.js.map +0 -1
- package/dist/PeginManager-DE2lTWMl.cjs +0 -2
- package/dist/PeginManager-DE2lTWMl.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-CB5VPETy.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-CB5VPETy.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-DD50pVB1.js.map +0 -1
- package/dist/pegin-registration-client-7Vbtdypu.js.map +0 -1
- package/dist/pegin-registration-client-CSe1vOum.cjs +0 -2
- package/dist/pegin-registration-client-CSe1vOum.cjs.map +0 -1
- package/dist/toRefundInputs-BH3wkNC4.cjs +0 -2
- package/dist/toRefundInputs-BH3wkNC4.cjs.map +0 -1
- package/dist/toRefundInputs-D708M8MA.js.map +0 -1
- package/dist/types-BN0jOH8K.cjs +0 -2
- package/dist/types-BN0jOH8K.cjs.map +0 -1
- package/dist/types-BwqkOoJ6.js.map +0 -1
|
@@ -1,44 +1,43 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var P = (o, e, t) =>
|
|
4
|
-
import { c as ve, d as
|
|
5
|
-
import * as
|
|
6
|
-
import { Transaction as
|
|
7
|
-
import { Buffer as
|
|
8
|
-
import { isAddressEqual as J
|
|
9
|
-
import { r as
|
|
10
|
-
import { pushTx as
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return e ? { h: Number(o & R), l: Number(o >> ae & R) } : { h: Number(o >> ae & R) | 0, l: Number(o & R) | 0 };
|
|
1
|
+
var ke = Object.defineProperty;
|
|
2
|
+
var Te = (o, e, t) => e in o ? ke(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var P = (o, e, t) => Te(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { c as ve, d as q, u as Ee, e as j, f as Y, g as Q, i as Se, a as he, s as pe } from "./sha2-CLpQd0Rd.js";
|
|
5
|
+
import * as de from "bitcoinjs-lib";
|
|
6
|
+
import { Transaction as ge, Psbt as Z } from "bitcoinjs-lib";
|
|
7
|
+
import { Buffer as _ } from "buffer";
|
|
8
|
+
import { isAddressEqual as J } from "viem";
|
|
9
|
+
import { r as Be, e as _e, V as Ce } from "./pegin-registration-client-pcczkzMg.js";
|
|
10
|
+
import { pushTx as Ae, getUtxoInfo as Ie } from "./tbv/core/clients/mempool/index.js";
|
|
11
|
+
import { expandWotsSeed as He, expandHashlockSecret as $e, expandAuthAnchor as Oe } from "./tbv/core/wasm/index.js";
|
|
12
|
+
import { a as ee, b as Re, i as te, j as We } from "./verifyScriptPathSchnorrSignature-D_epga4j.js";
|
|
13
|
+
import { d as Fe, b as Ve, e as Me, f as Ke, c as De } from "./verifyKeyPathSchnorrSignature-BVtNwgK6.js";
|
|
14
|
+
import { p as Ne, h as L, u as U, e as Le, i as oe, s as x, k as se } from "./bitcoin-C-TuHb-v.js";
|
|
15
|
+
import { c as Ue, a as Xe } from "./signing-Cm-McVR2.js";
|
|
16
|
+
import { M as ne, X as ze } from "./validation-OSC0xTHB.js";
|
|
17
|
+
import { p as Ge, d as fe } from "./parseFundingOutpoints-BQWvINfm.js";
|
|
18
|
+
import { c as qe, s as C, r as je, b as Ye, d as Qe } from "./signPsbtsWithFallback-f7QLp0q8.js";
|
|
19
|
+
import { s as Ze, h as Je } from "./psbtInputFields-CCVyaQMi.js";
|
|
20
|
+
import { p as et, f as tt } from "./fundPeginTransaction-CwhRbCQC.js";
|
|
21
|
+
import { M as ie, B as ot } from "./constants-D5vORbQE.js";
|
|
22
|
+
import * as st from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
23
|
+
import { v as nt, P as it, a as rt, b as at } from "./bip322Verify-DSco3Yhl.js";
|
|
24
|
+
const O = /* @__PURE__ */ BigInt(2 ** 32 - 1), re = /* @__PURE__ */ BigInt(32);
|
|
25
|
+
function ct(o, e = !1) {
|
|
26
|
+
return e ? { h: Number(o & O), l: Number(o >> re & O) } : { h: Number(o >> re & O) | 0, l: Number(o & O) | 0 };
|
|
28
27
|
}
|
|
29
|
-
function
|
|
28
|
+
function lt(o, e = !1) {
|
|
30
29
|
const t = o.length;
|
|
31
30
|
let s = new Uint32Array(t), r = new Uint32Array(t);
|
|
32
31
|
for (let n = 0; n < t; n++) {
|
|
33
|
-
const { h: i, l: a } =
|
|
32
|
+
const { h: i, l: a } = ct(o[n], e);
|
|
34
33
|
[s[n], r[n]] = [i, a];
|
|
35
34
|
}
|
|
36
35
|
return [s, r];
|
|
37
36
|
}
|
|
38
|
-
const
|
|
39
|
-
function
|
|
37
|
+
const ut = (o, e, t) => o << t | e >>> 32 - t, ht = (o, e, t) => e << t | o >>> 32 - t, pt = (o, e, t) => e << t - 32 | o >>> 64 - t, dt = (o, e, t) => o << t - 32 | e >>> 64 - t, gt = 64;
|
|
38
|
+
function ft(o) {
|
|
40
39
|
const e = o.prepeginTxid.toLowerCase();
|
|
41
|
-
if (!/^[0-9a-f]+$/.test(e) || e.length !==
|
|
40
|
+
if (!/^[0-9a-f]+$/.test(e) || e.length !== gt)
|
|
42
41
|
throw new Error(
|
|
43
42
|
`buildDepositTerms: prepeginTxid must be 64 hex chars, got "${o.prepeginTxid}"`
|
|
44
43
|
);
|
|
@@ -46,11 +45,11 @@ function yt(o) {
|
|
|
46
45
|
throw new Error("buildDepositTerms: at least one pegin amount is required");
|
|
47
46
|
if (o.timelockPegin <= 0 || o.timelockAssert <= 0 || o.timelockRefund <= 0)
|
|
48
47
|
throw new Error("buildDepositTerms: timelocks must be positive");
|
|
49
|
-
if (!Number.isInteger(o.maxAcceptableCommissionBps) || o.maxAcceptableCommissionBps < 0 || o.maxAcceptableCommissionBps >=
|
|
48
|
+
if (!Number.isInteger(o.maxAcceptableCommissionBps) || o.maxAcceptableCommissionBps < 0 || o.maxAcceptableCommissionBps >= ie)
|
|
50
49
|
throw new Error(
|
|
51
|
-
`buildDepositTerms: maxAcceptableCommissionBps must be an integer in [0, ${
|
|
50
|
+
`buildDepositTerms: maxAcceptableCommissionBps must be an integer in [0, ${ie}), got ${o.maxAcceptableCommissionBps}`
|
|
52
51
|
);
|
|
53
|
-
const t = BigInt(
|
|
52
|
+
const t = BigInt(ot), s = o.peginAmounts.map(
|
|
54
53
|
(r, n) => ({
|
|
55
54
|
htlcVout: n,
|
|
56
55
|
vaultProviderBtcPubkey: o.vaultProviderBtcPubkey,
|
|
@@ -77,37 +76,37 @@ function yt(o) {
|
|
|
77
76
|
vaults: s
|
|
78
77
|
};
|
|
79
78
|
}
|
|
80
|
-
const
|
|
81
|
-
function
|
|
79
|
+
const mt = /^0x[0-9a-f]+$/i, Pt = /^[0-9a-f]+$/i, bt = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
80
|
+
function B(o) {
|
|
82
81
|
if (typeof o != "string" || o.length === 0)
|
|
83
82
|
throw new Error("BTC wallet returned empty public key");
|
|
84
|
-
return
|
|
83
|
+
return Ne(o).toLowerCase();
|
|
85
84
|
}
|
|
86
|
-
function
|
|
85
|
+
function wt(o) {
|
|
87
86
|
if (typeof o != "string" || o.length === 0)
|
|
88
87
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
89
88
|
if (o.startsWith("0x") || o.startsWith("0X")) {
|
|
90
|
-
if (!
|
|
89
|
+
if (!mt.test(o) || o.length < 4 || o.length % 2 !== 0)
|
|
91
90
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
92
91
|
return o.toLowerCase();
|
|
93
92
|
}
|
|
94
|
-
if (
|
|
93
|
+
if (Pt.test(o)) {
|
|
95
94
|
if (o.length % 2 !== 0)
|
|
96
95
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
97
96
|
return `0x${o.toLowerCase()}`;
|
|
98
97
|
}
|
|
99
|
-
if (!
|
|
98
|
+
if (!bt.test(o) || o.length % 4 !== 0)
|
|
100
99
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
101
|
-
const e =
|
|
100
|
+
const e = _.from(o, "base64");
|
|
102
101
|
if (e.length === 0 || e.toString("base64") !== o)
|
|
103
102
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
104
103
|
return `0x${e.toString("hex")}`;
|
|
105
104
|
}
|
|
106
|
-
async function
|
|
105
|
+
async function yt(o) {
|
|
107
106
|
const { wallet: e, depositTerms: t, fundedPrePeginTxHex: s, depositorBtcPubkey: r } = o, n = typeof e.approveDepositTerms == "function" ? e.approveDepositTerms : void 0;
|
|
108
107
|
if (!n && !t)
|
|
109
108
|
return;
|
|
110
|
-
const i = s.startsWith("0x") ? s.slice(2) : s, c =
|
|
109
|
+
const i = s.startsWith("0x") ? s.slice(2) : s, c = ge.fromHex(i).getId();
|
|
111
110
|
if (t && t.prepeginTxid.replace(/^0x/, "").toLowerCase() !== c)
|
|
112
111
|
throw new Error(
|
|
113
112
|
`Deposit terms do not match the transaction being broadcast: terms are for prepeginTxid ${t.prepeginTxid}, but this transaction is ${c}.`
|
|
@@ -132,40 +131,40 @@ async function St(o) {
|
|
|
132
131
|
return;
|
|
133
132
|
}
|
|
134
133
|
typeof e.validateDepositTerms == "function" && await e.validateDepositTerms(t);
|
|
135
|
-
const
|
|
136
|
-
(await
|
|
134
|
+
const h = Ge(s);
|
|
135
|
+
(await fe(
|
|
137
136
|
{ deriveContextHash: e.deriveContextHash.bind(e) },
|
|
138
137
|
{
|
|
139
|
-
depositorBtcPubkey:
|
|
140
|
-
|
|
138
|
+
depositorBtcPubkey: L(
|
|
139
|
+
B(r)
|
|
141
140
|
),
|
|
142
|
-
fundingOutpoints:
|
|
141
|
+
fundingOutpoints: h
|
|
143
142
|
}
|
|
144
143
|
)).fill(0), await n.call(e, t);
|
|
145
144
|
}
|
|
146
|
-
const
|
|
145
|
+
const xt = BigInt(0), A = BigInt(1), kt = BigInt(2), Tt = BigInt(7), vt = BigInt(256), Et = BigInt(113), me = [], Pe = [], be = [];
|
|
147
146
|
for (let o = 0, e = A, t = 1, s = 0; o < 24; o++) {
|
|
148
|
-
[t, s] = [s, (2 * t + 3 * s) % 5],
|
|
149
|
-
let r =
|
|
147
|
+
[t, s] = [s, (2 * t + 3 * s) % 5], me.push(2 * (5 * s + t)), Pe.push((o + 1) * (o + 2) / 2 % 64);
|
|
148
|
+
let r = xt;
|
|
150
149
|
for (let n = 0; n < 7; n++)
|
|
151
|
-
e = (e << A ^ (e >>
|
|
152
|
-
|
|
150
|
+
e = (e << A ^ (e >> Tt) * Et) % vt, e & kt && (r ^= A << (A << BigInt(n)) - A);
|
|
151
|
+
be.push(r);
|
|
153
152
|
}
|
|
154
|
-
const
|
|
155
|
-
function
|
|
153
|
+
const we = lt(be, !0), St = we[0], Bt = we[1], ae = (o, e, t) => t > 32 ? pt(o, e, t) : ut(o, e, t), ce = (o, e, t) => t > 32 ? dt(o, e, t) : ht(o, e, t);
|
|
154
|
+
function _t(o, e = 24) {
|
|
156
155
|
const t = new Uint32Array(10);
|
|
157
156
|
for (let s = 24 - e; s < 24; s++) {
|
|
158
157
|
for (let i = 0; i < 10; i++)
|
|
159
158
|
t[i] = o[i] ^ o[i + 10] ^ o[i + 20] ^ o[i + 30] ^ o[i + 40];
|
|
160
159
|
for (let i = 0; i < 10; i += 2) {
|
|
161
|
-
const a = (i + 8) % 10, c = (i + 2) % 10,
|
|
160
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, h = t[c], p = t[c + 1], f = ae(h, p, 1) ^ t[a], y = ce(h, p, 1) ^ t[a + 1];
|
|
162
161
|
for (let b = 0; b < 50; b += 10)
|
|
163
|
-
o[i + b] ^= f, o[i + b + 1] ^=
|
|
162
|
+
o[i + b] ^= f, o[i + b + 1] ^= y;
|
|
164
163
|
}
|
|
165
164
|
let r = o[2], n = o[3];
|
|
166
165
|
for (let i = 0; i < 24; i++) {
|
|
167
|
-
const a =
|
|
168
|
-
r = o[
|
|
166
|
+
const a = Pe[i], c = ae(r, n, a), h = ce(r, n, a), p = me[i];
|
|
167
|
+
r = o[p], n = o[p + 1], o[p] = c, o[p + 1] = h;
|
|
169
168
|
}
|
|
170
169
|
for (let i = 0; i < 50; i += 10) {
|
|
171
170
|
for (let a = 0; a < 10; a++)
|
|
@@ -173,11 +172,11 @@ function $t(o, e = 24) {
|
|
|
173
172
|
for (let a = 0; a < 10; a++)
|
|
174
173
|
o[i + a] ^= ~t[(a + 2) % 10] & t[(a + 4) % 10];
|
|
175
174
|
}
|
|
176
|
-
o[0] ^=
|
|
175
|
+
o[0] ^= St[s], o[1] ^= Bt[s];
|
|
177
176
|
}
|
|
178
|
-
|
|
177
|
+
he(t);
|
|
179
178
|
}
|
|
180
|
-
class
|
|
179
|
+
class z {
|
|
181
180
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
182
181
|
constructor(e, t, s, r = !1, n = 24) {
|
|
183
182
|
P(this, "state");
|
|
@@ -191,18 +190,18 @@ class G {
|
|
|
191
190
|
P(this, "outputLen");
|
|
192
191
|
P(this, "enableXOF", !1);
|
|
193
192
|
P(this, "rounds");
|
|
194
|
-
if (this.blockLen = e, this.suffix = t, this.outputLen = s, this.enableXOF = r, this.rounds = n,
|
|
193
|
+
if (this.blockLen = e, this.suffix = t, this.outputLen = s, this.enableXOF = r, this.rounds = n, q(s, "outputLen"), !(0 < e && e < 200))
|
|
195
194
|
throw new Error("only keccak-f1600 function is supported");
|
|
196
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
195
|
+
this.state = new Uint8Array(200), this.state32 = Ee(this.state);
|
|
197
196
|
}
|
|
198
197
|
clone() {
|
|
199
198
|
return this._cloneInto();
|
|
200
199
|
}
|
|
201
200
|
keccak() {
|
|
202
|
-
|
|
201
|
+
j(this.state32), _t(this.state32, this.rounds), j(this.state32), this.posOut = 0, this.pos = 0;
|
|
203
202
|
}
|
|
204
203
|
update(e) {
|
|
205
|
-
|
|
204
|
+
Y(this), Q(e);
|
|
206
205
|
const { blockLen: t, state: s } = this, r = e.length;
|
|
207
206
|
for (let n = 0; n < r; ) {
|
|
208
207
|
const i = Math.min(t - this.pos, r - n);
|
|
@@ -220,7 +219,7 @@ class G {
|
|
|
220
219
|
e[s] ^= t, (t & 128) !== 0 && s === r - 1 && this.keccak(), e[r - 1] ^= 128, this.keccak();
|
|
221
220
|
}
|
|
222
221
|
writeInto(e) {
|
|
223
|
-
|
|
222
|
+
Y(this, !1), Q(e), this.finish();
|
|
224
223
|
const t = this.state, { blockLen: s } = this;
|
|
225
224
|
for (let r = 0, n = e.length; r < n; ) {
|
|
226
225
|
this.posOut >= s && this.keccak();
|
|
@@ -235,10 +234,10 @@ class G {
|
|
|
235
234
|
return this.writeInto(e);
|
|
236
235
|
}
|
|
237
236
|
xof(e) {
|
|
238
|
-
return
|
|
237
|
+
return q(e), this.xofInto(new Uint8Array(e));
|
|
239
238
|
}
|
|
240
239
|
digestInto(e) {
|
|
241
|
-
if (
|
|
240
|
+
if (Se(e, this), this.finished)
|
|
242
241
|
throw new Error("digest() was already called");
|
|
243
242
|
return this.writeInto(e), this.destroy(), e;
|
|
244
243
|
}
|
|
@@ -246,30 +245,30 @@ class G {
|
|
|
246
245
|
return this.digestInto(new Uint8Array(this.outputLen));
|
|
247
246
|
}
|
|
248
247
|
destroy() {
|
|
249
|
-
this.destroyed = !0,
|
|
248
|
+
this.destroyed = !0, he(this.state);
|
|
250
249
|
}
|
|
251
250
|
_cloneInto(e) {
|
|
252
251
|
const { blockLen: t, suffix: s, outputLen: r, rounds: n, enableXOF: i } = this;
|
|
253
|
-
return e || (e = new
|
|
252
|
+
return e || (e = new z(t, s, r, i, n)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = n, e.suffix = s, e.outputLen = r, e.enableXOF = i, e.destroyed = this.destroyed, e;
|
|
254
253
|
}
|
|
255
254
|
}
|
|
256
|
-
const
|
|
257
|
-
function
|
|
258
|
-
return
|
|
255
|
+
const Ct = (o, e, t, s = {}) => ve(() => new z(e, o, t), s), At = /* @__PURE__ */ Ct(1, 136, 32), le = 64, w = 20, X = 4, ye = 2, It = 0, Ht = 1, R = [64, 64], $t = (o) => Array.from(o).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
256
|
+
function G(o) {
|
|
257
|
+
return Be(pe(o));
|
|
259
258
|
}
|
|
260
|
-
function
|
|
259
|
+
function xe(o) {
|
|
261
260
|
return (1 << o) - 1;
|
|
262
261
|
}
|
|
263
|
-
function
|
|
262
|
+
function Ot(o) {
|
|
264
263
|
let e = 1;
|
|
265
264
|
for (; e * e < o + 1; ) e++;
|
|
266
265
|
return Math.max(e, 2);
|
|
267
266
|
}
|
|
268
|
-
function
|
|
269
|
-
const e = X, t = o *
|
|
270
|
-
return { d: e, n: o, checksum_radix:
|
|
267
|
+
function Rt(o) {
|
|
268
|
+
const e = X, t = o * xe(e);
|
|
269
|
+
return { d: e, n: o, checksum_radix: Ot(t) };
|
|
271
270
|
}
|
|
272
|
-
function
|
|
271
|
+
function V(o, e) {
|
|
273
272
|
const t = [];
|
|
274
273
|
let s = e;
|
|
275
274
|
for (; s > 0; )
|
|
@@ -278,53 +277,53 @@ function M(o, e) {
|
|
|
278
277
|
r.set(o);
|
|
279
278
|
for (let n = 0; n < t.length; n++)
|
|
280
279
|
r[o.length + n] = t[n];
|
|
281
|
-
return
|
|
280
|
+
return G(r);
|
|
282
281
|
}
|
|
283
|
-
function
|
|
282
|
+
function M(o, e) {
|
|
284
283
|
let t = o;
|
|
285
284
|
for (let s = 0; s < e; s++)
|
|
286
|
-
t =
|
|
285
|
+
t = G(t);
|
|
287
286
|
return t;
|
|
288
287
|
}
|
|
289
|
-
function
|
|
290
|
-
const t =
|
|
291
|
-
for (let
|
|
292
|
-
const f =
|
|
293
|
-
n.push(Array.from(
|
|
288
|
+
function Wt(o, e) {
|
|
289
|
+
const t = xe(e.d), s = e.checksum_radix - 1, r = Math.floor(e.n * t / e.checksum_radix), n = [];
|
|
290
|
+
for (let p = 0; p < e.n; p++) {
|
|
291
|
+
const f = V(o, p + ye), y = M(f, t);
|
|
292
|
+
n.push(Array.from(y));
|
|
294
293
|
}
|
|
295
|
-
const i =
|
|
294
|
+
const i = V(
|
|
296
295
|
o,
|
|
297
|
-
|
|
298
|
-
), a =
|
|
296
|
+
It
|
|
297
|
+
), a = M(
|
|
299
298
|
i,
|
|
300
299
|
s
|
|
301
|
-
), c =
|
|
300
|
+
), c = V(
|
|
302
301
|
o,
|
|
303
|
-
|
|
304
|
-
),
|
|
302
|
+
Ht
|
|
303
|
+
), h = M(
|
|
305
304
|
c,
|
|
306
305
|
r
|
|
307
306
|
);
|
|
308
307
|
return {
|
|
309
308
|
config: e,
|
|
310
309
|
message_terminals: n,
|
|
311
|
-
checksum_major_terminal: Array.from(
|
|
310
|
+
checksum_major_terminal: Array.from(h),
|
|
312
311
|
checksum_minor_terminal: Array.from(a)
|
|
313
312
|
};
|
|
314
313
|
}
|
|
315
|
-
async function
|
|
314
|
+
async function Ft(o) {
|
|
316
315
|
try {
|
|
317
|
-
if (o.length !==
|
|
316
|
+
if (o.length !== le)
|
|
318
317
|
throw new Error(
|
|
319
|
-
`WOTS seed must be exactly ${
|
|
318
|
+
`WOTS seed must be exactly ${le} bytes, got ${o.length}`
|
|
320
319
|
);
|
|
321
320
|
const e = [];
|
|
322
|
-
for (let t = 0; t <
|
|
323
|
-
const s =
|
|
321
|
+
for (let t = 0; t < R.length; t++) {
|
|
322
|
+
const s = R[t], r = Rt(s), n = new Uint8Array(o.length + 1);
|
|
324
323
|
n.set(o), n[o.length] = t;
|
|
325
|
-
const i =
|
|
324
|
+
const i = G(n);
|
|
326
325
|
try {
|
|
327
|
-
const a =
|
|
326
|
+
const a = Wt(i, r);
|
|
328
327
|
if (a.config.d !== X)
|
|
329
328
|
throw new Error(
|
|
330
329
|
`Block ${t}: expected d=${X}, got d=${a.config.d}`
|
|
@@ -338,36 +337,36 @@ async function Ut(o) {
|
|
|
338
337
|
`Block ${t}: expected ${s} message terminals, got ${a.message_terminals.length}`
|
|
339
338
|
);
|
|
340
339
|
for (let c = 0; c < a.message_terminals.length; c++)
|
|
341
|
-
if (a.message_terminals[c].length !==
|
|
340
|
+
if (a.message_terminals[c].length !== w)
|
|
342
341
|
throw new Error(
|
|
343
|
-
`Block ${t} terminal ${c}: expected ${
|
|
342
|
+
`Block ${t} terminal ${c}: expected ${w} bytes, got ${a.message_terminals[c].length}`
|
|
344
343
|
);
|
|
345
|
-
if (a.checksum_minor_terminal.length !==
|
|
344
|
+
if (a.checksum_minor_terminal.length !== w)
|
|
346
345
|
throw new Error(
|
|
347
|
-
`Block ${t} checksum_minor: expected ${
|
|
346
|
+
`Block ${t} checksum_minor: expected ${w} bytes`
|
|
348
347
|
);
|
|
349
|
-
if (a.checksum_major_terminal.length !==
|
|
348
|
+
if (a.checksum_major_terminal.length !== w)
|
|
350
349
|
throw new Error(
|
|
351
|
-
`Block ${t} checksum_major: expected ${
|
|
350
|
+
`Block ${t} checksum_major: expected ${w} bytes`
|
|
352
351
|
);
|
|
353
352
|
e.push(a);
|
|
354
353
|
} finally {
|
|
355
354
|
n.fill(0), i.fill(0);
|
|
356
355
|
}
|
|
357
356
|
}
|
|
358
|
-
if (e.length !==
|
|
357
|
+
if (e.length !== R.length)
|
|
359
358
|
throw new Error(
|
|
360
|
-
`Expected ${
|
|
359
|
+
`Expected ${R.length} blocks, got ${e.length}`
|
|
361
360
|
);
|
|
362
361
|
return e;
|
|
363
362
|
} finally {
|
|
364
363
|
o.fill(0);
|
|
365
364
|
}
|
|
366
365
|
}
|
|
367
|
-
function
|
|
368
|
-
if (o.length !==
|
|
366
|
+
function K(o, e, t) {
|
|
367
|
+
if (o.length !== w)
|
|
369
368
|
throw new Error(
|
|
370
|
-
`Block ${e} ${t}: expected ${
|
|
369
|
+
`Block ${e} ${t}: expected ${w} bytes, got ${o.length}`
|
|
371
370
|
);
|
|
372
371
|
for (let s = 0; s < o.length; s++) {
|
|
373
372
|
const r = o[s];
|
|
@@ -377,43 +376,43 @@ function D(o, e, t) {
|
|
|
377
376
|
);
|
|
378
377
|
}
|
|
379
378
|
}
|
|
380
|
-
function
|
|
379
|
+
function Vt(o) {
|
|
381
380
|
if (o.length === 0)
|
|
382
381
|
throw new Error("Public keys array must not be empty");
|
|
383
382
|
for (let n = 0; n < o.length; n++) {
|
|
384
383
|
const i = o[n];
|
|
385
|
-
|
|
384
|
+
K(i.checksum_minor_terminal, n, "checksum_minor_terminal"), K(i.checksum_major_terminal, n, "checksum_major_terminal");
|
|
386
385
|
for (let a = 0; a < i.message_terminals.length; a++)
|
|
387
|
-
|
|
386
|
+
K(i.message_terminals[a], n, `message_terminal[${a}]`);
|
|
388
387
|
}
|
|
389
388
|
let e = 0;
|
|
390
389
|
for (const n of o)
|
|
391
|
-
e +=
|
|
392
|
-
const t = new Uint8Array(e *
|
|
390
|
+
e += ye + n.message_terminals.length;
|
|
391
|
+
const t = new Uint8Array(e * w);
|
|
393
392
|
let s = 0;
|
|
394
393
|
for (const n of o) {
|
|
395
|
-
t.set(n.checksum_minor_terminal, s), s +=
|
|
394
|
+
t.set(n.checksum_minor_terminal, s), s += w, t.set(n.checksum_major_terminal, s), s += w;
|
|
396
395
|
for (const i of n.message_terminals)
|
|
397
|
-
t.set(i, s), s +=
|
|
396
|
+
t.set(i, s), s += w;
|
|
398
397
|
}
|
|
399
|
-
const r =
|
|
400
|
-
return `0x${
|
|
398
|
+
const r = At(t);
|
|
399
|
+
return `0x${$t(r)}`;
|
|
401
400
|
}
|
|
402
|
-
async function
|
|
401
|
+
async function Mt(o, e) {
|
|
403
402
|
const t = [], s = [], r = [], n = [];
|
|
404
403
|
try {
|
|
405
404
|
for (let i = 0; i < e; i++) {
|
|
406
|
-
const a = await
|
|
405
|
+
const a = await He(o, i);
|
|
407
406
|
try {
|
|
408
|
-
const
|
|
409
|
-
t.push(
|
|
407
|
+
const h = await Ft(a);
|
|
408
|
+
t.push(h), s.push(Vt(h));
|
|
410
409
|
} finally {
|
|
411
410
|
a.fill(0);
|
|
412
411
|
}
|
|
413
|
-
const c = await
|
|
412
|
+
const c = await $e(o, i);
|
|
414
413
|
try {
|
|
415
|
-
const
|
|
416
|
-
r.push(
|
|
414
|
+
const h = U(c);
|
|
415
|
+
r.push(h), n.push(qe(Le(h)).slice(2));
|
|
417
416
|
} finally {
|
|
418
417
|
c.fill(0);
|
|
419
418
|
}
|
|
@@ -423,73 +422,73 @@ async function Lt(o, e) {
|
|
|
423
422
|
}
|
|
424
423
|
return { perVaultWotsKeys: t, wotsPkHashes: s, htlcSecretHexes: r, hashlocks: n };
|
|
425
424
|
}
|
|
426
|
-
const
|
|
427
|
-
function
|
|
425
|
+
const Kt = 1, Dt = 2, Nt = 33, Lt = 2, Ut = 3, Xt = 1, W = 64, zt = 0, D = 1, ue = /^[0-9a-f]{64}$/i, Gt = /^(?:[0-9a-f]{2})+$/;
|
|
426
|
+
function qt(o) {
|
|
428
427
|
const e = o.slice(2);
|
|
429
|
-
if (!
|
|
428
|
+
if (!Gt.test(e))
|
|
430
429
|
throw new Error(
|
|
431
430
|
"proof of possession witness is not even-length lowercase hex"
|
|
432
431
|
);
|
|
433
|
-
return
|
|
434
|
-
Uint8Array.from(
|
|
432
|
+
return Fe(
|
|
433
|
+
Uint8Array.from(_.from(e, "hex")),
|
|
435
434
|
"proof of possession witness"
|
|
436
435
|
);
|
|
437
436
|
}
|
|
438
|
-
function
|
|
437
|
+
function jt(o, e, t) {
|
|
439
438
|
var r;
|
|
440
|
-
const s =
|
|
441
|
-
if (s.length ===
|
|
439
|
+
const s = qt(t);
|
|
440
|
+
if (s.length === Kt) {
|
|
442
441
|
const [n] = s;
|
|
443
442
|
let i, a;
|
|
444
|
-
if (n.length ===
|
|
445
|
-
i = n, a =
|
|
446
|
-
else if (n.length ===
|
|
447
|
-
i = n.subarray(0,
|
|
443
|
+
if (n.length === W)
|
|
444
|
+
i = n, a = zt;
|
|
445
|
+
else if (n.length === W + 1 && n[W] === D)
|
|
446
|
+
i = n.subarray(0, W), a = D;
|
|
448
447
|
else
|
|
449
448
|
throw new Error(
|
|
450
449
|
"proof of possession witness item must be a 64-byte Schnorr signature (or 65 bytes ending in 0x01)"
|
|
451
450
|
);
|
|
452
|
-
if (!
|
|
451
|
+
if (!ue.test(e))
|
|
453
452
|
throw new Error(
|
|
454
453
|
`depositor public key must be bare 64-char x-only hex, got "${e}"`
|
|
455
454
|
);
|
|
456
|
-
const c = Uint8Array.from(
|
|
457
|
-
if (!
|
|
455
|
+
const c = Uint8Array.from(_.from(e, "hex"));
|
|
456
|
+
if (!nt(o, c, i, a))
|
|
458
457
|
throw new Error(
|
|
459
458
|
"proof of possession signature does not verify against the depositor key"
|
|
460
459
|
);
|
|
461
460
|
return { kind: "p2tr-verified" };
|
|
462
461
|
}
|
|
463
|
-
if (s.length ===
|
|
464
|
-
if (!
|
|
462
|
+
if (s.length === Dt) {
|
|
463
|
+
if (!ue.test(e))
|
|
465
464
|
throw new Error(
|
|
466
465
|
`depositor public key must be bare 64-char x-only hex, got "${e}"`
|
|
467
466
|
);
|
|
468
467
|
const [n, i] = s;
|
|
469
|
-
if (i.length !==
|
|
468
|
+
if (i.length !== Nt || i[0] !== Lt && i[0] !== Ut)
|
|
470
469
|
throw new Error(
|
|
471
470
|
`proof of possession P2WPKH witness item 1 is not a compressed public key (${i.length} bytes, prefix 0x${((r = i[0]) == null ? void 0 : r.toString(16)) ?? "none"})`
|
|
472
471
|
);
|
|
473
|
-
if (!
|
|
472
|
+
if (!st.isPointCompressed(i))
|
|
474
473
|
throw new Error(
|
|
475
474
|
"proof of possession P2WPKH witness pubkey is not a valid secp256k1 point"
|
|
476
475
|
);
|
|
477
|
-
const a =
|
|
478
|
-
i.subarray(
|
|
476
|
+
const a = _.from(
|
|
477
|
+
i.subarray(Xt)
|
|
479
478
|
).toString("hex");
|
|
480
479
|
if (a !== e.toLowerCase())
|
|
481
480
|
throw new Error(
|
|
482
481
|
`proof of possession witness pubkey does not match the depositor key: witness carries ${a}, expected ${e}`
|
|
483
482
|
);
|
|
484
|
-
if (n.length <
|
|
483
|
+
if (n.length < it || n.length > rt)
|
|
485
484
|
throw new Error(
|
|
486
485
|
`proof of possession signature is ${n.length} bytes; vault ingestion accepts only 71/72-byte DER signatures with a sighash byte — try a different account or a Taproot address`
|
|
487
486
|
);
|
|
488
|
-
if (n[n.length - 1] !==
|
|
487
|
+
if (n[n.length - 1] !== D)
|
|
489
488
|
throw new Error(
|
|
490
489
|
`proof of possession P2WPKH signature must end in a SIGHASH_ALL (0x01) byte, got 0x${n[n.length - 1].toString(16)}`
|
|
491
490
|
);
|
|
492
|
-
if (!
|
|
491
|
+
if (!at(o, i, n))
|
|
493
492
|
throw new Error(
|
|
494
493
|
"proof of possession signature does not verify against the depositor key"
|
|
495
494
|
);
|
|
@@ -499,8 +498,8 @@ function eo(o, e, t) {
|
|
|
499
498
|
`proof of possession witness has ${s.length} items; expected 1 (P2TR) or 2 (P2WPKH)`
|
|
500
499
|
);
|
|
501
500
|
}
|
|
502
|
-
const
|
|
503
|
-
function
|
|
501
|
+
const N = "00".repeat(32), Yt = "00".repeat(32);
|
|
502
|
+
function Qt(o, e) {
|
|
504
503
|
const t = {
|
|
505
504
|
bitcoin: "bc",
|
|
506
505
|
testnet: "tb",
|
|
@@ -508,22 +507,22 @@ function oo(o, e) {
|
|
|
508
507
|
regtest: "bcrt"
|
|
509
508
|
};
|
|
510
509
|
try {
|
|
511
|
-
const s =
|
|
510
|
+
const s = de.address.fromBech32(o);
|
|
512
511
|
return s.prefix === t[e] && s.version === 0 && s.data.length === 20;
|
|
513
512
|
} catch {
|
|
514
513
|
return !1;
|
|
515
514
|
}
|
|
516
515
|
}
|
|
517
|
-
function
|
|
516
|
+
function Zt(o, e, t, s) {
|
|
518
517
|
const r = t == null ? void 0 : t[`${o}:${e}`];
|
|
519
518
|
return r ? Promise.resolve({
|
|
520
519
|
txid: o,
|
|
521
520
|
vout: e,
|
|
522
521
|
value: r.value,
|
|
523
522
|
scriptPubKey: r.scriptPubKey
|
|
524
|
-
}) :
|
|
523
|
+
}) : Ie(o, e, s);
|
|
525
524
|
}
|
|
526
|
-
class
|
|
525
|
+
class wo {
|
|
527
526
|
/**
|
|
528
527
|
* Creates a new PeginManager instance.
|
|
529
528
|
*
|
|
@@ -546,14 +545,14 @@ class Io {
|
|
|
546
545
|
async preparePegin(e) {
|
|
547
546
|
if (e.amounts.length === 0)
|
|
548
547
|
throw new Error("amounts must contain at least one entry");
|
|
549
|
-
const t = await this.config.btcWallet.getPublicKeyHex(), s =
|
|
548
|
+
const t = await this.config.btcWallet.getPublicKeyHex(), s = B(t);
|
|
550
549
|
if (C(this.config.btcWallet)) {
|
|
551
|
-
const l = (await
|
|
550
|
+
const l = (await je(this.config.btcWallet)).trim();
|
|
552
551
|
if (e.changeAddress.trim() !== l)
|
|
553
552
|
throw new Error(
|
|
554
553
|
`Pre-PegIn changeAddress "${e.changeAddress}" is not the approval wallet's change address ("${l}"). Refusing to build a tx the signing device would reject.`
|
|
555
554
|
);
|
|
556
|
-
} else if (!
|
|
555
|
+
} else if (!oe(
|
|
557
556
|
e.changeAddress,
|
|
558
557
|
t,
|
|
559
558
|
this.config.btcNetwork
|
|
@@ -568,7 +567,7 @@ class Io {
|
|
|
568
567
|
this.config.btcWallet,
|
|
569
568
|
this.buildPeginDepositTerms({
|
|
570
569
|
params: e,
|
|
571
|
-
prepeginTxid:
|
|
570
|
+
prepeginTxid: Yt,
|
|
572
571
|
prepeginMaxFee: r.fee,
|
|
573
572
|
depositorClaimValue: r.depositorClaimValue,
|
|
574
573
|
peginMaxFee: r.minPeginFee
|
|
@@ -577,25 +576,25 @@ class Io {
|
|
|
577
576
|
}
|
|
578
577
|
const n = r.selectedUTXOs.map(
|
|
579
578
|
(l) => ({
|
|
580
|
-
txid:
|
|
579
|
+
txid: L(l.txid),
|
|
581
580
|
vout: l.vout
|
|
582
581
|
})
|
|
583
|
-
), i = await
|
|
584
|
-
depositorBtcPubkey:
|
|
582
|
+
), i = await fe(this.config.btcWallet, {
|
|
583
|
+
depositorBtcPubkey: L(s),
|
|
585
584
|
fundingOutpoints: n
|
|
586
585
|
});
|
|
587
586
|
let a, c;
|
|
588
587
|
try {
|
|
589
|
-
const l = await
|
|
588
|
+
const l = await Oe(i);
|
|
590
589
|
try {
|
|
591
|
-
a =
|
|
590
|
+
a = U(l), c = U(pe(l));
|
|
592
591
|
} finally {
|
|
593
592
|
l.fill(0);
|
|
594
593
|
}
|
|
595
594
|
} catch (l) {
|
|
596
595
|
throw i.fill(0), l;
|
|
597
596
|
}
|
|
598
|
-
const
|
|
597
|
+
const h = await Mt(i, e.amounts.length), { perVaultWotsKeys: p, wotsPkHashes: f, htlcSecretHexes: y, hashlocks: b } = h, g = await this.preparePeginCommit({
|
|
599
598
|
depositorBtcPubkeyRaw: t,
|
|
600
599
|
depositorBtcPubkey: s,
|
|
601
600
|
hashlocks: b,
|
|
@@ -608,12 +607,12 @@ class Io {
|
|
|
608
607
|
throw new Error(
|
|
609
608
|
`Internal invariant violation: htlcVout/index mismatch at vault ${l} (expected ${l}, got ${g.perVault[l].htlcVout})`
|
|
610
609
|
);
|
|
611
|
-
|
|
610
|
+
Ye(
|
|
612
611
|
g.fundedPrePeginTxHex,
|
|
613
612
|
e.amounts.length,
|
|
614
613
|
c
|
|
615
614
|
);
|
|
616
|
-
const { depositTerms:
|
|
615
|
+
const { depositTerms: v, ...k } = g;
|
|
617
616
|
return {
|
|
618
617
|
transaction: {
|
|
619
618
|
...k,
|
|
@@ -623,12 +622,12 @@ class Io {
|
|
|
623
622
|
},
|
|
624
623
|
depositorBtcPubkey: s,
|
|
625
624
|
derivedSecrets: {
|
|
626
|
-
perVaultWotsKeys:
|
|
625
|
+
perVaultWotsKeys: p,
|
|
627
626
|
wotsPkHashes: f,
|
|
628
|
-
htlcSecretHexes:
|
|
627
|
+
htlcSecretHexes: y,
|
|
629
628
|
authAnchorHex: a
|
|
630
629
|
},
|
|
631
|
-
depositTerms:
|
|
630
|
+
depositTerms: v
|
|
632
631
|
};
|
|
633
632
|
}
|
|
634
633
|
/**
|
|
@@ -649,13 +648,13 @@ class Io {
|
|
|
649
648
|
*/
|
|
650
649
|
async prepareSizing(e, t) {
|
|
651
650
|
const s = t.amounts.map(
|
|
652
|
-
() =>
|
|
653
|
-
), r = t.vaultKeeperBtcPubkeys.length, n = await
|
|
651
|
+
() => N
|
|
652
|
+
), r = t.vaultKeeperBtcPubkeys.length, n = await ee({
|
|
654
653
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
655
654
|
depositorPubkey: e,
|
|
656
|
-
vaultProviderPubkey:
|
|
657
|
-
vaultKeeperPubkeys: t.vaultKeeperBtcPubkeys.map(
|
|
658
|
-
universalChallengerPubkeys: t.universalChallengerBtcPubkeys.map(
|
|
655
|
+
vaultProviderPubkey: x(t.vaultProviderBtcPubkey),
|
|
656
|
+
vaultKeeperPubkeys: t.vaultKeeperBtcPubkeys.map(x),
|
|
657
|
+
universalChallengerPubkeys: t.universalChallengerBtcPubkeys.map(x),
|
|
659
658
|
hashlocks: s,
|
|
660
659
|
timelockRefund: t.timelockRefund,
|
|
661
660
|
pegInAmounts: t.amounts,
|
|
@@ -665,12 +664,12 @@ class Io {
|
|
|
665
664
|
councilQuorum: t.councilQuorum,
|
|
666
665
|
councilSize: t.councilSize,
|
|
667
666
|
network: this.config.btcNetwork,
|
|
668
|
-
authAnchorHash:
|
|
669
|
-
}), i =
|
|
667
|
+
authAnchorHash: N
|
|
668
|
+
}), i = Ze(
|
|
670
669
|
[...t.availableUTXOs],
|
|
671
670
|
n.totalOutputValue,
|
|
672
671
|
t.mempoolFeeRate,
|
|
673
|
-
|
|
672
|
+
et(n.htlcValues.length, !0)
|
|
674
673
|
);
|
|
675
674
|
return {
|
|
676
675
|
selectedUTXOs: i.selectedUTXOs,
|
|
@@ -687,7 +686,7 @@ class Io {
|
|
|
687
686
|
*/
|
|
688
687
|
buildPeginDepositTerms(e) {
|
|
689
688
|
const { params: t } = e;
|
|
690
|
-
return
|
|
689
|
+
return ft({
|
|
691
690
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
692
691
|
protocolFeeRate: t.protocolFeeRate,
|
|
693
692
|
timelockPegin: t.timelockPegin,
|
|
@@ -695,10 +694,10 @@ class Io {
|
|
|
695
694
|
timelockRefund: t.timelockRefund,
|
|
696
695
|
prepeginTxid: e.prepeginTxid,
|
|
697
696
|
prepeginMaxFee: e.prepeginMaxFee,
|
|
698
|
-
vaultProviderBtcPubkey:
|
|
699
|
-
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys.map(
|
|
700
|
-
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys.map(
|
|
701
|
-
maxAcceptableCommissionBps:
|
|
697
|
+
vaultProviderBtcPubkey: x(t.vaultProviderBtcPubkey),
|
|
698
|
+
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys.map(x),
|
|
699
|
+
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys.map(x),
|
|
700
|
+
maxAcceptableCommissionBps: _e(
|
|
702
701
|
t.commissionBps
|
|
703
702
|
),
|
|
704
703
|
peginAmounts: t.amounts,
|
|
@@ -715,118 +714,118 @@ class Io {
|
|
|
715
714
|
authAnchorHash: n,
|
|
716
715
|
sizing: i,
|
|
717
716
|
params: a
|
|
718
|
-
} = e, c =
|
|
719
|
-
for (let
|
|
720
|
-
if (r[
|
|
717
|
+
} = e, c = N.toLowerCase();
|
|
718
|
+
for (let u = 0; u < r.length; u++)
|
|
719
|
+
if (r[u].toLowerCase() === c)
|
|
721
720
|
throw new Error(
|
|
722
|
-
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${
|
|
721
|
+
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${u} — internal substitution bug`
|
|
723
722
|
);
|
|
724
723
|
if (n.toLowerCase() === c)
|
|
725
724
|
throw new Error(
|
|
726
725
|
"preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
|
|
727
726
|
);
|
|
728
|
-
const
|
|
727
|
+
const h = x(
|
|
729
728
|
a.vaultProviderBtcPubkey
|
|
730
|
-
),
|
|
729
|
+
), p = a.vaultKeeperBtcPubkeys.map(x), f = a.universalChallengerBtcPubkeys.map(x), y = p.length, b = {
|
|
731
730
|
vaultCoreVersion: a.vaultCoreVersion,
|
|
732
731
|
depositorPubkey: s,
|
|
733
|
-
vaultProviderPubkey:
|
|
734
|
-
vaultKeeperPubkeys:
|
|
732
|
+
vaultProviderPubkey: h,
|
|
733
|
+
vaultKeeperPubkeys: p,
|
|
735
734
|
universalChallengerPubkeys: f,
|
|
736
735
|
hashlocks: r,
|
|
737
736
|
timelockRefund: a.timelockRefund,
|
|
738
737
|
pegInAmounts: a.amounts,
|
|
739
738
|
feeRate: a.protocolFeeRate,
|
|
740
739
|
minPeginFeeRate: a.minPeginFeeRate,
|
|
741
|
-
numLocalChallengers:
|
|
740
|
+
numLocalChallengers: y,
|
|
742
741
|
councilQuorum: a.councilQuorum,
|
|
743
742
|
councilSize: a.councilSize,
|
|
744
743
|
network: this.config.btcNetwork,
|
|
745
744
|
authAnchorHash: n
|
|
746
|
-
}, g = await
|
|
745
|
+
}, g = await ee(b);
|
|
747
746
|
if (g.depositorClaimValue !== i.depositorClaimValue || g.minPeginFee !== i.minPeginFee)
|
|
748
747
|
throw new Error(
|
|
749
748
|
`Pre-PegIn sizing/commit divergence: depositorClaimValue ${i.depositorClaimValue} -> ${g.depositorClaimValue}, minPeginFee ${i.minPeginFee} -> ${g.minPeginFee}. The provisional deposit terms validated before derivation would not match the terms sent for approval; refusing to continue.`
|
|
750
749
|
);
|
|
751
|
-
const
|
|
750
|
+
const v = se(this.config.btcNetwork), k = tt({
|
|
752
751
|
unfundedTxHex: g.psbtHex,
|
|
753
752
|
selectedUTXOs: i.selectedUTXOs,
|
|
754
753
|
changeAddress: a.changeAddress,
|
|
755
754
|
changeAmount: i.changeAmount,
|
|
756
|
-
network:
|
|
757
|
-
}), l = i.selectedUTXOs.reduce((
|
|
755
|
+
network: v
|
|
756
|
+
}), l = i.selectedUTXOs.reduce((u, S) => u + BigInt(S.value), 0n) - g.totalOutputValue - i.changeAmount;
|
|
758
757
|
if (l !== i.fee)
|
|
759
758
|
throw new Error(
|
|
760
759
|
`Pre-PegIn funded fee ${l} does not match the sizing-pass fee ${i.fee}; refusing to publish a deposit-terms fee bound the funded transaction does not pay.`
|
|
761
760
|
);
|
|
762
|
-
const I =
|
|
763
|
-
|
|
764
|
-
), H = [],
|
|
765
|
-
for (let
|
|
766
|
-
const
|
|
761
|
+
const I = x(
|
|
762
|
+
Ue(k)
|
|
763
|
+
), H = [], d = [], m = [];
|
|
764
|
+
for (let u = 0; u < r.length; u++) {
|
|
765
|
+
const S = await Re({
|
|
767
766
|
prePeginParams: b,
|
|
768
767
|
timelockPegin: a.timelockPegin,
|
|
769
768
|
fundedPrePeginTxHex: k,
|
|
770
|
-
htlcVout:
|
|
771
|
-
}),
|
|
769
|
+
htlcVout: u
|
|
770
|
+
}), F = await Ve({
|
|
772
771
|
vaultCoreVersion: a.vaultCoreVersion,
|
|
773
|
-
peginTxHex:
|
|
772
|
+
peginTxHex: S.txHex,
|
|
774
773
|
fundedPrePeginTxHex: k,
|
|
775
774
|
depositorPubkey: s,
|
|
776
|
-
vaultProviderPubkey:
|
|
777
|
-
vaultKeeperPubkeys:
|
|
775
|
+
vaultProviderPubkey: h,
|
|
776
|
+
vaultKeeperPubkeys: p,
|
|
778
777
|
universalChallengerPubkeys: f,
|
|
779
|
-
hashlock: r[
|
|
778
|
+
hashlock: r[u],
|
|
780
779
|
timelockRefund: a.timelockRefund,
|
|
781
780
|
network: this.config.btcNetwork
|
|
782
781
|
});
|
|
783
|
-
H.push(
|
|
784
|
-
|
|
782
|
+
H.push(S), d.push(F.psbtHex), m.push(
|
|
783
|
+
Xe(t, 1)
|
|
785
784
|
);
|
|
786
785
|
}
|
|
787
|
-
const
|
|
786
|
+
const T = this.buildPeginDepositTerms({
|
|
788
787
|
params: a,
|
|
789
788
|
prepeginTxid: I,
|
|
790
789
|
prepeginMaxFee: i.fee,
|
|
791
790
|
depositorClaimValue: g.depositorClaimValue,
|
|
792
791
|
peginMaxFee: g.minPeginFee
|
|
793
792
|
});
|
|
794
|
-
C(this.config.btcWallet) && await this.config.btcWallet.approveDepositTerms(
|
|
795
|
-
const
|
|
793
|
+
C(this.config.btcWallet) && await this.config.btcWallet.approveDepositTerms(T);
|
|
794
|
+
const E = await Qe(
|
|
796
795
|
this.config.btcWallet,
|
|
797
|
-
|
|
796
|
+
d,
|
|
798
797
|
m
|
|
799
798
|
), $ = [];
|
|
800
|
-
for (let
|
|
801
|
-
|
|
802
|
-
requestedPsbtHex:
|
|
803
|
-
returnedPsbtHex:
|
|
799
|
+
for (let u = 0; u < E.length; u++) {
|
|
800
|
+
te({
|
|
801
|
+
requestedPsbtHex: d[u],
|
|
802
|
+
returnedPsbtHex: E[u]
|
|
804
803
|
});
|
|
805
|
-
const
|
|
806
|
-
|
|
804
|
+
const S = Me(
|
|
805
|
+
E[u],
|
|
807
806
|
s
|
|
808
807
|
);
|
|
809
|
-
|
|
810
|
-
requestedPsbtHex:
|
|
811
|
-
signatureHex:
|
|
808
|
+
We({
|
|
809
|
+
requestedPsbtHex: d[u],
|
|
810
|
+
signatureHex: S,
|
|
812
811
|
signerXOnlyPubkeyHex: s,
|
|
813
812
|
inputIndex: 0
|
|
814
813
|
});
|
|
815
|
-
const
|
|
814
|
+
const F = Ke(E[u]);
|
|
816
815
|
$.push({
|
|
817
|
-
htlcVout:
|
|
818
|
-
htlcValue: g.htlcValues[
|
|
819
|
-
peginTxHex:
|
|
820
|
-
peginTxid: H[
|
|
821
|
-
peginInputSignature:
|
|
822
|
-
vaultScriptPubKey: H[
|
|
816
|
+
htlcVout: u,
|
|
817
|
+
htlcValue: g.htlcValues[u],
|
|
818
|
+
peginTxHex: F,
|
|
819
|
+
peginTxid: H[u].txid,
|
|
820
|
+
peginInputSignature: S,
|
|
821
|
+
vaultScriptPubKey: H[u].vaultScriptPubKey
|
|
823
822
|
});
|
|
824
823
|
}
|
|
825
824
|
return {
|
|
826
825
|
fundedPrePeginTxHex: k,
|
|
827
826
|
prePeginTxid: I,
|
|
828
827
|
perVault: $,
|
|
829
|
-
depositTerms:
|
|
828
|
+
depositTerms: T
|
|
830
829
|
};
|
|
831
830
|
}
|
|
832
831
|
/**
|
|
@@ -853,37 +852,37 @@ class Io {
|
|
|
853
852
|
* @throws Error if signing or broadcasting fails
|
|
854
853
|
*/
|
|
855
854
|
async signAndBroadcast(e) {
|
|
856
|
-
const { fundedPrePeginTxHex: t, depositorBtcPubkey: s } = e, r = t.startsWith("0x") ? t.slice(2) : t, n =
|
|
855
|
+
const { fundedPrePeginTxHex: t, depositorBtcPubkey: s } = e, r = t.startsWith("0x") ? t.slice(2) : t, n = ge.fromHex(r);
|
|
857
856
|
if (n.ins.length === 0)
|
|
858
857
|
throw new Error("Transaction has no inputs");
|
|
859
858
|
const i = new Z();
|
|
860
859
|
i.setVersion(n.version), i.setLocktime(n.locktime);
|
|
861
|
-
const a =
|
|
862
|
-
|
|
860
|
+
const a = _.from(
|
|
861
|
+
B(s),
|
|
863
862
|
"hex"
|
|
864
|
-
), c = this.config.mempoolApiUrl,
|
|
865
|
-
const m =
|
|
866
|
-
return
|
|
867
|
-
(
|
|
863
|
+
), c = this.config.mempoolApiUrl, h = n.ins.map((d) => {
|
|
864
|
+
const m = _.from(d.hash).reverse().toString("hex"), T = d.index;
|
|
865
|
+
return Zt(m, T, e.localPrevouts, c).then(
|
|
866
|
+
(E) => ({ input: d, utxoData: E, txid: m, vout: T })
|
|
868
867
|
);
|
|
869
|
-
}),
|
|
870
|
-
(
|
|
868
|
+
}), p = await Promise.all(h), f = p.reduce(
|
|
869
|
+
(d, m) => d + BigInt(m.utxoData.value),
|
|
871
870
|
0n
|
|
872
|
-
),
|
|
873
|
-
(
|
|
871
|
+
), y = n.outs.reduce(
|
|
872
|
+
(d, m) => d + BigInt(m.value),
|
|
874
873
|
0n
|
|
875
874
|
);
|
|
876
|
-
if (f <
|
|
875
|
+
if (f < y)
|
|
877
876
|
throw new Error(
|
|
878
|
-
`UTXO value mismatch: total input value (${f} sat) is less than total output value (${
|
|
877
|
+
`UTXO value mismatch: total input value (${f} sat) is less than total output value (${y} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
879
878
|
);
|
|
880
|
-
const b = f -
|
|
881
|
-
if (b >
|
|
879
|
+
const b = f - y;
|
|
880
|
+
if (b > ne)
|
|
882
881
|
throw new Error(
|
|
883
|
-
`Implied transaction fee (${b} sat) exceeds maximum reasonable fee (${
|
|
882
|
+
`Implied transaction fee (${b} sat) exceeds maximum reasonable fee (${ne} sat). This may indicate manipulated UTXO data.`
|
|
884
883
|
);
|
|
885
|
-
for (const { input:
|
|
886
|
-
const $ =
|
|
884
|
+
for (const { input: d, utxoData: m, txid: T, vout: E } of p) {
|
|
885
|
+
const $ = Je(
|
|
887
886
|
{
|
|
888
887
|
value: m.value,
|
|
889
888
|
scriptPubKey: m.scriptPubKey
|
|
@@ -891,49 +890,49 @@ class Io {
|
|
|
891
890
|
a
|
|
892
891
|
);
|
|
893
892
|
i.addInput({
|
|
894
|
-
hash:
|
|
895
|
-
index:
|
|
896
|
-
sequence:
|
|
893
|
+
hash: d.hash,
|
|
894
|
+
index: d.index,
|
|
895
|
+
sequence: d.sequence,
|
|
897
896
|
...$
|
|
898
897
|
});
|
|
899
898
|
}
|
|
900
|
-
for (const
|
|
899
|
+
for (const d of n.outs)
|
|
901
900
|
i.addOutput({
|
|
902
|
-
script:
|
|
903
|
-
value:
|
|
901
|
+
script: d.script,
|
|
902
|
+
value: d.value
|
|
904
903
|
});
|
|
905
|
-
await
|
|
904
|
+
await yt({
|
|
906
905
|
wallet: this.config.btcWallet,
|
|
907
906
|
depositTerms: e.depositTerms,
|
|
908
907
|
fundedPrePeginTxHex: t,
|
|
909
908
|
depositorBtcPubkey: s
|
|
910
909
|
});
|
|
911
|
-
const g = i.toHex(),
|
|
912
|
-
|
|
910
|
+
const g = i.toHex(), v = await this.config.btcWallet.signPsbt(g);
|
|
911
|
+
te({
|
|
913
912
|
requestedPsbtHex: g,
|
|
914
|
-
returnedPsbtHex:
|
|
913
|
+
returnedPsbtHex: v
|
|
915
914
|
});
|
|
916
|
-
const k =
|
|
915
|
+
const k = De({
|
|
917
916
|
requestedPsbtHex: g,
|
|
918
|
-
returnedPsbtHex:
|
|
917
|
+
returnedPsbtHex: v
|
|
919
918
|
});
|
|
920
919
|
if (C(this.config.btcWallet) && k !== i.data.inputs.length)
|
|
921
920
|
throw new Error(
|
|
922
921
|
`Key-path verification covered ${k} of ${i.data.inputs.length} Pre-PegIn inputs; an approval wallet signs every input key-path, so the unverified ones must not be broadcast.`
|
|
923
922
|
);
|
|
924
|
-
const l = Z.fromHex(
|
|
923
|
+
const l = Z.fromHex(v);
|
|
925
924
|
try {
|
|
926
925
|
l.finalizeAllInputs();
|
|
927
|
-
} catch (
|
|
926
|
+
} catch (d) {
|
|
928
927
|
if (!l.data.inputs.every(
|
|
929
|
-
(
|
|
928
|
+
(T) => T.finalScriptWitness || T.finalScriptSig
|
|
930
929
|
))
|
|
931
930
|
throw new Error(
|
|
932
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
931
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${d}`
|
|
933
932
|
);
|
|
934
933
|
}
|
|
935
934
|
const I = l.extractTransaction().toHex();
|
|
936
|
-
return await
|
|
935
|
+
return await Ae(I, c);
|
|
937
936
|
}
|
|
938
937
|
/**
|
|
939
938
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -986,7 +985,8 @@ class Io {
|
|
|
986
985
|
depositorBtcPubkeyRaw: s,
|
|
987
986
|
depositorWotsPkHash: e.depositorWotsPkHash,
|
|
988
987
|
popSignature: e.popSignature,
|
|
989
|
-
quotedCommissionBps: e.quotedCommissionBps
|
|
988
|
+
quotedCommissionBps: e.quotedCommissionBps,
|
|
989
|
+
expectedFingerprint: e.expectedFingerprint
|
|
990
990
|
});
|
|
991
991
|
}
|
|
992
992
|
/**
|
|
@@ -1026,6 +1026,7 @@ class Io {
|
|
|
1026
1026
|
popSignature: e.popSignature,
|
|
1027
1027
|
depositorBtcPubkeyRaw: s,
|
|
1028
1028
|
quotedCommissionBps: e.quotedCommissionBps,
|
|
1029
|
+
expectedFingerprint: e.expectedFingerprint,
|
|
1029
1030
|
requests: e.requests.map((n, i) => ({
|
|
1030
1031
|
depositorSignedPeginTx: n.depositorSignedPeginTx,
|
|
1031
1032
|
hashlock: n.hashlock,
|
|
@@ -1036,7 +1037,7 @@ class Io {
|
|
|
1036
1037
|
});
|
|
1037
1038
|
}
|
|
1038
1039
|
createRegistrationClient() {
|
|
1039
|
-
return new
|
|
1040
|
+
return new Ce({
|
|
1040
1041
|
ethWallet: this.config.ethWallet,
|
|
1041
1042
|
ethChain: this.config.ethChain,
|
|
1042
1043
|
publicClient: this.config.publicClient,
|
|
@@ -1063,20 +1064,20 @@ class Io {
|
|
|
1063
1064
|
* on-chain payout-script registration.
|
|
1064
1065
|
*/
|
|
1065
1066
|
resolvePayoutScriptPubKey(e, t) {
|
|
1066
|
-
if (!
|
|
1067
|
+
if (!oe(
|
|
1067
1068
|
t,
|
|
1068
1069
|
e,
|
|
1069
1070
|
this.config.btcNetwork
|
|
1070
1071
|
))
|
|
1071
|
-
throw
|
|
1072
|
+
throw x(e).length === ze && Qt(t, this.config.btcNetwork) ? new Error(
|
|
1072
1073
|
`BTC payout address "${t}" 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.`
|
|
1073
1074
|
) : new Error(
|
|
1074
1075
|
`BTC payout address "${t}" 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.`
|
|
1075
1076
|
);
|
|
1076
|
-
const s =
|
|
1077
|
+
const s = se(this.config.btcNetwork);
|
|
1077
1078
|
let r;
|
|
1078
1079
|
try {
|
|
1079
|
-
r =
|
|
1080
|
+
r = de.address.toOutputScript(t, s).toString("hex");
|
|
1080
1081
|
} catch {
|
|
1081
1082
|
throw new Error(
|
|
1082
1083
|
`Invalid BTC payout address: "${t}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1100,13 +1101,13 @@ class Io {
|
|
|
1100
1101
|
async signProofOfPossession() {
|
|
1101
1102
|
if (!this.config.ethWallet.account)
|
|
1102
1103
|
throw new Error("Ethereum wallet account not found");
|
|
1103
|
-
const e = this.config.ethWallet.account.address, t =
|
|
1104
|
+
const e = this.config.ethWallet.account.address, t = B(
|
|
1104
1105
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1105
1106
|
), s = this.config.vaultContracts.btcVaultRegistry, r = `${e.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, n = await this.config.btcWallet.signMessage(
|
|
1106
1107
|
r,
|
|
1107
1108
|
"bip322-simple"
|
|
1108
|
-
), i =
|
|
1109
|
-
return
|
|
1109
|
+
), i = wt(n);
|
|
1110
|
+
return jt(
|
|
1110
1111
|
new TextEncoder().encode(r),
|
|
1111
1112
|
t,
|
|
1112
1113
|
i
|
|
@@ -1121,7 +1122,7 @@ class Io {
|
|
|
1121
1122
|
* substitute the opposite-parity P2WPKH address.
|
|
1122
1123
|
*/
|
|
1123
1124
|
async assertPopMatchesBtcWallet(e) {
|
|
1124
|
-
const t = await this.config.btcWallet.getPublicKeyHex(), s =
|
|
1125
|
+
const t = await this.config.btcWallet.getPublicKeyHex(), s = B(t), r = B(e.depositorBtcPubkey);
|
|
1125
1126
|
if (s !== r)
|
|
1126
1127
|
throw new Error(
|
|
1127
1128
|
`Proof of possession was signed with BTC pubkey ${r} but the BTC wallet is currently connected to ${s}. Reconnect the original wallet or call signProofOfPossession() again.`
|
|
@@ -1145,72 +1146,12 @@ class Io {
|
|
|
1145
1146
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1146
1147
|
}
|
|
1147
1148
|
}
|
|
1148
|
-
const no = 80, io = 250, ro = 300, ao = 22, Ee = "ab";
|
|
1149
|
-
function co(o, e) {
|
|
1150
|
-
const t = Ee.repeat(ro), s = w(o).toLowerCase(), r = e.toString(16).padStart(8, "0"), n = `${s}${r}`, i = t.slice(n.length);
|
|
1151
|
-
return `0x${n}${i}`;
|
|
1152
|
-
}
|
|
1153
|
-
function lo(o, e) {
|
|
1154
|
-
const t = (s) => `0x${Ee.repeat(s)}`;
|
|
1155
|
-
return {
|
|
1156
|
-
depositorBtcPubKey: t(32),
|
|
1157
|
-
btcPopSignature: t(no),
|
|
1158
|
-
unsignedPrePeginTx: t(io),
|
|
1159
|
-
depositorSignedPeginTx: co(
|
|
1160
|
-
o,
|
|
1161
|
-
e
|
|
1162
|
-
),
|
|
1163
|
-
hashlock: t(32),
|
|
1164
|
-
htlcVout: e,
|
|
1165
|
-
referralCode: Re,
|
|
1166
|
-
depositorPayoutBtcAddress: t(ao),
|
|
1167
|
-
depositorWotsPkHash: t(32)
|
|
1168
|
-
};
|
|
1169
|
-
}
|
|
1170
|
-
async function Ho(o) {
|
|
1171
|
-
const {
|
|
1172
|
-
publicClient: e,
|
|
1173
|
-
btcVaultRegistry: t,
|
|
1174
|
-
depositorEthAddress: s,
|
|
1175
|
-
vaultProvider: r,
|
|
1176
|
-
batchSize: n
|
|
1177
|
-
} = o;
|
|
1178
|
-
if (n <= 0)
|
|
1179
|
-
throw new Error(
|
|
1180
|
-
`estimateSubmitPeginRequestBatchGas requires batchSize >= 1 (received ${n})`
|
|
1181
|
-
);
|
|
1182
|
-
const a = await e.readContract({
|
|
1183
|
-
address: t,
|
|
1184
|
-
abi: ee,
|
|
1185
|
-
functionName: "getPegInFee",
|
|
1186
|
-
args: [r]
|
|
1187
|
-
}) * BigInt(n), c = Array.from(
|
|
1188
|
-
{ length: n },
|
|
1189
|
-
(d, f) => lo(s, f)
|
|
1190
|
-
), u = Ce({
|
|
1191
|
-
abi: ee,
|
|
1192
|
-
functionName: "submitPeginRequestBatch",
|
|
1193
|
-
args: [
|
|
1194
|
-
s,
|
|
1195
|
-
r,
|
|
1196
|
-
$e,
|
|
1197
|
-
c
|
|
1198
|
-
]
|
|
1199
|
-
});
|
|
1200
|
-
return e.estimateGas({
|
|
1201
|
-
to: t,
|
|
1202
|
-
data: u,
|
|
1203
|
-
value: a,
|
|
1204
|
-
account: s
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
1149
|
export {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
Lt as f
|
|
1150
|
+
wo as P,
|
|
1151
|
+
Mt as a,
|
|
1152
|
+
ft as b,
|
|
1153
|
+
Vt as c,
|
|
1154
|
+
Ft as d,
|
|
1155
|
+
yt as e
|
|
1215
1156
|
};
|
|
1216
|
-
//# sourceMappingURL=PeginManager-
|
|
1157
|
+
//# sourceMappingURL=PeginManager-BXlh3ar0.js.map
|