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