@babylonlabs-io/ts-sdk 0.56.1 → 0.57.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/BTCVaultRegistry.abi-AUAyCHal.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-AUAyCHal.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-Chs4AFBj.js → BTCVaultRegistry.abi-CixOlp3B.js} +73 -14
- package/dist/BTCVaultRegistry.abi-CixOlp3B.js.map +1 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js +111 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js.map +1 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs +2 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs.map +1 -0
- package/dist/{PeginManager-Ba7Cr51Z.js → PeginManager-CnX3uFb0.js} +5 -5
- package/dist/{PeginManager-Ba7Cr51Z.js.map → PeginManager-CnX3uFb0.js.map} +1 -1
- package/dist/PeginManager-iDbqXsKD.cjs +2 -0
- package/dist/{PeginManager-CcjGRo4O.cjs.map → PeginManager-iDbqXsKD.cjs.map} +1 -1
- package/dist/ProtocolParams.abi-C8U7BHCS.cjs +2 -0
- package/dist/ProtocolParams.abi-C8U7BHCS.cjs.map +1 -0
- package/dist/{ApplicationRegistry.abi-w5prf7Ig.js → ProtocolParams.abi-CV938AYZ.js} +150 -80
- package/dist/ProtocolParams.abi-CV938AYZ.js.map +1 -0
- package/dist/{buildAndBroadcastRefund-BtXUqBkb.js → buildAndBroadcastRefund-CCb1_z24.js} +627 -452
- package/dist/buildAndBroadcastRefund-CCb1_z24.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CDzzTZ2U.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CDzzTZ2U.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +163 -153
- package/dist/index.js.map +1 -1
- package/dist/{types-CQDRQvV-.js → json-rpc-client-Ehjthcd7.js} +61 -61
- package/dist/json-rpc-client-Ehjthcd7.js.map +1 -0
- package/dist/{types-WA0LrDk1.cjs → json-rpc-client-fUoK-TzT.cjs} +2 -2
- package/dist/json-rpc-client-fUoK-TzT.cjs.map +1 -0
- package/dist/mempoolApi-C0olk43O.js +536 -0
- package/dist/mempoolApi-C0olk43O.js.map +1 -0
- package/dist/mempoolApi-Dsm2VPXp.cjs +2 -0
- package/dist/mempoolApi-Dsm2VPXp.cjs.map +1 -0
- package/dist/{noPayout-CihCk1HE.js → noPayout-CI4l1qu2.js} +2 -2
- package/dist/{noPayout-CihCk1HE.js.map → noPayout-CI4l1qu2.js.map} +1 -1
- package/dist/{noPayout-Cb8vFrkY.cjs → noPayout-Djrv31V5.cjs} +2 -2
- package/dist/{noPayout-Cb8vFrkY.cjs.map → noPayout-Djrv31V5.cjs.map} +1 -1
- package/dist/onChainBtcPubkey-Cd9kpz-S.cjs +2 -0
- package/dist/onChainBtcPubkey-Cd9kpz-S.cjs.map +1 -0
- package/dist/onChainBtcPubkey-aPY5ib3Q.js +19 -0
- package/dist/onChainBtcPubkey-aPY5ib3Q.js.map +1 -0
- package/dist/primeVpAuth-BlxUcdBf.cjs +2 -0
- package/dist/primeVpAuth-BlxUcdBf.cjs.map +1 -0
- package/dist/{primeVpAuth-Caa5J_uv.js → primeVpAuth-DkJbvywo.js} +479 -367
- package/dist/primeVpAuth-DkJbvywo.js.map +1 -0
- package/dist/signPsbtsWithFallback-C01N6Kdo.cjs +2 -0
- package/dist/signPsbtsWithFallback-C01N6Kdo.cjs.map +1 -0
- package/dist/{PayoutManager-BVgmuKuK.js → signPsbtsWithFallback-CzZFZf0I.js} +105 -101
- package/dist/signPsbtsWithFallback-CzZFZf0I.js.map +1 -0
- package/dist/tbv/core/clients/eth/index.d.ts +5 -3
- package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts +16 -0
- package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/operation-key-reader.d.ts +33 -0
- package/dist/tbv/core/clients/eth/operation-key-reader.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/types.d.ts +122 -3
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +25 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +35 -32
- package/dist/tbv/core/clients/index.js.map +1 -1
- package/dist/tbv/core/contracts/__tests__/BTCVaultRegistryKeyEpochs.abi.test.d.ts +2 -0
- package/dist/tbv/core/contracts/__tests__/BTCVaultRegistryKeyEpochs.abi.test.d.ts.map +1 -0
- package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts +66 -0
- package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +50 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistryKeyEpochs.abi.d.ts +111 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistryKeyEpochs.abi.d.ts.map +1 -0
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +36 -0
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.d.ts +2 -1
- package/dist/tbv/core/contracts/index.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.js +8 -6
- package/dist/tbv/core/contracts/index.js.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +163 -153
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/PayoutManager.d.ts +8 -0
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- 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 +2 -2
- package/dist/tbv/core/primitives/psbt/__tests__/standardPayoutScript.test.d.ts +2 -0
- package/dist/tbv/core/primitives/psbt/__tests__/standardPayoutScript.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts +5 -5
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +23 -0
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/standardPayoutScript.d.ts +41 -0
- package/dist/tbv/core/primitives/psbt/standardPayoutScript.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredParticipantKeys.test.d.ts +2 -0
- package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredParticipantKeys.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/index.d.ts +7 -6
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +10 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +9 -0
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts +38 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts +42 -0
- package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts.map +1 -0
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.d.ts +1 -0
- package/dist/tbv/core/services/index.d.ts.map +1 -1
- package/dist/tbv/core/services/index.js +36 -31
- package/dist/tbv/core/services/participants/__tests__/fixtures/rotation.d.ts +55 -0
- package/dist/tbv/core/services/participants/__tests__/fixtures/rotation.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/__tests__/resolveParticipantKeys.test.d.ts +2 -0
- package/dist/tbv/core/services/participants/__tests__/resolveParticipantKeys.test.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/index.d.ts +8 -0
- package/dist/tbv/core/services/participants/index.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts +26 -0
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/types.d.ts +62 -0
- package/dist/tbv/core/services/participants/types.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +163 -153
- package/dist/tbv/index.js.map +1 -1
- package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs.map +1 -0
- package/dist/{verifyScriptPathSchnorrSignature-CgrnAjMW.js → verifyScriptPathSchnorrSignature-Xoo9DOHW.js} +359 -301
- package/dist/verifyScriptPathSchnorrSignature-Xoo9DOHW.js.map +1 -0
- package/package.json +1 -1
- package/dist/ApplicationRegistry.abi-CLaa6E99.cjs +0 -2
- package/dist/ApplicationRegistry.abi-CLaa6E99.cjs.map +0 -1
- package/dist/ApplicationRegistry.abi-w5prf7Ig.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-Chs4AFBj.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-JdeqLz4x.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-JdeqLz4x.cjs.map +0 -1
- package/dist/PayoutManager-BVgmuKuK.js.map +0 -1
- package/dist/PayoutManager-Cu4_l-_Y.cjs +0 -2
- package/dist/PayoutManager-Cu4_l-_Y.cjs.map +0 -1
- package/dist/PeginManager-CcjGRo4O.cjs +0 -2
- package/dist/buildAndBroadcastRefund-BtXUqBkb.js.map +0 -1
- package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs +0 -2
- package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs.map +0 -1
- package/dist/mempoolApi-DkyKmmgI.cjs +0 -2
- package/dist/mempoolApi-DkyKmmgI.cjs.map +0 -1
- package/dist/mempoolApi-lpJdvPkK.js +0 -483
- package/dist/mempoolApi-lpJdvPkK.js.map +0 -1
- package/dist/primeVpAuth-Caa5J_uv.js.map +0 -1
- package/dist/primeVpAuth-y-4A88ah.cjs +0 -2
- package/dist/primeVpAuth-y-4A88ah.cjs.map +0 -1
- package/dist/types-CQDRQvV-.js.map +0 -1
- package/dist/types-WA0LrDk1.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-CgrnAjMW.js.map +0 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var E = (e, t, r) => t in e ?
|
|
3
|
-
var
|
|
4
|
-
import * as
|
|
5
|
-
import { s as
|
|
1
|
+
var B = Object.defineProperty;
|
|
2
|
+
var E = (e, t, r) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var p = (e, t, r) => E(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import * as w from "bitcoinjs-lib";
|
|
5
|
+
import { s as S, v as h } from "./bitcoin-B5aNKtsk.js";
|
|
6
6
|
import { s as R } from "./sha2-BYVxyZzX.js";
|
|
7
7
|
import "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
8
|
-
import { c as b, d as y, e as x, f } from "./verifyScriptPathSchnorrSignature-
|
|
8
|
+
import { c as b, d as y, e as x, f } from "./verifyScriptPathSchnorrSignature-Xoo9DOHW.js";
|
|
9
9
|
import { c as d } from "./signing-DaLvGwQe.js";
|
|
10
|
-
const
|
|
11
|
-
function
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
10
|
+
const m = 106, T = 32, l = 34;
|
|
11
|
+
function A(e, t, r) {
|
|
12
|
+
const o = S(e), n = w.Transaction.fromHex(o);
|
|
13
|
+
if (n.outs.length <= t)
|
|
14
14
|
throw new Error(
|
|
15
|
-
`Pre-PegIn auth-anchor OP_RETURN missing: tx has ${
|
|
15
|
+
`Pre-PegIn auth-anchor OP_RETURN missing: tx has ${n.outs.length} outputs, expected at least ${t + 1} (vault outputs + OP_RETURN)`
|
|
16
16
|
);
|
|
17
|
-
const c =
|
|
18
|
-
if (i.length !==
|
|
17
|
+
const c = n.outs[t], i = c.script;
|
|
18
|
+
if (i.length !== l || i[0] !== m || i[1] !== T)
|
|
19
19
|
throw new Error(
|
|
20
|
-
`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 ${
|
|
20
|
+
`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 ${l}-byte OP_RETURN + PUSH32 layout)`
|
|
21
21
|
);
|
|
22
22
|
const a = i.slice(2).toString("hex").toLowerCase();
|
|
23
23
|
if (a !== r.toLowerCase())
|
|
@@ -32,22 +32,22 @@ function C(e, t, r) {
|
|
|
32
32
|
function D(e) {
|
|
33
33
|
let t;
|
|
34
34
|
try {
|
|
35
|
-
t =
|
|
35
|
+
t = w.Transaction.fromHex(S(e));
|
|
36
36
|
} catch {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
const r = [];
|
|
40
|
-
for (let
|
|
41
|
-
const
|
|
42
|
-
c.length ===
|
|
43
|
-
vout:
|
|
40
|
+
for (let o = 0; o < t.outs.length; o++) {
|
|
41
|
+
const n = t.outs[o], c = n.script;
|
|
42
|
+
c.length === l && c[0] === m && c[1] === T && n.value === 0 && r.push({
|
|
43
|
+
vout: o,
|
|
44
44
|
hash: c.slice(2).toString("hex").toLowerCase()
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
return r.length === 1 ? r[0] : void 0;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
function
|
|
49
|
+
const k = 66;
|
|
50
|
+
function H(e) {
|
|
51
51
|
if (!e.startsWith("0x") && !e.startsWith("0X"))
|
|
52
52
|
throw new Error("Expected 0x-prefixed hex string");
|
|
53
53
|
const t = e.slice(2);
|
|
@@ -56,58 +56,42 @@ function S(e) {
|
|
|
56
56
|
if (!/^[0-9a-fA-F]*$/.test(t))
|
|
57
57
|
throw new Error("Hex string contains non-hex characters");
|
|
58
58
|
const r = new Uint8Array(t.length / 2);
|
|
59
|
-
for (let
|
|
60
|
-
r[
|
|
59
|
+
for (let o = 0; o < r.length; o++)
|
|
60
|
+
r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
|
|
61
61
|
return r;
|
|
62
62
|
}
|
|
63
63
|
function $(e) {
|
|
64
64
|
return `0x${Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
if (e.length !==
|
|
66
|
+
function g(e, t) {
|
|
67
|
+
if (e.length !== k)
|
|
68
68
|
throw new Error(
|
|
69
|
-
`${t} must be exactly 32 bytes (${
|
|
69
|
+
`${t} must be exactly 32 bytes (${k} hex chars with 0x prefix), got ${e.length}`
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
const t =
|
|
72
|
+
function K(e) {
|
|
73
|
+
g(e, "Secret");
|
|
74
|
+
const t = H(e), r = R(t);
|
|
75
75
|
return $(r);
|
|
76
76
|
}
|
|
77
77
|
function L(e, t) {
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
async function F(e, t, r) {
|
|
81
|
-
if (t.length === 1)
|
|
82
|
-
return [await e.signPsbt(t[0], r == null ? void 0 : r[0])];
|
|
83
|
-
if (typeof e.signPsbts == "function") {
|
|
84
|
-
const o = await e.signPsbts(t, r);
|
|
85
|
-
if (o.length !== t.length)
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Expected ${t.length} signed PSBTs but received ${o.length}`
|
|
88
|
-
);
|
|
89
|
-
return o;
|
|
90
|
-
}
|
|
91
|
-
const s = [];
|
|
92
|
-
for (let o = 0; o < t.length; o++)
|
|
93
|
-
s.push(await e.signPsbt(t[o], r == null ? void 0 : r[o]));
|
|
94
|
-
return s;
|
|
78
|
+
return g(e, "Secret"), g(t, "Hashlock"), H(t), K(e).toLowerCase() === t.toLowerCase();
|
|
95
79
|
}
|
|
96
|
-
function
|
|
80
|
+
function O(e) {
|
|
97
81
|
return typeof e.approveDepositTerms == "function";
|
|
98
82
|
}
|
|
99
|
-
function
|
|
100
|
-
return
|
|
83
|
+
function F(e) {
|
|
84
|
+
return O(e) ? { approveDepositTerms: (t) => e.approveDepositTerms(t) } : {};
|
|
101
85
|
}
|
|
102
|
-
const
|
|
103
|
-
class
|
|
86
|
+
const v = 0;
|
|
87
|
+
class z {
|
|
104
88
|
/**
|
|
105
89
|
* Creates a new PayoutManager instance.
|
|
106
90
|
*
|
|
107
91
|
* @param config - Manager configuration including wallet
|
|
108
92
|
*/
|
|
109
93
|
constructor(t) {
|
|
110
|
-
|
|
94
|
+
p(this, "config");
|
|
111
95
|
this.config = t;
|
|
112
96
|
}
|
|
113
97
|
/**
|
|
@@ -133,15 +117,15 @@ class X {
|
|
|
133
117
|
* @throws Error if wallet operations fail or signature extraction fails
|
|
134
118
|
*/
|
|
135
119
|
async signPayoutTransaction(t) {
|
|
136
|
-
const r = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey:
|
|
120
|
+
const r = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: o } = h(
|
|
137
121
|
r,
|
|
138
122
|
t.depositorBtcPubkey
|
|
139
|
-
),
|
|
123
|
+
), n = await b({
|
|
140
124
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
141
125
|
payoutTxHex: t.payoutTxHex,
|
|
142
126
|
peginTxHex: t.peginTxHex,
|
|
143
127
|
assertTxHex: t.assertTxHex,
|
|
144
|
-
depositorBtcPubkey:
|
|
128
|
+
depositorBtcPubkey: o,
|
|
145
129
|
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
146
130
|
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
147
131
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
@@ -151,24 +135,26 @@ class X {
|
|
|
151
135
|
registeredPayoutScriptPubKey: t.registeredPayoutScriptPubKey,
|
|
152
136
|
commissionBps: t.commissionBps,
|
|
153
137
|
protocolFeeRate: t.protocolFeeRate,
|
|
154
|
-
councilSize: t.councilSize
|
|
138
|
+
councilSize: t.councilSize,
|
|
139
|
+
vkClaimerPayoutScriptPubKeys: t.vkClaimerPayoutScriptPubKeys,
|
|
140
|
+
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
155
141
|
}), c = await this.config.btcWallet.signPsbt(
|
|
156
|
-
|
|
142
|
+
n.psbtHex,
|
|
157
143
|
d(r, 1)
|
|
158
144
|
);
|
|
159
145
|
y({
|
|
160
|
-
requestedPsbtHex:
|
|
146
|
+
requestedPsbtHex: n.psbtHex,
|
|
161
147
|
returnedPsbtHex: c
|
|
162
148
|
});
|
|
163
|
-
const i = x(c,
|
|
149
|
+
const i = x(c, o);
|
|
164
150
|
return f({
|
|
165
|
-
requestedPsbtHex:
|
|
151
|
+
requestedPsbtHex: n.psbtHex,
|
|
166
152
|
signatureHex: i,
|
|
167
|
-
signerXOnlyPubkeyHex:
|
|
168
|
-
inputIndex:
|
|
153
|
+
signerXOnlyPubkeyHex: o,
|
|
154
|
+
inputIndex: v
|
|
169
155
|
}), {
|
|
170
156
|
signature: i,
|
|
171
|
-
depositorBtcPubkey:
|
|
157
|
+
depositorBtcPubkey: o
|
|
172
158
|
};
|
|
173
159
|
}
|
|
174
160
|
/**
|
|
@@ -201,72 +187,90 @@ class X {
|
|
|
201
187
|
throw new Error(
|
|
202
188
|
"Wallet does not support batch signing (signPsbts method not available)"
|
|
203
189
|
);
|
|
204
|
-
const r = await this.config.btcWallet.getPublicKeyHex(),
|
|
205
|
-
for (const
|
|
206
|
-
const { depositorPubkey: u } =
|
|
190
|
+
const r = await this.config.btcWallet.getPublicKeyHex(), o = [], n = [], c = [];
|
|
191
|
+
for (const s of t) {
|
|
192
|
+
const { depositorPubkey: u } = h(
|
|
207
193
|
r,
|
|
208
|
-
|
|
194
|
+
s.depositorBtcPubkey
|
|
209
195
|
);
|
|
210
196
|
c.push(u);
|
|
211
|
-
const
|
|
212
|
-
vaultCoreVersion:
|
|
213
|
-
payoutTxHex:
|
|
214
|
-
peginTxHex:
|
|
215
|
-
assertTxHex:
|
|
197
|
+
const P = await b({
|
|
198
|
+
vaultCoreVersion: s.vaultCoreVersion,
|
|
199
|
+
payoutTxHex: s.payoutTxHex,
|
|
200
|
+
peginTxHex: s.peginTxHex,
|
|
201
|
+
assertTxHex: s.assertTxHex,
|
|
216
202
|
depositorBtcPubkey: u,
|
|
217
|
-
vaultProviderBtcPubkey:
|
|
218
|
-
vaultKeeperBtcPubkeys:
|
|
219
|
-
universalChallengerBtcPubkeys:
|
|
220
|
-
timelockPegin:
|
|
203
|
+
vaultProviderBtcPubkey: s.vaultProviderBtcPubkey,
|
|
204
|
+
vaultKeeperBtcPubkeys: s.vaultKeeperBtcPubkeys,
|
|
205
|
+
universalChallengerBtcPubkeys: s.universalChallengerBtcPubkeys,
|
|
206
|
+
timelockPegin: s.timelockPegin,
|
|
221
207
|
network: this.config.network,
|
|
222
|
-
claimerBtcPubkey:
|
|
223
|
-
registeredPayoutScriptPubKey:
|
|
224
|
-
commissionBps:
|
|
225
|
-
protocolFeeRate:
|
|
226
|
-
councilSize:
|
|
208
|
+
claimerBtcPubkey: s.claimerBtcPubkey,
|
|
209
|
+
registeredPayoutScriptPubKey: s.registeredPayoutScriptPubKey,
|
|
210
|
+
commissionBps: s.commissionBps,
|
|
211
|
+
protocolFeeRate: s.protocolFeeRate,
|
|
212
|
+
councilSize: s.councilSize,
|
|
213
|
+
vkClaimerPayoutScriptPubKeys: s.vkClaimerPayoutScriptPubKeys,
|
|
214
|
+
vpCommissionScriptPubKey: s.vpCommissionScriptPubKey
|
|
227
215
|
});
|
|
228
|
-
|
|
216
|
+
o.push(P.psbtHex), n.push(d(r, 1));
|
|
229
217
|
}
|
|
230
218
|
const i = await this.config.btcWallet.signPsbts(
|
|
231
|
-
|
|
232
|
-
|
|
219
|
+
o,
|
|
220
|
+
n
|
|
233
221
|
);
|
|
234
222
|
if (i.length !== t.length)
|
|
235
223
|
throw new Error(
|
|
236
224
|
`Expected ${t.length} signed PSBTs but received ${i.length}`
|
|
237
225
|
);
|
|
238
226
|
const a = [];
|
|
239
|
-
for (let
|
|
240
|
-
const u = c[
|
|
227
|
+
for (let s = 0; s < t.length; s++) {
|
|
228
|
+
const u = c[s];
|
|
241
229
|
y({
|
|
242
|
-
requestedPsbtHex: s
|
|
243
|
-
returnedPsbtHex: i[
|
|
230
|
+
requestedPsbtHex: o[s],
|
|
231
|
+
returnedPsbtHex: i[s]
|
|
244
232
|
});
|
|
245
|
-
const
|
|
246
|
-
i[
|
|
233
|
+
const P = x(
|
|
234
|
+
i[s],
|
|
247
235
|
u
|
|
248
236
|
);
|
|
249
237
|
f({
|
|
250
|
-
requestedPsbtHex: s
|
|
251
|
-
signatureHex:
|
|
238
|
+
requestedPsbtHex: o[s],
|
|
239
|
+
signatureHex: P,
|
|
252
240
|
signerXOnlyPubkeyHex: u,
|
|
253
|
-
inputIndex:
|
|
241
|
+
inputIndex: v
|
|
254
242
|
}), a.push({
|
|
255
|
-
payoutSignature:
|
|
243
|
+
payoutSignature: P,
|
|
256
244
|
depositorBtcPubkey: u
|
|
257
245
|
});
|
|
258
246
|
}
|
|
259
247
|
return a;
|
|
260
248
|
}
|
|
261
249
|
}
|
|
250
|
+
async function X(e, t, r) {
|
|
251
|
+
if (t.length === 1)
|
|
252
|
+
return [await e.signPsbt(t[0], r == null ? void 0 : r[0])];
|
|
253
|
+
if (typeof e.signPsbts == "function") {
|
|
254
|
+
const n = await e.signPsbts(t, r);
|
|
255
|
+
if (n.length !== t.length)
|
|
256
|
+
throw new Error(
|
|
257
|
+
`Expected ${t.length} signed PSBTs but received ${n.length}`
|
|
258
|
+
);
|
|
259
|
+
return n;
|
|
260
|
+
}
|
|
261
|
+
const o = [];
|
|
262
|
+
for (let n = 0; n < t.length; n++)
|
|
263
|
+
o.push(await e.signPsbt(t[n], r == null ? void 0 : r[n]));
|
|
264
|
+
return o;
|
|
265
|
+
}
|
|
262
266
|
export {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
z as P,
|
|
268
|
+
A as a,
|
|
269
|
+
X as b,
|
|
270
|
+
K as c,
|
|
267
271
|
D as d,
|
|
268
|
-
|
|
269
|
-
|
|
272
|
+
F as f,
|
|
273
|
+
O as s,
|
|
270
274
|
L as v
|
|
271
275
|
};
|
|
272
|
-
//# sourceMappingURL=
|
|
276
|
+
//# sourceMappingURL=signPsbtsWithFallback-CzZFZf0I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signPsbtsWithFallback-CzZFZf0I.js","sources":["../src/tbv/core/managers/pegin/assertAuthAnchorOpReturn.ts","../src/tbv/core/services/htlc/index.ts","../src/tbv/core/deposit-terms/depositTerms.ts","../src/tbv/core/managers/PayoutManager.ts","../src/tbv/core/managers/pegin/signPsbtsWithFallback.ts"],"sourcesContent":["/**\n * Structural verifier for the auth-anchor OP_RETURN in a funded\n * Pre-PegIn transaction.\n *\n * @module managers/pegin/assertAuthAnchorOpReturn\n */\n\nimport * as bitcoin from \"bitcoinjs-lib\";\n\nimport { stripHexPrefix } from \"../../primitives/utils/bitcoin\";\n\n/** OP_RETURN opcode. */\nconst OP_RETURN = 0x6a;\n/** Push-32-bytes opcode (raw push, not OP_PUSHDATA1). */\nconst OP_PUSH32 = 0x20;\n/** Encoded length of a standard OP_RETURN script with a 32-byte payload. */\nconst OP_RETURN_PUSH32_SCRIPT_LEN = 1 + 1 + 32;\n\n/**\n * Verify the broadcast Pre-PegIn carries the expected OP_RETURN\n * commitment to the auth anchor.\n *\n * The OP_RETURN sits at `vout = vaultCount` (right after the per-vault\n * HTLC outputs and before the depositor-claim/change outputs) and\n * pushes the 32-byte `SHA256(authAnchor)`. The script encoding is\n * exactly `OP_RETURN || PUSH32 || <32 bytes>` (34 bytes). A\n * non-conformant WASM build that omitted the OP_RETURN, swapped its\n * position, or changed its push payload would let the depositor\n * obtain a valid bearer token for a Pre-PegIn whose on-chain\n * commitment doesn't actually bind the anchor — degrading the auth\n * from on-chain-bound to a shared secret. Fail closed.\n *\n * @throws If the OP_RETURN is missing, mis-located, mis-encoded, or\n * pushes a payload other than `expectedAuthAnchorHashHex`.\n */\nexport function assertAuthAnchorOpReturn(\n fundedPrePeginTxHex: string,\n vaultCount: number,\n expectedAuthAnchorHashHex: string,\n): void {\n const cleanHex = stripHexPrefix(fundedPrePeginTxHex);\n const tx = bitcoin.Transaction.fromHex(cleanHex);\n\n if (tx.outs.length <= vaultCount) {\n throw new Error(\n `Pre-PegIn auth-anchor OP_RETURN missing: tx has ${tx.outs.length} ` +\n `outputs, expected at least ${vaultCount + 1} (vault outputs + OP_RETURN)`,\n );\n }\n\n const opReturnOutput = tx.outs[vaultCount];\n const script = opReturnOutput.script;\n if (\n script.length !== OP_RETURN_PUSH32_SCRIPT_LEN ||\n script[0] !== OP_RETURN ||\n script[1] !== OP_PUSH32\n ) {\n throw new Error(\n `Pre-PegIn auth-anchor OP_RETURN at vout ${vaultCount} has unexpected ` +\n `script encoding (got ${script.length}-byte script with prefix ` +\n `0x${script.slice(0, Math.min(2, script.length)).toString(\"hex\")}; ` +\n `expected ${OP_RETURN_PUSH32_SCRIPT_LEN}-byte OP_RETURN + PUSH32 layout)`,\n );\n }\n\n const pushedHex = script.slice(2).toString(\"hex\").toLowerCase();\n if (pushedHex !== expectedAuthAnchorHashHex.toLowerCase()) {\n throw new Error(\n `Pre-PegIn auth-anchor OP_RETURN payload mismatch at vout ${vaultCount}: ` +\n `tx pushes ${pushedHex}, expected ${expectedAuthAnchorHashHex}`,\n );\n }\n\n if (opReturnOutput.value !== 0) {\n throw new Error(\n `Pre-PegIn auth-anchor OP_RETURN at vout ${vaultCount} has non-zero ` +\n `value ${opReturnOutput.value}; OP_RETURN outputs must be 0-value`,\n );\n }\n}\n\n/**\n * Scan a funded Pre-PegIn transaction for its auth-anchor commitment\n * (an `OP_RETURN || PUSH32 || <32 bytes>` output with value 0).\n *\n * Returns `{ vout, hash }` when exactly one such output is found.\n * Returns `undefined` when:\n * - the hex is unparseable,\n * - no matching output exists (legacy non-auth-anchored Pre-PegIn),\n * - more than one matching output exists (ambiguous / malformed).\n *\n * Used by the refund orchestrator to (a) locate the on-chain anchor\n * regardless of how many HTLCs preceded it and (b) detect multi-vault\n * funded transactions structurally: the single-vault refund path\n * reconstructs only one hashlock and expects the anchor at vout 1, so\n * any other vout signals a layout this call cannot safely refund.\n */\nexport function findAuthAnchorOpReturn(\n fundedPrePeginTxHex: string,\n): { vout: number; hash: string } | undefined {\n let tx: bitcoin.Transaction;\n try {\n tx = bitcoin.Transaction.fromHex(stripHexPrefix(fundedPrePeginTxHex));\n } catch {\n return undefined;\n }\n\n const hits: { vout: number; hash: string }[] = [];\n for (let i = 0; i < tx.outs.length; i++) {\n const output = tx.outs[i];\n const script = output.script;\n if (\n script.length === OP_RETURN_PUSH32_SCRIPT_LEN &&\n script[0] === OP_RETURN &&\n script[1] === OP_PUSH32 &&\n output.value === 0\n ) {\n hits.push({\n vout: i,\n hash: script.slice(2).toString(\"hex\").toLowerCase(),\n });\n }\n }\n\n return hits.length === 1 ? hits[0] : undefined;\n}\n","/**\n * HTLC Secret / Hashlock Utilities\n *\n * Pure functions for computing and validating SHA-256 hashlocks used in the\n * vault deposit protocol's HTLC (Hash Time Lock Contract).\n *\n * The SDK does NOT generate secrets — that is the caller's responsibility.\n * Today callers use `crypto.getRandomValues(32)`; when the `deriveContextHash`\n * wallet API ships, callers will use `wallet.deriveContextHash(\"babylon-btc-vault\", ctx)`.\n * These utilities work identically regardless of how the secret was produced.\n *\n * On-chain contract validation (BTCVaultRegistry.activateVaultWithSecret):\n * if (sha256(abi.encodePacked(s)) != hashlock) revert InvalidSecret();\n *\n * @module htlc\n */\n\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport type { Hex } from \"viem\";\n\n/** Expected hex length for a 0x-prefixed bytes32 value. */\nconst HEX_BYTES32_LENGTH = 66; // \"0x\" + 64 hex chars\n\n/**\n * Decode a 0x-prefixed hex string to bytes, with strict validation.\n * @throws if the input is not a valid 0x-prefixed hex string\n */\nfunction hexToBytes(hex: Hex): Uint8Array {\n if (!hex.startsWith(\"0x\") && !hex.startsWith(\"0X\")) {\n throw new Error(\"Expected 0x-prefixed hex string\");\n }\n const clean = hex.slice(2);\n if (clean.length % 2 !== 0) {\n throw new Error(`Hex string has odd length: ${clean.length}`);\n }\n if (!/^[0-9a-fA-F]*$/.test(clean)) {\n throw new Error(\"Hex string contains non-hex characters\");\n }\n const bytes = new Uint8Array(clean.length / 2);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Encode a Uint8Array as a 0x-prefixed lowercase hex string.\n */\nfunction bytesToHex(bytes: Uint8Array): Hex {\n return `0x${Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\")}`;\n}\n\n/**\n * Validate that a value is a 0x-prefixed bytes32 (exactly 32 bytes).\n * @throws if the value is not exactly 32 bytes\n */\nfunction assertBytes32(value: Hex, label: string): void {\n if (value.length !== HEX_BYTES32_LENGTH) {\n throw new Error(\n `${label} must be exactly 32 bytes (${HEX_BYTES32_LENGTH} hex chars with 0x prefix), got ${value.length}`,\n );\n }\n}\n\n/**\n * Compute the SHA-256 hashlock from a secret preimage.\n *\n * Matches the on-chain validation: `sha256(abi.encodePacked(s))` where `s` is a `bytes32`.\n * `abi.encodePacked(bytes32)` is just the raw 32 bytes — no ABI padding.\n *\n * @param secret - 0x-prefixed bytes32 secret (66 hex chars)\n * @returns 0x-prefixed bytes32 SHA-256 hash\n * @throws if secret is not exactly 32 bytes\n */\nexport function computeHashlock(secret: Hex): Hex {\n assertBytes32(secret, \"Secret\");\n const secretBytes = hexToBytes(secret);\n const hash = sha256(secretBytes);\n return bytesToHex(hash);\n}\n\n/**\n * Validate that a secret's SHA-256 hash matches the expected hashlock.\n *\n * Use this for client-side pre-validation before sending the activation\n * transaction to avoid wasting gas on a contract revert.\n *\n * @param secret - 0x-prefixed bytes32 secret (66 hex chars)\n * @param hashlock - 0x-prefixed bytes32 expected hashlock from the vault\n * @returns true if SHA-256(secret) matches the hashlock\n * @throws if secret or hashlock is not exactly 32 bytes\n */\nexport function validateSecretAgainstHashlock(\n secret: Hex,\n hashlock: Hex,\n): boolean {\n assertBytes32(secret, \"Secret\");\n assertBytes32(hashlock, \"Hashlock\");\n // Validate hashlock is valid hex (secret is validated inside computeHashlock)\n hexToBytes(hashlock);\n\n const computed = computeHashlock(secret);\n return computed.toLowerCase() === hashlock.toLowerCase();\n}\n","import type { BitcoinWallet } from \"../../../shared/wallets/interfaces\";\n\n// Field docs use /** */ so they survive into the emitted .d.ts — the published\n// package is the only contract the external provider author (#2109) sees.\n\nexport interface DepositTermsVaultGroup {\n /** 0-based; equals the group's position (groups are ascending by vout). */\n readonly htlcVout: number;\n /** x-only hex (64 chars), as validated on-chain upstream. */\n readonly vaultProviderPk: string;\n /** sats */\n readonly vaultAmount: bigint;\n /** sats; floor(vaultAmount * commissionBps / 10_000). */\n readonly commissionFee: bigint;\n /** sats; the same value for every vault. */\n readonly depositorClaimValue: bigint;\n /** sats; the minimum PegIn fee for this graph version. */\n readonly peginMaxFee: bigint;\n}\n\nexport interface DepositTerms {\n /**\n * sat/vB; the tx-graph fee rate (protocolFeeRate), NOT the mempool funding\n * rate. An approving wallet bounds each payout's fee at baseFeeRate x a\n * conservative vsize estimate (v22 §4.9.7.1) — pass the exact graph rate,\n * not an inflated ceiling.\n */\n baseFeeRate: bigint;\n /** Vault-UTXO CSV timelock (blocks). */\n peginCsvTimelock: number;\n /**\n * Payout timelock on the Assert transaction's output 0; comes from the same\n * protocol param (timelockAssert) as peginCsvTimelock.\n */\n payoutTimelock: number;\n /** HTLC refund CSV timelock (blocks). */\n htlcRefundTimelock: number;\n /**\n * 64-char hex in display order. A device-wire encoder must byte-reverse it to\n * the little-endian form the device recomputes and compares against.\n */\n prepeginTxid: string;\n /** sats; the funded Pre-PegIn fee (an approving wallet caps the signed fee at this). */\n prepeginMaxFee: bigint;\n /**\n * x-only hex. Sorted ascending by the upstream on-chain validation\n * (validateOnChainParticipantKeys); the builder passes them through\n * unasserted — the device rejects unsorted lists at intent load.\n */\n keeperPks: readonly string[];\n /**\n * x-only hex, sorted ascending upstream independently of keeperPks (same\n * pass-through contract). Universal challengers only — the full graph\n * challenger set is keeperPks ∪ challengerPks (vault keepers are the local\n * challengers).\n */\n challengerPks: readonly string[];\n /** Per-vault groups, ordered by ascending htlcVout. */\n vaults: readonly DepositTermsVaultGroup[];\n}\n\n/**\n * Implemented only by depositor-approval wallets (e.g. a Ledger vault provider).\n * Either a class field or a prototype method works — the deposit flow spreads\n * the wallet object but forwards this method explicitly at every wrapper site.\n *\n * Seam invariant: never call deriveContextHash between approveDepositTerms and\n * the last terms-bound signature of a connection — deriving while an intent is\n * loaded nullifies it on-device. Design: the SDK owns approval (mirrors its\n * deriveContextHash/signPsbts orchestration); provider-internal and app-driven\n * placements were rejected.\n */\nexport interface DepositTermsApprover {\n approveDepositTerms(terms: DepositTerms): Promise<void>;\n}\n\n/** True when the wallet implements {@link DepositTermsApprover.approveDepositTerms}. */\nexport function supportsDepositApproval(\n wallet: BitcoinWallet,\n): wallet is BitcoinWallet & DepositTermsApprover {\n return typeof (wallet as Partial<DepositTermsApprover>).approveDepositTerms === \"function\";\n}\n\n/**\n * Spreadable forward of `approveDepositTerms` for wallet-wrapper objects.\n * Object spread drops prototype methods, so every `{...wallet}` wrapper site\n * must re-attach the capability explicitly: `...forwardDepositApproval(wallet)`.\n */\nexport function forwardDepositApproval(\n wallet: BitcoinWallet,\n): Partial<DepositTermsApprover> {\n return supportsDepositApproval(wallet)\n ? { approveDepositTerms: (terms) => wallet.approveDepositTerms(terms) }\n : {};\n}\n\nexport interface BuildDepositTermsInputs {\n protocolFeeRate: bigint;\n timelockPegin: number;\n timelockRefund: number;\n prepeginTxid: string;\n prepeginMaxFee: bigint;\n vaultProviderPk: string;\n keeperPks: readonly string[];\n challengerPks: readonly string[];\n commissionBps: number;\n vaultAmounts: readonly bigint[];\n depositorClaimValue: bigint;\n peginMaxFee: bigint;\n}\n","/**\n * Payout Manager\n *\n * High-level manager that orchestrates the payout signing flow by coordinating\n * SDK primitives ({@link buildPayoutPsbt}, {@link extractPayoutSignature})\n * with a user-provided Bitcoin wallet.\n *\n * The Payout transaction references the Assert transaction (input 1).\n *\n * @see {@link PeginManager} - For Steps 1–4 of the peg-in flow\n * @see {@link buildPayoutPsbt} - Lower-level primitive for custom implementations\n * @see {@link extractPayoutSignature} - Extract signatures from signed PSBTs\n *\n * @module managers/PayoutManager\n */\n\nimport type { BitcoinWallet, SignPsbtOptions } from \"../../../shared/wallets\";\nimport {\n assertPsbtUnsignedTxMatches,\n assertScriptPathSchnorrSignature,\n buildPayoutPsbt,\n extractPayoutSignature,\n validateWalletPubkey,\n type Network,\n} from \"../primitives\";\nimport { createTaprootScriptPathSignOptions } from \"../utils/signing\";\n\n/** Payout PSBTs are signed by the depositor on input 0 (Taproot script-path). */\nconst PAYOUT_SIGNED_INPUT_INDEX = 0;\n\n/**\n * Configuration for the PayoutManager.\n */\nexport interface PayoutManagerConfig {\n /**\n * Bitcoin network to use for transactions.\n */\n network: Network;\n\n /**\n * Bitcoin wallet for signing payout transactions.\n */\n btcWallet: BitcoinWallet;\n}\n\n/**\n * Base parameters shared by both payout transaction types.\n */\ninterface SignPayoutBaseParams {\n /**\n * Vault core (tx-graph) version the vault was registered under — the\n * vault's stamped on-chain `vaultCoreVersion`. Forwarded to\n * {@link buildPayoutPsbt} to derive the matching graph's payout scripts.\n */\n vaultCoreVersion: number;\n\n /**\n * Peg-in transaction hex.\n * The original transaction that created the vault output being spent.\n */\n peginTxHex: string;\n\n /**\n * Vault provider's BTC public key (x-only, 64-char hex).\n */\n vaultProviderBtcPubkey: string;\n\n /**\n * Vault keeper BTC public keys (x-only, 64-char hex).\n */\n vaultKeeperBtcPubkeys: string[];\n\n /**\n * Universal challenger BTC public keys (x-only, 64-char hex).\n */\n universalChallengerBtcPubkeys: string[];\n\n /**\n * CSV timelock in blocks for the PegIn output.\n */\n timelockPegin: number;\n\n /**\n * Depositor's BTC public key (x-only, 64-char hex). This MUST be the\n * key registered on-chain for the vault — typically read from\n * `BTCVaultRegistry.getBtcVaultBasicInfo(...).depositorBtcPubKey`.\n *\n * Required: omitting it would degrade `validateWalletPubkey` to a\n * self-comparison, allowing the wrong wallet to produce a signature\n * over a script tree that doesn't match the on-chain UTXO.\n */\n depositorBtcPubkey: string;\n\n /**\n * The on-chain registered depositor payout scriptPubKey (hex, with or without 0x prefix).\n * Used to validate that the VP-provided payout transaction actually pays to the\n * correct depositor payout address before signing.\n */\n registeredPayoutScriptPubKey: string;\n\n /**\n * The claimer's x-only BTC public key for this payout (64-char hex, no prefix).\n * Forwarded to {@link buildPayoutPsbt} for per-role output validation.\n */\n claimerBtcPubkey: string;\n\n /**\n * VP commission in basis points (`1..=9999`). Forwarded to {@link buildPayoutPsbt}.\n */\n commissionBps: number;\n\n /**\n * Version-locked tx-graph fee rate (sat/vB) the graph was built with.\n * Forwarded to {@link buildPayoutPsbt} for the fee band.\n */\n protocolFeeRate: bigint;\n\n /** Security council member count; forwarded to the fee floor (see PayoutParams). */\n councilSize: number;\n\n /**\n * RFC-006 resolved payout destinations, keyed by lowercased x-only operation\n * pubkey. Forwarded verbatim to {@link buildPayoutPsbt}; every VK claimer\n * must be present.\n */\n vkClaimerPayoutScriptPubKeys: Readonly<Record<string, string>>;\n /** RFC-006 VP commission destination. Forwarded to {@link buildPayoutPsbt}. */\n vpCommissionScriptPubKey: string;\n}\n\n/**\n * Parameters for signing a Payout transaction.\n *\n * Payout is used in the challenge path after Assert, when the claimer proves validity.\n * Input 1 references the Assert transaction.\n */\nexport interface SignPayoutParams extends SignPayoutBaseParams {\n /**\n * Payout transaction hex (unsigned).\n * This is the transaction from the vault provider that needs depositor signature.\n */\n payoutTxHex: string;\n\n /**\n * Assert transaction hex.\n * Payout input 1 references Assert output 0.\n */\n assertTxHex: string;\n}\n\n/**\n * Result of signing a payout transaction.\n */\nexport interface PayoutSignatureResult {\n /**\n * 64-byte Schnorr signature (128 hex characters).\n */\n signature: string;\n\n /**\n * Depositor's BTC public key used for signing.\n */\n depositorBtcPubkey: string;\n}\n\n/**\n * High-level manager for payout transaction signing.\n *\n * @remarks\n * After registering your peg-in on Ethereum (Step 3), the vault provider prepares\n * claim/payout transaction pairs. You must sign each payout transaction using this\n * manager and submit the signatures to the vault provider's RPC API.\n *\n * **What happens internally:**\n * 1. Validates your wallet's public key matches the vault's depositor\n * 2. Builds an unsigned PSBT with taproot script path spend info\n * 3. Signs input 0 (the vault UTXO) with your wallet\n * 4. Extracts the 64-byte Schnorr signature\n *\n * **Note:** The payout transaction has 2 inputs. PayoutManager only signs input 0\n * (from the peg-in tx). Input 1 (from the assert tx) is signed by the vault provider.\n *\n * @see {@link PeginManager} - For the complete peg-in flow context\n * @see {@link buildPayoutPsbt} - Lower-level primitive used internally\n * @see {@link extractPayoutSignature} - Signature extraction primitive\n */\nexport class PayoutManager {\n private readonly config: PayoutManagerConfig;\n\n /**\n * Creates a new PayoutManager instance.\n *\n * @param config - Manager configuration including wallet\n */\n constructor(config: PayoutManagerConfig) {\n this.config = config;\n }\n\n /**\n * Signs a Payout transaction and extracts the Schnorr signature.\n *\n * Flow:\n * 1. Vault provider submits Claim transaction\n * 2. Claimer submits Assert transaction to prove validity\n * 3. Payout can be executed (references Assert tx)\n *\n * This method orchestrates the following steps:\n * 1. Get wallet's public key and convert to x-only format\n * 2. Validate wallet pubkey matches on-chain depositor pubkey (if provided)\n * 3. Build unsigned PSBT using primitives\n * 4. Sign PSBT via btcWallet.signPsbt()\n * 5. Extract 64-byte Schnorr signature using primitives\n *\n * The returned signature can be submitted to the vault provider API.\n *\n * @param params - Payout signing parameters\n * @returns Signature result with 64-byte Schnorr signature and depositor pubkey\n * @throws Error if wallet pubkey doesn't match depositor pubkey\n * @throws Error if wallet operations fail or signature extraction fails\n */\n async signPayoutTransaction(\n params: SignPayoutParams,\n ): Promise<PayoutSignatureResult> {\n // Validate wallet pubkey matches depositor and get both formats\n const walletPubkeyRaw = await this.config.btcWallet.getPublicKeyHex();\n const { depositorPubkey } = validateWalletPubkey(\n walletPubkeyRaw,\n params.depositorBtcPubkey,\n );\n\n // Build unsigned PSBT for Payout (uses Assert tx). Per-role output\n // validation happens inside buildPayoutPsbt against the resolved input\n // values.\n const payoutPsbt = await buildPayoutPsbt({\n vaultCoreVersion: params.vaultCoreVersion,\n payoutTxHex: params.payoutTxHex,\n peginTxHex: params.peginTxHex,\n assertTxHex: params.assertTxHex,\n depositorBtcPubkey: depositorPubkey,\n vaultProviderBtcPubkey: params.vaultProviderBtcPubkey,\n vaultKeeperBtcPubkeys: params.vaultKeeperBtcPubkeys,\n universalChallengerBtcPubkeys: params.universalChallengerBtcPubkeys,\n timelockPegin: params.timelockPegin,\n network: this.config.network,\n claimerBtcPubkey: params.claimerBtcPubkey,\n registeredPayoutScriptPubKey: params.registeredPayoutScriptPubKey,\n commissionBps: params.commissionBps,\n protocolFeeRate: params.protocolFeeRate,\n councilSize: params.councilSize,\n vkClaimerPayoutScriptPubKeys: params.vkClaimerPayoutScriptPubKeys,\n vpCommissionScriptPubKey: params.vpCommissionScriptPubKey,\n });\n\n // Sign PSBT via wallet (Taproot script-path spend, input 0 only)\n const signedPsbtHex = await this.config.btcWallet.signPsbt(\n payoutPsbt.psbtHex,\n createTaprootScriptPathSignOptions(walletPubkeyRaw, 1),\n );\n\n assertPsbtUnsignedTxMatches({\n requestedPsbtHex: payoutPsbt.psbtHex,\n returnedPsbtHex: signedPsbtHex,\n });\n\n // Extract Schnorr signature\n const signature = extractPayoutSignature(signedPsbtHex, depositorPubkey);\n // Critical Path #7: verify the signature against a sighash recomputed from\n // the PSBT we built, not the wallet-returned one.\n assertScriptPathSchnorrSignature({\n requestedPsbtHex: payoutPsbt.psbtHex,\n signatureHex: signature,\n signerXOnlyPubkeyHex: depositorPubkey,\n inputIndex: PAYOUT_SIGNED_INPUT_INDEX,\n });\n\n return {\n signature,\n depositorBtcPubkey: depositorPubkey,\n };\n }\n\n /**\n * Gets the configured Bitcoin network.\n *\n * @returns The Bitcoin network (mainnet, testnet, signet, regtest)\n */\n getNetwork(): Network {\n return this.config.network;\n }\n\n /**\n * Checks if the wallet supports batch signing (signPsbts).\n *\n * @returns true if batch signing is supported\n */\n supportsBatchSigning(): boolean {\n return typeof this.config.btcWallet.signPsbts === \"function\";\n }\n\n /**\n * Batch signs multiple payout transactions (1 per claimer).\n * This allows signing all transactions with a single wallet interaction.\n *\n * @param transactions - Array of payout params to sign\n * @returns Array of signature results matching input order\n * @throws Error if wallet doesn't support batch signing\n * @throws Error if any signing operation fails\n */\n async signPayoutTransactionsBatch(transactions: SignPayoutParams[]): Promise<\n Array<{\n payoutSignature: string;\n depositorBtcPubkey: string;\n }>\n > {\n if (!this.supportsBatchSigning()) {\n throw new Error(\n \"Wallet does not support batch signing (signPsbts method not available)\",\n );\n }\n\n // Get wallet pubkey once\n const walletPubkeyRaw = await this.config.btcWallet.getPublicKeyHex();\n\n // Build all PSBTs (1 per claimer)\n const psbtsToSign: string[] = [];\n const signOptions: SignPsbtOptions[] = [];\n const depositorPubkeys: string[] = [];\n\n for (const tx of transactions) {\n // Validate wallet pubkey matches depositor\n const { depositorPubkey } = validateWalletPubkey(\n walletPubkeyRaw,\n tx.depositorBtcPubkey,\n );\n depositorPubkeys.push(depositorPubkey);\n\n // Build Payout PSBT (output validation runs inside buildPayoutPsbt\n // against resolved input values).\n const payoutPsbt = await buildPayoutPsbt({\n vaultCoreVersion: tx.vaultCoreVersion,\n payoutTxHex: tx.payoutTxHex,\n peginTxHex: tx.peginTxHex,\n assertTxHex: tx.assertTxHex,\n depositorBtcPubkey: depositorPubkey,\n vaultProviderBtcPubkey: tx.vaultProviderBtcPubkey,\n vaultKeeperBtcPubkeys: tx.vaultKeeperBtcPubkeys,\n universalChallengerBtcPubkeys: tx.universalChallengerBtcPubkeys,\n timelockPegin: tx.timelockPegin,\n network: this.config.network,\n claimerBtcPubkey: tx.claimerBtcPubkey,\n registeredPayoutScriptPubKey: tx.registeredPayoutScriptPubKey,\n commissionBps: tx.commissionBps,\n protocolFeeRate: tx.protocolFeeRate,\n councilSize: tx.councilSize,\n vkClaimerPayoutScriptPubKeys: tx.vkClaimerPayoutScriptPubKeys,\n vpCommissionScriptPubKey: tx.vpCommissionScriptPubKey,\n });\n psbtsToSign.push(payoutPsbt.psbtHex);\n signOptions.push(createTaprootScriptPathSignOptions(walletPubkeyRaw, 1));\n }\n\n // Batch sign all PSBTs with single wallet interaction\n const signedPsbts = await this.config.btcWallet.signPsbts!(\n psbtsToSign,\n signOptions,\n );\n\n // Validate that wallet returned the expected number of signed PSBTs\n if (signedPsbts.length !== transactions.length) {\n throw new Error(\n `Expected ${transactions.length} signed PSBTs but received ${signedPsbts.length}`,\n );\n }\n\n // Extract signatures from signed PSBTs\n const results: Array<{\n payoutSignature: string;\n depositorBtcPubkey: string;\n }> = [];\n\n for (let i = 0; i < transactions.length; i++) {\n const depositorPubkey = depositorPubkeys[i];\n assertPsbtUnsignedTxMatches({\n requestedPsbtHex: psbtsToSign[i],\n returnedPsbtHex: signedPsbts[i],\n });\n const payoutSignature = extractPayoutSignature(\n signedPsbts[i],\n depositorPubkey,\n );\n assertScriptPathSchnorrSignature({\n requestedPsbtHex: psbtsToSign[i],\n signatureHex: payoutSignature,\n signerXOnlyPubkeyHex: depositorPubkey,\n inputIndex: PAYOUT_SIGNED_INPUT_INDEX,\n });\n\n results.push({\n payoutSignature,\n depositorBtcPubkey: depositorPubkey,\n });\n }\n\n return results;\n }\n}\n","/**\n * Wallet-signing helper that routes a lone PSBT to `signPsbt`, prefers native\n * `signPsbts` for real batches, and falls back to sequential `signPsbt` for\n * wallets that don't implement batch signing.\n *\n * @module managers/pegin/signPsbtsWithFallback\n */\n\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../../../../shared/wallets\";\n\n/**\n * Sign one or more PSBTs against a wallet.\n *\n * A single PSBT is always signed via `signPsbt`, never the batch endpoint: it's\n * one wallet interaction either way, and `signPsbt` is the universally-required\n * wallet method (batch `signPsbts` is optional), so single-sign is the portable\n * choice — some integrations (notably MPC / institutional wallets) prefer it.\n * For a real batch (>1), wallets exposing native `signPsbts` (e.g. UniSat) sign\n * in one interaction; others loop `signPsbt`.\n *\n * @throws If native `signPsbts` returns a different number of signed PSBTs\n * than were submitted.\n */\nexport async function signPsbtsWithFallback(\n wallet: BitcoinWallet,\n psbtsHexes: string[],\n options?: SignPsbtOptions[],\n): Promise<string[]> {\n if (psbtsHexes.length === 1) {\n return [await wallet.signPsbt(psbtsHexes[0], options?.[0])];\n }\n\n if (typeof wallet.signPsbts === \"function\") {\n const signedPsbts = await wallet.signPsbts(psbtsHexes, options);\n if (signedPsbts.length !== psbtsHexes.length) {\n throw new Error(\n `Expected ${psbtsHexes.length} signed PSBTs but received ${signedPsbts.length}`,\n );\n }\n return signedPsbts;\n }\n\n const signedPsbts: string[] = [];\n for (let i = 0; i < psbtsHexes.length; i++) {\n signedPsbts.push(await wallet.signPsbt(psbtsHexes[i], options?.[i]));\n }\n return signedPsbts;\n}\n"],"names":["OP_RETURN","OP_PUSH32","OP_RETURN_PUSH32_SCRIPT_LEN","assertAuthAnchorOpReturn","fundedPrePeginTxHex","vaultCount","expectedAuthAnchorHashHex","cleanHex","stripHexPrefix","tx","bitcoin","opReturnOutput","script","pushedHex","findAuthAnchorOpReturn","hits","i","output","HEX_BYTES32_LENGTH","hexToBytes","hex","clean","bytes","bytesToHex","b","assertBytes32","value","label","computeHashlock","secret","secretBytes","hash","sha256","validateSecretAgainstHashlock","hashlock","supportsDepositApproval","wallet","forwardDepositApproval","terms","PAYOUT_SIGNED_INPUT_INDEX","PayoutManager","config","__publicField","params","walletPubkeyRaw","depositorPubkey","validateWalletPubkey","payoutPsbt","buildPayoutPsbt","signedPsbtHex","createTaprootScriptPathSignOptions","assertPsbtUnsignedTxMatches","signature","extractPayoutSignature","assertScriptPathSchnorrSignature","transactions","psbtsToSign","signOptions","depositorPubkeys","signedPsbts","results","payoutSignature","signPsbtsWithFallback","psbtsHexes","options"],"mappings":";;;;;;;;;AAYA,MAAMA,IAAY,KAEZC,IAAY,IAEZC,IAA8B;AAmB7B,SAASC,EACdC,GACAC,GACAC,GACM;AACN,QAAMC,IAAWC,EAAeJ,CAAmB,GAC7CK,IAAKC,EAAQ,YAAY,QAAQH,CAAQ;AAE/C,MAAIE,EAAG,KAAK,UAAUJ;AACpB,UAAM,IAAI;AAAA,MACR,mDAAmDI,EAAG,KAAK,MAAM,+BACjCJ,IAAa,CAAC;AAAA,IAAA;AAIlD,QAAMM,IAAiBF,EAAG,KAAKJ,CAAU,GACnCO,IAASD,EAAe;AAC9B,MACEC,EAAO,WAAWV,KAClBU,EAAO,CAAC,MAAMZ,KACdY,EAAO,CAAC,MAAMX;AAEd,UAAM,IAAI;AAAA,MACR,2CAA2CI,CAAU,wCAC3BO,EAAO,MAAM,8BAChCA,EAAO,MAAM,GAAG,KAA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,IAAwB,CAAA;AAC9B,WAAS3C,IAAI,GAAGA,IAAI+C,EAAW,QAAQ/C;AACrC,IAAA2C,EAAY,KAAK,MAAMvB,EAAO,SAAS2B,EAAW/C,CAAC,GAAGgD,KAAA,gBAAAA,EAAUhD,EAAE,CAAC;AAErE,SAAO2C;AACT;"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { resolveProtocolAddresses, type ProtocolAddresses, } from './contract-address-resolver';
|
|
2
|
-
export {
|
|
2
|
+
export { assertOnChainBtcPubkey } from './onChainBtcPubkey';
|
|
3
|
+
export { ViemOperationKeyReader, type OperationKeyContracts, } from './operation-key-reader';
|
|
3
4
|
export { ViemProtocolParamsReader } from './protocol-params-reader';
|
|
5
|
+
export { validateOffchainParams, validatePegInConfiguration, validateTBVProtocolParams, } from './protocol-params-validation';
|
|
4
6
|
export { ViemUniversalChallengerReader, ViemVaultKeeperReader, } from './signer-set-reader';
|
|
5
|
-
export { ViemVaultRegistryReader } from './vault-registry-reader';
|
|
6
7
|
export { OnChainBtcVaultStatus } from './types';
|
|
7
|
-
export type { AddressBTCKeyPair, AllOffchainParamsData, OnChainBtcPubkey, OnSkippedOffchainParamsVersion, PegInConfiguration, ProtocolParamsReader, TBVProtocolParams, UniversalChallengerReader, VaultBasicInfo, VaultData, VaultKeeperReader, VaultProtocolInfo, VaultRegistryReader, VersionedOffchainParams, } from './types';
|
|
8
|
+
export type { AddressBTCKeyPair, AllOffchainParamsData, KeyEpochs, OnChainBtcPubkey, OnSkippedOffchainParamsVersion, OperationKeyQuery, OperationKeyReader, PegInConfiguration, ProtocolParamsReader, RawOperationKeys, RawPayoutScripts, TBVProtocolParams, UniversalChallengerReader, VaultBasicInfo, VaultData, VaultKeeperReader, VaultProtocolInfo, VaultRegistryReader, VersionedOffchainParams, } from './types';
|
|
9
|
+
export { ViemVaultRegistryReader } from './vault-registry-reader';
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/clients/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,iBAAiB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/clients/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,iBAAiB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,SAAS,EACT,gBAAgB,EAChB,8BAA8B,EAC9B,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EACzB,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { OnChainBtcPubkey } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Validate a registry-returned `bytes32` as an x-only BTC pubkey and mint the
|
|
5
|
+
* brand. Checks length, hex form, and secp256k1 curve membership. Returns
|
|
6
|
+
* 64-char lowercase hex without the `0x` prefix.
|
|
7
|
+
*
|
|
8
|
+
* `label` identifies the read site in error messages (e.g.
|
|
9
|
+
* `getVaultProviderBTCKey (vp=0x…)`), so a failure names which participant and
|
|
10
|
+
* which getter produced it.
|
|
11
|
+
*
|
|
12
|
+
* A zero hash fails the curve check, so an unregistered operator or an epoch
|
|
13
|
+
* with no bonded key surfaces as an error rather than a silent all-zero key.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assertOnChainBtcPubkey(value: Hex, label: string): OnChainBtcPubkey;
|
|
16
|
+
//# sourceMappingURL=onChainBtcPubkey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onChainBtcPubkey.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/clients/eth/onChainBtcPubkey.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,MAAM,GACZ,gBAAgB,CAclB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Address, PublicClient } from 'viem';
|
|
2
|
+
import { KeyEpochs, OperationKeyQuery, OperationKeyReader, RawOperationKeys, RawPayoutScripts } from './types';
|
|
3
|
+
/** Addresses of the three registries an operation-key resolution spans. */
|
|
4
|
+
export interface OperationKeyContracts {
|
|
5
|
+
btcVaultRegistry: Address;
|
|
6
|
+
applicationRegistry: Address;
|
|
7
|
+
protocolParams: Address;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reads RFC-006 operation keys and payout scripts.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```ts
|
|
14
|
+
* const reader = new ViemOperationKeyReader(publicClient, contracts);
|
|
15
|
+
* const keys = await reader.getCurrentOperationKeys(query);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class ViemOperationKeyReader implements OperationKeyReader {
|
|
19
|
+
private publicClient;
|
|
20
|
+
private contracts;
|
|
21
|
+
constructor(publicClient: PublicClient, contracts: OperationKeyContracts);
|
|
22
|
+
/**
|
|
23
|
+
* One multicall, `allowFailure: false`, so every key in the set is read at
|
|
24
|
+
* the same block. A rotation landing between two separate `eth_call`s would
|
|
25
|
+
* otherwise produce a mixed-epoch key set and a lock no counterparty agrees
|
|
26
|
+
* with.
|
|
27
|
+
*/
|
|
28
|
+
private readAll;
|
|
29
|
+
getCurrentOperationKeys(query: OperationKeyQuery): Promise<RawOperationKeys>;
|
|
30
|
+
getOperationKeysAtEpochs(query: OperationKeyQuery, epochs: KeyEpochs): Promise<RawOperationKeys>;
|
|
31
|
+
getPayoutScriptsAtEpochs(query: OperationKeyQuery, epochs: KeyEpochs): Promise<RawPayoutScripts>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=operation-key-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-key-reader.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/clients/eth/operation-key-reader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAO,OAAO,EAAO,YAAY,EAAE,MAAM,MAAM,CAAC;AAK5D,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,2EAA2E;AAC3E,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,cAAc,EAAE,OAAO,CAAC;CACzB;AA+BD;;;;;;;;GAQG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;IAE7D,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,SAAS;gBADT,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,qBAAqB;IAG1C;;;;;OAKG;YACW,OAAO;IASf,uBAAuB,CAC3B,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC,gBAAgB,CAAC;IAyBtB,wBAAwB,CAC5B,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,gBAAgB,CAAC;IAsCtB,wBAAwB,CAC5B,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,gBAAgB,CAAC;CA8B7B"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Address, Hex } from 'viem';
|
|
2
2
|
declare const onChainBtcPubkeyBrand: unique symbol;
|
|
3
3
|
/**
|
|
4
|
-
* 64-char lowercase hex (no `0x`) x-only BTC pubkey sourced from
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 64-char lowercase hex (no `0x`) x-only BTC pubkey sourced from an on-chain
|
|
5
|
+
* registry. Minted only by `assertOnChainBtcPubkey`, which is the shared
|
|
6
|
+
* validator behind both producers:
|
|
7
|
+
* {@link VaultRegistryReader.getVaultProviderBtcPubKey} (the fixed
|
|
8
|
+
* registration key) and {@link OperationKeyReader} (RFC-006 operation keys,
|
|
9
|
+
* resolved current or at a vault's frozen epoch).
|
|
7
10
|
*
|
|
8
11
|
* @stability frozen
|
|
9
12
|
*/
|
|
@@ -61,6 +64,27 @@ export interface VaultData {
|
|
|
61
64
|
basic: VaultBasicInfo;
|
|
62
65
|
protocol: VaultProtocolInfo;
|
|
63
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* RFC-006 operation-key epochs a vault froze at `submitPeginRequest`.
|
|
69
|
+
*
|
|
70
|
+
* Each registry keeps a monotonic epoch counter that every key/payout setter
|
|
71
|
+
* pre-increments. A vault stamps the counters live at its creation, and every
|
|
72
|
+
* participant resolves "which key did this vault bond?" by asking the registry
|
|
73
|
+
* for the key whose appended version is the latest stamped `<=` this epoch. A
|
|
74
|
+
* rotation after the vault was created therefore never moves its keys.
|
|
75
|
+
*
|
|
76
|
+
* `uint64` — kept as `bigint` end-to-end and passed straight back to the
|
|
77
|
+
* `...AtEpoch` getters, never narrowed through `Number`.
|
|
78
|
+
*
|
|
79
|
+
* Only ever read through {@link VaultRegistryReader.getVaultKeyEpochs}, which
|
|
80
|
+
* uses the extended ABI. See `BTCVaultRegistryKeyEpochs.abi.ts` for why that
|
|
81
|
+
* read is quarantined to its own ABI.
|
|
82
|
+
*/
|
|
83
|
+
export interface KeyEpochs {
|
|
84
|
+
vpKeyEpoch: bigint;
|
|
85
|
+
appKeeperKeyEpoch: bigint;
|
|
86
|
+
ucKeyEpoch: bigint;
|
|
87
|
+
}
|
|
64
88
|
/** Interface for reading vault data from the BTCVaultRegistry contract. */
|
|
65
89
|
export interface VaultRegistryReader {
|
|
66
90
|
getVaultBasicInfo(vaultId: Hex): Promise<VaultBasicInfo>;
|
|
@@ -83,6 +107,24 @@ export interface VaultRegistryReader {
|
|
|
83
107
|
* is missing on-chain.
|
|
84
108
|
*/
|
|
85
109
|
getOffchainParamsVersionsByVaultIds(vaultIds: readonly Hex[]): Promise<number[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Read a vault's frozen RFC-006 key epochs.
|
|
112
|
+
*
|
|
113
|
+
* Uses the extended `getBtcVaultProtocolInfo` ABI. Against a registry that
|
|
114
|
+
* predates RFC-006 this returns silent garbage for a populated vault rather
|
|
115
|
+
* than throwing, so it must only be called against an RFC-006 registry —
|
|
116
|
+
* a deployment invariant, not something this call can detect. See
|
|
117
|
+
* `BTCVaultRegistryKeyEpochs.abi.ts`.
|
|
118
|
+
*/
|
|
119
|
+
getVaultKeyEpochs(vaultId: Hex): Promise<KeyEpochs>;
|
|
120
|
+
/** {@link getVaultKeyEpochs} for many vaults in one multicall. */
|
|
121
|
+
getVaultKeyEpochsBatch(vaultIds: readonly Hex[]): Promise<KeyEpochs[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Read a vault provider's *current* RFC-006 operation BTC key — the key its
|
|
124
|
+
* server signs auth tokens with. Falls back to the registration key when the
|
|
125
|
+
* provider has never rotated.
|
|
126
|
+
*/
|
|
127
|
+
getCurrentVaultProviderOperationBtcKey(vpAddress: Address): Promise<OnChainBtcPubkey>;
|
|
86
128
|
}
|
|
87
129
|
/**
|
|
88
130
|
* TBV protocol parameters from the ProtocolParams contract.
|
|
@@ -203,5 +245,82 @@ export interface UniversalChallengerReader {
|
|
|
203
245
|
getCurrentUniversalChallengers(): Promise<AddressBTCKeyPair[]>;
|
|
204
246
|
getLatestUniversalChallengersVersion(): Promise<number>;
|
|
205
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The participants whose operation keys are being resolved, and the roster
|
|
250
|
+
* they are resolved against.
|
|
251
|
+
*
|
|
252
|
+
* A roster entry's `ethAddress` is the operator's **admin** address — the
|
|
253
|
+
* lookup key for its key history — and its `btcPubKey` is the operator's
|
|
254
|
+
* **genesis** key. Both are needed: the `...AtEpochOrGenesis` getters take the
|
|
255
|
+
* roster key explicitly because the correct genesis for a keeper/challenger is
|
|
256
|
+
* its key in the vault's *frozen membership version*, which an operator that
|
|
257
|
+
* was later dropped from the roster no longer has a current entry for.
|
|
258
|
+
*/
|
|
259
|
+
export interface OperationKeyQuery {
|
|
260
|
+
vaultProviderEthAddress: Address;
|
|
261
|
+
/**
|
|
262
|
+
* The VP's genesis (registration) key, from `getVaultProviderBTCKey`.
|
|
263
|
+
*
|
|
264
|
+
* The VP has no roster entry to carry a genesis key the way keepers and
|
|
265
|
+
* challengers do, so it is supplied here. Every call site already reads it:
|
|
266
|
+
* it is what the indexer hint is compared against, and what makes the VP's
|
|
267
|
+
* `rotated` flag mean the same thing as everyone else's.
|
|
268
|
+
*/
|
|
269
|
+
vaultProviderGenesisBtcPubkey: Hex;
|
|
270
|
+
applicationEntryPoint: Address;
|
|
271
|
+
/** Keeper roster at the membership version being resolved against. */
|
|
272
|
+
vaultKeepers: readonly AddressBTCKeyPair[];
|
|
273
|
+
/** Challenger roster at the membership version being resolved against. */
|
|
274
|
+
universalChallengers: readonly AddressBTCKeyPair[];
|
|
275
|
+
}
|
|
276
|
+
/** Raw registry-returned operation keys, index-aligned with the query rosters. */
|
|
277
|
+
export interface RawOperationKeys {
|
|
278
|
+
vaultProvider: Hex;
|
|
279
|
+
vaultKeepers: Hex[];
|
|
280
|
+
universalChallengers: Hex[];
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Registry-returned payout scriptPubKeys, index-aligned with the query
|
|
284
|
+
* rosters. `universalChallengers` has no counterpart: a UC is never a claimer,
|
|
285
|
+
* so it has no payout script.
|
|
286
|
+
*/
|
|
287
|
+
export interface RawPayoutScripts {
|
|
288
|
+
vaultProvider: Hex;
|
|
289
|
+
vaultKeepers: Hex[];
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Reads RFC-006 operation keys and payout scripts across all three registries
|
|
293
|
+
* (BTCVaultRegistry, ApplicationRegistry, ProtocolParams).
|
|
294
|
+
*
|
|
295
|
+
* Every method resolves the whole participant set in a **single** multicall so
|
|
296
|
+
* the keys are pinned to one block. That atomicity is load-bearing: a rotation
|
|
297
|
+
* landing between two `eth_call`s would yield a self-inconsistent key set that
|
|
298
|
+
* builds a lock no counterparty agrees with.
|
|
299
|
+
*/
|
|
300
|
+
export interface OperationKeyReader {
|
|
301
|
+
/**
|
|
302
|
+
* Resolve every participant's *current* operation key.
|
|
303
|
+
*
|
|
304
|
+
* Used for new peg-ins and for the VP auth pin. Needs no epoch read at all —
|
|
305
|
+
* each registry's `getCurrentOperationBtcKey` resolves its own genesis
|
|
306
|
+
* fallback, so an operator that never rotated yields its registration key.
|
|
307
|
+
*/
|
|
308
|
+
getCurrentOperationKeys(query: OperationKeyQuery): Promise<RawOperationKeys>;
|
|
309
|
+
/**
|
|
310
|
+
* Resolve every participant's operation key bonded at a vault's frozen
|
|
311
|
+
* epochs. Used for every existing-vault path (resume, payout, refund).
|
|
312
|
+
*/
|
|
313
|
+
getOperationKeysAtEpochs(query: OperationKeyQuery, epochs: KeyEpochs): Promise<RawOperationKeys>;
|
|
314
|
+
/**
|
|
315
|
+
* Resolve the VP's commission payout script and each keeper's payout script
|
|
316
|
+
* at a vault's frozen epochs.
|
|
317
|
+
*
|
|
318
|
+
* The registry backfills BIP-86 P2TR of the epoch's operation key for any
|
|
319
|
+
* operator that never called `setPayoutScript`, so this returns byte-identical
|
|
320
|
+
* results to local BIP-86 derivation until an operator registers a custom
|
|
321
|
+
* script.
|
|
322
|
+
*/
|
|
323
|
+
getPayoutScriptsAtEpochs(query: OperationKeyQuery, epochs: KeyEpochs): Promise<RawPayoutScripts>;
|
|
324
|
+
}
|
|
206
325
|
export {};
|
|
207
326
|
//# sourceMappingURL=types.d.ts.map
|