@babylonlabs-io/ts-sdk 0.28.1 → 0.29.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/PeginManager-DcjXiKYC.cjs +2 -0
- package/dist/PeginManager-DcjXiKYC.cjs.map +1 -0
- package/dist/{PeginManager-DzMSIQ0I.js → PeginManager-Dj6oDaH5.js} +622 -580
- package/dist/PeginManager-Dj6oDaH5.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +17 -14
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/pegin/__tests__/assertAuthAnchorOpReturn.test.d.ts +2 -0
- package/dist/tbv/core/managers/pegin/__tests__/assertAuthAnchorOpReturn.test.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/__tests__/expandPerVaultSecrets.test.d.ts +2 -0
- package/dist/tbv/core/managers/pegin/__tests__/expandPerVaultSecrets.test.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/__tests__/normalizeWalletInputs.test.d.ts +2 -0
- package/dist/tbv/core/managers/pegin/__tests__/normalizeWalletInputs.test.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/__tests__/signPsbtsWithFallback.test.d.ts +2 -0
- package/dist/tbv/core/managers/pegin/__tests__/signPsbtsWithFallback.test.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/assertAuthAnchorOpReturn.d.ts +25 -0
- package/dist/tbv/core/managers/pegin/assertAuthAnchorOpReturn.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/expandPerVaultSecrets.d.ts +25 -0
- package/dist/tbv/core/managers/pegin/expandPerVaultSecrets.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/index.d.ts +12 -0
- package/dist/tbv/core/managers/pegin/index.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/normalizeWalletInputs.d.ts +23 -0
- package/dist/tbv/core/managers/pegin/normalizeWalletInputs.d.ts.map +1 -0
- package/dist/tbv/core/managers/pegin/signPsbtsWithFallback.d.ts +12 -0
- package/dist/tbv/core/managers/pegin/signPsbtsWithFallback.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +1 -1
- package/package.json +1 -1
- package/dist/PeginManager-Da4uSHzl.cjs +0 -2
- package/dist/PeginManager-Da4uSHzl.cjs.map +0 -1
- package/dist/PeginManager-DzMSIQ0I.js.map +0 -1
|
@@ -1,132 +1,65 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { h as
|
|
12
|
-
import { c as
|
|
13
|
-
import { M as
|
|
14
|
-
import {
|
|
15
|
-
import { b as
|
|
16
|
-
import { p as
|
|
17
|
-
import { p as
|
|
18
|
-
import { B as
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
23
|
-
"0x4fec082d": "Script mismatch: The Bitcoin transaction's taproot output does not match the expected vault script. This may be caused by incorrect vault participants or key configuration.",
|
|
24
|
-
// InvalidBTCProofOfPossession()
|
|
25
|
-
"0x6cc363a5": "Invalid BTC proof of possession: The signature could not be verified. Please ensure you're signing with the correct Bitcoin wallet.",
|
|
26
|
-
// InvalidBTCPublicKey()
|
|
27
|
-
"0x6c3f2bf6": "Invalid BTC public key: The Bitcoin public key format is invalid.",
|
|
28
|
-
// InvalidAmount()
|
|
29
|
-
"0x2c5211c6": "Invalid amount: The deposit amount is invalid or below the minimum required.",
|
|
30
|
-
// ApplicationNotRegistered()
|
|
31
|
-
"0x0405f772": "Application not registered: The application controller is not registered in the system.",
|
|
32
|
-
// InvalidProviderStatus()
|
|
33
|
-
"0x24e165cc": "Invalid provider status: The vault provider is not in a valid state to accept deposits.",
|
|
34
|
-
// ZeroAddress()
|
|
35
|
-
"0xd92e233d": "Zero address: One of the required addresses is the zero address.",
|
|
36
|
-
// BtcKeyMismatch()
|
|
37
|
-
"0x65aa7007": "BTC key mismatch: The Bitcoin public key does not match the expected key.",
|
|
38
|
-
// Unauthorized()
|
|
39
|
-
"0x82b42900": "Unauthorized: You must be the depositor or vault provider to submit this transaction.",
|
|
40
|
-
// InvalidSignature() - common signature verification error
|
|
41
|
-
"0x8baa579f": "Invalid signature: The BTC proof of possession signature could not be verified.",
|
|
42
|
-
// InvalidBtcTransaction()
|
|
43
|
-
"0x2f9d01e9": "Invalid BTC transaction: The Bitcoin transaction format is invalid.",
|
|
44
|
-
// VaultProviderNotRegistered()
|
|
45
|
-
"0x5a3c6b3e": "Vault provider not registered: The selected vault provider is not registered.",
|
|
46
|
-
// InvalidPeginFee(uint256,uint256)
|
|
47
|
-
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction.",
|
|
48
|
-
// PrePeginOutputAlreadyUsed()
|
|
49
|
-
"0x5fad9694": "This pre-pegin output has already been used to activate another vault.",
|
|
50
|
-
// PeginTransactionAlreadyUsed()
|
|
51
|
-
"0x7ed061c9": "This pegin transaction has already been used to activate another vault."
|
|
52
|
-
};
|
|
53
|
-
function at(e) {
|
|
54
|
-
if (!e || typeof e != "object") return;
|
|
55
|
-
const t = e;
|
|
56
|
-
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
57
|
-
return t.data;
|
|
58
|
-
if (typeof t.details == "string" && t.details.startsWith("0x"))
|
|
59
|
-
return t.details;
|
|
60
|
-
let n = t.cause, s = 0;
|
|
61
|
-
const o = 5;
|
|
62
|
-
for (; n && typeof n == "object" && s < o; ) {
|
|
63
|
-
const a = n;
|
|
64
|
-
if (typeof a.data == "string" && a.data.startsWith("0x"))
|
|
65
|
-
return a.data;
|
|
66
|
-
n = a.cause, s++;
|
|
67
|
-
}
|
|
68
|
-
const i = (typeof t.message == "string" ? t.message : "").match(/\b(0x[a-fA-F0-9]{8})\b/);
|
|
69
|
-
if (i)
|
|
70
|
-
return i[1];
|
|
71
|
-
}
|
|
72
|
-
function Ln(e) {
|
|
73
|
-
const t = at(e);
|
|
74
|
-
if (t) {
|
|
75
|
-
const n = t.substring(0, 10);
|
|
76
|
-
return S[t] ?? S[n];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function Vn(e) {
|
|
80
|
-
const t = at(e);
|
|
81
|
-
if (t === void 0) return !1;
|
|
82
|
-
const n = t.substring(0, 10);
|
|
83
|
-
return t in S || n in S;
|
|
84
|
-
}
|
|
85
|
-
function H(e) {
|
|
86
|
-
console.error("[Contract Error] Raw error:", e);
|
|
87
|
-
const t = at(e);
|
|
88
|
-
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
89
|
-
const s = t.substring(0, 10), o = S[t] ?? S[s];
|
|
90
|
-
if (o)
|
|
91
|
-
throw console.error("[Contract Error] Known error:", o), new Error(o);
|
|
92
|
-
}
|
|
93
|
-
const n = (e == null ? void 0 : e.message) || "";
|
|
94
|
-
if (n.includes("gas limit too high") || n.includes("21000000") || n.includes("Internal JSON-RPC error")) {
|
|
95
|
-
const s = t ? ` (error code: ${t})` : "";
|
|
96
|
-
throw console.error(
|
|
97
|
-
"[Contract Error] Transaction rejected. Error code:",
|
|
98
|
-
t,
|
|
99
|
-
"Message:",
|
|
100
|
-
n
|
|
101
|
-
), new Error(
|
|
102
|
-
`Transaction failed: The contract rejected this transaction${s}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
1
|
+
var ne = Object.defineProperty;
|
|
2
|
+
var se = (e, t, n) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var m = (e, t, n) => se(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { a as Lt, b as N, c as A, d as K, e as st, s as O, f as Nt, H as oe, r as V, u as re, g as pt, h as ie } from "./sha2-6wN58S6R.js";
|
|
5
|
+
import * as Vt from "bitcoinjs-lib";
|
|
6
|
+
import { Transaction as ae, Psbt as mt } from "bitcoinjs-lib";
|
|
7
|
+
import { Buffer as ot } from "buffer";
|
|
8
|
+
import { isAddressEqual as wt, createPublicClient as G, http as Z, encodeFunctionData as bt, zeroAddress as ce } from "viem";
|
|
9
|
+
import { deriveVaultId as yt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
import { b as xt, a as le, d as ue, e as he, f as de } from "./challengeAssert-j2Vwqo0-.js";
|
|
11
|
+
import { s as _, u as D, h as rt, e as I, p as fe, g as Pt, i as ge } from "./bitcoin-B-Y0DlqR.js";
|
|
12
|
+
import { c as pe } from "./signing-BZigafm0.js";
|
|
13
|
+
import { M as Et } from "./validation-CxqROCno.js";
|
|
14
|
+
import { h as me } from "./buildAndBroadcastRefund-xWS8frc6.js";
|
|
15
|
+
import { b as we, f as q, i as be } from "./psbtInputFields-DeTFSJOq.js";
|
|
16
|
+
import { p as ye, f as xe } from "./fundPeginTransaction-oV-dNJOU.js";
|
|
17
|
+
import { p as Pe, f as Ee } from "./vault-registry-reader-BywZhqJL.js";
|
|
18
|
+
import { B as R } from "./types-CnG3JsRs.js";
|
|
19
|
+
const W = /* @__PURE__ */ BigInt(2 ** 32 - 1), Tt = /* @__PURE__ */ BigInt(32);
|
|
20
|
+
function Te(e, t = !1) {
|
|
21
|
+
return t ? { h: Number(e & W), l: Number(e >> Tt & W) } : { h: Number(e >> Tt & W) | 0, l: Number(e & W) | 0 };
|
|
106
22
|
}
|
|
107
|
-
|
|
108
|
-
function Pe(e, t = !1) {
|
|
109
|
-
return t ? { h: Number(e & W), l: Number(e >> Pt & W) } : { h: Number(e >> Pt & W) | 0, l: Number(e & W) | 0 };
|
|
110
|
-
}
|
|
111
|
-
function Ee(e, t = !1) {
|
|
23
|
+
function ke(e, t = !1) {
|
|
112
24
|
const n = e.length;
|
|
113
25
|
let s = new Uint32Array(n), o = new Uint32Array(n);
|
|
114
26
|
for (let r = 0; r < n; r++) {
|
|
115
|
-
const { h: i, l: a } =
|
|
27
|
+
const { h: i, l: a } = Te(e[r], t);
|
|
116
28
|
[s[r], o[r]] = [i, a];
|
|
117
29
|
}
|
|
118
30
|
return [s, o];
|
|
119
31
|
}
|
|
120
|
-
const
|
|
121
|
-
|
|
32
|
+
const _e = (e, t, n) => e << n | t >>> 32 - n, ve = (e, t, n) => t << n | e >>> 32 - n, Ie = (e, t, n) => t << n - 32 | e >>> 64 - n, He = (e, t, n) => e << n - 32 | t >>> 64 - n, Be = 106, Se = 32, kt = 34;
|
|
33
|
+
function Ae(e, t, n) {
|
|
34
|
+
const s = _(e), o = Vt.Transaction.fromHex(s);
|
|
35
|
+
if (o.outs.length <= t)
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Pre-PegIn auth-anchor OP_RETURN missing: tx has ${o.outs.length} outputs, expected at least ${t + 1} (vault outputs + OP_RETURN)`
|
|
38
|
+
);
|
|
39
|
+
const r = o.outs[t], i = r.script;
|
|
40
|
+
if (i.length !== kt || i[0] !== Be || i[1] !== Se)
|
|
41
|
+
throw new Error(
|
|
42
|
+
`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 ${kt}-byte OP_RETURN + PUSH32 layout)`
|
|
43
|
+
);
|
|
44
|
+
const a = i.slice(2).toString("hex").toLowerCase();
|
|
45
|
+
if (a !== n.toLowerCase())
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Pre-PegIn auth-anchor OP_RETURN payload mismatch at vout ${t}: tx pushes ${a}, expected ${n}`
|
|
48
|
+
);
|
|
49
|
+
if (r.value !== 0)
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has non-zero value ${r.value}; OP_RETURN outputs must be 0-value`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
class Wt {
|
|
122
55
|
constructor(t, n) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (
|
|
56
|
+
m(this, "oHash");
|
|
57
|
+
m(this, "iHash");
|
|
58
|
+
m(this, "blockLen");
|
|
59
|
+
m(this, "outputLen");
|
|
60
|
+
m(this, "finished", !1);
|
|
61
|
+
m(this, "destroyed", !1);
|
|
62
|
+
if (Lt(t), N(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
130
63
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
131
64
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
132
65
|
const s = this.blockLen, o = new Uint8Array(s);
|
|
@@ -139,10 +72,10 @@ class Lt {
|
|
|
139
72
|
this.oHash.update(o), A(o);
|
|
140
73
|
}
|
|
141
74
|
update(t) {
|
|
142
|
-
return
|
|
75
|
+
return K(this), this.iHash.update(t), this;
|
|
143
76
|
}
|
|
144
77
|
digestInto(t) {
|
|
145
|
-
|
|
78
|
+
K(this), N(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
146
79
|
}
|
|
147
80
|
digest() {
|
|
148
81
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -160,137 +93,137 @@ class Lt {
|
|
|
160
93
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
161
94
|
}
|
|
162
95
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
function
|
|
167
|
-
|
|
96
|
+
const Mt = (e, t, n) => new Wt(e, t).update(n).digest();
|
|
97
|
+
Mt.create = (e, t) => new Wt(e, t);
|
|
98
|
+
const Y = /* @__PURE__ */ Uint8Array.of(0), _t = /* @__PURE__ */ Uint8Array.of();
|
|
99
|
+
function lt(e, t, n, s = 32) {
|
|
100
|
+
Lt(e), st(s, "length");
|
|
168
101
|
const o = e.outputLen;
|
|
169
102
|
if (s > 255 * o)
|
|
170
103
|
throw new Error("Length must be <= 255*HashLen");
|
|
171
104
|
const r = Math.ceil(s / o);
|
|
172
|
-
n === void 0 ? n =
|
|
173
|
-
const i = new Uint8Array(r * o), a =
|
|
105
|
+
n === void 0 ? n = _t : N(n, void 0, "info");
|
|
106
|
+
const i = new Uint8Array(r * o), a = Mt.create(e, t), l = a._cloneInto(), u = new Uint8Array(a.outputLen);
|
|
174
107
|
for (let c = 0; c < r; c++)
|
|
175
|
-
|
|
176
|
-
return a.destroy(), l.destroy(), A(u,
|
|
108
|
+
Y[0] = c + 1, l.update(c === 0 ? _t : u).update(n).update(Y).digestInto(u), i.set(u, o * c), a._cloneInto(l);
|
|
109
|
+
return a.destroy(), l.destroy(), A(u, Y), i.slice(0, s);
|
|
177
110
|
}
|
|
178
|
-
const
|
|
179
|
-
function
|
|
111
|
+
const Q = new TextEncoder().encode("babylonvault"), vt = 255, It = 65535, Ht = 2, Ce = "hashlock", Oe = "auth-anchor", Re = "wots-seed";
|
|
112
|
+
function Ft(e) {
|
|
180
113
|
if (!Number.isInteger(e) || e < 0 || e > 4294967295)
|
|
181
114
|
throw new Error(`i2osp4: value must be a u32, got ${e}`);
|
|
182
115
|
const t = new Uint8Array(4);
|
|
183
116
|
return t[0] = e >>> 24 & 255, t[1] = e >>> 16 & 255, t[2] = e >>> 8 & 255, t[3] = e & 255, t;
|
|
184
117
|
}
|
|
185
|
-
function
|
|
118
|
+
function ut(e, t = new Uint8Array(0)) {
|
|
186
119
|
const n = new TextEncoder().encode(e);
|
|
187
|
-
if (n.length === 0 || n.length >
|
|
120
|
+
if (n.length === 0 || n.length > vt)
|
|
188
121
|
throw new Error(
|
|
189
|
-
`info: label length must be in [1, ${
|
|
122
|
+
`info: label length must be in [1, ${vt}], got ${n.length}`
|
|
190
123
|
);
|
|
191
|
-
if (t.length >
|
|
124
|
+
if (t.length > It)
|
|
192
125
|
throw new Error(
|
|
193
|
-
`info: ctx length must be in [0, ${
|
|
126
|
+
`info: ctx length must be in [0, ${It}], got ${t.length}`
|
|
194
127
|
);
|
|
195
|
-
const s =
|
|
128
|
+
const s = Q.length + 1 + n.length + Ht + t.length, o = new Uint8Array(s);
|
|
196
129
|
let r = 0;
|
|
197
|
-
return o.set(
|
|
130
|
+
return o.set(Q, r), r += Q.length, o[r] = n.length, r += 1, o.set(n, r), r += n.length, o[r] = t.length >>> 8 & 255, o[r + 1] = t.length & 255, r += Ht, o.set(t, r), o;
|
|
198
131
|
}
|
|
199
|
-
const
|
|
200
|
-
function
|
|
201
|
-
if (e.length !==
|
|
132
|
+
const Bt = 32, $e = 32, Ue = 32, Le = 64;
|
|
133
|
+
function ht(e) {
|
|
134
|
+
if (e.length !== Bt)
|
|
202
135
|
throw new Error(
|
|
203
|
-
`vault-secrets: root must be exactly ${
|
|
136
|
+
`vault-secrets: root must be exactly ${Bt} bytes, got ${e.length}`
|
|
204
137
|
);
|
|
205
138
|
}
|
|
206
|
-
function
|
|
207
|
-
return
|
|
208
|
-
|
|
139
|
+
function Ne(e) {
|
|
140
|
+
return ht(e), lt(
|
|
141
|
+
O,
|
|
209
142
|
e,
|
|
210
|
-
|
|
211
|
-
|
|
143
|
+
ut(Oe),
|
|
144
|
+
$e
|
|
212
145
|
);
|
|
213
146
|
}
|
|
214
|
-
function
|
|
215
|
-
return
|
|
216
|
-
|
|
147
|
+
function Ve(e, t) {
|
|
148
|
+
return ht(e), lt(
|
|
149
|
+
O,
|
|
217
150
|
e,
|
|
218
|
-
|
|
219
|
-
|
|
151
|
+
ut(Ce, Ft(t)),
|
|
152
|
+
Ue
|
|
220
153
|
);
|
|
221
154
|
}
|
|
222
|
-
function
|
|
223
|
-
return
|
|
224
|
-
|
|
155
|
+
function We(e, t) {
|
|
156
|
+
return ht(e), lt(
|
|
157
|
+
O,
|
|
225
158
|
e,
|
|
226
|
-
|
|
227
|
-
|
|
159
|
+
ut(Re, Ft(t)),
|
|
160
|
+
Le
|
|
228
161
|
);
|
|
229
162
|
}
|
|
230
|
-
const
|
|
231
|
-
function
|
|
163
|
+
const L = 32, J = 32, it = 36, Xt = 32, z = 4, Me = z + L + z + Xt;
|
|
164
|
+
function at(e, t, n) {
|
|
232
165
|
e[t] = n >>> 24 & 255, e[t + 1] = n >>> 16 & 255, e[t + 2] = n >>> 8 & 255, e[t + 3] = n & 255;
|
|
233
166
|
}
|
|
234
|
-
function
|
|
235
|
-
if (e.txid.length !==
|
|
167
|
+
function Fe(e) {
|
|
168
|
+
if (e.txid.length !== J)
|
|
236
169
|
throw new Error(
|
|
237
|
-
`outpoint.txid must be exactly ${
|
|
170
|
+
`outpoint.txid must be exactly ${J} bytes, got ${e.txid.length}`
|
|
238
171
|
);
|
|
239
172
|
if (!Number.isInteger(e.vout) || e.vout < 0 || e.vout > 4294967295)
|
|
240
173
|
throw new Error(`outpoint.vout must be a u32, got ${e.vout}`);
|
|
241
|
-
const t = new Uint8Array(
|
|
242
|
-
return t.set(e.txid, 0),
|
|
174
|
+
const t = new Uint8Array(it);
|
|
175
|
+
return t.set(e.txid, 0), at(t, J, e.vout), t;
|
|
243
176
|
}
|
|
244
|
-
function
|
|
177
|
+
function St(e, t) {
|
|
245
178
|
const n = Math.min(e.length, t.length);
|
|
246
179
|
for (let s = 0; s < n; s++)
|
|
247
180
|
if (e[s] !== t[s]) return e[s] - t[s];
|
|
248
181
|
return e.length - t.length;
|
|
249
182
|
}
|
|
250
|
-
function
|
|
183
|
+
function Xe(e) {
|
|
251
184
|
if (e.length === 0)
|
|
252
185
|
throw new Error(
|
|
253
186
|
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
254
187
|
);
|
|
255
|
-
const t = e.map(
|
|
256
|
-
t.sort(
|
|
188
|
+
const t = e.map(Fe);
|
|
189
|
+
t.sort(St);
|
|
257
190
|
for (let s = 1; s < t.length; s++)
|
|
258
|
-
if (
|
|
191
|
+
if (St(t[s - 1], t[s]) === 0)
|
|
259
192
|
throw new Error(
|
|
260
193
|
"buildFundingOutpointsCommitment: duplicate outpoint detected"
|
|
261
194
|
);
|
|
262
|
-
const n = new Uint8Array(t.length *
|
|
195
|
+
const n = new Uint8Array(t.length * it);
|
|
263
196
|
for (let s = 0; s < t.length; s++)
|
|
264
|
-
n.set(t[s], s *
|
|
265
|
-
return
|
|
197
|
+
n.set(t[s], s * it);
|
|
198
|
+
return O(n);
|
|
266
199
|
}
|
|
267
|
-
function
|
|
268
|
-
if (e.depositorBtcPubkey.length !==
|
|
200
|
+
function Ke(e) {
|
|
201
|
+
if (e.depositorBtcPubkey.length !== L)
|
|
269
202
|
throw new Error(
|
|
270
|
-
`vaultContext: depositorBtcPubkey must be exactly ${
|
|
203
|
+
`vaultContext: depositorBtcPubkey must be exactly ${L} bytes, got ${e.depositorBtcPubkey.length}`
|
|
271
204
|
);
|
|
272
|
-
const t =
|
|
205
|
+
const t = Xe(e.fundingOutpoints), n = new Uint8Array(Me);
|
|
273
206
|
let s = 0;
|
|
274
|
-
return
|
|
207
|
+
return at(n, s, L), s += z, n.set(e.depositorBtcPubkey, s), s += L, at(n, s, Xt), s += z, n.set(t, s), n;
|
|
275
208
|
}
|
|
276
|
-
const
|
|
277
|
-
async function
|
|
278
|
-
const n =
|
|
209
|
+
const De = "babylon-vault", Kt = 32, At = Kt * 2, ze = /^[0-9a-f]+$/;
|
|
210
|
+
async function je(e, t) {
|
|
211
|
+
const n = Ke(t), s = D(n), o = await e.deriveContextHash(De, s);
|
|
279
212
|
if (typeof o != "string")
|
|
280
213
|
throw new Error(
|
|
281
214
|
`deriveVaultRoot: wallet must return a string, got ${typeof o}`
|
|
282
215
|
);
|
|
283
|
-
if (o.length !==
|
|
216
|
+
if (o.length !== At)
|
|
284
217
|
throw new Error(
|
|
285
|
-
`deriveVaultRoot: wallet must return a ${
|
|
218
|
+
`deriveVaultRoot: wallet must return a ${At}-character hex string (${Kt} bytes), got length ${o.length}`
|
|
286
219
|
);
|
|
287
|
-
if (!
|
|
220
|
+
if (!ze.test(o))
|
|
288
221
|
throw new Error(
|
|
289
222
|
"deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
|
|
290
223
|
);
|
|
291
|
-
return
|
|
224
|
+
return rt(o);
|
|
292
225
|
}
|
|
293
|
-
const
|
|
226
|
+
const Ge = /* @__PURE__ */ Uint8Array.from([
|
|
294
227
|
7,
|
|
295
228
|
4,
|
|
296
229
|
13,
|
|
@@ -307,43 +240,43 @@ const Fe = /* @__PURE__ */ Uint8Array.from([
|
|
|
307
240
|
14,
|
|
308
241
|
11,
|
|
309
242
|
8
|
|
310
|
-
]),
|
|
311
|
-
const n = [[
|
|
243
|
+
]), Dt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ze = Dt.map((e) => (9 * e + 5) % 16), zt = /* @__PURE__ */ (() => {
|
|
244
|
+
const n = [[Dt], [Ze]];
|
|
312
245
|
for (let s = 0; s < 4; s++)
|
|
313
246
|
for (let o of n)
|
|
314
|
-
o.push(o[s].map((r) =>
|
|
247
|
+
o.push(o[s].map((r) => Ge[r]));
|
|
315
248
|
return n;
|
|
316
|
-
})(),
|
|
249
|
+
})(), jt = zt[0], Gt = zt[1], Zt = /* @__PURE__ */ [
|
|
317
250
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
318
251
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
319
252
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
320
253
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
321
254
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
322
|
-
].map((e) => Uint8Array.from(e)),
|
|
255
|
+
].map((e) => Uint8Array.from(e)), qe = /* @__PURE__ */ jt.map((e, t) => e.map((n) => Zt[t][n])), Ye = /* @__PURE__ */ Gt.map((e, t) => e.map((n) => Zt[t][n])), Qe = /* @__PURE__ */ Uint32Array.from([
|
|
323
256
|
0,
|
|
324
257
|
1518500249,
|
|
325
258
|
1859775393,
|
|
326
259
|
2400959708,
|
|
327
260
|
2840853838
|
|
328
|
-
]),
|
|
261
|
+
]), Je = /* @__PURE__ */ Uint32Array.from([
|
|
329
262
|
1352829926,
|
|
330
263
|
1548603684,
|
|
331
264
|
1836072691,
|
|
332
265
|
2053994217,
|
|
333
266
|
0
|
|
334
267
|
]);
|
|
335
|
-
function
|
|
268
|
+
function Ct(e, t, n, s) {
|
|
336
269
|
return e === 0 ? t ^ n ^ s : e === 1 ? t & n | ~t & s : e === 2 ? (t | ~n) ^ s : e === 3 ? t & s | n & ~s : t ^ (n | ~s);
|
|
337
270
|
}
|
|
338
|
-
const
|
|
339
|
-
class
|
|
271
|
+
const M = /* @__PURE__ */ new Uint32Array(16);
|
|
272
|
+
class tn extends oe {
|
|
340
273
|
constructor() {
|
|
341
274
|
super(64, 20, 8, !0);
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
275
|
+
m(this, "h0", 1732584193);
|
|
276
|
+
m(this, "h1", -271733879);
|
|
277
|
+
m(this, "h2", -1732584194);
|
|
278
|
+
m(this, "h3", 271733878);
|
|
279
|
+
m(this, "h4", -1009589776);
|
|
347
280
|
}
|
|
348
281
|
get() {
|
|
349
282
|
const { h0: n, h1: s, h2: o, h3: r, h4: i } = this;
|
|
@@ -353,51 +286,51 @@ class qe extends de {
|
|
|
353
286
|
this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
354
287
|
}
|
|
355
288
|
process(n, s) {
|
|
356
|
-
for (let
|
|
357
|
-
|
|
358
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, l = this.h2 | 0, u = l, c = this.h3 | 0,
|
|
359
|
-
for (let
|
|
360
|
-
const
|
|
361
|
-
for (let
|
|
362
|
-
const
|
|
363
|
-
o =
|
|
289
|
+
for (let h = 0; h < 16; h++, s += 4)
|
|
290
|
+
M[h] = n.getUint32(s, !0);
|
|
291
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, l = this.h2 | 0, u = l, c = this.h3 | 0, w = c, b = this.h4 | 0, y = b;
|
|
292
|
+
for (let h = 0; h < 5; h++) {
|
|
293
|
+
const f = 4 - h, T = Qe[h], H = Je[h], d = jt[h], P = Gt[h], g = qe[h], E = Ye[h];
|
|
294
|
+
for (let x = 0; x < 16; x++) {
|
|
295
|
+
const p = V(o + Ct(h, i, l, c) + M[d[x]] + T, g[x]) + b | 0;
|
|
296
|
+
o = b, b = c, c = V(l, 10) | 0, l = i, i = p;
|
|
364
297
|
}
|
|
365
|
-
for (let
|
|
366
|
-
const
|
|
367
|
-
r =
|
|
298
|
+
for (let x = 0; x < 16; x++) {
|
|
299
|
+
const p = V(r + Ct(f, a, u, w) + M[P[x]] + H, E[x]) + y | 0;
|
|
300
|
+
r = y, y = w, w = V(u, 10) | 0, u = a, a = p;
|
|
368
301
|
}
|
|
369
302
|
}
|
|
370
|
-
this.set(this.h1 + l +
|
|
303
|
+
this.set(this.h1 + l + w | 0, this.h2 + c + y | 0, this.h3 + b + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
|
|
371
304
|
}
|
|
372
305
|
roundClean() {
|
|
373
|
-
A(
|
|
306
|
+
A(M);
|
|
374
307
|
}
|
|
375
308
|
destroy() {
|
|
376
309
|
this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
377
310
|
}
|
|
378
311
|
}
|
|
379
|
-
const
|
|
380
|
-
for (let e = 0, t =
|
|
381
|
-
[n, s] = [s, (2 * n + 3 * s) % 5],
|
|
382
|
-
let o =
|
|
312
|
+
const en = /* @__PURE__ */ Nt(() => new tn()), nn = BigInt(0), $ = BigInt(1), sn = BigInt(2), on = BigInt(7), rn = BigInt(256), an = BigInt(113), qt = [], Yt = [], Qt = [];
|
|
313
|
+
for (let e = 0, t = $, n = 1, s = 0; e < 24; e++) {
|
|
314
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], qt.push(2 * (5 * s + n)), Yt.push((e + 1) * (e + 2) / 2 % 64);
|
|
315
|
+
let o = nn;
|
|
383
316
|
for (let r = 0; r < 7; r++)
|
|
384
|
-
t = (t <<
|
|
385
|
-
|
|
317
|
+
t = (t << $ ^ (t >> on) * an) % rn, t & sn && (o ^= $ << ($ << BigInt(r)) - $);
|
|
318
|
+
Qt.push(o);
|
|
386
319
|
}
|
|
387
|
-
const
|
|
388
|
-
function
|
|
320
|
+
const Jt = ke(Qt, !0), cn = Jt[0], ln = Jt[1], Ot = (e, t, n) => n > 32 ? Ie(e, t, n) : _e(e, t, n), Rt = (e, t, n) => n > 32 ? He(e, t, n) : ve(e, t, n);
|
|
321
|
+
function un(e, t = 24) {
|
|
389
322
|
const n = new Uint32Array(10);
|
|
390
323
|
for (let s = 24 - t; s < 24; s++) {
|
|
391
324
|
for (let i = 0; i < 10; i++)
|
|
392
325
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
393
326
|
for (let i = 0; i < 10; i += 2) {
|
|
394
|
-
const a = (i + 8) % 10, l = (i + 2) % 10, u = n[l], c = n[l + 1],
|
|
395
|
-
for (let
|
|
396
|
-
e[i +
|
|
327
|
+
const a = (i + 8) % 10, l = (i + 2) % 10, u = n[l], c = n[l + 1], w = Ot(u, c, 1) ^ n[a], b = Rt(u, c, 1) ^ n[a + 1];
|
|
328
|
+
for (let y = 0; y < 50; y += 10)
|
|
329
|
+
e[i + y] ^= w, e[i + y + 1] ^= b;
|
|
397
330
|
}
|
|
398
331
|
let o = e[2], r = e[3];
|
|
399
332
|
for (let i = 0; i < 24; i++) {
|
|
400
|
-
const a =
|
|
333
|
+
const a = Yt[i], l = Ot(o, r, a), u = Rt(o, r, a), c = qt[i];
|
|
401
334
|
o = e[c], r = e[c + 1], e[c] = l, e[c + 1] = u;
|
|
402
335
|
}
|
|
403
336
|
for (let i = 0; i < 50; i += 10) {
|
|
@@ -406,36 +339,36 @@ function sn(e, t = 24) {
|
|
|
406
339
|
for (let a = 0; a < 10; a++)
|
|
407
340
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
408
341
|
}
|
|
409
|
-
e[0] ^=
|
|
342
|
+
e[0] ^= cn[s], e[1] ^= ln[s];
|
|
410
343
|
}
|
|
411
344
|
A(n);
|
|
412
345
|
}
|
|
413
|
-
class
|
|
346
|
+
class dt {
|
|
414
347
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
415
348
|
constructor(t, n, s, o = !1, r = 24) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
349
|
+
m(this, "state");
|
|
350
|
+
m(this, "pos", 0);
|
|
351
|
+
m(this, "posOut", 0);
|
|
352
|
+
m(this, "finished", !1);
|
|
353
|
+
m(this, "state32");
|
|
354
|
+
m(this, "destroyed", !1);
|
|
355
|
+
m(this, "blockLen");
|
|
356
|
+
m(this, "suffix");
|
|
357
|
+
m(this, "outputLen");
|
|
358
|
+
m(this, "enableXOF", !1);
|
|
359
|
+
m(this, "rounds");
|
|
427
360
|
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, st(s, "outputLen"), !(0 < t && t < 200))
|
|
428
361
|
throw new Error("only keccak-f1600 function is supported");
|
|
429
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
362
|
+
this.state = new Uint8Array(200), this.state32 = re(this.state);
|
|
430
363
|
}
|
|
431
364
|
clone() {
|
|
432
365
|
return this._cloneInto();
|
|
433
366
|
}
|
|
434
367
|
keccak() {
|
|
435
|
-
|
|
368
|
+
pt(this.state32), un(this.state32, this.rounds), pt(this.state32), this.posOut = 0, this.pos = 0;
|
|
436
369
|
}
|
|
437
370
|
update(t) {
|
|
438
|
-
|
|
371
|
+
K(this), N(t);
|
|
439
372
|
const { blockLen: n, state: s } = this, o = t.length;
|
|
440
373
|
for (let r = 0; r < o; ) {
|
|
441
374
|
const i = Math.min(n - this.pos, o - r);
|
|
@@ -453,7 +386,7 @@ class ht {
|
|
|
453
386
|
t[s] ^= n, (n & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
454
387
|
}
|
|
455
388
|
writeInto(t) {
|
|
456
|
-
|
|
389
|
+
K(this, !1), N(t), this.finish();
|
|
457
390
|
const n = this.state, { blockLen: s } = this;
|
|
458
391
|
for (let o = 0, r = t.length; o < r; ) {
|
|
459
392
|
this.posOut >= s && this.keccak();
|
|
@@ -471,7 +404,7 @@ class ht {
|
|
|
471
404
|
return st(t), this.xofInto(new Uint8Array(t));
|
|
472
405
|
}
|
|
473
406
|
digestInto(t) {
|
|
474
|
-
if (
|
|
407
|
+
if (ie(t, this), this.finished)
|
|
475
408
|
throw new Error("digest() was already called");
|
|
476
409
|
return this.writeInto(t), this.destroy(), t;
|
|
477
410
|
}
|
|
@@ -483,26 +416,26 @@ class ht {
|
|
|
483
416
|
}
|
|
484
417
|
_cloneInto(t) {
|
|
485
418
|
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
486
|
-
return t || (t = new
|
|
419
|
+
return t || (t = new dt(n, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
487
420
|
}
|
|
488
421
|
}
|
|
489
|
-
const
|
|
490
|
-
function
|
|
491
|
-
return
|
|
422
|
+
const hn = (e, t, n, s = {}) => Nt(() => new dt(t, e, n), s), dn = /* @__PURE__ */ hn(1, 136, 32), $t = 64, v = 20, ct = 4, te = 2, fn = 0, gn = 1, F = [64, 64], pn = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
423
|
+
function ft(e) {
|
|
424
|
+
return en(O(e));
|
|
492
425
|
}
|
|
493
|
-
function
|
|
426
|
+
function ee(e) {
|
|
494
427
|
return (1 << e) - 1;
|
|
495
428
|
}
|
|
496
|
-
function
|
|
429
|
+
function mn(e) {
|
|
497
430
|
let t = 1;
|
|
498
431
|
for (; t * t < e + 1; ) t++;
|
|
499
432
|
return Math.max(t, 2);
|
|
500
433
|
}
|
|
501
|
-
function
|
|
502
|
-
const t =
|
|
503
|
-
return { d: t, n: e, checksum_radix:
|
|
434
|
+
function wn(e) {
|
|
435
|
+
const t = ct, n = e * ee(t);
|
|
436
|
+
return { d: t, n: e, checksum_radix: mn(n) };
|
|
504
437
|
}
|
|
505
|
-
function
|
|
438
|
+
function tt(e, t) {
|
|
506
439
|
const n = [];
|
|
507
440
|
let s = t;
|
|
508
441
|
for (; s > 0; )
|
|
@@ -511,30 +444,30 @@ function Q(e, t) {
|
|
|
511
444
|
o.set(e);
|
|
512
445
|
for (let r = 0; r < n.length; r++)
|
|
513
446
|
o[e.length + r] = n[r];
|
|
514
|
-
return
|
|
447
|
+
return ft(o);
|
|
515
448
|
}
|
|
516
|
-
function
|
|
449
|
+
function et(e, t) {
|
|
517
450
|
let n = e;
|
|
518
451
|
for (let s = 0; s < t; s++)
|
|
519
|
-
n =
|
|
452
|
+
n = ft(n);
|
|
520
453
|
return n;
|
|
521
454
|
}
|
|
522
|
-
function
|
|
523
|
-
const n =
|
|
455
|
+
function bn(e, t) {
|
|
456
|
+
const n = ee(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
|
|
524
457
|
for (let c = 0; c < t.n; c++) {
|
|
525
|
-
const
|
|
526
|
-
r.push(Array.from(
|
|
458
|
+
const w = tt(e, c + te), b = et(w, n);
|
|
459
|
+
r.push(Array.from(b));
|
|
527
460
|
}
|
|
528
|
-
const i =
|
|
461
|
+
const i = tt(
|
|
529
462
|
e,
|
|
530
|
-
|
|
531
|
-
), a =
|
|
463
|
+
fn
|
|
464
|
+
), a = et(
|
|
532
465
|
i,
|
|
533
466
|
s
|
|
534
|
-
), l =
|
|
467
|
+
), l = tt(
|
|
535
468
|
e,
|
|
536
|
-
|
|
537
|
-
), u =
|
|
469
|
+
gn
|
|
470
|
+
), u = et(
|
|
538
471
|
l,
|
|
539
472
|
o
|
|
540
473
|
);
|
|
@@ -545,22 +478,22 @@ function dn(e, t) {
|
|
|
545
478
|
checksum_minor_terminal: Array.from(a)
|
|
546
479
|
};
|
|
547
480
|
}
|
|
548
|
-
async function
|
|
481
|
+
async function yn(e) {
|
|
549
482
|
try {
|
|
550
|
-
if (e.length !==
|
|
483
|
+
if (e.length !== $t)
|
|
551
484
|
throw new Error(
|
|
552
|
-
`WOTS seed must be exactly ${
|
|
485
|
+
`WOTS seed must be exactly ${$t} bytes, got ${e.length}`
|
|
553
486
|
);
|
|
554
487
|
const t = [];
|
|
555
|
-
for (let n = 0; n <
|
|
556
|
-
const s =
|
|
488
|
+
for (let n = 0; n < F.length; n++) {
|
|
489
|
+
const s = F[n], o = wn(s), r = new Uint8Array(e.length + 1);
|
|
557
490
|
r.set(e), r[e.length] = n;
|
|
558
|
-
const i =
|
|
491
|
+
const i = ft(r);
|
|
559
492
|
try {
|
|
560
|
-
const a =
|
|
561
|
-
if (a.config.d !==
|
|
493
|
+
const a = bn(i, o);
|
|
494
|
+
if (a.config.d !== ct)
|
|
562
495
|
throw new Error(
|
|
563
|
-
`Block ${n}: expected d=${
|
|
496
|
+
`Block ${n}: expected d=${ct}, got d=${a.config.d}`
|
|
564
497
|
);
|
|
565
498
|
if (a.config.n !== s)
|
|
566
499
|
throw new Error(
|
|
@@ -571,36 +504,36 @@ async function fn(e) {
|
|
|
571
504
|
`Block ${n}: expected ${s} message terminals, got ${a.message_terminals.length}`
|
|
572
505
|
);
|
|
573
506
|
for (let l = 0; l < a.message_terminals.length; l++)
|
|
574
|
-
if (a.message_terminals[l].length !==
|
|
507
|
+
if (a.message_terminals[l].length !== v)
|
|
575
508
|
throw new Error(
|
|
576
|
-
`Block ${n} terminal ${l}: expected ${
|
|
509
|
+
`Block ${n} terminal ${l}: expected ${v} bytes, got ${a.message_terminals[l].length}`
|
|
577
510
|
);
|
|
578
|
-
if (a.checksum_minor_terminal.length !==
|
|
511
|
+
if (a.checksum_minor_terminal.length !== v)
|
|
579
512
|
throw new Error(
|
|
580
|
-
`Block ${n} checksum_minor: expected ${
|
|
513
|
+
`Block ${n} checksum_minor: expected ${v} bytes`
|
|
581
514
|
);
|
|
582
|
-
if (a.checksum_major_terminal.length !==
|
|
515
|
+
if (a.checksum_major_terminal.length !== v)
|
|
583
516
|
throw new Error(
|
|
584
|
-
`Block ${n} checksum_major: expected ${
|
|
517
|
+
`Block ${n} checksum_major: expected ${v} bytes`
|
|
585
518
|
);
|
|
586
519
|
t.push(a);
|
|
587
520
|
} finally {
|
|
588
521
|
r.fill(0), i.fill(0);
|
|
589
522
|
}
|
|
590
523
|
}
|
|
591
|
-
if (t.length !==
|
|
524
|
+
if (t.length !== F.length)
|
|
592
525
|
throw new Error(
|
|
593
|
-
`Expected ${
|
|
526
|
+
`Expected ${F.length} blocks, got ${t.length}`
|
|
594
527
|
);
|
|
595
528
|
return t;
|
|
596
529
|
} finally {
|
|
597
530
|
e.fill(0);
|
|
598
531
|
}
|
|
599
532
|
}
|
|
600
|
-
function
|
|
601
|
-
if (e.length !==
|
|
533
|
+
function nt(e, t, n) {
|
|
534
|
+
if (e.length !== v)
|
|
602
535
|
throw new Error(
|
|
603
|
-
`Block ${t} ${n}: expected ${
|
|
536
|
+
`Block ${t} ${n}: expected ${v} bytes, got ${e.length}`
|
|
604
537
|
);
|
|
605
538
|
for (let s = 0; s < e.length; s++) {
|
|
606
539
|
const o = e[s];
|
|
@@ -610,76 +543,205 @@ function tt(e, t, n) {
|
|
|
610
543
|
);
|
|
611
544
|
}
|
|
612
545
|
}
|
|
613
|
-
function
|
|
546
|
+
function xn(e) {
|
|
614
547
|
if (e.length === 0)
|
|
615
548
|
throw new Error("Public keys array must not be empty");
|
|
616
549
|
for (let r = 0; r < e.length; r++) {
|
|
617
550
|
const i = e[r];
|
|
618
|
-
|
|
551
|
+
nt(i.checksum_minor_terminal, r, "checksum_minor_terminal"), nt(i.checksum_major_terminal, r, "checksum_major_terminal");
|
|
619
552
|
for (let a = 0; a < i.message_terminals.length; a++)
|
|
620
|
-
|
|
553
|
+
nt(i.message_terminals[a], r, `message_terminal[${a}]`);
|
|
621
554
|
}
|
|
622
555
|
let t = 0;
|
|
623
556
|
for (const r of e)
|
|
624
|
-
t +=
|
|
625
|
-
const n = new Uint8Array(t *
|
|
557
|
+
t += te + r.message_terminals.length;
|
|
558
|
+
const n = new Uint8Array(t * v);
|
|
626
559
|
let s = 0;
|
|
627
560
|
for (const r of e) {
|
|
628
|
-
n.set(r.checksum_minor_terminal, s), s +=
|
|
561
|
+
n.set(r.checksum_minor_terminal, s), s += v, n.set(r.checksum_major_terminal, s), s += v;
|
|
629
562
|
for (const i of r.message_terminals)
|
|
630
|
-
n.set(i, s), s +=
|
|
563
|
+
n.set(i, s), s += v;
|
|
631
564
|
}
|
|
632
|
-
const o =
|
|
633
|
-
return `0x${
|
|
565
|
+
const o = dn(n);
|
|
566
|
+
return `0x${pn(o)}`;
|
|
634
567
|
}
|
|
635
|
-
function
|
|
568
|
+
function Kn(e) {
|
|
636
569
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
637
570
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
638
571
|
}
|
|
639
|
-
|
|
640
|
-
|
|
572
|
+
async function Pn(e, t) {
|
|
573
|
+
const n = [], s = [], o = [], r = [];
|
|
574
|
+
try {
|
|
575
|
+
for (let i = 0; i < t; i++) {
|
|
576
|
+
const a = We(e, i);
|
|
577
|
+
try {
|
|
578
|
+
const u = await yn(a);
|
|
579
|
+
n.push(u), s.push(xn(u));
|
|
580
|
+
} finally {
|
|
581
|
+
a.fill(0);
|
|
582
|
+
}
|
|
583
|
+
const l = Ve(e, i);
|
|
584
|
+
try {
|
|
585
|
+
const u = D(l);
|
|
586
|
+
o.push(u), r.push(me(I(u)).slice(2));
|
|
587
|
+
} finally {
|
|
588
|
+
l.fill(0);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
} finally {
|
|
592
|
+
e.fill(0);
|
|
593
|
+
}
|
|
594
|
+
return { perVaultWotsKeys: n, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
|
|
595
|
+
}
|
|
596
|
+
const En = /^0x[0-9a-f]+$/i, Tn = /^[0-9a-f]+$/i, kn = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
597
|
+
function U(e) {
|
|
641
598
|
if (typeof e != "string" || e.length === 0)
|
|
642
599
|
throw new Error("BTC wallet returned empty public key");
|
|
643
|
-
return
|
|
600
|
+
return fe(e).toLowerCase();
|
|
644
601
|
}
|
|
645
|
-
function
|
|
602
|
+
function _n(e) {
|
|
646
603
|
if (typeof e != "string" || e.length === 0)
|
|
647
604
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
648
605
|
if (e.startsWith("0x") || e.startsWith("0X")) {
|
|
649
|
-
if (!
|
|
606
|
+
if (!En.test(e) || e.length < 4 || e.length % 2 !== 0)
|
|
650
607
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
651
608
|
return e.toLowerCase();
|
|
652
609
|
}
|
|
653
|
-
if (
|
|
610
|
+
if (Tn.test(e)) {
|
|
654
611
|
if (e.length % 2 !== 0)
|
|
655
612
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
656
613
|
return `0x${e.toLowerCase()}`;
|
|
657
614
|
}
|
|
658
|
-
if (!
|
|
615
|
+
if (!kn.test(e) || e.length % 4 !== 0)
|
|
659
616
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
660
|
-
const t =
|
|
617
|
+
const t = ot.from(e, "base64");
|
|
661
618
|
if (t.length === 0 || t.toString("base64") !== e)
|
|
662
619
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
663
620
|
return `0x${t.toString("hex")}`;
|
|
664
621
|
}
|
|
665
|
-
function
|
|
622
|
+
async function vn(e, t, n) {
|
|
623
|
+
if (typeof e.signPsbts == "function") {
|
|
624
|
+
const o = await e.signPsbts(t, n);
|
|
625
|
+
if (o.length !== t.length)
|
|
626
|
+
throw new Error(
|
|
627
|
+
`Expected ${t.length} signed PSBTs but received ${o.length}`
|
|
628
|
+
);
|
|
629
|
+
return o;
|
|
630
|
+
}
|
|
631
|
+
const s = [];
|
|
632
|
+
for (let o = 0; o < t.length; o++) {
|
|
633
|
+
const r = await e.signPsbt(t[o], n[o]);
|
|
634
|
+
s.push(r);
|
|
635
|
+
}
|
|
636
|
+
return s;
|
|
637
|
+
}
|
|
638
|
+
const C = {
|
|
639
|
+
// VaultAlreadyExists()
|
|
640
|
+
"0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
|
|
641
|
+
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
642
|
+
"0x4fec082d": "Script mismatch: The Bitcoin transaction's taproot output does not match the expected vault script. This may be caused by incorrect vault participants or key configuration.",
|
|
643
|
+
// InvalidBTCProofOfPossession()
|
|
644
|
+
"0x6cc363a5": "Invalid BTC proof of possession: The signature could not be verified. Please ensure you're signing with the correct Bitcoin wallet.",
|
|
645
|
+
// InvalidBTCPublicKey()
|
|
646
|
+
"0x6c3f2bf6": "Invalid BTC public key: The Bitcoin public key format is invalid.",
|
|
647
|
+
// InvalidAmount()
|
|
648
|
+
"0x2c5211c6": "Invalid amount: The deposit amount is invalid or below the minimum required.",
|
|
649
|
+
// ApplicationNotRegistered()
|
|
650
|
+
"0x0405f772": "Application not registered: The application controller is not registered in the system.",
|
|
651
|
+
// InvalidProviderStatus()
|
|
652
|
+
"0x24e165cc": "Invalid provider status: The vault provider is not in a valid state to accept deposits.",
|
|
653
|
+
// ZeroAddress()
|
|
654
|
+
"0xd92e233d": "Zero address: One of the required addresses is the zero address.",
|
|
655
|
+
// BtcKeyMismatch()
|
|
656
|
+
"0x65aa7007": "BTC key mismatch: The Bitcoin public key does not match the expected key.",
|
|
657
|
+
// Unauthorized()
|
|
658
|
+
"0x82b42900": "Unauthorized: You must be the depositor or vault provider to submit this transaction.",
|
|
659
|
+
// InvalidSignature() - common signature verification error
|
|
660
|
+
"0x8baa579f": "Invalid signature: The BTC proof of possession signature could not be verified.",
|
|
661
|
+
// InvalidBtcTransaction()
|
|
662
|
+
"0x2f9d01e9": "Invalid BTC transaction: The Bitcoin transaction format is invalid.",
|
|
663
|
+
// VaultProviderNotRegistered()
|
|
664
|
+
"0x5a3c6b3e": "Vault provider not registered: The selected vault provider is not registered.",
|
|
665
|
+
// InvalidPeginFee(uint256,uint256)
|
|
666
|
+
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction.",
|
|
667
|
+
// PrePeginOutputAlreadyUsed()
|
|
668
|
+
"0x5fad9694": "This pre-pegin output has already been used to activate another vault.",
|
|
669
|
+
// PeginTransactionAlreadyUsed()
|
|
670
|
+
"0x7ed061c9": "This pegin transaction has already been used to activate another vault."
|
|
671
|
+
};
|
|
672
|
+
function gt(e) {
|
|
673
|
+
if (!e || typeof e != "object") return;
|
|
674
|
+
const t = e;
|
|
675
|
+
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
676
|
+
return t.data;
|
|
677
|
+
if (typeof t.details == "string" && t.details.startsWith("0x"))
|
|
678
|
+
return t.details;
|
|
679
|
+
let n = t.cause, s = 0;
|
|
680
|
+
const o = 5;
|
|
681
|
+
for (; n && typeof n == "object" && s < o; ) {
|
|
682
|
+
const a = n;
|
|
683
|
+
if (typeof a.data == "string" && a.data.startsWith("0x"))
|
|
684
|
+
return a.data;
|
|
685
|
+
n = a.cause, s++;
|
|
686
|
+
}
|
|
687
|
+
const i = (typeof t.message == "string" ? t.message : "").match(/\b(0x[a-fA-F0-9]{8})\b/);
|
|
688
|
+
if (i)
|
|
689
|
+
return i[1];
|
|
690
|
+
}
|
|
691
|
+
function Dn(e) {
|
|
692
|
+
const t = gt(e);
|
|
693
|
+
if (t) {
|
|
694
|
+
const n = t.substring(0, 10);
|
|
695
|
+
return C[t] ?? C[n];
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
function zn(e) {
|
|
699
|
+
const t = gt(e);
|
|
700
|
+
if (t === void 0) return !1;
|
|
701
|
+
const n = t.substring(0, 10);
|
|
702
|
+
return t in C || n in C;
|
|
703
|
+
}
|
|
704
|
+
function S(e) {
|
|
705
|
+
console.error("[Contract Error] Raw error:", e);
|
|
706
|
+
const t = gt(e);
|
|
707
|
+
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
708
|
+
const s = t.substring(0, 10), o = C[t] ?? C[s];
|
|
709
|
+
if (o)
|
|
710
|
+
throw console.error("[Contract Error] Known error:", o), new Error(o);
|
|
711
|
+
}
|
|
712
|
+
const n = (e == null ? void 0 : e.message) || "";
|
|
713
|
+
if (n.includes("gas limit too high") || n.includes("21000000") || n.includes("Internal JSON-RPC error")) {
|
|
714
|
+
const s = t ? ` (error code: ${t})` : "";
|
|
715
|
+
throw console.error(
|
|
716
|
+
"[Contract Error] Transaction rejected. Error code:",
|
|
717
|
+
t,
|
|
718
|
+
"Message:",
|
|
719
|
+
n
|
|
720
|
+
), new Error(
|
|
721
|
+
`Transaction failed: The contract rejected this transaction${s}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
725
|
+
}
|
|
726
|
+
const In = 0, X = "00".repeat(32);
|
|
727
|
+
function Hn(e, t, n, s) {
|
|
666
728
|
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
667
729
|
return o ? Promise.resolve({
|
|
668
730
|
txid: e,
|
|
669
731
|
vout: t,
|
|
670
732
|
value: o.value,
|
|
671
733
|
scriptPubKey: o.scriptPubKey
|
|
672
|
-
}) :
|
|
734
|
+
}) : Ee(e, t, s);
|
|
673
735
|
}
|
|
674
|
-
const
|
|
675
|
-
class
|
|
736
|
+
const Ut = 12e4;
|
|
737
|
+
class jn {
|
|
676
738
|
/**
|
|
677
739
|
* Creates a new PeginManager instance.
|
|
678
740
|
*
|
|
679
741
|
* @param config - Manager configuration including wallets and contract addresses
|
|
680
742
|
*/
|
|
681
743
|
constructor(t) {
|
|
682
|
-
|
|
744
|
+
m(this, "config");
|
|
683
745
|
this.config = t;
|
|
684
746
|
}
|
|
685
747
|
/**
|
|
@@ -694,72 +756,59 @@ class Mn {
|
|
|
694
756
|
async preparePegin(t) {
|
|
695
757
|
if (t.amounts.length === 0)
|
|
696
758
|
throw new Error("amounts must contain at least one entry");
|
|
697
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s =
|
|
698
|
-
(
|
|
699
|
-
txid:
|
|
700
|
-
vout:
|
|
759
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = U(n), o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
|
|
760
|
+
(f) => ({
|
|
761
|
+
txid: rt(f.txid),
|
|
762
|
+
vout: f.vout
|
|
701
763
|
})
|
|
702
|
-
), i = await
|
|
703
|
-
depositorBtcPubkey:
|
|
764
|
+
), i = await je(this.config.btcWallet, {
|
|
765
|
+
depositorBtcPubkey: rt(s),
|
|
704
766
|
fundingOutpoints: r
|
|
705
|
-
})
|
|
767
|
+
});
|
|
768
|
+
let a, l;
|
|
769
|
+
try {
|
|
770
|
+
const f = Ne(i);
|
|
771
|
+
try {
|
|
772
|
+
a = D(f), l = D(O(f));
|
|
773
|
+
} finally {
|
|
774
|
+
f.fill(0);
|
|
775
|
+
}
|
|
776
|
+
} catch (f) {
|
|
777
|
+
throw i.fill(0), f;
|
|
778
|
+
}
|
|
779
|
+
const u = await Pn(i, t.amounts.length), { perVaultWotsKeys: c, wotsPkHashes: w, htlcSecretHexes: b, hashlocks: y } = u, h = await this.preparePeginCommit({
|
|
706
780
|
depositorBtcPubkeyRaw: n,
|
|
707
781
|
depositorBtcPubkey: s,
|
|
708
782
|
hashlocks: y,
|
|
783
|
+
authAnchorHash: l,
|
|
709
784
|
sizing: o,
|
|
710
785
|
params: t
|
|
711
786
|
});
|
|
712
|
-
for (let
|
|
713
|
-
if (
|
|
787
|
+
for (let f = 0; f < h.perVault.length; f++)
|
|
788
|
+
if (h.perVault[f].htlcVout !== f)
|
|
714
789
|
throw new Error(
|
|
715
|
-
`Internal invariant violation: htlcVout/index mismatch at vault ${
|
|
790
|
+
`Internal invariant violation: htlcVout/index mismatch at vault ${f} (expected ${f}, got ${h.perVault[f].htlcVout})`
|
|
716
791
|
);
|
|
717
|
-
return
|
|
792
|
+
return Ae(
|
|
793
|
+
h.fundedPrePeginTxHex,
|
|
794
|
+
t.amounts.length,
|
|
795
|
+
l
|
|
796
|
+
), {
|
|
718
797
|
transaction: {
|
|
719
|
-
...
|
|
798
|
+
...h,
|
|
720
799
|
selectedUTXOs: o.selectedUTXOs,
|
|
721
800
|
fee: o.fee,
|
|
722
801
|
changeAmount: o.changeAmount
|
|
723
802
|
},
|
|
724
803
|
depositorBtcPubkey: s,
|
|
725
804
|
derivedSecrets: {
|
|
726
|
-
perVaultWotsKeys:
|
|
727
|
-
wotsPkHashes:
|
|
728
|
-
htlcSecretHexes:
|
|
805
|
+
perVaultWotsKeys: c,
|
|
806
|
+
wotsPkHashes: w,
|
|
807
|
+
htlcSecretHexes: b,
|
|
808
|
+
authAnchorHex: a
|
|
729
809
|
}
|
|
730
810
|
};
|
|
731
811
|
}
|
|
732
|
-
/**
|
|
733
|
-
* Derive per-vault WOTS keys + HTLC preimages from the wallet root.
|
|
734
|
-
* Takes ownership of `root`: zeros the buffer (and per-vault secret
|
|
735
|
-
* buffers) before returning, regardless of how the caller exits.
|
|
736
|
-
*/
|
|
737
|
-
async expandPerVaultSecrets(t, n) {
|
|
738
|
-
const s = [], o = [], r = [], i = [];
|
|
739
|
-
try {
|
|
740
|
-
for (let a = 0; a < n; a++) {
|
|
741
|
-
const l = $e(t, a);
|
|
742
|
-
try {
|
|
743
|
-
const c = await fn(l);
|
|
744
|
-
s.push(c), o.push(gn(c));
|
|
745
|
-
} finally {
|
|
746
|
-
l.fill(0);
|
|
747
|
-
}
|
|
748
|
-
const u = Oe(t, a);
|
|
749
|
-
try {
|
|
750
|
-
const c = $t(u);
|
|
751
|
-
r.push(c), i.push(
|
|
752
|
-
ue(I(c)).slice(2)
|
|
753
|
-
);
|
|
754
|
-
} finally {
|
|
755
|
-
u.fill(0);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
} finally {
|
|
759
|
-
t.fill(0);
|
|
760
|
-
}
|
|
761
|
-
return { perVaultWotsKeys: s, wotsPkHashes: o, htlcSecretHexes: r, hashlocks: i };
|
|
762
|
-
}
|
|
763
812
|
/**
|
|
764
813
|
* Build unfunded Pre-PegIn + select UTXOs. No PSBT signing.
|
|
765
814
|
*
|
|
@@ -769,11 +818,17 @@ class Mn {
|
|
|
769
818
|
* `selectUtxosForPegin` in the commit pass would be deterministic given
|
|
770
819
|
* the same inputs, but threading the result through guarantees the
|
|
771
820
|
* domain separator structurally matches the funded tx inputs.
|
|
821
|
+
*
|
|
822
|
+
* Sizing runs before the wallet popup, so neither the real per-vault
|
|
823
|
+
* hashlocks nor the real `authAnchorHash` are known yet. Both slots
|
|
824
|
+
* are filled with a 32-byte placeholder; the commit pass swaps in the
|
|
825
|
+
* real values. Output budget is identical (32-byte push regardless of
|
|
826
|
+
* content), so UTXO selection is invariant under substitution.
|
|
772
827
|
*/
|
|
773
828
|
async prepareSizing(t, n) {
|
|
774
829
|
const s = n.amounts.map(
|
|
775
|
-
() =>
|
|
776
|
-
), o = n.vaultKeeperBtcPubkeys.length, r = await
|
|
830
|
+
() => X
|
|
831
|
+
), o = n.vaultKeeperBtcPubkeys.length, r = await xt({
|
|
777
832
|
depositorPubkey: t,
|
|
778
833
|
vaultProviderPubkey: _(n.vaultProviderBtcPubkey),
|
|
779
834
|
vaultKeeperPubkeys: n.vaultKeeperBtcPubkeys.map(_),
|
|
@@ -785,13 +840,16 @@ class Mn {
|
|
|
785
840
|
numLocalChallengers: o,
|
|
786
841
|
councilQuorum: n.councilQuorum,
|
|
787
842
|
councilSize: n.councilSize,
|
|
788
|
-
network: this.config.btcNetwork
|
|
789
|
-
|
|
843
|
+
network: this.config.btcNetwork,
|
|
844
|
+
authAnchorHash: X
|
|
845
|
+
}), i = we(
|
|
790
846
|
[...n.availableUTXOs],
|
|
791
847
|
r.totalOutputValue,
|
|
792
848
|
n.mempoolFeeRate,
|
|
793
|
-
|
|
794
|
-
|
|
849
|
+
ye(
|
|
850
|
+
r.htlcValues.length,
|
|
851
|
+
X
|
|
852
|
+
)
|
|
795
853
|
);
|
|
796
854
|
return {
|
|
797
855
|
selectedUTXOs: i.selectedUTXOs,
|
|
@@ -805,102 +863,86 @@ class Mn {
|
|
|
805
863
|
depositorBtcPubkeyRaw: n,
|
|
806
864
|
depositorBtcPubkey: s,
|
|
807
865
|
hashlocks: o,
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
866
|
+
authAnchorHash: r,
|
|
867
|
+
sizing: i,
|
|
868
|
+
params: a
|
|
869
|
+
} = t, l = X.toLowerCase();
|
|
870
|
+
for (let p = 0; p < o.length; p++)
|
|
871
|
+
if (o[p].toLowerCase() === l)
|
|
872
|
+
throw new Error(
|
|
873
|
+
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${p} — internal substitution bug`
|
|
874
|
+
);
|
|
875
|
+
if (r.toLowerCase() === l)
|
|
876
|
+
throw new Error(
|
|
877
|
+
"preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
|
|
878
|
+
);
|
|
879
|
+
const u = _(a.vaultProviderBtcPubkey), c = a.vaultKeeperBtcPubkeys.map(_), w = a.universalChallengerBtcPubkeys.map(_), b = c.length, y = {
|
|
811
880
|
depositorPubkey: s,
|
|
812
|
-
vaultProviderPubkey:
|
|
813
|
-
vaultKeeperPubkeys:
|
|
814
|
-
universalChallengerPubkeys:
|
|
881
|
+
vaultProviderPubkey: u,
|
|
882
|
+
vaultKeeperPubkeys: c,
|
|
883
|
+
universalChallengerPubkeys: w,
|
|
815
884
|
hashlocks: o,
|
|
816
|
-
timelockRefund:
|
|
817
|
-
pegInAmounts:
|
|
818
|
-
feeRate:
|
|
819
|
-
numLocalChallengers:
|
|
820
|
-
councilQuorum:
|
|
821
|
-
councilSize:
|
|
822
|
-
network: this.config.btcNetwork
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
885
|
+
timelockRefund: a.timelockRefund,
|
|
886
|
+
pegInAmounts: a.amounts,
|
|
887
|
+
feeRate: a.protocolFeeRate,
|
|
888
|
+
numLocalChallengers: b,
|
|
889
|
+
councilQuorum: a.councilQuorum,
|
|
890
|
+
councilSize: a.councilSize,
|
|
891
|
+
network: this.config.btcNetwork,
|
|
892
|
+
authAnchorHash: r
|
|
893
|
+
}, h = await xt(y), f = Pt(this.config.btcNetwork), T = xe({
|
|
894
|
+
unfundedTxHex: h.psbtHex,
|
|
895
|
+
selectedUTXOs: i.selectedUTXOs,
|
|
896
|
+
changeAddress: a.changeAddress,
|
|
897
|
+
changeAmount: i.changeAmount,
|
|
898
|
+
network: f
|
|
899
|
+
}), H = _(q(T)), d = [], P = [], g = [];
|
|
900
|
+
for (let p = 0; p < o.length; p++) {
|
|
901
|
+
const k = await le({
|
|
832
902
|
prePeginParams: y,
|
|
833
|
-
timelockPegin:
|
|
834
|
-
fundedPrePeginTxHex:
|
|
835
|
-
htlcVout:
|
|
836
|
-
}),
|
|
837
|
-
peginTxHex:
|
|
838
|
-
fundedPrePeginTxHex:
|
|
903
|
+
timelockPegin: a.timelockPegin,
|
|
904
|
+
fundedPrePeginTxHex: T,
|
|
905
|
+
htlcVout: p
|
|
906
|
+
}), B = await ue({
|
|
907
|
+
peginTxHex: k.txHex,
|
|
908
|
+
fundedPrePeginTxHex: T,
|
|
839
909
|
depositorPubkey: s,
|
|
840
|
-
vaultProviderPubkey:
|
|
841
|
-
vaultKeeperPubkeys:
|
|
842
|
-
universalChallengerPubkeys:
|
|
843
|
-
hashlock: o[
|
|
844
|
-
timelockRefund:
|
|
910
|
+
vaultProviderPubkey: u,
|
|
911
|
+
vaultKeeperPubkeys: c,
|
|
912
|
+
universalChallengerPubkeys: w,
|
|
913
|
+
hashlock: o[p],
|
|
914
|
+
timelockRefund: a.timelockRefund,
|
|
845
915
|
network: this.config.btcNetwork
|
|
846
916
|
});
|
|
847
|
-
|
|
848
|
-
|
|
917
|
+
d.push(k), P.push(B.psbtHex), g.push(
|
|
918
|
+
pe(n, 1)
|
|
849
919
|
);
|
|
850
920
|
}
|
|
851
|
-
const
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
921
|
+
const E = await vn(
|
|
922
|
+
this.config.btcWallet,
|
|
923
|
+
P,
|
|
924
|
+
g
|
|
925
|
+
), x = [];
|
|
926
|
+
for (let p = 0; p < E.length; p++) {
|
|
927
|
+
const k = he(
|
|
928
|
+
E[p],
|
|
858
929
|
s
|
|
859
|
-
),
|
|
860
|
-
|
|
861
|
-
htlcVout:
|
|
862
|
-
htlcValue:
|
|
863
|
-
peginTxHex:
|
|
864
|
-
peginTxid:
|
|
865
|
-
peginInputSignature:
|
|
866
|
-
vaultScriptPubKey:
|
|
930
|
+
), B = de(E[p]);
|
|
931
|
+
x.push({
|
|
932
|
+
htlcVout: p,
|
|
933
|
+
htlcValue: h.htlcValues[p],
|
|
934
|
+
peginTxHex: B,
|
|
935
|
+
peginTxid: d[p].txid,
|
|
936
|
+
peginInputSignature: k,
|
|
937
|
+
vaultScriptPubKey: d[p].vaultScriptPubKey
|
|
867
938
|
});
|
|
868
939
|
}
|
|
869
940
|
return {
|
|
870
|
-
fundedPrePeginTxHex:
|
|
871
|
-
prePeginTxid:
|
|
872
|
-
perVault:
|
|
941
|
+
fundedPrePeginTxHex: T,
|
|
942
|
+
prePeginTxid: H,
|
|
943
|
+
perVault: x
|
|
873
944
|
};
|
|
874
945
|
}
|
|
875
|
-
/**
|
|
876
|
-
* Signs multiple PSBTs using batch signing if available, falling back to sequential signing.
|
|
877
|
-
*
|
|
878
|
-
* Wallets that support native batch signing (e.g. UniSat) will sign all PSBTs
|
|
879
|
-
* in a single interaction. Others (e.g. Ledger, AppKit) implement signPsbts
|
|
880
|
-
* by looping signPsbt internally, so the UX depends on the wallet adapter.
|
|
881
|
-
*/
|
|
882
|
-
async signPsbtsWithFallback(t, n) {
|
|
883
|
-
if (typeof this.config.btcWallet.signPsbts == "function") {
|
|
884
|
-
const o = await this.config.btcWallet.signPsbts(
|
|
885
|
-
t,
|
|
886
|
-
n
|
|
887
|
-
);
|
|
888
|
-
if (o.length !== t.length)
|
|
889
|
-
throw new Error(
|
|
890
|
-
`Expected ${t.length} signed PSBTs but received ${o.length}`
|
|
891
|
-
);
|
|
892
|
-
return o;
|
|
893
|
-
}
|
|
894
|
-
const s = [];
|
|
895
|
-
for (let o = 0; o < t.length; o++) {
|
|
896
|
-
const r = await this.config.btcWallet.signPsbt(
|
|
897
|
-
t[o],
|
|
898
|
-
n[o]
|
|
899
|
-
);
|
|
900
|
-
s.push(r);
|
|
901
|
-
}
|
|
902
|
-
return s;
|
|
903
|
-
}
|
|
904
946
|
/**
|
|
905
947
|
* Signs and broadcasts a funded peg-in transaction to the Bitcoin network.
|
|
906
948
|
*
|
|
@@ -917,40 +959,40 @@ class Mn {
|
|
|
917
959
|
* @throws Error if signing or broadcasting fails
|
|
918
960
|
*/
|
|
919
961
|
async signAndBroadcast(t) {
|
|
920
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r =
|
|
962
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = ae.fromHex(o);
|
|
921
963
|
if (r.ins.length === 0)
|
|
922
964
|
throw new Error("Transaction has no inputs");
|
|
923
|
-
const i = new
|
|
965
|
+
const i = new mt();
|
|
924
966
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
925
|
-
const a =
|
|
926
|
-
|
|
967
|
+
const a = ot.from(
|
|
968
|
+
U(s),
|
|
927
969
|
"hex"
|
|
928
970
|
), l = this.config.mempoolApiUrl, u = r.ins.map((d) => {
|
|
929
|
-
const
|
|
930
|
-
return
|
|
931
|
-
(
|
|
971
|
+
const P = ot.from(d.hash).reverse().toString("hex"), g = d.index;
|
|
972
|
+
return Hn(P, g, t.localPrevouts, l).then(
|
|
973
|
+
(E) => ({ input: d, utxoData: E, txid: P, vout: g })
|
|
932
974
|
);
|
|
933
|
-
}), c = await Promise.all(u),
|
|
934
|
-
(d,
|
|
975
|
+
}), c = await Promise.all(u), w = c.reduce(
|
|
976
|
+
(d, P) => d + BigInt(P.utxoData.value),
|
|
935
977
|
0n
|
|
936
|
-
),
|
|
937
|
-
(d,
|
|
978
|
+
), b = r.outs.reduce(
|
|
979
|
+
(d, P) => d + BigInt(P.value),
|
|
938
980
|
0n
|
|
939
981
|
);
|
|
940
|
-
if (
|
|
982
|
+
if (w < b)
|
|
941
983
|
throw new Error(
|
|
942
|
-
`UTXO value mismatch: total input value (${
|
|
984
|
+
`UTXO value mismatch: total input value (${w} sat) is less than total output value (${b} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
943
985
|
);
|
|
944
|
-
const
|
|
945
|
-
if (
|
|
986
|
+
const y = w - b;
|
|
987
|
+
if (y > Et)
|
|
946
988
|
throw new Error(
|
|
947
|
-
`Implied transaction fee (${
|
|
989
|
+
`Implied transaction fee (${y} sat) exceeds maximum reasonable fee (${Et} sat). This may indicate manipulated UTXO data.`
|
|
948
990
|
);
|
|
949
|
-
for (const { input: d, utxoData:
|
|
950
|
-
const
|
|
991
|
+
for (const { input: d, utxoData: P, txid: g, vout: E } of c) {
|
|
992
|
+
const x = be(
|
|
951
993
|
{
|
|
952
|
-
value:
|
|
953
|
-
scriptPubKey:
|
|
994
|
+
value: P.value,
|
|
995
|
+
scriptPubKey: P.scriptPubKey
|
|
954
996
|
},
|
|
955
997
|
a
|
|
956
998
|
);
|
|
@@ -958,7 +1000,7 @@ class Mn {
|
|
|
958
1000
|
hash: d.hash,
|
|
959
1001
|
index: d.index,
|
|
960
1002
|
sequence: d.sequence,
|
|
961
|
-
...
|
|
1003
|
+
...x
|
|
962
1004
|
});
|
|
963
1005
|
}
|
|
964
1006
|
for (const d of r.outs)
|
|
@@ -966,19 +1008,19 @@ class Mn {
|
|
|
966
1008
|
script: d.script,
|
|
967
1009
|
value: d.value
|
|
968
1010
|
});
|
|
969
|
-
const
|
|
1011
|
+
const h = await this.config.btcWallet.signPsbt(i.toHex()), f = mt.fromHex(h);
|
|
970
1012
|
try {
|
|
971
|
-
|
|
1013
|
+
f.finalizeAllInputs();
|
|
972
1014
|
} catch (d) {
|
|
973
|
-
if (!
|
|
974
|
-
(
|
|
1015
|
+
if (!f.data.inputs.every(
|
|
1016
|
+
(g) => g.finalScriptWitness || g.finalScriptSig
|
|
975
1017
|
))
|
|
976
1018
|
throw new Error(
|
|
977
1019
|
`PSBT finalization failed and wallet did not auto-finalize: ${d}`
|
|
978
1020
|
);
|
|
979
1021
|
}
|
|
980
|
-
const
|
|
981
|
-
return await
|
|
1022
|
+
const T = f.extractTransaction().toHex();
|
|
1023
|
+
return await Pe(T, l);
|
|
982
1024
|
}
|
|
983
1025
|
/**
|
|
984
1026
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -1018,30 +1060,30 @@ class Mn {
|
|
|
1018
1060
|
if (!this.config.ethWallet.account)
|
|
1019
1061
|
throw new Error("Ethereum wallet account not found");
|
|
1020
1062
|
const c = this.config.ethWallet.account.address;
|
|
1021
|
-
if (!
|
|
1063
|
+
if (!wt(u.depositorEthAddress, c))
|
|
1022
1064
|
throw new Error(
|
|
1023
1065
|
`Proof of possession was signed for ${u.depositorEthAddress} but the Ethereum wallet is currently connected to ${c}. Reconnect the original account or call signProofOfPossession() again.`
|
|
1024
1066
|
);
|
|
1025
1067
|
await this.assertPopMatchesBtcWallet(u);
|
|
1026
|
-
const
|
|
1068
|
+
const w = u.btcPopSignature, b = I(u.depositorBtcPubkey), y = I(n), h = I(s), f = await this.resolvePayoutScriptPubKey(
|
|
1027
1069
|
a
|
|
1028
|
-
),
|
|
1029
|
-
_(
|
|
1070
|
+
), T = q(h), H = await yt(
|
|
1071
|
+
_(T),
|
|
1030
1072
|
_(c)
|
|
1031
|
-
), d = I(
|
|
1073
|
+
), d = I(H);
|
|
1032
1074
|
if (await this.checkVaultExists(d))
|
|
1033
1075
|
throw new Error(
|
|
1034
|
-
`Vault already exists (ID: ${d}, peginTxHash: ${
|
|
1076
|
+
`Vault already exists (ID: ${d}, peginTxHash: ${T}). 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.`
|
|
1035
1077
|
);
|
|
1036
|
-
const
|
|
1078
|
+
const g = G({
|
|
1037
1079
|
chain: this.config.ethChain,
|
|
1038
|
-
transport:
|
|
1080
|
+
transport: Z()
|
|
1039
1081
|
});
|
|
1040
|
-
let
|
|
1082
|
+
let E;
|
|
1041
1083
|
try {
|
|
1042
|
-
|
|
1084
|
+
E = await g.readContract({
|
|
1043
1085
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1044
|
-
abi:
|
|
1086
|
+
abi: R,
|
|
1045
1087
|
functionName: "getPegInFee",
|
|
1046
1088
|
args: [o]
|
|
1047
1089
|
});
|
|
@@ -1050,58 +1092,58 @@ class Mn {
|
|
|
1050
1092
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1051
1093
|
);
|
|
1052
1094
|
}
|
|
1053
|
-
const
|
|
1054
|
-
abi:
|
|
1095
|
+
const x = bt({
|
|
1096
|
+
abi: R,
|
|
1055
1097
|
functionName: "submitPeginRequest",
|
|
1056
1098
|
args: [
|
|
1057
1099
|
c,
|
|
1058
|
-
|
|
1100
|
+
b,
|
|
1101
|
+
w,
|
|
1059
1102
|
y,
|
|
1060
1103
|
h,
|
|
1061
|
-
p,
|
|
1062
1104
|
o,
|
|
1063
1105
|
r,
|
|
1064
1106
|
i,
|
|
1065
|
-
|
|
1107
|
+
f,
|
|
1066
1108
|
l
|
|
1067
1109
|
]
|
|
1068
1110
|
});
|
|
1069
|
-
let
|
|
1111
|
+
let p;
|
|
1070
1112
|
try {
|
|
1071
|
-
|
|
1113
|
+
p = await g.estimateGas({
|
|
1072
1114
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1073
|
-
data:
|
|
1074
|
-
value:
|
|
1115
|
+
data: x,
|
|
1116
|
+
value: E,
|
|
1075
1117
|
account: this.config.ethWallet.account.address
|
|
1076
1118
|
});
|
|
1077
|
-
} catch (
|
|
1078
|
-
|
|
1119
|
+
} catch (j) {
|
|
1120
|
+
S(j);
|
|
1079
1121
|
}
|
|
1080
|
-
let
|
|
1122
|
+
let k;
|
|
1081
1123
|
try {
|
|
1082
|
-
|
|
1124
|
+
k = await this.config.ethWallet.sendTransaction({
|
|
1083
1125
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1084
|
-
data:
|
|
1085
|
-
value:
|
|
1126
|
+
data: x,
|
|
1127
|
+
value: E,
|
|
1086
1128
|
account: this.config.ethWallet.account,
|
|
1087
1129
|
chain: this.config.ethChain,
|
|
1088
|
-
gas:
|
|
1130
|
+
gas: p
|
|
1089
1131
|
});
|
|
1090
|
-
} catch (
|
|
1091
|
-
|
|
1132
|
+
} catch (j) {
|
|
1133
|
+
S(j);
|
|
1092
1134
|
}
|
|
1093
|
-
const
|
|
1094
|
-
hash:
|
|
1095
|
-
timeout:
|
|
1135
|
+
const B = await g.waitForTransactionReceipt({
|
|
1136
|
+
hash: k,
|
|
1137
|
+
timeout: Ut
|
|
1096
1138
|
});
|
|
1097
|
-
return
|
|
1139
|
+
return B.status === "reverted" && S(
|
|
1098
1140
|
new Error(
|
|
1099
|
-
`Transaction reverted. Hash: ${
|
|
1141
|
+
`Transaction reverted. Hash: ${k}. Check the transaction on block explorer for details.`
|
|
1100
1142
|
)
|
|
1101
1143
|
), {
|
|
1102
|
-
ethTxHash:
|
|
1144
|
+
ethTxHash: B.transactionHash,
|
|
1103
1145
|
vaultId: d,
|
|
1104
|
-
peginTxHash:
|
|
1146
|
+
peginTxHash: T
|
|
1105
1147
|
};
|
|
1106
1148
|
}
|
|
1107
1149
|
/**
|
|
@@ -1121,39 +1163,39 @@ class Mn {
|
|
|
1121
1163
|
if (!this.config.ethWallet.account)
|
|
1122
1164
|
throw new Error("Ethereum wallet account not found");
|
|
1123
1165
|
const i = this.config.ethWallet.account.address;
|
|
1124
|
-
if (!
|
|
1166
|
+
if (!wt(r.depositorEthAddress, i))
|
|
1125
1167
|
throw new Error(
|
|
1126
1168
|
`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.`
|
|
1127
1169
|
);
|
|
1128
1170
|
await this.assertPopMatchesBtcWallet(r);
|
|
1129
1171
|
const a = r.btcPopSignature, l = [];
|
|
1130
|
-
for (const
|
|
1172
|
+
for (const g of o)
|
|
1131
1173
|
l.push(
|
|
1132
|
-
await this.resolvePayoutScriptPubKey(
|
|
1174
|
+
await this.resolvePayoutScriptPubKey(g.depositorPayoutBtcAddress)
|
|
1133
1175
|
);
|
|
1134
1176
|
const u = [];
|
|
1135
|
-
for (const
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
),
|
|
1139
|
-
_(
|
|
1177
|
+
for (const g of o) {
|
|
1178
|
+
const E = I(
|
|
1179
|
+
g.depositorSignedPeginTx
|
|
1180
|
+
), x = q(E), p = await yt(
|
|
1181
|
+
_(x),
|
|
1140
1182
|
_(i)
|
|
1141
|
-
),
|
|
1142
|
-
if (await this.checkVaultExists(
|
|
1183
|
+
), k = I(p);
|
|
1184
|
+
if (await this.checkVaultExists(k))
|
|
1143
1185
|
throw new Error(
|
|
1144
|
-
`Vault already exists (ID: ${
|
|
1186
|
+
`Vault already exists (ID: ${k}, peginTxHash: ${x}). To create a new vault, use different UTXOs or a different amount.`
|
|
1145
1187
|
);
|
|
1146
|
-
u.push({ vaultId:
|
|
1188
|
+
u.push({ vaultId: k, peginTxHash: x });
|
|
1147
1189
|
}
|
|
1148
|
-
const c =
|
|
1190
|
+
const c = G({
|
|
1149
1191
|
chain: this.config.ethChain,
|
|
1150
|
-
transport:
|
|
1192
|
+
transport: Z()
|
|
1151
1193
|
});
|
|
1152
|
-
let
|
|
1194
|
+
let w;
|
|
1153
1195
|
try {
|
|
1154
|
-
|
|
1196
|
+
w = await c.readContract({
|
|
1155
1197
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1156
|
-
abi:
|
|
1198
|
+
abi: R,
|
|
1157
1199
|
functionName: "getPegInFee",
|
|
1158
1200
|
args: [n]
|
|
1159
1201
|
});
|
|
@@ -1162,59 +1204,59 @@ class Mn {
|
|
|
1162
1204
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1163
1205
|
);
|
|
1164
1206
|
}
|
|
1165
|
-
const
|
|
1207
|
+
const b = w * BigInt(o.length), y = I(
|
|
1166
1208
|
r.depositorBtcPubkey
|
|
1167
|
-
),
|
|
1168
|
-
depositorBtcPubKey:
|
|
1209
|
+
), h = I(s), f = o.map((g, E) => ({
|
|
1210
|
+
depositorBtcPubKey: y,
|
|
1169
1211
|
btcPopSignature: a,
|
|
1170
|
-
unsignedPrePeginTx:
|
|
1212
|
+
unsignedPrePeginTx: h,
|
|
1171
1213
|
depositorSignedPeginTx: I(
|
|
1172
|
-
|
|
1214
|
+
g.depositorSignedPeginTx
|
|
1173
1215
|
),
|
|
1174
|
-
hashlock:
|
|
1175
|
-
htlcVout:
|
|
1176
|
-
referralCode:
|
|
1177
|
-
depositorPayoutBtcAddress: l[
|
|
1178
|
-
depositorWotsPkHash:
|
|
1179
|
-
})),
|
|
1180
|
-
abi:
|
|
1216
|
+
hashlock: g.hashlock,
|
|
1217
|
+
htlcVout: g.htlcVout,
|
|
1218
|
+
referralCode: In,
|
|
1219
|
+
depositorPayoutBtcAddress: l[E],
|
|
1220
|
+
depositorWotsPkHash: g.depositorWotsPkHash
|
|
1221
|
+
})), T = bt({
|
|
1222
|
+
abi: R,
|
|
1181
1223
|
functionName: "submitPeginRequestBatch",
|
|
1182
|
-
args: [i, n,
|
|
1224
|
+
args: [i, n, f]
|
|
1183
1225
|
});
|
|
1184
|
-
let
|
|
1226
|
+
let H;
|
|
1185
1227
|
try {
|
|
1186
|
-
|
|
1228
|
+
H = await c.estimateGas({
|
|
1187
1229
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1188
|
-
data:
|
|
1189
|
-
value:
|
|
1230
|
+
data: T,
|
|
1231
|
+
value: b,
|
|
1190
1232
|
account: this.config.ethWallet.account.address
|
|
1191
1233
|
});
|
|
1192
|
-
} catch (
|
|
1193
|
-
|
|
1234
|
+
} catch (g) {
|
|
1235
|
+
S(g);
|
|
1194
1236
|
}
|
|
1195
1237
|
let d;
|
|
1196
1238
|
try {
|
|
1197
1239
|
d = await this.config.ethWallet.sendTransaction({
|
|
1198
1240
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1199
|
-
data:
|
|
1200
|
-
value:
|
|
1241
|
+
data: T,
|
|
1242
|
+
value: b,
|
|
1201
1243
|
account: this.config.ethWallet.account,
|
|
1202
1244
|
chain: this.config.ethChain,
|
|
1203
|
-
gas:
|
|
1245
|
+
gas: H
|
|
1204
1246
|
});
|
|
1205
|
-
} catch (
|
|
1206
|
-
|
|
1247
|
+
} catch (g) {
|
|
1248
|
+
S(g);
|
|
1207
1249
|
}
|
|
1208
|
-
const
|
|
1250
|
+
const P = await c.waitForTransactionReceipt({
|
|
1209
1251
|
hash: d,
|
|
1210
|
-
timeout:
|
|
1252
|
+
timeout: Ut
|
|
1211
1253
|
});
|
|
1212
|
-
return
|
|
1254
|
+
return P.status === "reverted" && S(
|
|
1213
1255
|
new Error(
|
|
1214
1256
|
`Batch transaction reverted. Hash: ${d}. Check the transaction on block explorer for details.`
|
|
1215
1257
|
)
|
|
1216
1258
|
), {
|
|
1217
|
-
ethTxHash:
|
|
1259
|
+
ethTxHash: P.transactionHash,
|
|
1218
1260
|
vaults: u
|
|
1219
1261
|
};
|
|
1220
1262
|
}
|
|
@@ -1226,15 +1268,15 @@ class Mn {
|
|
|
1226
1268
|
*/
|
|
1227
1269
|
async checkVaultExists(t) {
|
|
1228
1270
|
try {
|
|
1229
|
-
return (await
|
|
1271
|
+
return (await G({
|
|
1230
1272
|
chain: this.config.ethChain,
|
|
1231
|
-
transport:
|
|
1273
|
+
transport: Z()
|
|
1232
1274
|
}).readContract({
|
|
1233
1275
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1234
|
-
abi:
|
|
1276
|
+
abi: R,
|
|
1235
1277
|
functionName: "getBtcVaultBasicInfo",
|
|
1236
1278
|
args: [t]
|
|
1237
|
-
})).depositor !==
|
|
1279
|
+
})).depositor !== ce;
|
|
1238
1280
|
} catch {
|
|
1239
1281
|
return !1;
|
|
1240
1282
|
}
|
|
@@ -1253,7 +1295,7 @@ class Mn {
|
|
|
1253
1295
|
else {
|
|
1254
1296
|
n = await this.config.btcWallet.getAddress();
|
|
1255
1297
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
1256
|
-
if (!
|
|
1298
|
+
if (!ge(
|
|
1257
1299
|
n,
|
|
1258
1300
|
o,
|
|
1259
1301
|
this.config.btcNetwork
|
|
@@ -1262,9 +1304,9 @@ class Mn {
|
|
|
1262
1304
|
"The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
|
|
1263
1305
|
);
|
|
1264
1306
|
}
|
|
1265
|
-
const s =
|
|
1307
|
+
const s = Pt(this.config.btcNetwork);
|
|
1266
1308
|
try {
|
|
1267
|
-
return `0x${
|
|
1309
|
+
return `0x${Vt.address.toOutputScript(n, s).toString("hex")}`;
|
|
1268
1310
|
} catch {
|
|
1269
1311
|
throw new Error(
|
|
1270
1312
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1280,22 +1322,22 @@ class Mn {
|
|
|
1280
1322
|
async signProofOfPossession() {
|
|
1281
1323
|
if (!this.config.ethWallet.account)
|
|
1282
1324
|
throw new Error("Ethereum wallet account not found");
|
|
1283
|
-
const t = this.config.ethWallet.account.address, n =
|
|
1325
|
+
const t = this.config.ethWallet.account.address, n = U(
|
|
1284
1326
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1285
1327
|
), s = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
|
|
1286
1328
|
o,
|
|
1287
1329
|
"bip322-simple"
|
|
1288
1330
|
);
|
|
1289
1331
|
return {
|
|
1290
|
-
btcPopSignature:
|
|
1332
|
+
btcPopSignature: _n(r),
|
|
1291
1333
|
depositorEthAddress: t,
|
|
1292
1334
|
depositorBtcPubkey: n
|
|
1293
1335
|
};
|
|
1294
1336
|
}
|
|
1295
1337
|
async assertPopMatchesBtcWallet(t) {
|
|
1296
|
-
const n =
|
|
1338
|
+
const n = U(
|
|
1297
1339
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1298
|
-
), s =
|
|
1340
|
+
), s = U(t.depositorBtcPubkey);
|
|
1299
1341
|
if (n !== s)
|
|
1300
1342
|
throw new Error(
|
|
1301
1343
|
`Proof of possession was signed with BTC pubkey ${s} but the BTC wallet is currently connected to ${n}. Reconnect the original wallet or call signProofOfPossession() again.`
|
|
@@ -1319,21 +1361,21 @@ class Mn {
|
|
|
1319
1361
|
}
|
|
1320
1362
|
}
|
|
1321
1363
|
export {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1364
|
+
C,
|
|
1365
|
+
jn as P,
|
|
1366
|
+
De as V,
|
|
1367
|
+
Kn as a,
|
|
1368
|
+
Ne as b,
|
|
1369
|
+
xn as c,
|
|
1370
|
+
yn as d,
|
|
1371
|
+
gt as e,
|
|
1372
|
+
Ve as f,
|
|
1373
|
+
Dn as g,
|
|
1374
|
+
S as h,
|
|
1375
|
+
zn as i,
|
|
1376
|
+
We as j,
|
|
1377
|
+
Xe as k,
|
|
1378
|
+
Ke as l,
|
|
1379
|
+
je as m
|
|
1338
1380
|
};
|
|
1339
|
-
//# sourceMappingURL=PeginManager-
|
|
1381
|
+
//# sourceMappingURL=PeginManager-Dj6oDaH5.js.map
|