@babylonlabs-io/ts-sdk 0.33.1 → 0.33.3
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-LeGYbRN2.js → PeginManager-C-L3huRO.js} +330 -334
- package/dist/PeginManager-C-L3huRO.js.map +1 -0
- package/dist/{PeginManager-D2pBM0E-.cjs → PeginManager-DmPmzPHz.cjs} +2 -2
- package/dist/PeginManager-DmPmzPHz.cjs.map +1 -0
- package/dist/{bitcoin-0_T6KJON.js → bitcoin-B0S8SHCX.js} +24 -20
- package/dist/bitcoin-B0S8SHCX.js.map +1 -0
- package/dist/bitcoin-B3aqjuMP.cjs +2 -0
- package/dist/bitcoin-B3aqjuMP.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-CK8MbGQh.js → buildAndBroadcastRefund-Dx09Zbla.js} +4 -4
- package/dist/buildAndBroadcastRefund-Dx09Zbla.js.map +1 -0
- package/dist/{buildAndBroadcastRefund-BXjYAqdb.cjs → buildAndBroadcastRefund-PmJMNrhO.cjs} +2 -2
- package/dist/buildAndBroadcastRefund-PmJMNrhO.cjs.map +1 -0
- package/dist/{challengeAssert-KGVKQh0J.js → challengeAssert-D3tHnLWb.js} +2 -2
- package/dist/{challengeAssert-KGVKQh0J.js.map → challengeAssert-D3tHnLWb.js.map} +1 -1
- package/dist/{challengeAssert-06GLZtV8.cjs → challengeAssert-Dp9d1bg1.cjs} +2 -2
- package/dist/{challengeAssert-06GLZtV8.cjs.map → challengeAssert-Dp9d1bg1.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +8 -8
- package/dist/{noPayout-BmMd4NNH.js → noPayout-BnsetBKW.js} +2 -2
- package/dist/{noPayout-BmMd4NNH.js.map → noPayout-BnsetBKW.js.map} +1 -1
- package/dist/{noPayout-Bp2TYA_X.cjs → noPayout-DWaCtpMU.cjs} +2 -2
- package/dist/{noPayout-Bp2TYA_X.cjs.map → noPayout-DWaCtpMU.cjs.map} +1 -1
- package/dist/{psbtInputFields-BLi7Ta-T.cjs → psbtInputFields-6sRcZqdb.cjs} +2 -2
- package/dist/{psbtInputFields-BLi7Ta-T.cjs.map → psbtInputFields-6sRcZqdb.cjs.map} +1 -1
- package/dist/{psbtInputFields-DPCFHgGd.js → psbtInputFields-C5QPn1YK.js} +2 -2
- package/dist/{psbtInputFields-DPCFHgGd.js.map → psbtInputFields-C5QPn1YK.js.map} +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/clients/vault-provider/api.d.ts +2 -0
- package/dist/tbv/core/clients/vault-provider/api.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +9 -0
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +8 -8
- package/dist/tbv/core/managers/PayoutManager.d.ts +8 -4
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +15 -1
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +3 -3
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +6 -4
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +2 -2
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +8 -8
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/types-PthVHz5q.cjs +2 -0
- package/dist/types-PthVHz5q.cjs.map +1 -0
- package/dist/{types-D1o_3Q__.js → types-SYvSQWnc.js} +128 -87
- package/dist/types-SYvSQWnc.js.map +1 -0
- package/dist/{vault-registry-reader-DdUgC5IF.cjs → vault-registry-reader-CKe9TbX6.cjs} +2 -2
- package/dist/vault-registry-reader-CKe9TbX6.cjs.map +1 -0
- package/dist/{vault-registry-reader-BeIEh62N.js → vault-registry-reader-CWGbw_wZ.js} +117 -116
- package/dist/vault-registry-reader-CWGbw_wZ.js.map +1 -0
- package/package.json +1 -1
- package/dist/PeginManager-D2pBM0E-.cjs.map +0 -1
- package/dist/PeginManager-LeGYbRN2.js.map +0 -1
- package/dist/bitcoin-0_T6KJON.js.map +0 -1
- package/dist/bitcoin-EYBKDtEW.cjs +0 -2
- package/dist/bitcoin-EYBKDtEW.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-BXjYAqdb.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-CK8MbGQh.js.map +0 -1
- package/dist/types-C2IUB0Jd.cjs +0 -2
- package/dist/types-C2IUB0Jd.cjs.map +0 -1
- package/dist/types-D1o_3Q__.js.map +0 -1
- package/dist/vault-registry-reader-BeIEh62N.js.map +0 -1
- package/dist/vault-registry-reader-DdUgC5IF.cjs.map +0 -1
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var m = (e, t, n) =>
|
|
4
|
-
import * as
|
|
5
|
-
import { Transaction as
|
|
6
|
-
import { Buffer as
|
|
7
|
-
import { a as
|
|
8
|
-
import { isAddressEqual as
|
|
9
|
-
import { deriveVaultId as
|
|
10
|
-
import { b as
|
|
11
|
-
import { s as _, u as
|
|
12
|
-
import { c as
|
|
13
|
-
import { M as
|
|
14
|
-
import { h as
|
|
15
|
-
import { b as
|
|
16
|
-
import { p as
|
|
17
|
-
import { p as
|
|
18
|
-
import { B as
|
|
19
|
-
const
|
|
20
|
-
function
|
|
21
|
-
return t ? { h: Number(e &
|
|
1
|
+
var ee = Object.defineProperty;
|
|
2
|
+
var ne = (e, t, n) => t in e ? ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var m = (e, t, n) => ne(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as $t from "bitcoinjs-lib";
|
|
5
|
+
import { Transaction as Ut, Psbt as ft } from "bitcoinjs-lib";
|
|
6
|
+
import { Buffer as D } from "buffer";
|
|
7
|
+
import { a as Lt, b as V, c as A, d as z, e as nt, s as O, f as Nt, H as se, r as W, u as oe, g as gt, h as re } from "./sha2-6wN58S6R.js";
|
|
8
|
+
import { isAddressEqual as pt, encodeFunctionData as mt, zeroAddress as ie } from "viem";
|
|
9
|
+
import { deriveVaultId as wt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
import { b as bt, a as ae, d as ce, e as le, f as ue } from "./challengeAssert-D3tHnLWb.js";
|
|
11
|
+
import { s as _, u as j, h as st, e as I, p as he, g as yt, i as de } from "./bitcoin-B0S8SHCX.js";
|
|
12
|
+
import { c as fe } from "./signing-BZigafm0.js";
|
|
13
|
+
import { M as xt } from "./validation-CxqROCno.js";
|
|
14
|
+
import { h as ge } from "./buildAndBroadcastRefund-Dx09Zbla.js";
|
|
15
|
+
import { b as pe, f as Z, i as me } from "./psbtInputFields-C5QPn1YK.js";
|
|
16
|
+
import { p as we, f as be } from "./fundPeginTransaction-oV-dNJOU.js";
|
|
17
|
+
import { p as ye, f as xe } from "./vault-registry-reader-CWGbw_wZ.js";
|
|
18
|
+
import { B as $ } from "./types-SYvSQWnc.js";
|
|
19
|
+
const M = /* @__PURE__ */ BigInt(2 ** 32 - 1), Pt = /* @__PURE__ */ BigInt(32);
|
|
20
|
+
function Pe(e, t = !1) {
|
|
21
|
+
return t ? { h: Number(e & M), l: Number(e >> Pt & M) } : { h: Number(e >> Pt & M) | 0, l: Number(e & M) | 0 };
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function Ee(e, t = !1) {
|
|
24
24
|
const n = e.length;
|
|
25
25
|
let s = new Uint32Array(n), o = new Uint32Array(n);
|
|
26
26
|
for (let r = 0; r < n; r++) {
|
|
27
|
-
const { h: i, l: a } =
|
|
27
|
+
const { h: i, l: a } = Pe(e[r], t);
|
|
28
28
|
[s[r], o[r]] = [i, a];
|
|
29
29
|
}
|
|
30
30
|
return [s, o];
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
function
|
|
34
|
-
const s = _(e), o =
|
|
32
|
+
const Te = (e, t, n) => e << n | t >>> 32 - n, ke = (e, t, n) => t << n | e >>> 32 - n, _e = (e, t, n) => t << n - 32 | e >>> 64 - n, ve = (e, t, n) => e << n - 32 | t >>> 64 - n, Ie = 106, Be = 32, Et = 34;
|
|
33
|
+
function He(e, t, n) {
|
|
34
|
+
const s = _(e), o = $t.Transaction.fromHex(s);
|
|
35
35
|
if (o.outs.length <= t)
|
|
36
36
|
throw new Error(
|
|
37
37
|
`Pre-PegIn auth-anchor OP_RETURN missing: tx has ${o.outs.length} outputs, expected at least ${t + 1} (vault outputs + OP_RETURN)`
|
|
38
38
|
);
|
|
39
39
|
const r = o.outs[t], i = r.script;
|
|
40
|
-
if (i.length !==
|
|
40
|
+
if (i.length !== Et || i[0] !== Ie || i[1] !== Be)
|
|
41
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 ${
|
|
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 ${Et}-byte OP_RETURN + PUSH32 layout)`
|
|
43
43
|
);
|
|
44
44
|
const a = i.slice(2).toString("hex").toLowerCase();
|
|
45
45
|
if (a !== n.toLowerCase())
|
|
@@ -51,7 +51,7 @@ function Ae(e, t, n) {
|
|
|
51
51
|
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has non-zero value ${r.value}; OP_RETURN outputs must be 0-value`
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
|
-
class
|
|
54
|
+
class Vt {
|
|
55
55
|
constructor(t, n) {
|
|
56
56
|
m(this, "oHash");
|
|
57
57
|
m(this, "iHash");
|
|
@@ -59,7 +59,7 @@ class Mt {
|
|
|
59
59
|
m(this, "outputLen");
|
|
60
60
|
m(this, "finished", !1);
|
|
61
61
|
m(this, "destroyed", !1);
|
|
62
|
-
if (
|
|
62
|
+
if (Lt(t), V(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
63
63
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
64
64
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
65
65
|
const s = this.blockLen, o = new Uint8Array(s);
|
|
@@ -72,10 +72,10 @@ class Mt {
|
|
|
72
72
|
this.oHash.update(o), A(o);
|
|
73
73
|
}
|
|
74
74
|
update(t) {
|
|
75
|
-
return
|
|
75
|
+
return z(this), this.iHash.update(t), this;
|
|
76
76
|
}
|
|
77
77
|
digestInto(t) {
|
|
78
|
-
|
|
78
|
+
z(this), V(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
79
79
|
}
|
|
80
80
|
digest() {
|
|
81
81
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -93,148 +93,148 @@ class Mt {
|
|
|
93
93
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
function
|
|
100
|
-
|
|
96
|
+
const Wt = (e, t, n) => new Vt(e, t).update(n).digest();
|
|
97
|
+
Wt.create = (e, t) => new Vt(e, t);
|
|
98
|
+
const q = /* @__PURE__ */ Uint8Array.of(0), Tt = /* @__PURE__ */ Uint8Array.of();
|
|
99
|
+
function at(e, t, n, s = 32) {
|
|
100
|
+
Lt(e), nt(s, "length");
|
|
101
101
|
const o = e.outputLen;
|
|
102
102
|
if (s > 255 * o)
|
|
103
103
|
throw new Error("Length must be <= 255*HashLen");
|
|
104
104
|
const r = Math.ceil(s / o);
|
|
105
|
-
n === void 0 ? n =
|
|
106
|
-
const i = new Uint8Array(r * o), a =
|
|
105
|
+
n === void 0 ? n = Tt : V(n, void 0, "info");
|
|
106
|
+
const i = new Uint8Array(r * o), a = Wt.create(e, t), l = a._cloneInto(), u = new Uint8Array(a.outputLen);
|
|
107
107
|
for (let c = 0; c < r; c++)
|
|
108
|
-
|
|
109
|
-
return a.destroy(), l.destroy(), A(u,
|
|
108
|
+
q[0] = c + 1, l.update(c === 0 ? Tt : u).update(n).update(q).digestInto(u), i.set(u, o * c), a._cloneInto(l);
|
|
109
|
+
return a.destroy(), l.destroy(), A(u, q), i.slice(0, s);
|
|
110
110
|
}
|
|
111
|
-
const
|
|
112
|
-
function
|
|
111
|
+
const Y = new TextEncoder().encode("babylonvault"), kt = 255, _t = 65535, vt = 2, Se = "hashlock", Ae = "auth-anchor", Ce = "wots-seed";
|
|
112
|
+
function Mt(e) {
|
|
113
113
|
if (!Number.isInteger(e) || e < 0 || e > 4294967295)
|
|
114
114
|
throw new Error(`i2osp4: value must be a u32, got ${e}`);
|
|
115
115
|
const t = new Uint8Array(4);
|
|
116
116
|
return t[0] = e >>> 24 & 255, t[1] = e >>> 16 & 255, t[2] = e >>> 8 & 255, t[3] = e & 255, t;
|
|
117
117
|
}
|
|
118
|
-
function
|
|
118
|
+
function ct(e, t = new Uint8Array(0)) {
|
|
119
119
|
const n = new TextEncoder().encode(e);
|
|
120
|
-
if (n.length === 0 || n.length >
|
|
120
|
+
if (n.length === 0 || n.length > kt)
|
|
121
121
|
throw new Error(
|
|
122
|
-
`info: label length must be in [1, ${
|
|
122
|
+
`info: label length must be in [1, ${kt}], got ${n.length}`
|
|
123
123
|
);
|
|
124
|
-
if (t.length >
|
|
124
|
+
if (t.length > _t)
|
|
125
125
|
throw new Error(
|
|
126
|
-
`info: ctx length must be in [0, ${
|
|
126
|
+
`info: ctx length must be in [0, ${_t}], got ${t.length}`
|
|
127
127
|
);
|
|
128
|
-
const s =
|
|
128
|
+
const s = Y.length + 1 + n.length + vt + t.length, o = new Uint8Array(s);
|
|
129
129
|
let r = 0;
|
|
130
|
-
return o.set(
|
|
130
|
+
return o.set(Y, r), r += Y.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 += vt, o.set(t, r), o;
|
|
131
131
|
}
|
|
132
|
-
const
|
|
133
|
-
function
|
|
134
|
-
if (e.length !==
|
|
132
|
+
const It = 32, Oe = 32, Re = 32, $e = 64;
|
|
133
|
+
function lt(e) {
|
|
134
|
+
if (e.length !== It)
|
|
135
135
|
throw new Error(
|
|
136
|
-
`vault-secrets: root must be exactly ${
|
|
136
|
+
`vault-secrets: root must be exactly ${It} bytes, got ${e.length}`
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
|
-
function
|
|
140
|
-
return
|
|
139
|
+
function Ue(e) {
|
|
140
|
+
return lt(e), at(
|
|
141
141
|
O,
|
|
142
142
|
e,
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
ct(Ae),
|
|
144
|
+
Oe
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
return
|
|
147
|
+
function Le(e, t) {
|
|
148
|
+
return lt(e), at(
|
|
149
149
|
O,
|
|
150
150
|
e,
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
ct(Se, Mt(t)),
|
|
152
|
+
Re
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
return
|
|
155
|
+
function Ne(e, t) {
|
|
156
|
+
return lt(e), at(
|
|
157
157
|
O,
|
|
158
158
|
e,
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
ct(Ce, Mt(t)),
|
|
160
|
+
$e
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
|
-
const
|
|
164
|
-
function
|
|
163
|
+
const N = 32, Q = 32, ot = 36, Ft = 32, G = 4, Ve = G + N + G + Ft;
|
|
164
|
+
function rt(e, t, n) {
|
|
165
165
|
e[t] = n >>> 24 & 255, e[t + 1] = n >>> 16 & 255, e[t + 2] = n >>> 8 & 255, e[t + 3] = n & 255;
|
|
166
166
|
}
|
|
167
|
-
function
|
|
168
|
-
if (e.txid.length !==
|
|
167
|
+
function We(e) {
|
|
168
|
+
if (e.txid.length !== Q)
|
|
169
169
|
throw new Error(
|
|
170
|
-
`outpoint.txid must be exactly ${
|
|
170
|
+
`outpoint.txid must be exactly ${Q} bytes, got ${e.txid.length}`
|
|
171
171
|
);
|
|
172
172
|
if (!Number.isInteger(e.vout) || e.vout < 0 || e.vout > 4294967295)
|
|
173
173
|
throw new Error(`outpoint.vout must be a u32, got ${e.vout}`);
|
|
174
|
-
const t = new Uint8Array(
|
|
175
|
-
return t.set(e.txid, 0),
|
|
174
|
+
const t = new Uint8Array(ot);
|
|
175
|
+
return t.set(e.txid, 0), rt(t, Q, e.vout), t;
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function Bt(e, t) {
|
|
178
178
|
const n = Math.min(e.length, t.length);
|
|
179
179
|
for (let s = 0; s < n; s++)
|
|
180
180
|
if (e[s] !== t[s]) return e[s] - t[s];
|
|
181
181
|
return e.length - t.length;
|
|
182
182
|
}
|
|
183
|
-
function
|
|
183
|
+
function Me(e) {
|
|
184
184
|
if (e.length === 0)
|
|
185
185
|
throw new Error(
|
|
186
186
|
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
187
187
|
);
|
|
188
|
-
const t = e.map(
|
|
189
|
-
t.sort(
|
|
188
|
+
const t = e.map(We);
|
|
189
|
+
t.sort(Bt);
|
|
190
190
|
for (let s = 1; s < t.length; s++)
|
|
191
|
-
if (
|
|
191
|
+
if (Bt(t[s - 1], t[s]) === 0)
|
|
192
192
|
throw new Error(
|
|
193
193
|
"buildFundingOutpointsCommitment: duplicate outpoint detected"
|
|
194
194
|
);
|
|
195
|
-
const n = new Uint8Array(t.length *
|
|
195
|
+
const n = new Uint8Array(t.length * ot);
|
|
196
196
|
for (let s = 0; s < t.length; s++)
|
|
197
|
-
n.set(t[s], s *
|
|
197
|
+
n.set(t[s], s * ot);
|
|
198
198
|
return O(n);
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
if (e.depositorBtcPubkey.length !==
|
|
200
|
+
function Fe(e) {
|
|
201
|
+
if (e.depositorBtcPubkey.length !== N)
|
|
202
202
|
throw new Error(
|
|
203
|
-
`vaultContext: depositorBtcPubkey must be exactly ${
|
|
203
|
+
`vaultContext: depositorBtcPubkey must be exactly ${N} bytes, got ${e.depositorBtcPubkey.length}`
|
|
204
204
|
);
|
|
205
|
-
const t =
|
|
205
|
+
const t = Me(e.fundingOutpoints), n = new Uint8Array(Ve);
|
|
206
206
|
let s = 0;
|
|
207
|
-
return
|
|
207
|
+
return rt(n, s, N), s += G, n.set(e.depositorBtcPubkey, s), s += N, rt(n, s, Ft), s += G, n.set(t, s), n;
|
|
208
208
|
}
|
|
209
|
-
const
|
|
210
|
-
async function
|
|
211
|
-
const n =
|
|
209
|
+
const Xe = "babylon-vault", Xt = 32, Ht = Xt * 2, Ke = /^[0-9a-f]+$/;
|
|
210
|
+
async function De(e, t) {
|
|
211
|
+
const n = Fe(t), s = j(n), o = await e.deriveContextHash(Xe, s);
|
|
212
212
|
if (typeof o != "string")
|
|
213
213
|
throw new Error(
|
|
214
214
|
`deriveVaultRoot: wallet must return a string, got ${typeof o}`
|
|
215
215
|
);
|
|
216
|
-
if (o.length !==
|
|
216
|
+
if (o.length !== Ht)
|
|
217
217
|
throw new Error(
|
|
218
|
-
`deriveVaultRoot: wallet must return a ${
|
|
218
|
+
`deriveVaultRoot: wallet must return a ${Ht}-character hex string (${Xt} bytes), got length ${o.length}`
|
|
219
219
|
);
|
|
220
|
-
if (!
|
|
220
|
+
if (!Ke.test(o))
|
|
221
221
|
throw new Error(
|
|
222
222
|
"deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
|
|
223
223
|
);
|
|
224
|
-
return
|
|
224
|
+
return st(o);
|
|
225
225
|
}
|
|
226
|
-
function
|
|
226
|
+
function Fn(e) {
|
|
227
227
|
if (!e)
|
|
228
228
|
throw new Error("Pre-pegin transaction hex is empty");
|
|
229
|
-
const t = e.startsWith("0x") ? e.slice(2) : e, n =
|
|
229
|
+
const t = e.startsWith("0x") ? e.slice(2) : e, n = Ut.fromHex(t);
|
|
230
230
|
if (n.ins.length === 0)
|
|
231
231
|
throw new Error("Pre-pegin transaction has no inputs");
|
|
232
232
|
return n.ins.map((s) => ({
|
|
233
|
-
txid: Uint8Array.from(
|
|
233
|
+
txid: Uint8Array.from(D.from(s.hash).reverse()),
|
|
234
234
|
vout: s.index
|
|
235
235
|
}));
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const ze = /* @__PURE__ */ Uint8Array.from([
|
|
238
238
|
7,
|
|
239
239
|
4,
|
|
240
240
|
13,
|
|
@@ -251,36 +251,36 @@ const Ge = /* @__PURE__ */ Uint8Array.from([
|
|
|
251
251
|
14,
|
|
252
252
|
11,
|
|
253
253
|
8
|
|
254
|
-
]),
|
|
255
|
-
const n = [[
|
|
254
|
+
]), Kt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), je = Kt.map((e) => (9 * e + 5) % 16), Dt = /* @__PURE__ */ (() => {
|
|
255
|
+
const n = [[Kt], [je]];
|
|
256
256
|
for (let s = 0; s < 4; s++)
|
|
257
257
|
for (let o of n)
|
|
258
|
-
o.push(o[s].map((r) =>
|
|
258
|
+
o.push(o[s].map((r) => ze[r]));
|
|
259
259
|
return n;
|
|
260
|
-
})(),
|
|
260
|
+
})(), zt = Dt[0], jt = Dt[1], Gt = /* @__PURE__ */ [
|
|
261
261
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
262
262
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
263
263
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
264
264
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
265
265
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
266
|
-
].map((e) => Uint8Array.from(e)),
|
|
266
|
+
].map((e) => Uint8Array.from(e)), Ge = /* @__PURE__ */ zt.map((e, t) => e.map((n) => Gt[t][n])), Ze = /* @__PURE__ */ jt.map((e, t) => e.map((n) => Gt[t][n])), qe = /* @__PURE__ */ Uint32Array.from([
|
|
267
267
|
0,
|
|
268
268
|
1518500249,
|
|
269
269
|
1859775393,
|
|
270
270
|
2400959708,
|
|
271
271
|
2840853838
|
|
272
|
-
]),
|
|
272
|
+
]), Ye = /* @__PURE__ */ Uint32Array.from([
|
|
273
273
|
1352829926,
|
|
274
274
|
1548603684,
|
|
275
275
|
1836072691,
|
|
276
276
|
2053994217,
|
|
277
277
|
0
|
|
278
278
|
]);
|
|
279
|
-
function
|
|
279
|
+
function St(e, t, n, s) {
|
|
280
280
|
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
281
|
}
|
|
282
|
-
const
|
|
283
|
-
class
|
|
282
|
+
const F = /* @__PURE__ */ new Uint32Array(16);
|
|
283
|
+
class Qe extends se {
|
|
284
284
|
constructor() {
|
|
285
285
|
super(64, 20, 8, !0);
|
|
286
286
|
m(this, "h0", 1732584193);
|
|
@@ -298,50 +298,50 @@ class tn extends re {
|
|
|
298
298
|
}
|
|
299
299
|
process(n, s) {
|
|
300
300
|
for (let h = 0; h < 16; h++, s += 4)
|
|
301
|
-
|
|
301
|
+
F[h] = n.getUint32(s, !0);
|
|
302
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, y = b;
|
|
303
303
|
for (let h = 0; h < 5; h++) {
|
|
304
|
-
const
|
|
304
|
+
const g = 4 - h, T = qe[h], B = Ye[h], d = zt[h], P = jt[h], f = Ge[h], E = Ze[h];
|
|
305
305
|
for (let x = 0; x < 16; x++) {
|
|
306
|
-
const p =
|
|
307
|
-
o = b, b = c, c =
|
|
306
|
+
const p = W(o + St(h, i, l, c) + F[d[x]] + T, f[x]) + b | 0;
|
|
307
|
+
o = b, b = c, c = W(l, 10) | 0, l = i, i = p;
|
|
308
308
|
}
|
|
309
309
|
for (let x = 0; x < 16; x++) {
|
|
310
|
-
const p =
|
|
311
|
-
r = y, y = w, w =
|
|
310
|
+
const p = W(r + St(g, a, u, w) + F[P[x]] + B, E[x]) + y | 0;
|
|
311
|
+
r = y, y = w, w = W(u, 10) | 0, u = a, a = p;
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
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);
|
|
315
315
|
}
|
|
316
316
|
roundClean() {
|
|
317
|
-
A(
|
|
317
|
+
A(F);
|
|
318
318
|
}
|
|
319
319
|
destroy() {
|
|
320
320
|
this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
const
|
|
324
|
-
for (let e = 0, t =
|
|
325
|
-
[n, s] = [s, (2 * n + 3 * s) % 5],
|
|
326
|
-
let o =
|
|
323
|
+
const Je = /* @__PURE__ */ Nt(() => new Qe()), tn = BigInt(0), U = BigInt(1), en = BigInt(2), nn = BigInt(7), sn = BigInt(256), on = BigInt(113), Zt = [], qt = [], Yt = [];
|
|
324
|
+
for (let e = 0, t = U, n = 1, s = 0; e < 24; e++) {
|
|
325
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], Zt.push(2 * (5 * s + n)), qt.push((e + 1) * (e + 2) / 2 % 64);
|
|
326
|
+
let o = tn;
|
|
327
327
|
for (let r = 0; r < 7; r++)
|
|
328
|
-
t = (t <<
|
|
329
|
-
|
|
328
|
+
t = (t << U ^ (t >> nn) * on) % sn, t & en && (o ^= U << (U << BigInt(r)) - U);
|
|
329
|
+
Yt.push(o);
|
|
330
330
|
}
|
|
331
|
-
const
|
|
332
|
-
function
|
|
331
|
+
const Qt = Ee(Yt, !0), rn = Qt[0], an = Qt[1], At = (e, t, n) => n > 32 ? _e(e, t, n) : Te(e, t, n), Ct = (e, t, n) => n > 32 ? ve(e, t, n) : ke(e, t, n);
|
|
332
|
+
function cn(e, t = 24) {
|
|
333
333
|
const n = new Uint32Array(10);
|
|
334
334
|
for (let s = 24 - t; s < 24; s++) {
|
|
335
335
|
for (let i = 0; i < 10; i++)
|
|
336
336
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
337
337
|
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 =
|
|
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 = Ct(u, c, 1) ^ n[a + 1];
|
|
339
339
|
for (let y = 0; y < 50; y += 10)
|
|
340
340
|
e[i + y] ^= w, e[i + y + 1] ^= b;
|
|
341
341
|
}
|
|
342
342
|
let o = e[2], r = e[3];
|
|
343
343
|
for (let i = 0; i < 24; i++) {
|
|
344
|
-
const a =
|
|
344
|
+
const a = qt[i], l = At(o, r, a), u = Ct(o, r, a), c = Zt[i];
|
|
345
345
|
o = e[c], r = e[c + 1], e[c] = l, e[c + 1] = u;
|
|
346
346
|
}
|
|
347
347
|
for (let i = 0; i < 50; i += 10) {
|
|
@@ -350,11 +350,11 @@ function un(e, t = 24) {
|
|
|
350
350
|
for (let a = 0; a < 10; a++)
|
|
351
351
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
352
352
|
}
|
|
353
|
-
e[0] ^=
|
|
353
|
+
e[0] ^= rn[s], e[1] ^= an[s];
|
|
354
354
|
}
|
|
355
355
|
A(n);
|
|
356
356
|
}
|
|
357
|
-
class
|
|
357
|
+
class ut {
|
|
358
358
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
359
359
|
constructor(t, n, s, o = !1, r = 24) {
|
|
360
360
|
m(this, "state");
|
|
@@ -368,18 +368,18 @@ class dt {
|
|
|
368
368
|
m(this, "outputLen");
|
|
369
369
|
m(this, "enableXOF", !1);
|
|
370
370
|
m(this, "rounds");
|
|
371
|
-
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r,
|
|
371
|
+
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, nt(s, "outputLen"), !(0 < t && t < 200))
|
|
372
372
|
throw new Error("only keccak-f1600 function is supported");
|
|
373
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
373
|
+
this.state = new Uint8Array(200), this.state32 = oe(this.state);
|
|
374
374
|
}
|
|
375
375
|
clone() {
|
|
376
376
|
return this._cloneInto();
|
|
377
377
|
}
|
|
378
378
|
keccak() {
|
|
379
|
-
|
|
379
|
+
gt(this.state32), cn(this.state32, this.rounds), gt(this.state32), this.posOut = 0, this.pos = 0;
|
|
380
380
|
}
|
|
381
381
|
update(t) {
|
|
382
|
-
|
|
382
|
+
z(this), V(t);
|
|
383
383
|
const { blockLen: n, state: s } = this, o = t.length;
|
|
384
384
|
for (let r = 0; r < o; ) {
|
|
385
385
|
const i = Math.min(n - this.pos, o - r);
|
|
@@ -397,7 +397,7 @@ class dt {
|
|
|
397
397
|
t[s] ^= n, (n & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
398
398
|
}
|
|
399
399
|
writeInto(t) {
|
|
400
|
-
|
|
400
|
+
z(this, !1), V(t), this.finish();
|
|
401
401
|
const n = this.state, { blockLen: s } = this;
|
|
402
402
|
for (let o = 0, r = t.length; o < r; ) {
|
|
403
403
|
this.posOut >= s && this.keccak();
|
|
@@ -412,10 +412,10 @@ class dt {
|
|
|
412
412
|
return this.writeInto(t);
|
|
413
413
|
}
|
|
414
414
|
xof(t) {
|
|
415
|
-
return
|
|
415
|
+
return nt(t), this.xofInto(new Uint8Array(t));
|
|
416
416
|
}
|
|
417
417
|
digestInto(t) {
|
|
418
|
-
if (
|
|
418
|
+
if (re(t, this), this.finished)
|
|
419
419
|
throw new Error("digest() was already called");
|
|
420
420
|
return this.writeInto(t), this.destroy(), t;
|
|
421
421
|
}
|
|
@@ -427,26 +427,26 @@ class dt {
|
|
|
427
427
|
}
|
|
428
428
|
_cloneInto(t) {
|
|
429
429
|
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
430
|
-
return t || (t = new
|
|
430
|
+
return t || (t = new ut(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
431
|
}
|
|
432
432
|
}
|
|
433
|
-
const
|
|
434
|
-
function
|
|
435
|
-
return
|
|
433
|
+
const ln = (e, t, n, s = {}) => Nt(() => new ut(t, e, n), s), un = /* @__PURE__ */ ln(1, 136, 32), Ot = 64, v = 20, it = 4, Jt = 2, hn = 0, dn = 1, X = [64, 64], fn = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
434
|
+
function ht(e) {
|
|
435
|
+
return Je(O(e));
|
|
436
436
|
}
|
|
437
|
-
function
|
|
437
|
+
function te(e) {
|
|
438
438
|
return (1 << e) - 1;
|
|
439
439
|
}
|
|
440
|
-
function
|
|
440
|
+
function gn(e) {
|
|
441
441
|
let t = 1;
|
|
442
442
|
for (; t * t < e + 1; ) t++;
|
|
443
443
|
return Math.max(t, 2);
|
|
444
444
|
}
|
|
445
|
-
function
|
|
446
|
-
const t =
|
|
447
|
-
return { d: t, n: e, checksum_radix:
|
|
445
|
+
function pn(e) {
|
|
446
|
+
const t = it, n = e * te(t);
|
|
447
|
+
return { d: t, n: e, checksum_radix: gn(n) };
|
|
448
448
|
}
|
|
449
|
-
function
|
|
449
|
+
function J(e, t) {
|
|
450
450
|
const n = [];
|
|
451
451
|
let s = t;
|
|
452
452
|
for (; s > 0; )
|
|
@@ -455,30 +455,30 @@ function et(e, t) {
|
|
|
455
455
|
o.set(e);
|
|
456
456
|
for (let r = 0; r < n.length; r++)
|
|
457
457
|
o[e.length + r] = n[r];
|
|
458
|
-
return
|
|
458
|
+
return ht(o);
|
|
459
459
|
}
|
|
460
|
-
function
|
|
460
|
+
function tt(e, t) {
|
|
461
461
|
let n = e;
|
|
462
462
|
for (let s = 0; s < t; s++)
|
|
463
|
-
n =
|
|
463
|
+
n = ht(n);
|
|
464
464
|
return n;
|
|
465
465
|
}
|
|
466
|
-
function
|
|
467
|
-
const n =
|
|
466
|
+
function mn(e, t) {
|
|
467
|
+
const n = te(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
|
|
468
468
|
for (let c = 0; c < t.n; c++) {
|
|
469
|
-
const w =
|
|
469
|
+
const w = J(e, c + Jt), b = tt(w, n);
|
|
470
470
|
r.push(Array.from(b));
|
|
471
471
|
}
|
|
472
|
-
const i =
|
|
472
|
+
const i = J(
|
|
473
473
|
e,
|
|
474
|
-
|
|
475
|
-
), a =
|
|
474
|
+
hn
|
|
475
|
+
), a = tt(
|
|
476
476
|
i,
|
|
477
477
|
s
|
|
478
|
-
), l =
|
|
478
|
+
), l = J(
|
|
479
479
|
e,
|
|
480
|
-
|
|
481
|
-
), u =
|
|
480
|
+
dn
|
|
481
|
+
), u = tt(
|
|
482
482
|
l,
|
|
483
483
|
o
|
|
484
484
|
);
|
|
@@ -489,22 +489,22 @@ function bn(e, t) {
|
|
|
489
489
|
checksum_minor_terminal: Array.from(a)
|
|
490
490
|
};
|
|
491
491
|
}
|
|
492
|
-
async function
|
|
492
|
+
async function wn(e) {
|
|
493
493
|
try {
|
|
494
|
-
if (e.length !==
|
|
494
|
+
if (e.length !== Ot)
|
|
495
495
|
throw new Error(
|
|
496
|
-
`WOTS seed must be exactly ${
|
|
496
|
+
`WOTS seed must be exactly ${Ot} bytes, got ${e.length}`
|
|
497
497
|
);
|
|
498
498
|
const t = [];
|
|
499
|
-
for (let n = 0; n <
|
|
500
|
-
const s =
|
|
499
|
+
for (let n = 0; n < X.length; n++) {
|
|
500
|
+
const s = X[n], o = pn(s), r = new Uint8Array(e.length + 1);
|
|
501
501
|
r.set(e), r[e.length] = n;
|
|
502
|
-
const i =
|
|
502
|
+
const i = ht(r);
|
|
503
503
|
try {
|
|
504
|
-
const a =
|
|
505
|
-
if (a.config.d !==
|
|
504
|
+
const a = mn(i, o);
|
|
505
|
+
if (a.config.d !== it)
|
|
506
506
|
throw new Error(
|
|
507
|
-
`Block ${n}: expected d=${
|
|
507
|
+
`Block ${n}: expected d=${it}, got d=${a.config.d}`
|
|
508
508
|
);
|
|
509
509
|
if (a.config.n !== s)
|
|
510
510
|
throw new Error(
|
|
@@ -532,16 +532,16 @@ async function yn(e) {
|
|
|
532
532
|
r.fill(0), i.fill(0);
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
|
-
if (t.length !==
|
|
535
|
+
if (t.length !== X.length)
|
|
536
536
|
throw new Error(
|
|
537
|
-
`Expected ${
|
|
537
|
+
`Expected ${X.length} blocks, got ${t.length}`
|
|
538
538
|
);
|
|
539
539
|
return t;
|
|
540
540
|
} finally {
|
|
541
541
|
e.fill(0);
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
|
-
function
|
|
544
|
+
function et(e, t, n) {
|
|
545
545
|
if (e.length !== v)
|
|
546
546
|
throw new Error(
|
|
547
547
|
`Block ${t} ${n}: expected ${v} bytes, got ${e.length}`
|
|
@@ -554,18 +554,18 @@ function st(e, t, n) {
|
|
|
554
554
|
);
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
|
-
function
|
|
557
|
+
function bn(e) {
|
|
558
558
|
if (e.length === 0)
|
|
559
559
|
throw new Error("Public keys array must not be empty");
|
|
560
560
|
for (let r = 0; r < e.length; r++) {
|
|
561
561
|
const i = e[r];
|
|
562
|
-
|
|
562
|
+
et(i.checksum_minor_terminal, r, "checksum_minor_terminal"), et(i.checksum_major_terminal, r, "checksum_major_terminal");
|
|
563
563
|
for (let a = 0; a < i.message_terminals.length; a++)
|
|
564
|
-
|
|
564
|
+
et(i.message_terminals[a], r, `message_terminal[${a}]`);
|
|
565
565
|
}
|
|
566
566
|
let t = 0;
|
|
567
567
|
for (const r of e)
|
|
568
|
-
t +=
|
|
568
|
+
t += Jt + r.message_terminals.length;
|
|
569
569
|
const n = new Uint8Array(t * v);
|
|
570
570
|
let s = 0;
|
|
571
571
|
for (const r of e) {
|
|
@@ -573,28 +573,28 @@ function xn(e) {
|
|
|
573
573
|
for (const i of r.message_terminals)
|
|
574
574
|
n.set(i, s), s += v;
|
|
575
575
|
}
|
|
576
|
-
const o =
|
|
577
|
-
return `0x${
|
|
576
|
+
const o = un(n);
|
|
577
|
+
return `0x${fn(o)}`;
|
|
578
578
|
}
|
|
579
|
-
function
|
|
579
|
+
function Xn(e) {
|
|
580
580
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
581
581
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
582
582
|
}
|
|
583
|
-
async function
|
|
583
|
+
async function yn(e, t) {
|
|
584
584
|
const n = [], s = [], o = [], r = [];
|
|
585
585
|
try {
|
|
586
586
|
for (let i = 0; i < t; i++) {
|
|
587
|
-
const a =
|
|
587
|
+
const a = Ne(e, i);
|
|
588
588
|
try {
|
|
589
|
-
const u = await
|
|
590
|
-
n.push(u), s.push(
|
|
589
|
+
const u = await wn(a);
|
|
590
|
+
n.push(u), s.push(bn(u));
|
|
591
591
|
} finally {
|
|
592
592
|
a.fill(0);
|
|
593
593
|
}
|
|
594
|
-
const l =
|
|
594
|
+
const l = Le(e, i);
|
|
595
595
|
try {
|
|
596
|
-
const u =
|
|
597
|
-
o.push(u), r.push(
|
|
596
|
+
const u = j(l);
|
|
597
|
+
o.push(u), r.push(ge(I(u)).slice(2));
|
|
598
598
|
} finally {
|
|
599
599
|
l.fill(0);
|
|
600
600
|
}
|
|
@@ -604,33 +604,33 @@ async function Pn(e, t) {
|
|
|
604
604
|
}
|
|
605
605
|
return { perVaultWotsKeys: n, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
|
|
606
606
|
}
|
|
607
|
-
const
|
|
608
|
-
function
|
|
607
|
+
const xn = /^0x[0-9a-f]+$/i, Pn = /^[0-9a-f]+$/i, En = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
608
|
+
function L(e) {
|
|
609
609
|
if (typeof e != "string" || e.length === 0)
|
|
610
610
|
throw new Error("BTC wallet returned empty public key");
|
|
611
|
-
return
|
|
611
|
+
return he(e).toLowerCase();
|
|
612
612
|
}
|
|
613
|
-
function
|
|
613
|
+
function Tn(e) {
|
|
614
614
|
if (typeof e != "string" || e.length === 0)
|
|
615
615
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
616
616
|
if (e.startsWith("0x") || e.startsWith("0X")) {
|
|
617
|
-
if (!
|
|
617
|
+
if (!xn.test(e) || e.length < 4 || e.length % 2 !== 0)
|
|
618
618
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
619
619
|
return e.toLowerCase();
|
|
620
620
|
}
|
|
621
|
-
if (
|
|
621
|
+
if (Pn.test(e)) {
|
|
622
622
|
if (e.length % 2 !== 0)
|
|
623
623
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
624
624
|
return `0x${e.toLowerCase()}`;
|
|
625
625
|
}
|
|
626
|
-
if (!
|
|
626
|
+
if (!En.test(e) || e.length % 4 !== 0)
|
|
627
627
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
628
|
-
const t =
|
|
628
|
+
const t = D.from(e, "base64");
|
|
629
629
|
if (t.length === 0 || t.toString("base64") !== e)
|
|
630
630
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
631
631
|
return `0x${t.toString("hex")}`;
|
|
632
632
|
}
|
|
633
|
-
async function
|
|
633
|
+
async function kn(e, t, n) {
|
|
634
634
|
if (typeof e.signPsbts == "function") {
|
|
635
635
|
const o = await e.signPsbts(t, n);
|
|
636
636
|
if (o.length !== t.length)
|
|
@@ -680,7 +680,7 @@ const C = {
|
|
|
680
680
|
// PeginTransactionAlreadyUsed()
|
|
681
681
|
"0x7ed061c9": "This pegin transaction has already been used to activate another vault."
|
|
682
682
|
};
|
|
683
|
-
function
|
|
683
|
+
function dt(e) {
|
|
684
684
|
if (!e || typeof e != "object") return;
|
|
685
685
|
const t = e;
|
|
686
686
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -699,22 +699,22 @@ function gt(e) {
|
|
|
699
699
|
if (i)
|
|
700
700
|
return i[1];
|
|
701
701
|
}
|
|
702
|
-
function
|
|
703
|
-
const t =
|
|
702
|
+
function Kn(e) {
|
|
703
|
+
const t = dt(e);
|
|
704
704
|
if (t) {
|
|
705
705
|
const n = t.substring(0, 10);
|
|
706
706
|
return C[t] ?? C[n];
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
|
-
function
|
|
710
|
-
const t =
|
|
709
|
+
function Dn(e) {
|
|
710
|
+
const t = dt(e);
|
|
711
711
|
if (t === void 0) return !1;
|
|
712
712
|
const n = t.substring(0, 10);
|
|
713
713
|
return t in C || n in C;
|
|
714
714
|
}
|
|
715
715
|
function S(e) {
|
|
716
716
|
console.error("[Contract Error] Raw error:", e);
|
|
717
|
-
const t =
|
|
717
|
+
const t = dt(e);
|
|
718
718
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
719
719
|
const s = t.substring(0, 10), o = C[t] ?? C[s];
|
|
720
720
|
if (o)
|
|
@@ -734,18 +734,18 @@ function S(e) {
|
|
|
734
734
|
}
|
|
735
735
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
736
736
|
}
|
|
737
|
-
const
|
|
738
|
-
function
|
|
737
|
+
const _n = 0, K = "00".repeat(32);
|
|
738
|
+
function vn(e, t, n, s) {
|
|
739
739
|
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
740
740
|
return o ? Promise.resolve({
|
|
741
741
|
txid: e,
|
|
742
742
|
vout: t,
|
|
743
743
|
value: o.value,
|
|
744
744
|
scriptPubKey: o.scriptPubKey
|
|
745
|
-
}) :
|
|
745
|
+
}) : xe(e, t, s);
|
|
746
746
|
}
|
|
747
|
-
const
|
|
748
|
-
class
|
|
747
|
+
const Rt = 12e4;
|
|
748
|
+
class zn {
|
|
749
749
|
/**
|
|
750
750
|
* Creates a new PeginManager instance.
|
|
751
751
|
*
|
|
@@ -767,27 +767,27 @@ class Gn {
|
|
|
767
767
|
async preparePegin(t) {
|
|
768
768
|
if (t.amounts.length === 0)
|
|
769
769
|
throw new Error("amounts must contain at least one entry");
|
|
770
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s =
|
|
771
|
-
(
|
|
772
|
-
txid:
|
|
773
|
-
vout:
|
|
770
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = L(n), o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
|
|
771
|
+
(g) => ({
|
|
772
|
+
txid: st(g.txid),
|
|
773
|
+
vout: g.vout
|
|
774
774
|
})
|
|
775
|
-
), i = await
|
|
776
|
-
depositorBtcPubkey:
|
|
775
|
+
), i = await De(this.config.btcWallet, {
|
|
776
|
+
depositorBtcPubkey: st(s),
|
|
777
777
|
fundingOutpoints: r
|
|
778
778
|
});
|
|
779
779
|
let a, l;
|
|
780
780
|
try {
|
|
781
|
-
const
|
|
781
|
+
const g = Ue(i);
|
|
782
782
|
try {
|
|
783
|
-
a =
|
|
783
|
+
a = j(g), l = j(O(g));
|
|
784
784
|
} finally {
|
|
785
|
-
|
|
785
|
+
g.fill(0);
|
|
786
786
|
}
|
|
787
|
-
} catch (
|
|
788
|
-
throw i.fill(0),
|
|
787
|
+
} catch (g) {
|
|
788
|
+
throw i.fill(0), g;
|
|
789
789
|
}
|
|
790
|
-
const u = await
|
|
790
|
+
const u = await yn(i, t.amounts.length), { perVaultWotsKeys: c, wotsPkHashes: w, htlcSecretHexes: b, hashlocks: y } = u, h = await this.preparePeginCommit({
|
|
791
791
|
depositorBtcPubkeyRaw: n,
|
|
792
792
|
depositorBtcPubkey: s,
|
|
793
793
|
hashlocks: y,
|
|
@@ -795,12 +795,12 @@ class Gn {
|
|
|
795
795
|
sizing: o,
|
|
796
796
|
params: t
|
|
797
797
|
});
|
|
798
|
-
for (let
|
|
799
|
-
if (h.perVault[
|
|
798
|
+
for (let g = 0; g < h.perVault.length; g++)
|
|
799
|
+
if (h.perVault[g].htlcVout !== g)
|
|
800
800
|
throw new Error(
|
|
801
|
-
`Internal invariant violation: htlcVout/index mismatch at vault ${
|
|
801
|
+
`Internal invariant violation: htlcVout/index mismatch at vault ${g} (expected ${g}, got ${h.perVault[g].htlcVout})`
|
|
802
802
|
);
|
|
803
|
-
return
|
|
803
|
+
return He(
|
|
804
804
|
h.fundedPrePeginTxHex,
|
|
805
805
|
t.amounts.length,
|
|
806
806
|
l
|
|
@@ -838,8 +838,8 @@ class Gn {
|
|
|
838
838
|
*/
|
|
839
839
|
async prepareSizing(t, n) {
|
|
840
840
|
const s = n.amounts.map(
|
|
841
|
-
() =>
|
|
842
|
-
), o = n.vaultKeeperBtcPubkeys.length, r = await
|
|
841
|
+
() => K
|
|
842
|
+
), o = n.vaultKeeperBtcPubkeys.length, r = await bt({
|
|
843
843
|
depositorPubkey: t,
|
|
844
844
|
vaultProviderPubkey: _(n.vaultProviderBtcPubkey),
|
|
845
845
|
vaultKeeperPubkeys: n.vaultKeeperBtcPubkeys.map(_),
|
|
@@ -852,14 +852,14 @@ class Gn {
|
|
|
852
852
|
councilQuorum: n.councilQuorum,
|
|
853
853
|
councilSize: n.councilSize,
|
|
854
854
|
network: this.config.btcNetwork,
|
|
855
|
-
authAnchorHash:
|
|
856
|
-
}), i =
|
|
855
|
+
authAnchorHash: K
|
|
856
|
+
}), i = pe(
|
|
857
857
|
[...n.availableUTXOs],
|
|
858
858
|
r.totalOutputValue,
|
|
859
859
|
n.mempoolFeeRate,
|
|
860
|
-
|
|
860
|
+
we(
|
|
861
861
|
r.htlcValues.length,
|
|
862
|
-
|
|
862
|
+
K
|
|
863
863
|
)
|
|
864
864
|
);
|
|
865
865
|
return {
|
|
@@ -877,7 +877,7 @@ class Gn {
|
|
|
877
877
|
authAnchorHash: r,
|
|
878
878
|
sizing: i,
|
|
879
879
|
params: a
|
|
880
|
-
} = t, l =
|
|
880
|
+
} = t, l = K.toLowerCase();
|
|
881
881
|
for (let p = 0; p < o.length; p++)
|
|
882
882
|
if (o[p].toLowerCase() === l)
|
|
883
883
|
throw new Error(
|
|
@@ -901,20 +901,20 @@ class Gn {
|
|
|
901
901
|
councilSize: a.councilSize,
|
|
902
902
|
network: this.config.btcNetwork,
|
|
903
903
|
authAnchorHash: r
|
|
904
|
-
}, h = await
|
|
904
|
+
}, h = await bt(y), g = yt(this.config.btcNetwork), T = be({
|
|
905
905
|
unfundedTxHex: h.psbtHex,
|
|
906
906
|
selectedUTXOs: i.selectedUTXOs,
|
|
907
907
|
changeAddress: a.changeAddress,
|
|
908
908
|
changeAmount: i.changeAmount,
|
|
909
|
-
network:
|
|
910
|
-
}), B = _(
|
|
909
|
+
network: g
|
|
910
|
+
}), B = _(Z(T)), d = [], P = [], f = [];
|
|
911
911
|
for (let p = 0; p < o.length; p++) {
|
|
912
|
-
const k = await
|
|
912
|
+
const k = await ae({
|
|
913
913
|
prePeginParams: y,
|
|
914
914
|
timelockPegin: a.timelockPegin,
|
|
915
915
|
fundedPrePeginTxHex: T,
|
|
916
916
|
htlcVout: p
|
|
917
|
-
}), H = await
|
|
917
|
+
}), H = await ce({
|
|
918
918
|
peginTxHex: k.txHex,
|
|
919
919
|
fundedPrePeginTxHex: T,
|
|
920
920
|
depositorPubkey: s,
|
|
@@ -925,20 +925,20 @@ class Gn {
|
|
|
925
925
|
timelockRefund: a.timelockRefund,
|
|
926
926
|
network: this.config.btcNetwork
|
|
927
927
|
});
|
|
928
|
-
d.push(k), P.push(H.psbtHex),
|
|
929
|
-
|
|
928
|
+
d.push(k), P.push(H.psbtHex), f.push(
|
|
929
|
+
fe(n, 1)
|
|
930
930
|
);
|
|
931
931
|
}
|
|
932
|
-
const E = await
|
|
932
|
+
const E = await kn(
|
|
933
933
|
this.config.btcWallet,
|
|
934
934
|
P,
|
|
935
|
-
|
|
935
|
+
f
|
|
936
936
|
), x = [];
|
|
937
937
|
for (let p = 0; p < E.length; p++) {
|
|
938
|
-
const k =
|
|
938
|
+
const k = le(
|
|
939
939
|
E[p],
|
|
940
940
|
s
|
|
941
|
-
), H =
|
|
941
|
+
), H = ue(E[p]);
|
|
942
942
|
x.push({
|
|
943
943
|
htlcVout: p,
|
|
944
944
|
htlcValue: h.htlcValues[p],
|
|
@@ -970,18 +970,18 @@ class Gn {
|
|
|
970
970
|
* @throws Error if signing or broadcasting fails
|
|
971
971
|
*/
|
|
972
972
|
async signAndBroadcast(t) {
|
|
973
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r =
|
|
973
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = Ut.fromHex(o);
|
|
974
974
|
if (r.ins.length === 0)
|
|
975
975
|
throw new Error("Transaction has no inputs");
|
|
976
|
-
const i = new
|
|
976
|
+
const i = new ft();
|
|
977
977
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
978
|
-
const a =
|
|
979
|
-
|
|
978
|
+
const a = D.from(
|
|
979
|
+
L(s),
|
|
980
980
|
"hex"
|
|
981
981
|
), l = this.config.mempoolApiUrl, u = r.ins.map((d) => {
|
|
982
|
-
const P =
|
|
983
|
-
return
|
|
984
|
-
(E) => ({ input: d, utxoData: E, txid: P, vout:
|
|
982
|
+
const P = D.from(d.hash).reverse().toString("hex"), f = d.index;
|
|
983
|
+
return vn(P, f, t.localPrevouts, l).then(
|
|
984
|
+
(E) => ({ input: d, utxoData: E, txid: P, vout: f })
|
|
985
985
|
);
|
|
986
986
|
}), c = await Promise.all(u), w = c.reduce(
|
|
987
987
|
(d, P) => d + BigInt(P.utxoData.value),
|
|
@@ -995,12 +995,12 @@ class Gn {
|
|
|
995
995
|
`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
996
|
);
|
|
997
997
|
const y = w - b;
|
|
998
|
-
if (y >
|
|
998
|
+
if (y > xt)
|
|
999
999
|
throw new Error(
|
|
1000
|
-
`Implied transaction fee (${y} sat) exceeds maximum reasonable fee (${
|
|
1000
|
+
`Implied transaction fee (${y} sat) exceeds maximum reasonable fee (${xt} sat). This may indicate manipulated UTXO data.`
|
|
1001
1001
|
);
|
|
1002
|
-
for (const { input: d, utxoData: P, txid:
|
|
1003
|
-
const x =
|
|
1002
|
+
for (const { input: d, utxoData: P, txid: f, vout: E } of c) {
|
|
1003
|
+
const x = me(
|
|
1004
1004
|
{
|
|
1005
1005
|
value: P.value,
|
|
1006
1006
|
scriptPubKey: P.scriptPubKey
|
|
@@ -1019,19 +1019,19 @@ class Gn {
|
|
|
1019
1019
|
script: d.script,
|
|
1020
1020
|
value: d.value
|
|
1021
1021
|
});
|
|
1022
|
-
const h = await this.config.btcWallet.signPsbt(i.toHex()),
|
|
1022
|
+
const h = await this.config.btcWallet.signPsbt(i.toHex()), g = ft.fromHex(h);
|
|
1023
1023
|
try {
|
|
1024
|
-
|
|
1024
|
+
g.finalizeAllInputs();
|
|
1025
1025
|
} catch (d) {
|
|
1026
|
-
if (!
|
|
1027
|
-
(
|
|
1026
|
+
if (!g.data.inputs.every(
|
|
1027
|
+
(f) => f.finalScriptWitness || f.finalScriptSig
|
|
1028
1028
|
))
|
|
1029
1029
|
throw new Error(
|
|
1030
1030
|
`PSBT finalization failed and wallet did not auto-finalize: ${d}`
|
|
1031
1031
|
);
|
|
1032
1032
|
}
|
|
1033
|
-
const T =
|
|
1034
|
-
return await
|
|
1033
|
+
const T = g.extractTransaction().toHex();
|
|
1034
|
+
return await ye(T, l);
|
|
1035
1035
|
}
|
|
1036
1036
|
/**
|
|
1037
1037
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -1071,14 +1071,14 @@ class Gn {
|
|
|
1071
1071
|
if (!this.config.ethWallet.account)
|
|
1072
1072
|
throw new Error("Ethereum wallet account not found");
|
|
1073
1073
|
const c = this.config.ethWallet.account.address;
|
|
1074
|
-
if (!
|
|
1074
|
+
if (!pt(u.depositorEthAddress, c))
|
|
1075
1075
|
throw new Error(
|
|
1076
1076
|
`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
1077
|
);
|
|
1078
1078
|
await this.assertPopMatchesBtcWallet(u);
|
|
1079
|
-
const w = u.btcPopSignature, b = I(u.depositorBtcPubkey), y = I(n), h = I(s),
|
|
1079
|
+
const w = u.btcPopSignature, b = I(u.depositorBtcPubkey), y = I(n), h = I(s), g = await this.resolvePayoutScriptPubKey(
|
|
1080
1080
|
a
|
|
1081
|
-
), T =
|
|
1081
|
+
), T = Z(h), B = await wt(
|
|
1082
1082
|
_(T),
|
|
1083
1083
|
_(c)
|
|
1084
1084
|
), d = I(B);
|
|
@@ -1086,25 +1086,23 @@ class Gn {
|
|
|
1086
1086
|
throw new Error(
|
|
1087
1087
|
`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.`
|
|
1088
1088
|
);
|
|
1089
|
-
const
|
|
1090
|
-
chain: this.config.ethChain,
|
|
1091
|
-
transport: q()
|
|
1092
|
-
});
|
|
1089
|
+
const f = this.config.publicClient;
|
|
1093
1090
|
let E;
|
|
1094
1091
|
try {
|
|
1095
|
-
E = await
|
|
1092
|
+
E = await f.readContract({
|
|
1096
1093
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1097
|
-
abi:
|
|
1094
|
+
abi: $,
|
|
1098
1095
|
functionName: "getPegInFee",
|
|
1099
1096
|
args: [o]
|
|
1100
1097
|
});
|
|
1101
|
-
} catch {
|
|
1098
|
+
} catch (R) {
|
|
1102
1099
|
throw new Error(
|
|
1103
|
-
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1100
|
+
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
1101
|
+
{ cause: R }
|
|
1104
1102
|
);
|
|
1105
1103
|
}
|
|
1106
|
-
const x =
|
|
1107
|
-
abi:
|
|
1104
|
+
const x = mt({
|
|
1105
|
+
abi: $,
|
|
1108
1106
|
functionName: "submitPeginRequest",
|
|
1109
1107
|
args: [
|
|
1110
1108
|
c,
|
|
@@ -1115,20 +1113,20 @@ class Gn {
|
|
|
1115
1113
|
o,
|
|
1116
1114
|
r,
|
|
1117
1115
|
i,
|
|
1118
|
-
|
|
1116
|
+
g,
|
|
1119
1117
|
l
|
|
1120
1118
|
]
|
|
1121
1119
|
});
|
|
1122
1120
|
let p;
|
|
1123
1121
|
try {
|
|
1124
|
-
p = await
|
|
1122
|
+
p = await f.estimateGas({
|
|
1125
1123
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1126
1124
|
data: x,
|
|
1127
1125
|
value: E,
|
|
1128
1126
|
account: this.config.ethWallet.account.address
|
|
1129
1127
|
});
|
|
1130
|
-
} catch (
|
|
1131
|
-
S(
|
|
1128
|
+
} catch (R) {
|
|
1129
|
+
S(R);
|
|
1132
1130
|
}
|
|
1133
1131
|
let k;
|
|
1134
1132
|
try {
|
|
@@ -1140,12 +1138,12 @@ class Gn {
|
|
|
1140
1138
|
chain: this.config.ethChain,
|
|
1141
1139
|
gas: p
|
|
1142
1140
|
});
|
|
1143
|
-
} catch (
|
|
1144
|
-
S(
|
|
1141
|
+
} catch (R) {
|
|
1142
|
+
S(R);
|
|
1145
1143
|
}
|
|
1146
|
-
const H = await
|
|
1144
|
+
const H = await f.waitForTransactionReceipt({
|
|
1147
1145
|
hash: k,
|
|
1148
|
-
timeout:
|
|
1146
|
+
timeout: Rt
|
|
1149
1147
|
});
|
|
1150
1148
|
return H.status === "reverted" && S(
|
|
1151
1149
|
new Error(
|
|
@@ -1174,21 +1172,21 @@ class Gn {
|
|
|
1174
1172
|
if (!this.config.ethWallet.account)
|
|
1175
1173
|
throw new Error("Ethereum wallet account not found");
|
|
1176
1174
|
const i = this.config.ethWallet.account.address;
|
|
1177
|
-
if (!
|
|
1175
|
+
if (!pt(r.depositorEthAddress, i))
|
|
1178
1176
|
throw new Error(
|
|
1179
1177
|
`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.`
|
|
1180
1178
|
);
|
|
1181
1179
|
await this.assertPopMatchesBtcWallet(r);
|
|
1182
1180
|
const a = r.btcPopSignature, l = [];
|
|
1183
|
-
for (const
|
|
1181
|
+
for (const f of o)
|
|
1184
1182
|
l.push(
|
|
1185
|
-
await this.resolvePayoutScriptPubKey(
|
|
1183
|
+
await this.resolvePayoutScriptPubKey(f.depositorPayoutBtcAddress)
|
|
1186
1184
|
);
|
|
1187
1185
|
const u = [];
|
|
1188
|
-
for (const
|
|
1186
|
+
for (const f of o) {
|
|
1189
1187
|
const E = I(
|
|
1190
|
-
|
|
1191
|
-
), x =
|
|
1188
|
+
f.depositorSignedPeginTx
|
|
1189
|
+
), x = Z(E), p = await wt(
|
|
1192
1190
|
_(x),
|
|
1193
1191
|
_(i)
|
|
1194
1192
|
), k = I(p);
|
|
@@ -1198,41 +1196,39 @@ class Gn {
|
|
|
1198
1196
|
);
|
|
1199
1197
|
u.push({ vaultId: k, peginTxHash: x });
|
|
1200
1198
|
}
|
|
1201
|
-
const c =
|
|
1202
|
-
chain: this.config.ethChain,
|
|
1203
|
-
transport: q()
|
|
1204
|
-
});
|
|
1199
|
+
const c = this.config.publicClient;
|
|
1205
1200
|
let w;
|
|
1206
1201
|
try {
|
|
1207
1202
|
w = await c.readContract({
|
|
1208
1203
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1209
|
-
abi:
|
|
1204
|
+
abi: $,
|
|
1210
1205
|
functionName: "getPegInFee",
|
|
1211
1206
|
args: [n]
|
|
1212
1207
|
});
|
|
1213
|
-
} catch {
|
|
1208
|
+
} catch (f) {
|
|
1214
1209
|
throw new Error(
|
|
1215
|
-
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1210
|
+
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
1211
|
+
{ cause: f }
|
|
1216
1212
|
);
|
|
1217
1213
|
}
|
|
1218
1214
|
const b = w * BigInt(o.length), y = I(
|
|
1219
1215
|
r.depositorBtcPubkey
|
|
1220
|
-
), h = I(s),
|
|
1216
|
+
), h = I(s), g = o.map((f, E) => ({
|
|
1221
1217
|
depositorBtcPubKey: y,
|
|
1222
1218
|
btcPopSignature: a,
|
|
1223
1219
|
unsignedPrePeginTx: h,
|
|
1224
1220
|
depositorSignedPeginTx: I(
|
|
1225
|
-
|
|
1221
|
+
f.depositorSignedPeginTx
|
|
1226
1222
|
),
|
|
1227
|
-
hashlock:
|
|
1228
|
-
htlcVout:
|
|
1229
|
-
referralCode:
|
|
1223
|
+
hashlock: f.hashlock,
|
|
1224
|
+
htlcVout: f.htlcVout,
|
|
1225
|
+
referralCode: _n,
|
|
1230
1226
|
depositorPayoutBtcAddress: l[E],
|
|
1231
|
-
depositorWotsPkHash:
|
|
1232
|
-
})), T =
|
|
1233
|
-
abi:
|
|
1227
|
+
depositorWotsPkHash: f.depositorWotsPkHash
|
|
1228
|
+
})), T = mt({
|
|
1229
|
+
abi: $,
|
|
1234
1230
|
functionName: "submitPeginRequestBatch",
|
|
1235
|
-
args: [i, n,
|
|
1231
|
+
args: [i, n, g]
|
|
1236
1232
|
});
|
|
1237
1233
|
let B;
|
|
1238
1234
|
try {
|
|
@@ -1242,8 +1238,8 @@ class Gn {
|
|
|
1242
1238
|
value: b,
|
|
1243
1239
|
account: this.config.ethWallet.account.address
|
|
1244
1240
|
});
|
|
1245
|
-
} catch (
|
|
1246
|
-
S(
|
|
1241
|
+
} catch (f) {
|
|
1242
|
+
S(f);
|
|
1247
1243
|
}
|
|
1248
1244
|
let d;
|
|
1249
1245
|
try {
|
|
@@ -1255,12 +1251,12 @@ class Gn {
|
|
|
1255
1251
|
chain: this.config.ethChain,
|
|
1256
1252
|
gas: B
|
|
1257
1253
|
});
|
|
1258
|
-
} catch (
|
|
1259
|
-
S(
|
|
1254
|
+
} catch (f) {
|
|
1255
|
+
S(f);
|
|
1260
1256
|
}
|
|
1261
1257
|
const P = await c.waitForTransactionReceipt({
|
|
1262
1258
|
hash: d,
|
|
1263
|
-
timeout:
|
|
1259
|
+
timeout: Rt
|
|
1264
1260
|
});
|
|
1265
1261
|
return P.status === "reverted" && S(
|
|
1266
1262
|
new Error(
|
|
@@ -1274,23 +1270,23 @@ class Gn {
|
|
|
1274
1270
|
/**
|
|
1275
1271
|
* Check if a vault already exists for a given vault ID.
|
|
1276
1272
|
*
|
|
1273
|
+
* The contract returns a default struct (with `depositor === zeroAddress`)
|
|
1274
|
+
* when no vault is registered, so existence is signalled in the response,
|
|
1275
|
+
* not via a thrown error. RPC/network failures are propagated rather than
|
|
1276
|
+
* silently treated as "vault doesn't exist", which would otherwise let
|
|
1277
|
+
* downstream calls run with stale assumptions.
|
|
1278
|
+
*
|
|
1277
1279
|
* @param vaultId - The Bitcoin transaction hash (vault ID)
|
|
1278
1280
|
* @returns True if vault exists, false otherwise
|
|
1281
|
+
* @throws If the underlying RPC read fails
|
|
1279
1282
|
*/
|
|
1280
1283
|
async checkVaultExists(t) {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
abi: R,
|
|
1288
|
-
functionName: "getBtcVaultBasicInfo",
|
|
1289
|
-
args: [t]
|
|
1290
|
-
})).depositor !== ce;
|
|
1291
|
-
} catch {
|
|
1292
|
-
return !1;
|
|
1293
|
-
}
|
|
1284
|
+
return (await this.config.publicClient.readContract({
|
|
1285
|
+
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1286
|
+
abi: $,
|
|
1287
|
+
functionName: "getBtcVaultBasicInfo",
|
|
1288
|
+
args: [t]
|
|
1289
|
+
})).depositor !== ie;
|
|
1294
1290
|
}
|
|
1295
1291
|
/**
|
|
1296
1292
|
* Resolve the BTC payout address to a scriptPubKey hex for the contract.
|
|
@@ -1306,7 +1302,7 @@ class Gn {
|
|
|
1306
1302
|
else {
|
|
1307
1303
|
n = await this.config.btcWallet.getAddress();
|
|
1308
1304
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
1309
|
-
if (!
|
|
1305
|
+
if (!de(
|
|
1310
1306
|
n,
|
|
1311
1307
|
o,
|
|
1312
1308
|
this.config.btcNetwork
|
|
@@ -1315,9 +1311,9 @@ class Gn {
|
|
|
1315
1311
|
"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)."
|
|
1316
1312
|
);
|
|
1317
1313
|
}
|
|
1318
|
-
const s =
|
|
1314
|
+
const s = yt(this.config.btcNetwork);
|
|
1319
1315
|
try {
|
|
1320
|
-
return `0x${
|
|
1316
|
+
return `0x${$t.address.toOutputScript(n, s).toString("hex")}`;
|
|
1321
1317
|
} catch {
|
|
1322
1318
|
throw new Error(
|
|
1323
1319
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1333,22 +1329,22 @@ class Gn {
|
|
|
1333
1329
|
async signProofOfPossession() {
|
|
1334
1330
|
if (!this.config.ethWallet.account)
|
|
1335
1331
|
throw new Error("Ethereum wallet account not found");
|
|
1336
|
-
const t = this.config.ethWallet.account.address, n =
|
|
1332
|
+
const t = this.config.ethWallet.account.address, n = L(
|
|
1337
1333
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1338
1334
|
), s = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
|
|
1339
1335
|
o,
|
|
1340
1336
|
"bip322-simple"
|
|
1341
1337
|
);
|
|
1342
1338
|
return {
|
|
1343
|
-
btcPopSignature:
|
|
1339
|
+
btcPopSignature: Tn(r),
|
|
1344
1340
|
depositorEthAddress: t,
|
|
1345
1341
|
depositorBtcPubkey: n
|
|
1346
1342
|
};
|
|
1347
1343
|
}
|
|
1348
1344
|
async assertPopMatchesBtcWallet(t) {
|
|
1349
|
-
const n =
|
|
1345
|
+
const n = L(
|
|
1350
1346
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1351
|
-
), s =
|
|
1347
|
+
), s = L(t.depositorBtcPubkey);
|
|
1352
1348
|
if (n !== s)
|
|
1353
1349
|
throw new Error(
|
|
1354
1350
|
`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.`
|
|
@@ -1373,21 +1369,21 @@ class Gn {
|
|
|
1373
1369
|
}
|
|
1374
1370
|
export {
|
|
1375
1371
|
C,
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1372
|
+
zn as P,
|
|
1373
|
+
Xe as V,
|
|
1374
|
+
Xn as a,
|
|
1375
|
+
Ue as b,
|
|
1376
|
+
bn as c,
|
|
1377
|
+
wn as d,
|
|
1378
|
+
dt as e,
|
|
1379
|
+
Le as f,
|
|
1380
|
+
Kn as g,
|
|
1385
1381
|
S as h,
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1382
|
+
Dn as i,
|
|
1383
|
+
Ne as j,
|
|
1384
|
+
Me as k,
|
|
1385
|
+
Fe as l,
|
|
1386
|
+
De as m,
|
|
1387
|
+
Fn as p
|
|
1392
1388
|
};
|
|
1393
|
-
//# sourceMappingURL=PeginManager-
|
|
1389
|
+
//# sourceMappingURL=PeginManager-C-L3huRO.js.map
|