@babylonlabs-io/ts-sdk 0.74.0 → 0.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PeginManager-E-UHA1un.cjs → PeginManager-DEByBX5R.cjs} +2 -2
- package/dist/{PeginManager-E-UHA1un.cjs.map → PeginManager-DEByBX5R.cjs.map} +1 -1
- package/dist/{PeginManager-C9RPOd0L.js → PeginManager-DNimKlmw.js} +11 -11
- package/dist/{PeginManager-C9RPOd0L.js.map → PeginManager-DNimKlmw.js.map} +1 -1
- package/dist/{bip322Verify-D6sBBUHE.js → bip322Verify-DSco3Yhl.js} +2 -2
- package/dist/{bip322Verify-D6sBBUHE.js.map → bip322Verify-DSco3Yhl.js.map} +1 -1
- package/dist/buildAndBroadcastReclaim-Cqc6Jiqk.cjs +2 -0
- package/dist/{buildAndBroadcastReclaim-U-PyFfDg.cjs.map → buildAndBroadcastReclaim-Cqc6Jiqk.cjs.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-BXclIcu_.js → buildAndBroadcastReclaim-DCGcupg7.js} +6 -6
- package/dist/{buildAndBroadcastReclaim-BXclIcu_.js.map → buildAndBroadcastReclaim-DCGcupg7.js.map} +1 -1
- package/dist/constants-BTZdyOuk.cjs +2 -0
- package/dist/constants-BTZdyOuk.cjs.map +1 -0
- package/dist/constants-D5vORbQE.js +29 -0
- package/dist/constants-D5vORbQE.js.map +1 -0
- package/dist/fundPeginTransaction-54-Rwb2k.cjs +2 -0
- package/dist/fundPeginTransaction-54-Rwb2k.cjs.map +1 -0
- package/dist/fundPeginTransaction-CwhRbCQC.js +88 -0
- package/dist/fundPeginTransaction-CwhRbCQC.js.map +1 -0
- package/dist/{index-Cs7_Evtk.cjs → index-CK1Xvq4K.cjs} +2 -2
- package/dist/{index-Cs7_Evtk.cjs.map → index-CK1Xvq4K.cjs.map} +1 -1
- package/dist/{index-LgmJhdEN.js → index-DQ5bfoT3.js} +2 -2
- package/dist/{index-LgmJhdEN.js.map → index-DQ5bfoT3.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +15 -15
- package/dist/noPayout-4RZB2g1e.cjs +2 -0
- package/dist/noPayout-4RZB2g1e.cjs.map +1 -0
- package/dist/noPayout-DiGr4eas.js +361 -0
- package/dist/noPayout-DiGr4eas.js.map +1 -0
- package/dist/{parseFundingOutpoints-B67CoXpF.js → parseFundingOutpoints-BQWvINfm.js} +2 -2
- package/dist/{parseFundingOutpoints-B67CoXpF.js.map → parseFundingOutpoints-BQWvINfm.js.map} +1 -1
- package/dist/pegin-registration-client-CXK3B_D1.js +882 -0
- package/dist/pegin-registration-client-CXK3B_D1.js.map +1 -0
- package/dist/pegin-registration-client-DLsMNm8Z.cjs +2 -0
- package/dist/pegin-registration-client-DLsMNm8Z.cjs.map +1 -0
- package/dist/{primeVpAuth-DBHohVKM.cjs → primeVpAuth-BOGKniTl.cjs} +2 -2
- package/dist/{primeVpAuth-DBHohVKM.cjs.map → primeVpAuth-BOGKniTl.cjs.map} +1 -1
- package/dist/{primeVpAuth-DvaD45q_.js → primeVpAuth-DdfHSC53.js} +4 -4
- package/dist/{primeVpAuth-DvaD45q_.js.map → primeVpAuth-DdfHSC53.js.map} +1 -1
- package/dist/{psbtInputFields-BIxBpPj2.cjs → psbtInputFields-BrV_ZfL_.cjs} +2 -2
- package/dist/{psbtInputFields-BIxBpPj2.cjs.map → psbtInputFields-BrV_ZfL_.cjs.map} +1 -1
- package/dist/{psbtInputFields-B3e05Xe6.js → psbtInputFields-CCVyaQMi.js} +2 -2
- package/dist/{psbtInputFields-B3e05Xe6.js.map → psbtInputFields-CCVyaQMi.js.map} +1 -1
- package/dist/secp256k1-D-H9jmd7.js +1766 -0
- package/dist/secp256k1-D-H9jmd7.js.map +1 -0
- package/dist/secp256k1-DDHQ1_za.cjs +2 -0
- package/dist/secp256k1-DDHQ1_za.cjs.map +1 -0
- package/dist/{sha2-CrlWM5S8.js → sha2-CLpQd0Rd.js} +8 -8
- package/dist/{sha2-CrlWM5S8.js.map → sha2-CLpQd0Rd.js.map} +1 -1
- package/dist/{signPsbtsWithFallback-DMSpIQWH.cjs → signPsbtsWithFallback-DtwzL5AA.cjs} +2 -2
- package/dist/{signPsbtsWithFallback-DMSpIQWH.cjs.map → signPsbtsWithFallback-DtwzL5AA.cjs.map} +1 -1
- package/dist/{signPsbtsWithFallback-0VBALhjS.js → signPsbtsWithFallback-f7QLp0q8.js} +4 -4
- package/dist/{signPsbtsWithFallback-0VBALhjS.js.map → signPsbtsWithFallback-f7QLp0q8.js.map} +1 -1
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.js +3 -3
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +5 -5
- package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +15 -15
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +2 -2
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +4 -4
- package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +5 -6
- package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/assertWasmPeginSizing.test.d.ts +2 -2
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +36 -14
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts +39 -0
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +2 -2
- package/dist/tbv/core/utils/fee/constants.d.ts +4 -4
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +2 -2
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +15 -15
- package/dist/tbv/integrations/aave/constants.d.ts +9 -3
- package/dist/tbv/integrations/aave/constants.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +106 -102
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts +10 -7
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts.map +1 -1
- package/dist/test/setup.browser.d.ts +2 -0
- package/dist/test/setup.browser.d.ts.map +1 -0
- package/dist/testing/index.js +1 -1
- package/dist/{toRefundInputs-C3oIN0aW.js → toRefundInputs-BNSXIymn.js} +7 -7
- package/dist/{toRefundInputs-C3oIN0aW.js.map → toRefundInputs-BNSXIymn.js.map} +1 -1
- package/dist/{toRefundInputs-BwG6T0PP.cjs → toRefundInputs-meTyor7r.cjs} +2 -2
- package/dist/{toRefundInputs-BwG6T0PP.cjs.map → toRefundInputs-meTyor7r.cjs.map} +1 -1
- package/dist/{types-DSlcXtog.cjs → types-BzSOthHH.cjs} +2 -2
- package/dist/{types-DSlcXtog.cjs.map → types-BzSOthHH.cjs.map} +1 -1
- package/dist/{types-CPDLZm3l.js → types-C5DyrC8F.js} +2 -2
- package/dist/{types-CPDLZm3l.js.map → types-C5DyrC8F.js.map} +1 -1
- package/dist/verifyKeyPathSchnorrSignature-BVtNwgK6.js +360 -0
- package/dist/verifyKeyPathSchnorrSignature-BVtNwgK6.js.map +1 -0
- package/dist/verifyKeyPathSchnorrSignature-BjB8Znly.cjs +2 -0
- package/dist/verifyKeyPathSchnorrSignature-BjB8Znly.cjs.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js +1140 -0
- package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs.map +1 -0
- package/package.json +4 -1
- package/dist/buildAndBroadcastReclaim-U-PyFfDg.cjs +0 -2
- package/dist/constants-Bh38W9mq.cjs +0 -2
- package/dist/constants-Bh38W9mq.cjs.map +0 -1
- package/dist/constants-CPzppOdq.js +0 -17
- package/dist/constants-CPzppOdq.js.map +0 -1
- package/dist/fundPeginTransaction-B2wyjqp0.js +0 -83
- package/dist/fundPeginTransaction-B2wyjqp0.js.map +0 -1
- package/dist/fundPeginTransaction-BLD8FRL9.cjs +0 -2
- package/dist/fundPeginTransaction-BLD8FRL9.cjs.map +0 -1
- package/dist/noPayout-DpGRzidi.js +0 -353
- package/dist/noPayout-DpGRzidi.js.map +0 -1
- package/dist/noPayout-zEifyecV.cjs +0 -2
- package/dist/noPayout-zEifyecV.cjs.map +0 -1
- package/dist/pegin-registration-client-6vLk2itL.cjs +0 -2
- package/dist/pegin-registration-client-6vLk2itL.cjs.map +0 -1
- package/dist/pegin-registration-client-BdRiR8br.js +0 -2635
- package/dist/pegin-registration-client-BdRiR8br.js.map +0 -1
- package/dist/vaultCoreVersion-DYfw3qed.cjs +0 -2
- package/dist/vaultCoreVersion-DYfw3qed.cjs.map +0 -1
- package/dist/vaultCoreVersion-D_fP9P3C.js +0 -10
- package/dist/vaultCoreVersion-D_fP9P3C.js.map +0 -1
- package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs +0 -2
- package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs.map +0 -1
- package/dist/verifyKeyPathSchnorrSignature-BrgUJmV0.js +0 -372
- package/dist/verifyKeyPathSchnorrSignature-BrgUJmV0.js.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-Ciq_xZhw.js +0 -951
- package/dist/verifyScriptPathSchnorrSignature-Ciq_xZhw.js.map +0 -1
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
var ut = Object.defineProperty;
|
|
2
|
+
var ht = (t, e, o) => e in t ? ut(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
|
|
3
|
+
var w = (t, e, o) => ht(t, typeof e != "symbol" ? e + "" : e, o);
|
|
4
|
+
import { isAddress as lt, keccak256 as dt, encodeAbiParameters as pt, encodeFunctionData as N, isAddressEqual as ft, zeroAddress as gt } from "viem";
|
|
5
|
+
import { B as f } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
|
|
6
|
+
import { B as H, h as T } from "./BTCVaultRegistryKeyEpochs.abi-D8cIbMtH.js";
|
|
7
|
+
import { M as K, b as O } from "./constants-D5vORbQE.js";
|
|
8
|
+
import { waitForTransactionReceiptSmartAware as mt } from "./tbv/core/utils/eth/index.js";
|
|
9
|
+
import { a as x } from "./onChainBtcPubkey-C-6UWpD8.js";
|
|
10
|
+
import { s as Y, b as C, a as Pt } from "./secp256k1-D-H9jmd7.js";
|
|
11
|
+
import { c as bt, H as yt, r as E, a as F, h as j, b as _, s as S } from "./sha2-CLpQd0Rd.js";
|
|
12
|
+
const k = 25, wt = 9999;
|
|
13
|
+
function M(t) {
|
|
14
|
+
if (!Number.isInteger(t) || t < 0 || t >= K)
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Quoted commissionBps must be an integer in [0, ${K}), got ${t}`
|
|
17
|
+
);
|
|
18
|
+
return Math.min(
|
|
19
|
+
t + k,
|
|
20
|
+
wt
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const Ct = /* @__PURE__ */ Uint8Array.from([
|
|
24
|
+
7,
|
|
25
|
+
4,
|
|
26
|
+
13,
|
|
27
|
+
1,
|
|
28
|
+
10,
|
|
29
|
+
6,
|
|
30
|
+
15,
|
|
31
|
+
3,
|
|
32
|
+
12,
|
|
33
|
+
0,
|
|
34
|
+
9,
|
|
35
|
+
5,
|
|
36
|
+
2,
|
|
37
|
+
14,
|
|
38
|
+
11,
|
|
39
|
+
8
|
|
40
|
+
]), J = Uint8Array.from(new Array(16).fill(0).map((t, e) => e)), xt = J.map((t) => (9 * t + 5) % 16), Z = /* @__PURE__ */ (() => {
|
|
41
|
+
const o = [[J], [xt]];
|
|
42
|
+
for (let n = 0; n < 4; n++)
|
|
43
|
+
for (let s of o)
|
|
44
|
+
s.push(s[n].map((a) => Ct[a]));
|
|
45
|
+
return o;
|
|
46
|
+
})(), tt = Z[0], et = Z[1], ot = /* @__PURE__ */ [
|
|
47
|
+
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
48
|
+
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
49
|
+
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
50
|
+
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
51
|
+
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
52
|
+
].map((t) => Uint8Array.from(t)), Et = /* @__PURE__ */ tt.map((t, e) => t.map((o) => ot[e][o])), It = /* @__PURE__ */ et.map((t, e) => t.map((o) => ot[e][o])), Bt = /* @__PURE__ */ Uint32Array.from([
|
|
53
|
+
0,
|
|
54
|
+
1518500249,
|
|
55
|
+
1859775393,
|
|
56
|
+
2400959708,
|
|
57
|
+
2840853838
|
|
58
|
+
]), $t = /* @__PURE__ */ Uint32Array.from([
|
|
59
|
+
1352829926,
|
|
60
|
+
1548603684,
|
|
61
|
+
1836072691,
|
|
62
|
+
2053994217,
|
|
63
|
+
0
|
|
64
|
+
]);
|
|
65
|
+
function q(t, e, o, n) {
|
|
66
|
+
return t === 0 ? e ^ o ^ n : t === 1 ? e & o | ~e & n : t === 2 ? (e | ~o) ^ n : t === 3 ? e & n | o & ~n : e ^ (o | ~n);
|
|
67
|
+
}
|
|
68
|
+
const I = /* @__PURE__ */ new Uint32Array(16);
|
|
69
|
+
class Tt extends yt {
|
|
70
|
+
constructor() {
|
|
71
|
+
super(64, 20, 8, !0);
|
|
72
|
+
w(this, "h0", 1732584193);
|
|
73
|
+
w(this, "h1", -271733879);
|
|
74
|
+
w(this, "h2", -1732584194);
|
|
75
|
+
w(this, "h3", 271733878);
|
|
76
|
+
w(this, "h4", -1009589776);
|
|
77
|
+
}
|
|
78
|
+
get() {
|
|
79
|
+
const { h0: o, h1: n, h2: s, h3: a, h4: c } = this;
|
|
80
|
+
return [o, n, s, a, c];
|
|
81
|
+
}
|
|
82
|
+
set(o, n, s, a, c) {
|
|
83
|
+
this.h0 = o | 0, this.h1 = n | 0, this.h2 = s | 0, this.h3 = a | 0, this.h4 = c | 0;
|
|
84
|
+
}
|
|
85
|
+
process(o, n) {
|
|
86
|
+
for (let r = 0; r < 16; r++, n += 4)
|
|
87
|
+
I[r] = o.getUint32(n, !0);
|
|
88
|
+
let s = this.h0 | 0, a = s, c = this.h1 | 0, l = c, d = this.h2 | 0, p = d, g = this.h3 | 0, P = g, i = this.h4 | 0, h = i;
|
|
89
|
+
for (let r = 0; r < 5; r++) {
|
|
90
|
+
const u = 4 - r, b = Bt[r], st = $t[r], it = tt[r], rt = et[r], at = Et[r], ct = It[r];
|
|
91
|
+
for (let m = 0; m < 16; m++) {
|
|
92
|
+
const $ = E(s + q(r, c, d, g) + I[it[m]] + b, at[m]) + i | 0;
|
|
93
|
+
s = i, i = g, g = E(d, 10) | 0, d = c, c = $;
|
|
94
|
+
}
|
|
95
|
+
for (let m = 0; m < 16; m++) {
|
|
96
|
+
const $ = E(a + q(u, l, p, P) + I[rt[m]] + st, ct[m]) + h | 0;
|
|
97
|
+
a = h, h = P, P = E(p, 10) | 0, p = l, l = $;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.set(this.h1 + d + P | 0, this.h2 + g + h | 0, this.h3 + i + a | 0, this.h4 + s + l | 0, this.h0 + c + p | 0);
|
|
101
|
+
}
|
|
102
|
+
roundClean() {
|
|
103
|
+
F(I);
|
|
104
|
+
}
|
|
105
|
+
destroy() {
|
|
106
|
+
this.destroyed = !0, F(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const vt = /* @__PURE__ */ bt(() => new Tt()), At = "5120", R = "0014", Vt = 20, W = 33, St = 65, kt = 2, Rt = 3, _t = 4;
|
|
110
|
+
function nt(t, e) {
|
|
111
|
+
const o = t.startsWith("0x") || t.startsWith("0X") ? t.slice(2) : t;
|
|
112
|
+
if (!/^(?:[0-9a-fA-F]{2})+$/.test(o))
|
|
113
|
+
throw new Error(`${e} must be non-empty, even-length hex`);
|
|
114
|
+
return `0x${o.toLowerCase()}`;
|
|
115
|
+
}
|
|
116
|
+
function Nt(t) {
|
|
117
|
+
const e = j(t), o = C.utils.lift_x(BigInt(`0x${t}`)), n = C.utils.bytesToNumberBE(
|
|
118
|
+
C.utils.taggedHash("TapTweak", e)
|
|
119
|
+
);
|
|
120
|
+
if (n >= Y.CURVE.n)
|
|
121
|
+
throw new Error("Proof of possession BTC pubkey has an invalid TapTweak");
|
|
122
|
+
const s = n === 0n ? o : o.add(C.Point.BASE.multiply(n));
|
|
123
|
+
return `0x${At}${_(
|
|
124
|
+
C.utils.pointToBytes(s)
|
|
125
|
+
)}`;
|
|
126
|
+
}
|
|
127
|
+
function Ht(t) {
|
|
128
|
+
const e = nt(t, "depositorBtcPubkeyRaw"), o = j(e.slice(2));
|
|
129
|
+
if (o.length === 32)
|
|
130
|
+
return {
|
|
131
|
+
xOnlyPubkey: x(e, "Payout BTC pubkey")
|
|
132
|
+
};
|
|
133
|
+
const n = o.length === W && (o[0] === kt || o[0] === Rt), s = o.length === St && o[0] === _t;
|
|
134
|
+
if (!n && !s)
|
|
135
|
+
throw new Error(
|
|
136
|
+
"depositorBtcPubkeyRaw must be x-only, compressed, or uncompressed"
|
|
137
|
+
);
|
|
138
|
+
try {
|
|
139
|
+
Y.Point.fromBytes(o);
|
|
140
|
+
} catch {
|
|
141
|
+
throw new Error("depositorBtcPubkeyRaw is not a valid BTC pubkey");
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
xOnlyPubkey: _(o.subarray(1, W)),
|
|
145
|
+
compressedPubkey: n ? o : void 0
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function Kt(t) {
|
|
149
|
+
return `0x${R}${_(vt(S(t)))}`;
|
|
150
|
+
}
|
|
151
|
+
function Ot(t, e, o) {
|
|
152
|
+
const n = nt(
|
|
153
|
+
t,
|
|
154
|
+
"depositorPayoutScriptPubKey"
|
|
155
|
+
);
|
|
156
|
+
if ((n.length - 2) / 2 > O)
|
|
157
|
+
throw new Error(
|
|
158
|
+
`depositorPayoutScriptPubKey exceeds ${O} bytes`
|
|
159
|
+
);
|
|
160
|
+
const s = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e, a = x(
|
|
161
|
+
`0x${s}`,
|
|
162
|
+
"Proof of possession BTC pubkey"
|
|
163
|
+
), c = Ht(o);
|
|
164
|
+
if (c.xOnlyPubkey !== a)
|
|
165
|
+
throw new Error(
|
|
166
|
+
"depositorBtcPubkeyRaw does not match the proof of possession BTC pubkey"
|
|
167
|
+
);
|
|
168
|
+
if (n === Nt(a))
|
|
169
|
+
return n;
|
|
170
|
+
if (n.startsWith(`0x${R}`) && n.length === 2 + R.length + Vt * 2) {
|
|
171
|
+
if (!c.compressedPubkey)
|
|
172
|
+
throw new Error("A P2WPKH payout requires a compressed BTC pubkey");
|
|
173
|
+
if (n === Kt(c.compressedPubkey))
|
|
174
|
+
return n;
|
|
175
|
+
}
|
|
176
|
+
throw new Error(
|
|
177
|
+
"depositorPayoutScriptPubKey does not match the proof of possession BTC pubkey"
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function Ft(t, e) {
|
|
181
|
+
const o = t.startsWith("0x") ? t.slice(2) : t;
|
|
182
|
+
if (o.length === 0 || o.length % 2 !== 0)
|
|
183
|
+
throw new Error(`${e} must be non-empty, even-length hex`);
|
|
184
|
+
if (!/^[0-9a-fA-F]+$/.test(o))
|
|
185
|
+
throw new Error(`${e} contains non-hex characters`);
|
|
186
|
+
const n = new Uint8Array(o.length / 2);
|
|
187
|
+
for (let s = 0; s < n.length; s++)
|
|
188
|
+
n[s] = Number.parseInt(o.slice(s * 2, s * 2 + 2), 16);
|
|
189
|
+
return n;
|
|
190
|
+
}
|
|
191
|
+
function Mt(t) {
|
|
192
|
+
return Array.from(t, (e) => e.toString(16).padStart(2, "0")).join(
|
|
193
|
+
""
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function qt(t) {
|
|
197
|
+
const e = new Uint8Array(
|
|
198
|
+
t.reduce((n, s) => n + s.length, 0)
|
|
199
|
+
);
|
|
200
|
+
let o = 0;
|
|
201
|
+
for (const n of t)
|
|
202
|
+
e.set(n, o), o += n.length;
|
|
203
|
+
return e;
|
|
204
|
+
}
|
|
205
|
+
function Wt(t) {
|
|
206
|
+
let e = 0;
|
|
207
|
+
const o = (i, h) => {
|
|
208
|
+
if (!Number.isSafeInteger(i) || i < 0)
|
|
209
|
+
throw new Error(`Invalid ${h} length ${i}`);
|
|
210
|
+
if (e + i > t.length)
|
|
211
|
+
throw new Error(`Truncated Bitcoin transaction while reading ${h}`);
|
|
212
|
+
const r = t.slice(e, e + i);
|
|
213
|
+
return e += i, r;
|
|
214
|
+
}, n = (i, h) => {
|
|
215
|
+
const r = o(i, h);
|
|
216
|
+
let u = 0n;
|
|
217
|
+
for (let b = r.length - 1; b >= 0; b--)
|
|
218
|
+
u = u << 8n | BigInt(r[b]);
|
|
219
|
+
return u;
|
|
220
|
+
}, s = (i) => {
|
|
221
|
+
const h = e, r = o(1, i)[0];
|
|
222
|
+
let u;
|
|
223
|
+
if (r < 253)
|
|
224
|
+
u = BigInt(r);
|
|
225
|
+
else if (r === 253) {
|
|
226
|
+
if (u = n(2, i), u < 0xfdn) throw new Error(`Non-canonical ${i}`);
|
|
227
|
+
} else if (r === 254) {
|
|
228
|
+
if (u = n(4, i), u <= 0xffffn) throw new Error(`Non-canonical ${i}`);
|
|
229
|
+
} else if (u = n(8, i), u <= 0xffffffffn) throw new Error(`Non-canonical ${i}`);
|
|
230
|
+
if (u > BigInt(Number.MAX_SAFE_INTEGER))
|
|
231
|
+
throw new Error(`${i} exceeds JavaScript's safe integer range`);
|
|
232
|
+
return {
|
|
233
|
+
encoded: t.slice(h, e),
|
|
234
|
+
value: Number(u)
|
|
235
|
+
};
|
|
236
|
+
}, a = o(4, "version"), c = t[e] === 0 && t[e + 1] === 1;
|
|
237
|
+
c && (e += 2);
|
|
238
|
+
const l = s("input count"), d = [];
|
|
239
|
+
for (let i = 0; i < l.value; i++) {
|
|
240
|
+
const h = e;
|
|
241
|
+
o(32, `input ${i} previous transaction hash`), o(4, `input ${i} previous output index`);
|
|
242
|
+
const r = s(`input ${i} script length`);
|
|
243
|
+
o(r.value, `input ${i} script`), o(4, `input ${i} sequence`), d.push(t.slice(h, e));
|
|
244
|
+
}
|
|
245
|
+
const p = s("output count"), g = [];
|
|
246
|
+
for (let i = 0; i < p.value; i++) {
|
|
247
|
+
const h = e;
|
|
248
|
+
o(8, `output ${i} value`);
|
|
249
|
+
const r = s(`output ${i} script length`);
|
|
250
|
+
o(r.value, `output ${i} script`), g.push(t.slice(h, e));
|
|
251
|
+
}
|
|
252
|
+
if (c) {
|
|
253
|
+
let i = !1;
|
|
254
|
+
for (let h = 0; h < l.value; h++) {
|
|
255
|
+
const r = s(`input ${h} witness item count`);
|
|
256
|
+
i || (i = r.value > 0);
|
|
257
|
+
for (let u = 0; u < r.value; u++) {
|
|
258
|
+
const b = s(
|
|
259
|
+
`input ${h} witness item ${u} length`
|
|
260
|
+
);
|
|
261
|
+
o(b.value, `input ${h} witness item ${u}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (!i)
|
|
265
|
+
throw new Error("Bitcoin transaction has superfluous witness marker");
|
|
266
|
+
}
|
|
267
|
+
const P = o(4, "locktime");
|
|
268
|
+
if (e !== t.length)
|
|
269
|
+
throw new Error(
|
|
270
|
+
`Bitcoin transaction has ${t.length - e} trailing byte(s)`
|
|
271
|
+
);
|
|
272
|
+
return qt([
|
|
273
|
+
a,
|
|
274
|
+
l.encoded,
|
|
275
|
+
...d,
|
|
276
|
+
p.encoded,
|
|
277
|
+
...g,
|
|
278
|
+
P
|
|
279
|
+
]);
|
|
280
|
+
}
|
|
281
|
+
function Ut(t) {
|
|
282
|
+
const e = Wt(
|
|
283
|
+
Ft(t, "transactionHex")
|
|
284
|
+
), o = S(S(e));
|
|
285
|
+
return o.reverse(), `0x${Mt(o)}`;
|
|
286
|
+
}
|
|
287
|
+
function Dt(t, e) {
|
|
288
|
+
const o = t.startsWith("0x") ? t : `0x${t}`;
|
|
289
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(o))
|
|
290
|
+
throw new Error("peginTxHash must be a 32-byte hex value");
|
|
291
|
+
const n = e.startsWith("0x") ? e : `0x${e}`;
|
|
292
|
+
if (!lt(n, { strict: !0 }))
|
|
293
|
+
throw new Error(`Invalid depositor Ethereum address: ${e}`);
|
|
294
|
+
return dt(
|
|
295
|
+
pt(
|
|
296
|
+
[{ type: "bytes32" }, { type: "address" }],
|
|
297
|
+
[o, n]
|
|
298
|
+
)
|
|
299
|
+
).slice(2);
|
|
300
|
+
}
|
|
301
|
+
const v = 65535, U = 1e4, B = 4294967295, D = 255;
|
|
302
|
+
function Xt(t) {
|
|
303
|
+
if (!Number.isInteger(t) || t < 0 || t > B)
|
|
304
|
+
throw new Error(
|
|
305
|
+
`Invalid offchainParamsVersion from contract: must be a uint32, got ${t}`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
function zt(t) {
|
|
309
|
+
const e = [];
|
|
310
|
+
if (t.timelockAssert <= 0n && e.push(
|
|
311
|
+
`timelockAssert must be positive, got ${t.timelockAssert}`
|
|
312
|
+
), t.timelockAssert > BigInt(v) && e.push(
|
|
313
|
+
`timelockAssert ${t.timelockAssert} exceeds uint16 max (${v})`
|
|
314
|
+
), t.timelockChallengeAssert <= 0n && e.push(
|
|
315
|
+
`timelockChallengeAssert must be positive, got ${t.timelockChallengeAssert}`
|
|
316
|
+
), t.tRefund <= 0 && e.push(`tRefund must be positive, got ${t.tRefund}`), t.tStale <= 0 && e.push(`tStale must be positive, got ${t.tStale}`), t.securityCouncilKeys.length === 0 && e.push("securityCouncilKeys must not be empty"), t.councilQuorum <= 0 && e.push(`councilQuorum must be positive, got ${t.councilQuorum}`), t.councilQuorum > t.securityCouncilKeys.length && e.push(
|
|
317
|
+
`councilQuorum (${t.councilQuorum}) exceeds securityCouncilKeys count (${t.securityCouncilKeys.length})`
|
|
318
|
+
), t.feeRate <= 0n && e.push(`feeRate must be positive, got ${t.feeRate}`), t.minPeginFeeRate <= 0n && e.push(
|
|
319
|
+
`minPeginFeeRate must be positive, got ${t.minPeginFeeRate}`
|
|
320
|
+
), (!Number.isInteger(t.proverCircuitVersion) || t.proverCircuitVersion < 0 || t.proverCircuitVersion > v) && e.push(
|
|
321
|
+
`proverCircuitVersion must be a uint16, got ${t.proverCircuitVersion}`
|
|
322
|
+
), (!Number.isInteger(t.minPrepeginDepth) || t.minPrepeginDepth <= 0 || t.minPrepeginDepth > B) && e.push(
|
|
323
|
+
`minPrepeginDepth must be a uint32 in [1, ${B}], got ${t.minPrepeginDepth}`
|
|
324
|
+
), t.babeTotalInstances <= 0 && e.push(
|
|
325
|
+
`babeTotalInstances must be positive, got ${t.babeTotalInstances}`
|
|
326
|
+
), t.babeInstancesToFinalize <= 0 && e.push(
|
|
327
|
+
`babeInstancesToFinalize must be positive, got ${t.babeInstancesToFinalize}`
|
|
328
|
+
), t.babeInstancesToFinalize > t.babeTotalInstances && e.push(
|
|
329
|
+
`babeInstancesToFinalize (${t.babeInstancesToFinalize}) exceeds babeTotalInstances (${t.babeTotalInstances})`
|
|
330
|
+
), (t.minVpCommissionBps < 0 || t.minVpCommissionBps > U) && e.push(
|
|
331
|
+
`minVpCommissionBps must be in [0, ${U}], got ${t.minVpCommissionBps}`
|
|
332
|
+
), e.length > 0)
|
|
333
|
+
throw new Error(
|
|
334
|
+
`Invalid offchain protocol parameters: ${e.join("; ")}`
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
function Lt(t) {
|
|
338
|
+
const e = [];
|
|
339
|
+
if (t.minimumPegInAmount <= 0n && e.push(
|
|
340
|
+
`minimumPegInAmount must be positive, got ${t.minimumPegInAmount}`
|
|
341
|
+
), t.maxPegInAmount < t.minimumPegInAmount && e.push(
|
|
342
|
+
`maxPegInAmount (${t.maxPegInAmount}) must be >= minimumPegInAmount (${t.minimumPegInAmount})`
|
|
343
|
+
), t.pegInAckTimeout <= 0n && e.push(
|
|
344
|
+
`pegInAckTimeout must be positive, got ${t.pegInAckTimeout}`
|
|
345
|
+
), t.pegInActivationTimeout <= 0n && e.push(
|
|
346
|
+
`pegInActivationTimeout must be positive, got ${t.pegInActivationTimeout}`
|
|
347
|
+
), (!Number.isInteger(t.maxHtlcOutputCount) || t.maxHtlcOutputCount <= 0 || t.maxHtlcOutputCount > D) && e.push(
|
|
348
|
+
`maxHtlcOutputCount must be an integer in [1, ${D}], got ${t.maxHtlcOutputCount}`
|
|
349
|
+
), (typeof t.expiredPegInGraceBlocks != "bigint" || t.expiredPegInGraceBlocks <= 0n) && e.push(
|
|
350
|
+
`expiredPegInGraceBlocks must be a positive bigint, got ${t.expiredPegInGraceBlocks}`
|
|
351
|
+
), e.length > 0)
|
|
352
|
+
throw new Error(`Invalid TBV protocol parameters: ${e.join("; ")}`);
|
|
353
|
+
}
|
|
354
|
+
function ue(t) {
|
|
355
|
+
if (Lt(t), zt(t.offchainParams), !Number.isInteger(t.offchainParamsVersion) || t.offchainParamsVersion < 0 || t.offchainParamsVersion > B)
|
|
356
|
+
throw new Error(
|
|
357
|
+
`Invalid peg-in configuration: offchainParamsVersion must be a uint32, got ${t.offchainParamsVersion}`
|
|
358
|
+
);
|
|
359
|
+
Pt(
|
|
360
|
+
t.activeVaultCoreVersion,
|
|
361
|
+
"ProtocolParams.activeVaultCoreVersion()"
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
const X = 9999;
|
|
365
|
+
function z(t) {
|
|
366
|
+
return {
|
|
367
|
+
depositor: t.depositor,
|
|
368
|
+
depositorBtcPubKey: t.depositorBtcPubKey,
|
|
369
|
+
amount: t.amount,
|
|
370
|
+
vaultProvider: t.vaultProvider,
|
|
371
|
+
status: t.status,
|
|
372
|
+
applicationEntryPoint: t.applicationEntryPoint,
|
|
373
|
+
createdAt: t.createdAt
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function A(t) {
|
|
377
|
+
const e = Number(t.offchainParamsVersion);
|
|
378
|
+
return Xt(e), {
|
|
379
|
+
depositorSignedPeginTx: t.depositorSignedPeginTx,
|
|
380
|
+
universalChallengersVersion: t.universalChallengersVersion,
|
|
381
|
+
appVaultKeepersVersion: t.appVaultKeepersVersion,
|
|
382
|
+
offchainParamsVersion: e,
|
|
383
|
+
verifiedAt: t.verifiedAt,
|
|
384
|
+
depositorWotsPkHash: t.depositorWotsPkHash,
|
|
385
|
+
hashlock: t.hashlock,
|
|
386
|
+
htlcVout: t.htlcVout,
|
|
387
|
+
depositorPopSignature: t.depositorPopSignature,
|
|
388
|
+
prePeginTxHash: t.prePeginTxHash,
|
|
389
|
+
vaultProviderCommissionBps: t.vaultProviderCommissionBps,
|
|
390
|
+
vaultCoreVersion: t.vaultCoreVersion
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const Qt = 1n << 64n, L = 0n;
|
|
394
|
+
function V(t, e, o) {
|
|
395
|
+
if (t < 0n || t >= Qt)
|
|
396
|
+
throw new Error(
|
|
397
|
+
`getBtcVaultProtocolInfo returned ${e}=${t} for vault ${o}, outside the uint64 range — the registry may predate RFC-006`
|
|
398
|
+
);
|
|
399
|
+
return t;
|
|
400
|
+
}
|
|
401
|
+
function Q(t, e) {
|
|
402
|
+
return {
|
|
403
|
+
vpKeyEpoch: V(t.vpKeyEpoch, "vpKeyEpoch", e),
|
|
404
|
+
appKeeperKeyEpoch: V(
|
|
405
|
+
t.appKeeperKeyEpoch,
|
|
406
|
+
"appKeeperKeyEpoch",
|
|
407
|
+
e
|
|
408
|
+
),
|
|
409
|
+
ucKeyEpoch: V(t.ucKeyEpoch, "ucKeyEpoch", e)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
class Gt {
|
|
413
|
+
constructor(e, o) {
|
|
414
|
+
this.publicClient = e, this.contractAddress = o;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Read the VP's **genesis** (registration) x-only BTC pubkey — the key bonded
|
|
418
|
+
* at version 0, which never moves when the operator rotates.
|
|
419
|
+
*
|
|
420
|
+
* Resolved as "the operation key at epoch 0" rather than through the
|
|
421
|
+
* dedicated `getVaultProviderBTCKey` getter, which
|
|
422
|
+
* https://github.com/babylonlabs-io/vault-contracts-aave-v4/pull/539 removes.
|
|
423
|
+
* Epoch 0 predates any rotation — appended versions are stamped at epoch 1 or
|
|
424
|
+
* later — so it resolves to the registration key, and the contracts team has
|
|
425
|
+
* confirmed that is a property we can rely on rather than an implementation
|
|
426
|
+
* detail. The devnet comparison behind that claim — both getters returning the
|
|
427
|
+
* identical key for a provider that *has* rotated, while
|
|
428
|
+
* `getCurrentOperationBtcKey` differed — is recorded in
|
|
429
|
+
* https://github.com/babylonlabs-io/babylon-toolkit/issues/2188.
|
|
430
|
+
*
|
|
431
|
+
* This makes the read RFC-006-only, where the removed getter also existed on a
|
|
432
|
+
* legacy registry. That costs nothing: every caller of this method already
|
|
433
|
+
* resolves participant keys through `OperationKeyReader`, so all of them
|
|
434
|
+
* require an RFC-006 registry regardless.
|
|
435
|
+
*
|
|
436
|
+
* Validates length, hex form, and secp256k1 curve membership before minting
|
|
437
|
+
* the brand. Returns 64-char lowercase hex without the `0x` prefix.
|
|
438
|
+
*/
|
|
439
|
+
async getVaultProviderGenesisBtcPubKey(e, o) {
|
|
440
|
+
const n = await this.publicClient.readContract({
|
|
441
|
+
address: this.contractAddress,
|
|
442
|
+
abi: f,
|
|
443
|
+
functionName: "getOperationBtcKeyAtEpoch",
|
|
444
|
+
args: [e, L],
|
|
445
|
+
blockNumber: o
|
|
446
|
+
});
|
|
447
|
+
return x(
|
|
448
|
+
n,
|
|
449
|
+
`getOperationBtcKeyAtEpoch (vp=${e}, epoch=${L})`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Read a vault provider's *current* RFC-006 operation BTC key.
|
|
454
|
+
*
|
|
455
|
+
* Falls back on-chain to the registration key when the provider has never
|
|
456
|
+
* rotated, so this returns the same value as
|
|
457
|
+
* `getVaultProviderGenesisBtcPubKey` until the first rotation.
|
|
458
|
+
*
|
|
459
|
+
* This is the key the VP's server signs its BIP-322 auth tokens with — a
|
|
460
|
+
* live per-operator identity, not a per-vault binding, so the auth pin uses
|
|
461
|
+
* the current key rather than any vault's frozen epoch.
|
|
462
|
+
*/
|
|
463
|
+
async getCurrentVaultProviderOperationBtcKey(e) {
|
|
464
|
+
const o = await this.publicClient.readContract({
|
|
465
|
+
address: this.contractAddress,
|
|
466
|
+
abi: f,
|
|
467
|
+
functionName: "getCurrentOperationBtcKey",
|
|
468
|
+
args: [e]
|
|
469
|
+
});
|
|
470
|
+
return x(
|
|
471
|
+
o,
|
|
472
|
+
`getCurrentOperationBtcKey (vp=${e})`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Read a vault's frozen RFC-006 operation-key epochs.
|
|
477
|
+
*
|
|
478
|
+
* Reads `getBtcVaultProtocolInfo` through the **extended** ABI, which is only
|
|
479
|
+
* valid against an RFC-006 registry: against one whose `BTCVaultProtocolInfo`
|
|
480
|
+
* struct is not extended this call does not fail for a populated vault, it
|
|
481
|
+
* silently returns three words of tail data as epochs. Nothing here can detect
|
|
482
|
+
* that, so the guarantee is a deployment one — every network this ships to has
|
|
483
|
+
* the RFC-006 getters, and mainnet is a fresh RFC-006 deploy.
|
|
484
|
+
*
|
|
485
|
+
* A registry missing the operation-key getters entirely is the *safer* of the
|
|
486
|
+
* two cases: `resolveParticipantKeysAtEpochs` reverts downstream and these
|
|
487
|
+
* epochs never reach key resolution. See {@link UINT64_EXCLUSIVE_UPPER_BOUND}
|
|
488
|
+
* for which state the range check actually guards, and
|
|
489
|
+
* `BTCVaultRegistryKeyEpochs.abi.ts` for the decode hazard.
|
|
490
|
+
*/
|
|
491
|
+
async getVaultKeyEpochs(e) {
|
|
492
|
+
const o = await this.publicClient.readContract({
|
|
493
|
+
address: this.contractAddress,
|
|
494
|
+
abi: H,
|
|
495
|
+
functionName: "getBtcVaultProtocolInfo",
|
|
496
|
+
args: [e]
|
|
497
|
+
});
|
|
498
|
+
return Q(o, e);
|
|
499
|
+
}
|
|
500
|
+
async getVaultKeyEpochsBatch(e) {
|
|
501
|
+
return e.length === 0 ? [] : (await this.publicClient.multicall({
|
|
502
|
+
contracts: e.map((n) => ({
|
|
503
|
+
address: this.contractAddress,
|
|
504
|
+
abi: H,
|
|
505
|
+
functionName: "getBtcVaultProtocolInfo",
|
|
506
|
+
args: [n]
|
|
507
|
+
})),
|
|
508
|
+
allowFailure: !1
|
|
509
|
+
})).map(
|
|
510
|
+
(n, s) => Q(n, e[s])
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
async getVaultBasicInfo(e) {
|
|
514
|
+
const o = await this.publicClient.readContract({
|
|
515
|
+
address: this.contractAddress,
|
|
516
|
+
abi: f,
|
|
517
|
+
functionName: "getBtcVaultBasicInfo",
|
|
518
|
+
args: [e]
|
|
519
|
+
});
|
|
520
|
+
return z(o);
|
|
521
|
+
}
|
|
522
|
+
async getVaultProtocolInfo(e) {
|
|
523
|
+
const o = await this.publicClient.readContract({
|
|
524
|
+
address: this.contractAddress,
|
|
525
|
+
abi: f,
|
|
526
|
+
functionName: "getBtcVaultProtocolInfo",
|
|
527
|
+
args: [e]
|
|
528
|
+
});
|
|
529
|
+
return A(o);
|
|
530
|
+
}
|
|
531
|
+
async getProtocolInfoBatch(e) {
|
|
532
|
+
return e.length === 0 ? [] : (await this.publicClient.multicall({
|
|
533
|
+
contracts: e.map((n) => ({
|
|
534
|
+
address: this.contractAddress,
|
|
535
|
+
abi: f,
|
|
536
|
+
functionName: "getBtcVaultProtocolInfo",
|
|
537
|
+
args: [n]
|
|
538
|
+
})),
|
|
539
|
+
allowFailure: !1
|
|
540
|
+
})).map((n, s) => {
|
|
541
|
+
const a = n;
|
|
542
|
+
if (!a.depositorSignedPeginTx || a.depositorSignedPeginTx === "0x")
|
|
543
|
+
throw new Error(
|
|
544
|
+
`Vault ${e[s]} not found on-chain or has no pegin transaction`
|
|
545
|
+
);
|
|
546
|
+
return A(a);
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Read the protocol pegin fee (in wei) for a given vault provider.
|
|
551
|
+
* Mirrors the `getPegInFee(address)` view on BTCVaultRegistry.
|
|
552
|
+
*/
|
|
553
|
+
async getPegInFee(e) {
|
|
554
|
+
return await this.publicClient.readContract({
|
|
555
|
+
address: this.contractAddress,
|
|
556
|
+
abi: f,
|
|
557
|
+
functionName: "getPegInFee",
|
|
558
|
+
args: [e]
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Read a vault provider's current commission in basis points from
|
|
563
|
+
* BTCVaultRegistry. The contract enforces `commissionBps < 10000`, so the
|
|
564
|
+
* legitimate range is `[0, 9999]`; anything outside indicates a wrong
|
|
565
|
+
* contract address or ABI drift and is surfaced as an error rather than
|
|
566
|
+
* trusted.
|
|
567
|
+
*/
|
|
568
|
+
async getVaultProviderCommission(e) {
|
|
569
|
+
const o = await this.publicClient.readContract({
|
|
570
|
+
address: this.contractAddress,
|
|
571
|
+
abi: f,
|
|
572
|
+
functionName: "getVaultProviderCommission",
|
|
573
|
+
args: [e]
|
|
574
|
+
});
|
|
575
|
+
if (!Number.isInteger(o) || o < 0 || o > X)
|
|
576
|
+
throw new Error(
|
|
577
|
+
`getVaultProviderCommission returned ${o} bps for ${e}, outside the protocol range [0, ${X}]`
|
|
578
|
+
);
|
|
579
|
+
return o;
|
|
580
|
+
}
|
|
581
|
+
async getVaultData(e) {
|
|
582
|
+
const [o, n] = await this.publicClient.multicall({
|
|
583
|
+
contracts: [
|
|
584
|
+
{
|
|
585
|
+
address: this.contractAddress,
|
|
586
|
+
abi: f,
|
|
587
|
+
functionName: "getBtcVaultBasicInfo",
|
|
588
|
+
args: [e]
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
address: this.contractAddress,
|
|
592
|
+
abi: f,
|
|
593
|
+
functionName: "getBtcVaultProtocolInfo",
|
|
594
|
+
args: [e]
|
|
595
|
+
}
|
|
596
|
+
],
|
|
597
|
+
allowFailure: !1
|
|
598
|
+
}), s = z(o), a = A(n);
|
|
599
|
+
if (!a.depositorSignedPeginTx || a.depositorSignedPeginTx === "0x")
|
|
600
|
+
throw new Error(
|
|
601
|
+
`Vault ${e} not found on-chain or has no pegin transaction`
|
|
602
|
+
);
|
|
603
|
+
return { basic: s, protocol: a };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const Yt = 0, jt = 255, Jt = 12e4;
|
|
607
|
+
function y(t, e) {
|
|
608
|
+
const o = t.startsWith("0x") ? t : t.startsWith("0X") ? `0x${t.slice(2)}` : `0x${t}`;
|
|
609
|
+
if (!/^0x(?:[0-9a-fA-F]{2})+$/.test(o))
|
|
610
|
+
throw new Error(`${e} must be non-empty, even-length hex`);
|
|
611
|
+
return o;
|
|
612
|
+
}
|
|
613
|
+
function G(t, e) {
|
|
614
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(t))
|
|
615
|
+
throw new Error(`${e} must be a 32-byte hex value`);
|
|
616
|
+
}
|
|
617
|
+
function Zt(t) {
|
|
618
|
+
if (!Number.isInteger(t) || t < 0 || t > jt)
|
|
619
|
+
throw new Error(`htlcVout must be a uint8, got ${t}`);
|
|
620
|
+
}
|
|
621
|
+
class he {
|
|
622
|
+
constructor(e) {
|
|
623
|
+
this.config = e;
|
|
624
|
+
}
|
|
625
|
+
async registerPeginOnChain(e) {
|
|
626
|
+
const o = {
|
|
627
|
+
...e,
|
|
628
|
+
popSignature: { ...e.popSignature }
|
|
629
|
+
};
|
|
630
|
+
this.assertQuotedCommissionPresentWhenRequired(o.quotedCommissionBps);
|
|
631
|
+
const n = this.assertPopMatchesEthAccount(o.popSignature), s = this.normalizeBtcPubkey(o.popSignature), a = y(
|
|
632
|
+
o.popSignature.btcPopSignature,
|
|
633
|
+
"btcPopSignature"
|
|
634
|
+
), c = this.normalizeRequest(
|
|
635
|
+
o,
|
|
636
|
+
n,
|
|
637
|
+
s
|
|
638
|
+
);
|
|
639
|
+
await this.assertVaultDoesNotExist(
|
|
640
|
+
c.vaultId,
|
|
641
|
+
c.peginTxHash
|
|
642
|
+
);
|
|
643
|
+
const l = await this.readPeginFee(o.vaultProvider), d = await this.resolveMaxAcceptableCommissionBps(
|
|
644
|
+
o.vaultProvider,
|
|
645
|
+
o.quotedCommissionBps
|
|
646
|
+
), p = N({
|
|
647
|
+
abi: f,
|
|
648
|
+
functionName: "submitPeginRequest",
|
|
649
|
+
args: [
|
|
650
|
+
n,
|
|
651
|
+
s,
|
|
652
|
+
a,
|
|
653
|
+
c.unsignedPrePeginTx,
|
|
654
|
+
c.depositorSignedPeginTx,
|
|
655
|
+
o.vaultProvider,
|
|
656
|
+
d,
|
|
657
|
+
o.hashlock,
|
|
658
|
+
o.htlcVout,
|
|
659
|
+
c.payoutScript,
|
|
660
|
+
o.depositorWotsPkHash
|
|
661
|
+
]
|
|
662
|
+
});
|
|
663
|
+
return {
|
|
664
|
+
ethTxHash: await this.sendAndWait(
|
|
665
|
+
p,
|
|
666
|
+
l,
|
|
667
|
+
!1,
|
|
668
|
+
n
|
|
669
|
+
),
|
|
670
|
+
vaultId: c.vaultId,
|
|
671
|
+
peginTxHash: c.peginTxHash
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
async registerPeginBatchOnChain(e) {
|
|
675
|
+
const o = {
|
|
676
|
+
...e,
|
|
677
|
+
popSignature: { ...e.popSignature },
|
|
678
|
+
requests: e.requests.map((r) => ({ ...r }))
|
|
679
|
+
};
|
|
680
|
+
if (o.requests.length === 0)
|
|
681
|
+
throw new Error("Batch pegin requires at least one request");
|
|
682
|
+
this.assertQuotedCommissionPresentWhenRequired(o.quotedCommissionBps);
|
|
683
|
+
const n = this.assertPopMatchesEthAccount(o.popSignature), s = y(
|
|
684
|
+
o.unsignedPrePeginTx,
|
|
685
|
+
"unsignedPrePeginTx"
|
|
686
|
+
), a = this.normalizeBtcPubkey(o.popSignature), c = y(
|
|
687
|
+
o.popSignature.btcPopSignature,
|
|
688
|
+
"btcPopSignature"
|
|
689
|
+
), l = [], d = [], p = /* @__PURE__ */ new Set();
|
|
690
|
+
for (const r of o.requests) {
|
|
691
|
+
const u = this.normalizeRequest(
|
|
692
|
+
{
|
|
693
|
+
...r,
|
|
694
|
+
unsignedPrePeginTx: o.unsignedPrePeginTx,
|
|
695
|
+
vaultProvider: o.vaultProvider,
|
|
696
|
+
depositorBtcPubkeyRaw: o.depositorBtcPubkeyRaw
|
|
697
|
+
},
|
|
698
|
+
n,
|
|
699
|
+
a
|
|
700
|
+
);
|
|
701
|
+
if (p.has(u.vaultId))
|
|
702
|
+
throw new Error(`Duplicate vault in batch: ${u.vaultId}`);
|
|
703
|
+
p.add(u.vaultId), l.push({
|
|
704
|
+
vaultId: u.vaultId,
|
|
705
|
+
peginTxHash: u.peginTxHash
|
|
706
|
+
}), d.push({
|
|
707
|
+
depositorBtcPubKey: a,
|
|
708
|
+
btcPopSignature: c,
|
|
709
|
+
unsignedPrePeginTx: s,
|
|
710
|
+
depositorSignedPeginTx: u.depositorSignedPeginTx,
|
|
711
|
+
hashlock: r.hashlock,
|
|
712
|
+
htlcVout: r.htlcVout,
|
|
713
|
+
referralCode: Yt,
|
|
714
|
+
depositorPayoutBtcAddress: u.payoutScript,
|
|
715
|
+
depositorWotsPkHash: r.depositorWotsPkHash
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
for (const r of l)
|
|
719
|
+
await this.assertVaultDoesNotExist(r.vaultId, r.peginTxHash);
|
|
720
|
+
const g = await this.readPeginFee(o.vaultProvider), P = await this.resolveMaxAcceptableCommissionBps(
|
|
721
|
+
o.vaultProvider,
|
|
722
|
+
o.quotedCommissionBps
|
|
723
|
+
), i = N({
|
|
724
|
+
abi: f,
|
|
725
|
+
functionName: "submitPeginRequestBatch",
|
|
726
|
+
args: [n, o.vaultProvider, P, d]
|
|
727
|
+
});
|
|
728
|
+
return { ethTxHash: await this.sendAndWait(
|
|
729
|
+
i,
|
|
730
|
+
g * BigInt(o.requests.length),
|
|
731
|
+
!0,
|
|
732
|
+
n
|
|
733
|
+
), vaults: l };
|
|
734
|
+
}
|
|
735
|
+
assertQuotedCommissionPresentWhenRequired(e) {
|
|
736
|
+
if (e === void 0 && this.config.requireQuotedCommissionBps)
|
|
737
|
+
throw new Error(
|
|
738
|
+
"quotedCommissionBps is required when the wallet approved deposit terms: the registration ceiling must anchor to the approved quote."
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
assertPopMatchesEthAccount(e) {
|
|
742
|
+
return this.assertEthAccount(e.depositorEthAddress);
|
|
743
|
+
}
|
|
744
|
+
assertEthAccount(e) {
|
|
745
|
+
const o = this.config.ethWallet.account;
|
|
746
|
+
if (!o) throw new Error("Ethereum wallet account not found");
|
|
747
|
+
if (!ft(e, o.address))
|
|
748
|
+
throw new Error(
|
|
749
|
+
`Proof of possession was signed for ${e} but the Ethereum wallet is currently connected to ${o.address}. Reconnect the original account or sign a new proof of possession.`
|
|
750
|
+
);
|
|
751
|
+
return o.address;
|
|
752
|
+
}
|
|
753
|
+
normalizeBtcPubkey(e) {
|
|
754
|
+
return `0x${x(
|
|
755
|
+
y(e.depositorBtcPubkey, "Proof of possession BTC pubkey"),
|
|
756
|
+
"Proof of possession BTC pubkey"
|
|
757
|
+
)}`;
|
|
758
|
+
}
|
|
759
|
+
normalizeRequest(e, o, n) {
|
|
760
|
+
G(e.hashlock, "hashlock"), G(e.depositorWotsPkHash, "depositorWotsPkHash"), Zt(e.htlcVout);
|
|
761
|
+
const s = y(
|
|
762
|
+
e.unsignedPrePeginTx,
|
|
763
|
+
"unsignedPrePeginTx"
|
|
764
|
+
), a = y(
|
|
765
|
+
e.depositorSignedPeginTx,
|
|
766
|
+
"depositorSignedPeginTx"
|
|
767
|
+
), c = Ut(a);
|
|
768
|
+
return {
|
|
769
|
+
unsignedPrePeginTx: s,
|
|
770
|
+
depositorSignedPeginTx: a,
|
|
771
|
+
payoutScript: Ot(
|
|
772
|
+
e.depositorPayoutScriptPubKey,
|
|
773
|
+
n,
|
|
774
|
+
e.depositorBtcPubkeyRaw
|
|
775
|
+
),
|
|
776
|
+
peginTxHash: c,
|
|
777
|
+
vaultId: y(Dt(c, o), "vaultId")
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
async assertVaultDoesNotExist(e, o) {
|
|
781
|
+
if ((await this.config.publicClient.readContract({
|
|
782
|
+
address: this.config.btcVaultRegistry,
|
|
783
|
+
abi: f,
|
|
784
|
+
functionName: "getBtcVaultBasicInfo",
|
|
785
|
+
args: [e]
|
|
786
|
+
})).depositor !== gt)
|
|
787
|
+
throw new Error(
|
|
788
|
+
`Vault already exists (ID: ${e}, peginTxHash: ${o}). 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.`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
async readPeginFee(e) {
|
|
792
|
+
try {
|
|
793
|
+
return await this.config.publicClient.readContract({
|
|
794
|
+
address: this.config.btcVaultRegistry,
|
|
795
|
+
abi: f,
|
|
796
|
+
functionName: "getPegInFee",
|
|
797
|
+
args: [e]
|
|
798
|
+
});
|
|
799
|
+
} catch (o) {
|
|
800
|
+
throw new Error(
|
|
801
|
+
"Failed to query pegin fee from the contract. Please check your network connection and contract address.",
|
|
802
|
+
{ cause: o }
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
async resolveMaxAcceptableCommissionBps(e, o) {
|
|
807
|
+
let n;
|
|
808
|
+
try {
|
|
809
|
+
n = await new Gt(
|
|
810
|
+
this.config.publicClient,
|
|
811
|
+
this.config.btcVaultRegistry
|
|
812
|
+
).getVaultProviderCommission(e);
|
|
813
|
+
} catch (s) {
|
|
814
|
+
throw new Error(
|
|
815
|
+
"Failed to query vault provider commission from the contract. Please check your network connection and contract address.",
|
|
816
|
+
{ cause: s }
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
if (o !== void 0) {
|
|
820
|
+
if (n > o + k)
|
|
821
|
+
throw new Error(
|
|
822
|
+
`Vault provider commission changed since quote: quoted ${o} bps, chain currently reports ${n} bps (allowed drift ${k} bps). Please refresh and try again.`
|
|
823
|
+
);
|
|
824
|
+
return M(o);
|
|
825
|
+
}
|
|
826
|
+
return M(n);
|
|
827
|
+
}
|
|
828
|
+
async sendAndWait(e, o, n, s) {
|
|
829
|
+
let a = this.assertEthAccount(s), c;
|
|
830
|
+
try {
|
|
831
|
+
c = await this.config.publicClient.estimateGas({
|
|
832
|
+
to: this.config.btcVaultRegistry,
|
|
833
|
+
data: e,
|
|
834
|
+
value: o,
|
|
835
|
+
account: a
|
|
836
|
+
});
|
|
837
|
+
} catch (p) {
|
|
838
|
+
T(p);
|
|
839
|
+
}
|
|
840
|
+
a = this.assertEthAccount(s);
|
|
841
|
+
let l;
|
|
842
|
+
try {
|
|
843
|
+
l = await this.config.ethWallet.sendTransaction({
|
|
844
|
+
to: this.config.btcVaultRegistry,
|
|
845
|
+
data: e,
|
|
846
|
+
value: o,
|
|
847
|
+
gas: c,
|
|
848
|
+
account: a,
|
|
849
|
+
chain: this.config.ethChain
|
|
850
|
+
});
|
|
851
|
+
} catch (p) {
|
|
852
|
+
T(p);
|
|
853
|
+
}
|
|
854
|
+
const d = await mt({
|
|
855
|
+
publicClient: this.config.publicClient,
|
|
856
|
+
walletAddress: s,
|
|
857
|
+
hash: l,
|
|
858
|
+
timeout: this.config.receiptTimeoutMs ?? Jt
|
|
859
|
+
});
|
|
860
|
+
return d.status === "reverted" && T(
|
|
861
|
+
new Error(
|
|
862
|
+
`${n ? "Batch transaction" : "Transaction"} reverted. Hash: ${d.transactionHash}. Check a block explorer for details.`
|
|
863
|
+
)
|
|
864
|
+
), d.transactionHash;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
export {
|
|
868
|
+
k as C,
|
|
869
|
+
wt as M,
|
|
870
|
+
Yt as N,
|
|
871
|
+
he as V,
|
|
872
|
+
ue as a,
|
|
873
|
+
Lt as b,
|
|
874
|
+
Gt as c,
|
|
875
|
+
Dt as d,
|
|
876
|
+
M as e,
|
|
877
|
+
Ut as f,
|
|
878
|
+
Xt as g,
|
|
879
|
+
vt as r,
|
|
880
|
+
zt as v
|
|
881
|
+
};
|
|
882
|
+
//# sourceMappingURL=pegin-registration-client-CXK3B_D1.js.map
|