@bitgo-beta/babylonlabs-io-btc-staking-ts 0.4.0-bitgo.1
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/LICENSE +168 -0
- package/README.md +1 -0
- package/dist/index.cjs +2521 -0
- package/dist/index.d.cts +937 -0
- package/dist/index.js +2455 -0
- package/package.json +49 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,937 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { ProofOfPossessionBTC } from '@babylonlabs-io/babylon-proto-ts/dist/generated/babylon/btcstaking/v1/pop';
|
|
4
|
+
import { PsbtInputExtended } from 'bip174/src/lib/interfaces';
|
|
5
|
+
import { Psbt, Transaction, networks } from 'bitcoinjs-lib';
|
|
6
|
+
import { Input } from 'bitcoinjs-lib/src/transaction';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base interface for staking parameters that define the rules and constraints
|
|
10
|
+
* for staking operations.
|
|
11
|
+
*/
|
|
12
|
+
export interface StakingParams {
|
|
13
|
+
covenantNoCoordPks: string[];
|
|
14
|
+
covenantQuorum: number;
|
|
15
|
+
unbondingTime: number;
|
|
16
|
+
unbondingFeeSat: number;
|
|
17
|
+
maxStakingAmountSat: number;
|
|
18
|
+
minStakingAmountSat: number;
|
|
19
|
+
maxStakingTimeBlocks: number;
|
|
20
|
+
minStakingTimeBlocks: number;
|
|
21
|
+
slashing?: {
|
|
22
|
+
slashingPkScriptHex: string;
|
|
23
|
+
slashingRate: number;
|
|
24
|
+
minSlashingTxFeeSat: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extension of StakingParams that includes activation height and version information.
|
|
29
|
+
* These parameters are used to identify and select the appropriate staking rules at
|
|
30
|
+
* different blockchain heights, but do not affect the actual staking transaction content.
|
|
31
|
+
*/
|
|
32
|
+
export interface VersionedStakingParams extends StakingParams {
|
|
33
|
+
btcActivationHeight: number;
|
|
34
|
+
version: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Extension of VersionedStakingParams that includes a tag field for observability.
|
|
38
|
+
*/
|
|
39
|
+
export interface ObservableVersionedStakingParams extends VersionedStakingParams {
|
|
40
|
+
tag: string;
|
|
41
|
+
}
|
|
42
|
+
export interface UTXO {
|
|
43
|
+
txid: string;
|
|
44
|
+
vout: number;
|
|
45
|
+
value: number;
|
|
46
|
+
scriptPubKey: string;
|
|
47
|
+
rawTxHex?: string;
|
|
48
|
+
redeemScript?: string;
|
|
49
|
+
witnessScript?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface StakingScripts {
|
|
52
|
+
timelockScript: Buffer;
|
|
53
|
+
unbondingScript: Buffer;
|
|
54
|
+
slashingScript: Buffer;
|
|
55
|
+
unbondingTimelockScript: Buffer;
|
|
56
|
+
}
|
|
57
|
+
export declare class StakingScriptData {
|
|
58
|
+
stakerKey: Buffer;
|
|
59
|
+
finalityProviderKeys: Buffer[];
|
|
60
|
+
covenantKeys: Buffer[];
|
|
61
|
+
covenantThreshold: number;
|
|
62
|
+
stakingTimeLock: number;
|
|
63
|
+
unbondingTimeLock: number;
|
|
64
|
+
constructor(stakerKey: Buffer, finalityProviderKeys: Buffer[], covenantKeys: Buffer[], covenantThreshold: number, stakingTimelock: number, unbondingTimelock: number);
|
|
65
|
+
/**
|
|
66
|
+
* Validates the staking script.
|
|
67
|
+
* @returns {boolean} Returns true if the staking script is valid, otherwise false.
|
|
68
|
+
*/
|
|
69
|
+
validate(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Builds a timelock script.
|
|
72
|
+
* @param timelock - The timelock value to encode in the script.
|
|
73
|
+
* @returns {Buffer} containing the compiled timelock script.
|
|
74
|
+
*/
|
|
75
|
+
buildTimelockScript(timelock: number): Buffer;
|
|
76
|
+
/**
|
|
77
|
+
* Builds the staking timelock script.
|
|
78
|
+
* Only holder of private key for given pubKey can spend after relative lock time
|
|
79
|
+
* Creates the timelock script in the form:
|
|
80
|
+
* <stakerPubKey>
|
|
81
|
+
* OP_CHECKSIGVERIFY
|
|
82
|
+
* <stakingTimeBlocks>
|
|
83
|
+
* OP_CHECKSEQUENCEVERIFY
|
|
84
|
+
* @returns {Buffer} The staking timelock script.
|
|
85
|
+
*/
|
|
86
|
+
buildStakingTimelockScript(): Buffer;
|
|
87
|
+
/**
|
|
88
|
+
* Builds the unbonding timelock script.
|
|
89
|
+
* Creates the unbonding timelock script in the form:
|
|
90
|
+
* <stakerPubKey>
|
|
91
|
+
* OP_CHECKSIGVERIFY
|
|
92
|
+
* <unbondingTimeBlocks>
|
|
93
|
+
* OP_CHECKSEQUENCEVERIFY
|
|
94
|
+
* @returns {Buffer} The unbonding timelock script.
|
|
95
|
+
*/
|
|
96
|
+
buildUnbondingTimelockScript(): Buffer;
|
|
97
|
+
/**
|
|
98
|
+
* Builds the unbonding script in the form:
|
|
99
|
+
* buildSingleKeyScript(stakerPk, true) ||
|
|
100
|
+
* buildMultiKeyScript(covenantPks, covenantThreshold, false)
|
|
101
|
+
* || means combining the scripts
|
|
102
|
+
* @returns {Buffer} The unbonding script.
|
|
103
|
+
*/
|
|
104
|
+
buildUnbondingScript(): Buffer;
|
|
105
|
+
/**
|
|
106
|
+
* Builds the slashing script for staking in the form:
|
|
107
|
+
* buildSingleKeyScript(stakerPk, true) ||
|
|
108
|
+
* buildMultiKeyScript(finalityProviderPKs, 1, true) ||
|
|
109
|
+
* buildMultiKeyScript(covenantPks, covenantThreshold, false)
|
|
110
|
+
* || means combining the scripts
|
|
111
|
+
* The slashing script is a combination of single-key and multi-key scripts.
|
|
112
|
+
* The single-key script is used for staker key verification.
|
|
113
|
+
* The multi-key script is used for finality provider key verification and covenant key verification.
|
|
114
|
+
* @returns {Buffer} The slashing script as a Buffer.
|
|
115
|
+
*/
|
|
116
|
+
buildSlashingScript(): Buffer;
|
|
117
|
+
/**
|
|
118
|
+
* Builds the staking scripts.
|
|
119
|
+
* @returns {StakingScripts} The staking scripts.
|
|
120
|
+
*/
|
|
121
|
+
buildScripts(): StakingScripts;
|
|
122
|
+
/**
|
|
123
|
+
* Builds a single key script in the form:
|
|
124
|
+
* buildSingleKeyScript creates a single key script
|
|
125
|
+
* <pk> OP_CHECKSIGVERIFY (if withVerify is true)
|
|
126
|
+
* <pk> OP_CHECKSIG (if withVerify is false)
|
|
127
|
+
* @param pk - The public key buffer.
|
|
128
|
+
* @param withVerify - A boolean indicating whether to include the OP_CHECKSIGVERIFY opcode.
|
|
129
|
+
* @returns The compiled script buffer.
|
|
130
|
+
*/
|
|
131
|
+
buildSingleKeyScript(pk: Buffer, withVerify: boolean): Buffer;
|
|
132
|
+
/**
|
|
133
|
+
* Builds a multi-key script in the form:
|
|
134
|
+
* <pk1> OP_CHEKCSIG <pk2> OP_CHECKSIGADD <pk3> OP_CHECKSIGADD ... <pkN> OP_CHECKSIGADD <threshold> OP_NUMEQUAL
|
|
135
|
+
* <withVerify -> OP_NUMEQUALVERIFY>
|
|
136
|
+
* It validates whether provided keys are unique and the threshold is not greater than number of keys
|
|
137
|
+
* If there is only one key provided it will return single key sig script
|
|
138
|
+
* @param pks - An array of public keys.
|
|
139
|
+
* @param threshold - The required number of valid signers.
|
|
140
|
+
* @param withVerify - A boolean indicating whether to include the OP_VERIFY opcode.
|
|
141
|
+
* @returns The compiled multi-key script as a Buffer.
|
|
142
|
+
* @throws {Error} If no keys are provided, if the required number of valid signers is greater than the number of provided keys, or if duplicate keys are provided.
|
|
143
|
+
*/
|
|
144
|
+
buildMultiKeyScript(pks: Buffer[], threshold: number, withVerify: boolean): Buffer;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* PsbtResult is an object containing a partially signed transaction and its fee
|
|
148
|
+
*/
|
|
149
|
+
export interface PsbtResult {
|
|
150
|
+
psbt: Psbt;
|
|
151
|
+
fee: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* TransactionResult is an object containing an unsigned transaction and its fee
|
|
155
|
+
*/
|
|
156
|
+
export interface TransactionResult {
|
|
157
|
+
transaction: Transaction;
|
|
158
|
+
fee: number;
|
|
159
|
+
}
|
|
160
|
+
export interface StakerInfo {
|
|
161
|
+
address: string;
|
|
162
|
+
publicKeyNoCoordHex: string;
|
|
163
|
+
}
|
|
164
|
+
export declare class Staking {
|
|
165
|
+
network: networks.Network;
|
|
166
|
+
stakerInfo: StakerInfo;
|
|
167
|
+
params: StakingParams;
|
|
168
|
+
finalityProviderPkNoCoordHex: string;
|
|
169
|
+
stakingTimelock: number;
|
|
170
|
+
constructor(network: networks.Network, stakerInfo: StakerInfo, params: StakingParams, finalityProviderPkNoCoordHex: string, stakingTimelock: number);
|
|
171
|
+
/**
|
|
172
|
+
* buildScripts builds the staking scripts for the staking transaction.
|
|
173
|
+
* Note: different staking types may have different scripts.
|
|
174
|
+
* e.g the observable staking script has a data embed script.
|
|
175
|
+
*
|
|
176
|
+
* @returns {StakingScripts} - The staking scripts.
|
|
177
|
+
*/
|
|
178
|
+
buildScripts(): StakingScripts;
|
|
179
|
+
/**
|
|
180
|
+
* Create a staking transaction for staking.
|
|
181
|
+
*
|
|
182
|
+
* @param {number} stakingAmountSat - The amount to stake in satoshis.
|
|
183
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
184
|
+
* transaction.
|
|
185
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
186
|
+
* @returns {TransactionResult} - An object containing the unsigned
|
|
187
|
+
* transaction, and fee
|
|
188
|
+
* @throws {StakingError} - If the transaction cannot be built
|
|
189
|
+
*/
|
|
190
|
+
createStakingTransaction(stakingAmountSat: number, inputUTXOs: UTXO[], feeRate: number): TransactionResult;
|
|
191
|
+
/**
|
|
192
|
+
* Create a staking psbt based on the existing staking transaction.
|
|
193
|
+
*
|
|
194
|
+
* @param {Transaction} stakingTx - The staking transaction.
|
|
195
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
196
|
+
* transaction. The UTXOs that were used to create the staking transaction should
|
|
197
|
+
* be included in this array.
|
|
198
|
+
* @returns {Psbt} - The psbt.
|
|
199
|
+
*/
|
|
200
|
+
toStakingPsbt(stakingTx: Transaction, inputUTXOs: UTXO[]): Psbt;
|
|
201
|
+
/**
|
|
202
|
+
* Create an unbonding transaction for staking.
|
|
203
|
+
*
|
|
204
|
+
* @param {Transaction} stakingTx - The staking transaction to unbond.
|
|
205
|
+
* @returns {TransactionResult} - An object containing the unsigned
|
|
206
|
+
* transaction, and fee
|
|
207
|
+
* @throws {StakingError} - If the transaction cannot be built
|
|
208
|
+
*/
|
|
209
|
+
createUnbondingTransaction(stakingTx: Transaction): TransactionResult;
|
|
210
|
+
/**
|
|
211
|
+
* Create an unbonding psbt based on the existing unbonding transaction and
|
|
212
|
+
* staking transaction.
|
|
213
|
+
*
|
|
214
|
+
* @param {Transaction} unbondingTx - The unbonding transaction.
|
|
215
|
+
* @param {Transaction} stakingTx - The staking transaction.
|
|
216
|
+
*
|
|
217
|
+
* @returns {Psbt} - The psbt.
|
|
218
|
+
*/
|
|
219
|
+
toUnbondingPsbt(unbondingTx: Transaction, stakingTx: Transaction): Psbt;
|
|
220
|
+
/**
|
|
221
|
+
* Creates a withdrawal transaction that spends from an unbonding or slashing
|
|
222
|
+
* transaction. The timelock on the input transaction must have expired before
|
|
223
|
+
* this withdrawal can be valid.
|
|
224
|
+
*
|
|
225
|
+
* @param {Transaction} earlyUnbondedTx - The unbonding or slashing
|
|
226
|
+
* transaction to withdraw from
|
|
227
|
+
* @param {number} feeRate - Fee rate in satoshis per byte for the withdrawal
|
|
228
|
+
* transaction
|
|
229
|
+
* @returns {PsbtResult} - Contains the unsigned PSBT and fee amount
|
|
230
|
+
* @throws {StakingError} - If the input transaction is invalid or withdrawal
|
|
231
|
+
* transaction cannot be built
|
|
232
|
+
*/
|
|
233
|
+
createWithdrawEarlyUnbondedTransaction(earlyUnbondedTx: Transaction, feeRate: number): PsbtResult;
|
|
234
|
+
/**
|
|
235
|
+
* Create a withdrawal psbt that spends a naturally expired staking
|
|
236
|
+
* transaction.
|
|
237
|
+
*
|
|
238
|
+
* @param {Transaction} stakingTx - The staking transaction to withdraw from.
|
|
239
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
240
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
241
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
242
|
+
*/
|
|
243
|
+
createWithdrawStakingExpiredPsbt(stakingTx: Transaction, feeRate: number): PsbtResult;
|
|
244
|
+
/**
|
|
245
|
+
* Create a slashing psbt spending from the staking output.
|
|
246
|
+
*
|
|
247
|
+
* @param {Transaction} stakingTx - The staking transaction to slash.
|
|
248
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
249
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
250
|
+
*/
|
|
251
|
+
createStakingOutputSlashingPsbt(stakingTx: Transaction): PsbtResult;
|
|
252
|
+
/**
|
|
253
|
+
* Create a slashing psbt for an unbonding output.
|
|
254
|
+
*
|
|
255
|
+
* @param {Transaction} unbondingTx - The unbonding transaction to slash.
|
|
256
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
257
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
258
|
+
*/
|
|
259
|
+
createUnbondingOutputSlashingPsbt(unbondingTx: Transaction): PsbtResult;
|
|
260
|
+
/**
|
|
261
|
+
* Create a withdraw slashing psbt that spends a slashing transaction from the
|
|
262
|
+
* staking output.
|
|
263
|
+
*
|
|
264
|
+
* @param {Transaction} slashingTx - The slashing transaction.
|
|
265
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
266
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
267
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
268
|
+
*/
|
|
269
|
+
createWithdrawSlashingPsbt(slashingTx: Transaction, feeRate: number): PsbtResult;
|
|
270
|
+
}
|
|
271
|
+
export interface ObservableStakingScripts extends StakingScripts {
|
|
272
|
+
dataEmbedScript: Buffer;
|
|
273
|
+
}
|
|
274
|
+
export declare class ObservableStakingScriptData extends StakingScriptData {
|
|
275
|
+
magicBytes: Buffer;
|
|
276
|
+
constructor(stakerKey: Buffer, finalityProviderKeys: Buffer[], covenantKeys: Buffer[], covenantThreshold: number, stakingTimelock: number, unbondingTimelock: number, magicBytes: Buffer);
|
|
277
|
+
/**
|
|
278
|
+
* Builds a data embed script for staking in the form:
|
|
279
|
+
* OP_RETURN || <serializedStakingData>
|
|
280
|
+
* where serializedStakingData is the concatenation of:
|
|
281
|
+
* MagicBytes || Version || StakerPublicKey || FinalityProviderPublicKey || StakingTimeLock
|
|
282
|
+
* Note: Only a single finality provider key is supported for now in phase 1
|
|
283
|
+
* @throws {Error} If the number of finality provider keys is not equal to 1.
|
|
284
|
+
* @returns {Buffer} The compiled data embed script.
|
|
285
|
+
*/
|
|
286
|
+
buildDataEmbedScript(): Buffer;
|
|
287
|
+
/**
|
|
288
|
+
* Builds the staking scripts.
|
|
289
|
+
* @returns {ObservableStakingScripts} The staking scripts that can be used to stake.
|
|
290
|
+
* contains the timelockScript, unbondingScript, slashingScript,
|
|
291
|
+
* unbondingTimelockScript, and dataEmbedScript.
|
|
292
|
+
* @throws {Error} If script data is invalid.
|
|
293
|
+
*/
|
|
294
|
+
buildScripts(): ObservableStakingScripts;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* ObservableStaking is a class that provides an interface to create observable
|
|
298
|
+
* staking transactions for the Babylon Staking protocol.
|
|
299
|
+
*
|
|
300
|
+
* The class requires a network and staker information to create staking
|
|
301
|
+
* transactions.
|
|
302
|
+
* The staker information includes the staker's address and
|
|
303
|
+
* public key(without coordinates).
|
|
304
|
+
*/
|
|
305
|
+
export declare class ObservableStaking extends Staking {
|
|
306
|
+
params: ObservableVersionedStakingParams;
|
|
307
|
+
constructor(network: networks.Network, stakerInfo: StakerInfo, params: ObservableVersionedStakingParams, finalityProviderPkNoCoordHex: string, stakingTimelock: number);
|
|
308
|
+
/**
|
|
309
|
+
* Build the staking scripts for observable staking.
|
|
310
|
+
* This method overwrites the base method to include the OP_RETURN tag based
|
|
311
|
+
* on the tag provided in the parameters.
|
|
312
|
+
*
|
|
313
|
+
* @returns {ObservableStakingScripts} - The staking scripts for observable staking.
|
|
314
|
+
* @throws {StakingError} - If the scripts cannot be built.
|
|
315
|
+
*/
|
|
316
|
+
buildScripts(): ObservableStakingScripts;
|
|
317
|
+
/**
|
|
318
|
+
* Create a staking transaction for observable staking.
|
|
319
|
+
* This overwrites the method from the Staking class with the addtion
|
|
320
|
+
* of the
|
|
321
|
+
* 1. OP_RETURN tag in the staking scripts
|
|
322
|
+
* 2. lockHeight parameter
|
|
323
|
+
*
|
|
324
|
+
* @param {number} stakingAmountSat - The amount to stake in satoshis.
|
|
325
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
326
|
+
* transaction.
|
|
327
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
328
|
+
* @returns {TransactionResult} - An object containing the unsigned transaction,
|
|
329
|
+
* and fee
|
|
330
|
+
*/
|
|
331
|
+
createStakingTransaction(stakingAmountSat: number, inputUTXOs: UTXO[], feeRate: number): TransactionResult;
|
|
332
|
+
/**
|
|
333
|
+
* Create a staking psbt for observable staking.
|
|
334
|
+
*
|
|
335
|
+
* @param {Transaction} stakingTx - The staking transaction.
|
|
336
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
337
|
+
* transaction.
|
|
338
|
+
* @returns {Psbt} - The psbt.
|
|
339
|
+
*/
|
|
340
|
+
toStakingPsbt(stakingTx: Transaction, inputUTXOs: UTXO[]): Psbt;
|
|
341
|
+
}
|
|
342
|
+
export interface CovenantSignature {
|
|
343
|
+
btcPkHex: string;
|
|
344
|
+
sigHex: string;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Constructs an unsigned BTC Staking transaction in psbt format.
|
|
348
|
+
*
|
|
349
|
+
* Outputs:
|
|
350
|
+
* - psbt:
|
|
351
|
+
* - The first output corresponds to the staking script with the specified amount.
|
|
352
|
+
* - The second output corresponds to the change from spending the amount and the transaction fee.
|
|
353
|
+
* - If a data embed script is provided, it will be added as the second output, and the fee will be the third output.
|
|
354
|
+
* - fee: The total fee amount for the transaction.
|
|
355
|
+
*
|
|
356
|
+
* Inputs:
|
|
357
|
+
* - scripts:
|
|
358
|
+
* - timelockScript, unbondingScript, slashingScript: Scripts for different transaction types.
|
|
359
|
+
* - dataEmbedScript: Optional data embed script.
|
|
360
|
+
* - amount: Amount to stake.
|
|
361
|
+
* - changeAddress: Address to send the change to.
|
|
362
|
+
* - inputUTXOs: All available UTXOs from the wallet.
|
|
363
|
+
* - network: Bitcoin network.
|
|
364
|
+
* - feeRate: Fee rate in satoshis per byte.
|
|
365
|
+
* - publicKeyNoCoord: Public key if the wallet is in taproot mode.
|
|
366
|
+
* - lockHeight: Optional block height locktime to set for the transaction (i.e., not mined until the block height).
|
|
367
|
+
*
|
|
368
|
+
* @param {Object} scripts - Scripts used to construct the taproot output.
|
|
369
|
+
* such as timelockScript, unbondingScript, slashingScript, and dataEmbedScript.
|
|
370
|
+
* @param {number} amount - The amount to stake.
|
|
371
|
+
* @param {string} changeAddress - The address to send the change to.
|
|
372
|
+
* @param {UTXO[]} inputUTXOs - All available UTXOs from the wallet.
|
|
373
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
374
|
+
* @param {number} feeRate - The fee rate in satoshis per byte.
|
|
375
|
+
* @param {number} [lockHeight] - The optional block height locktime.
|
|
376
|
+
* @returns {TransactionResult} - An object containing the unsigned transaction and fee
|
|
377
|
+
* @throws Will throw an error if the amount or fee rate is less than or equal
|
|
378
|
+
* to 0, if the change address is invalid, or if the public key is invalid.
|
|
379
|
+
*/
|
|
380
|
+
export declare function stakingTransaction(scripts: {
|
|
381
|
+
timelockScript: Buffer;
|
|
382
|
+
unbondingScript: Buffer;
|
|
383
|
+
slashingScript: Buffer;
|
|
384
|
+
dataEmbedScript?: Buffer;
|
|
385
|
+
}, amount: number, changeAddress: string, inputUTXOs: UTXO[], network: networks.Network, feeRate: number, lockHeight?: number): TransactionResult;
|
|
386
|
+
/**
|
|
387
|
+
* Constructs a withdrawal transaction for manually unbonded delegation.
|
|
388
|
+
*
|
|
389
|
+
* This transaction spends the unbonded output from the staking transaction.
|
|
390
|
+
*
|
|
391
|
+
* Inputs:
|
|
392
|
+
* - scripts: Scripts used to construct the taproot output.
|
|
393
|
+
* - unbondingTimelockScript: Script for the unbonding timelock condition.
|
|
394
|
+
* - slashingScript: Script for the slashing condition.
|
|
395
|
+
* - unbondingTx: The unbonding transaction.
|
|
396
|
+
* - withdrawalAddress: The address to send the withdrawn funds to.
|
|
397
|
+
* - network: The Bitcoin network.
|
|
398
|
+
* - feeRate: The fee rate for the transaction in satoshis per byte.
|
|
399
|
+
*
|
|
400
|
+
* Returns:
|
|
401
|
+
* - psbt: The partially signed transaction (PSBT).
|
|
402
|
+
*
|
|
403
|
+
* @param {Object} scripts - The scripts used in the transaction.
|
|
404
|
+
* @param {Transaction} unbondingTx - The unbonding transaction.
|
|
405
|
+
* @param {string} withdrawalAddress - The address to send the withdrawn funds to.
|
|
406
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
407
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
408
|
+
* @returns {PsbtResult} An object containing the partially signed transaction (PSBT).
|
|
409
|
+
*/
|
|
410
|
+
export declare function withdrawEarlyUnbondedTransaction(scripts: {
|
|
411
|
+
unbondingTimelockScript: Buffer;
|
|
412
|
+
slashingScript: Buffer;
|
|
413
|
+
}, unbondingTx: Transaction, withdrawalAddress: string, network: networks.Network, feeRate: number): PsbtResult;
|
|
414
|
+
/**
|
|
415
|
+
* Constructs a withdrawal transaction for naturally unbonded delegation.
|
|
416
|
+
*
|
|
417
|
+
* This transaction spends the unbonded output from the staking transaction when the timelock has expired.
|
|
418
|
+
*
|
|
419
|
+
* Inputs:
|
|
420
|
+
* - scripts: Scripts used to construct the taproot output.
|
|
421
|
+
* - timelockScript: Script for the timelock condition.
|
|
422
|
+
* - slashingScript: Script for the slashing condition.
|
|
423
|
+
* - unbondingScript: Script for the unbonding condition.
|
|
424
|
+
* - tx: The original staking transaction.
|
|
425
|
+
* - withdrawalAddress: The address to send the withdrawn funds to.
|
|
426
|
+
* - network: The Bitcoin network.
|
|
427
|
+
* - feeRate: The fee rate for the transaction in satoshis per byte.
|
|
428
|
+
* - outputIndex: The index of the output to be spent in the original transaction (default is 0).
|
|
429
|
+
*
|
|
430
|
+
* Returns:
|
|
431
|
+
* - psbt: The partially signed transaction (PSBT).
|
|
432
|
+
*
|
|
433
|
+
* @param {Object} scripts - The scripts used in the transaction.
|
|
434
|
+
* @param {Transaction} tx - The original staking transaction.
|
|
435
|
+
* @param {string} withdrawalAddress - The address to send the withdrawn funds to.
|
|
436
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
437
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
438
|
+
* @param {number} [outputIndex=0] - The index of the output to be spent in the original transaction.
|
|
439
|
+
* @returns {PsbtResult} An object containing the partially signed transaction (PSBT).
|
|
440
|
+
*/
|
|
441
|
+
export declare function withdrawTimelockUnbondedTransaction(scripts: {
|
|
442
|
+
timelockScript: Buffer;
|
|
443
|
+
slashingScript: Buffer;
|
|
444
|
+
unbondingScript: Buffer;
|
|
445
|
+
}, tx: Transaction, withdrawalAddress: string, network: networks.Network, feeRate: number, outputIndex?: number): PsbtResult;
|
|
446
|
+
/**
|
|
447
|
+
* Constructs a withdrawal transaction for a slashing transaction.
|
|
448
|
+
*
|
|
449
|
+
* This transaction spends the output from the slashing transaction.
|
|
450
|
+
*
|
|
451
|
+
* @param {Object} scripts - The unbondingTimelockScript
|
|
452
|
+
* We use the unbonding timelock script as the timelock of the slashing transaction.
|
|
453
|
+
* This is due to slashing tx timelock is the same as the unbonding timelock.
|
|
454
|
+
* @param {Transaction} slashingTx - The slashing transaction.
|
|
455
|
+
* @param {string} withdrawalAddress - The address to send the withdrawn funds to.
|
|
456
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
457
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
458
|
+
* @param {number} outputIndex - The index of the output to be spent in the original transaction.
|
|
459
|
+
* @returns {PsbtResult} An object containing the partially signed transaction (PSBT).
|
|
460
|
+
*/
|
|
461
|
+
export declare function withdrawSlashingTransaction(scripts: {
|
|
462
|
+
unbondingTimelockScript: Buffer;
|
|
463
|
+
}, slashingTx: Transaction, withdrawalAddress: string, network: networks.Network, feeRate: number, outputIndex: number): PsbtResult;
|
|
464
|
+
/**
|
|
465
|
+
* Constructs a slashing transaction for a staking output without prior unbonding.
|
|
466
|
+
*
|
|
467
|
+
* This transaction spends the staking output of the staking transaction and distributes the funds
|
|
468
|
+
* according to the specified slashing rate.
|
|
469
|
+
*
|
|
470
|
+
* Outputs:
|
|
471
|
+
* - The first output sends `input * slashing_rate` funds to the slashing address.
|
|
472
|
+
* - The second output sends `input * (1 - slashing_rate) - fee` funds back to the user's address.
|
|
473
|
+
*
|
|
474
|
+
* Inputs:
|
|
475
|
+
* - scripts: Scripts used to construct the taproot output.
|
|
476
|
+
* - slashingScript: Script for the slashing condition.
|
|
477
|
+
* - timelockScript: Script for the timelock condition.
|
|
478
|
+
* - unbondingScript: Script for the unbonding condition.
|
|
479
|
+
* - unbondingTimelockScript: Script for the unbonding timelock condition.
|
|
480
|
+
* - transaction: The original staking transaction.
|
|
481
|
+
* - slashingAddress: The address to send the slashed funds to.
|
|
482
|
+
* - slashingRate: The rate at which the funds are slashed (0 < slashingRate < 1).
|
|
483
|
+
* - minimumFee: The minimum fee for the transaction in satoshis.
|
|
484
|
+
* - network: The Bitcoin network.
|
|
485
|
+
* - outputIndex: The index of the output to be spent in the original transaction (default is 0).
|
|
486
|
+
*
|
|
487
|
+
* @param {Object} scripts - The scripts used in the transaction.
|
|
488
|
+
* @param {Transaction} stakingTransaction - The original staking transaction.
|
|
489
|
+
* @param {string} slashingPkScriptHex - The public key script to send the slashed funds to.
|
|
490
|
+
* @param {number} slashingRate - The rate at which the funds are slashed.
|
|
491
|
+
* @param {number} minimumFee - The minimum fee for the transaction in satoshis.
|
|
492
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
493
|
+
* @param {number} [outputIndex=0] - The index of the output to be spent in the original transaction.
|
|
494
|
+
* @returns {{ psbt: Psbt }} An object containing the partially signed transaction (PSBT).
|
|
495
|
+
*/
|
|
496
|
+
export declare function slashTimelockUnbondedTransaction(scripts: {
|
|
497
|
+
slashingScript: Buffer;
|
|
498
|
+
timelockScript: Buffer;
|
|
499
|
+
unbondingScript: Buffer;
|
|
500
|
+
unbondingTimelockScript: Buffer;
|
|
501
|
+
}, stakingTransaction: Transaction, slashingPkScriptHex: string, slashingRate: number, minimumFee: number, network: networks.Network, outputIndex?: number): {
|
|
502
|
+
psbt: Psbt;
|
|
503
|
+
};
|
|
504
|
+
/**
|
|
505
|
+
* Constructs a slashing transaction for an early unbonded transaction.
|
|
506
|
+
*
|
|
507
|
+
* This transaction spends the staking output of the staking transaction and distributes the funds
|
|
508
|
+
* according to the specified slashing rate.
|
|
509
|
+
*
|
|
510
|
+
* Transaction outputs:
|
|
511
|
+
* - The first output sends `input * slashing_rate` funds to the slashing address.
|
|
512
|
+
* - The second output sends `input * (1 - slashing_rate) - fee` funds back to the user's address.
|
|
513
|
+
*
|
|
514
|
+
* @param {Object} scripts - The scripts used in the transaction. e.g slashingScript, unbondingTimelockScript
|
|
515
|
+
* @param {Transaction} unbondingTx - The unbonding transaction.
|
|
516
|
+
* @param {string} slashingPkScriptHex - The public key script to send the slashed funds to.
|
|
517
|
+
* @param {number} slashingRate - The rate at which the funds are slashed.
|
|
518
|
+
* @param {number} minimumSlashingFee - The minimum fee for the transaction in satoshis.
|
|
519
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
520
|
+
* @returns {{ psbt: Psbt }} An object containing the partially signed transaction (PSBT).
|
|
521
|
+
*/
|
|
522
|
+
export declare function slashEarlyUnbondedTransaction(scripts: {
|
|
523
|
+
slashingScript: Buffer;
|
|
524
|
+
unbondingTimelockScript: Buffer;
|
|
525
|
+
}, unbondingTx: Transaction, slashingPkScriptHex: string, slashingRate: number, minimumSlashingFee: number, network: networks.Network): {
|
|
526
|
+
psbt: Psbt;
|
|
527
|
+
};
|
|
528
|
+
export declare function unbondingTransaction(scripts: {
|
|
529
|
+
unbondingTimelockScript: Buffer;
|
|
530
|
+
slashingScript: Buffer;
|
|
531
|
+
}, stakingTx: Transaction, unbondingFee: number, network: networks.Network, outputIndex?: number): TransactionResult;
|
|
532
|
+
export declare const createCovenantWitness: (originalWitness: Buffer[], paramsCovenants: Buffer[], covenantSigs: CovenantSignature[], covenantQuorum: number) => Buffer<ArrayBufferLike>[];
|
|
533
|
+
export declare const initBTCCurve: () => void;
|
|
534
|
+
/**
|
|
535
|
+
* Check whether the given address is a valid Bitcoin address.
|
|
536
|
+
*
|
|
537
|
+
* @param {string} btcAddress - The Bitcoin address to check.
|
|
538
|
+
* @param {object} network - The Bitcoin network (e.g., bitcoin.networks.bitcoin).
|
|
539
|
+
* @returns {boolean} - True if the address is valid, otherwise false.
|
|
540
|
+
*/
|
|
541
|
+
export declare const isValidBitcoinAddress: (btcAddress: string, network: networks.Network) => boolean;
|
|
542
|
+
/**
|
|
543
|
+
* Check whether the given address is a Taproot address.
|
|
544
|
+
*
|
|
545
|
+
* @param {string} taprootAddress - The Bitcoin bech32 encoded address to check.
|
|
546
|
+
* @param {object} network - The Bitcoin network (e.g., bitcoin.networks.bitcoin).
|
|
547
|
+
* @returns {boolean} - True if the address is a Taproot address, otherwise false.
|
|
548
|
+
*/
|
|
549
|
+
export declare const isTaproot: (taprootAddress: string, network: networks.Network) => boolean;
|
|
550
|
+
/**
|
|
551
|
+
* Check whether the given public key is a valid public key without a coordinate.
|
|
552
|
+
*
|
|
553
|
+
* @param {string} pkWithNoCoord - public key without the coordinate.
|
|
554
|
+
* @returns {boolean} - True if the public key without the coordinate is valid, otherwise false.
|
|
555
|
+
*/
|
|
556
|
+
export declare const isValidNoCoordPublicKey: (pkWithNoCoord: string) => boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Get the public key without the coordinate.
|
|
559
|
+
*
|
|
560
|
+
* @param {string} pkHex - The public key in hex, with or without the coordinate.
|
|
561
|
+
* @returns {string} - The public key without the coordinate in hex.
|
|
562
|
+
* @throws {Error} - If the public key is invalid.
|
|
563
|
+
*/
|
|
564
|
+
export declare const getPublicKeyNoCoord: (pkHex: string) => String;
|
|
565
|
+
/**
|
|
566
|
+
* Convert a transaction id to a hash. in buffer format.
|
|
567
|
+
*
|
|
568
|
+
* @param {string} txId - The transaction id.
|
|
569
|
+
* @returns {Buffer} - The transaction hash.
|
|
570
|
+
*/
|
|
571
|
+
export declare const transactionIdToHash: (txId: string) => Buffer;
|
|
572
|
+
export type TransactionOutput = {
|
|
573
|
+
scriptPubKey: Buffer;
|
|
574
|
+
value: number;
|
|
575
|
+
};
|
|
576
|
+
export interface OutputInfo {
|
|
577
|
+
scriptPubKey: Buffer;
|
|
578
|
+
outputAddress: string;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Build the staking output for the transaction which contains p2tr output
|
|
582
|
+
* with staking scripts.
|
|
583
|
+
*
|
|
584
|
+
* @param {StakingScripts} scripts - The staking scripts.
|
|
585
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
586
|
+
* @param {number} amount - The amount to stake.
|
|
587
|
+
* @returns {TransactionOutput[]} - The staking transaction outputs.
|
|
588
|
+
* @throws {Error} - If the staking output cannot be built.
|
|
589
|
+
*/
|
|
590
|
+
export declare const buildStakingTransactionOutputs: (scripts: {
|
|
591
|
+
timelockScript: Buffer;
|
|
592
|
+
unbondingScript: Buffer;
|
|
593
|
+
slashingScript: Buffer;
|
|
594
|
+
dataEmbedScript?: Buffer;
|
|
595
|
+
}, network: networks.Network, amount: number) => TransactionOutput[];
|
|
596
|
+
/**
|
|
597
|
+
* Derive the staking output address from the staking scripts.
|
|
598
|
+
*
|
|
599
|
+
* @param {StakingScripts} scripts - The staking scripts.
|
|
600
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
601
|
+
* @returns {StakingOutput} - The staking output address and scriptPubKey.
|
|
602
|
+
* @throws {StakingError} - If the staking output address cannot be derived.
|
|
603
|
+
*/
|
|
604
|
+
export declare const deriveStakingOutputInfo: (scripts: {
|
|
605
|
+
timelockScript: Buffer;
|
|
606
|
+
unbondingScript: Buffer;
|
|
607
|
+
slashingScript: Buffer;
|
|
608
|
+
}, network: networks.Network) => {
|
|
609
|
+
outputAddress: string;
|
|
610
|
+
scriptPubKey: Buffer<ArrayBufferLike>;
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* Derive the unbonding output address and scriptPubKey from the staking scripts.
|
|
614
|
+
*
|
|
615
|
+
* @param {StakingScripts} scripts - The staking scripts.
|
|
616
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
617
|
+
* @returns {OutputInfo} - The unbonding output address and scriptPubKey.
|
|
618
|
+
* @throws {StakingError} - If the unbonding output address cannot be derived.
|
|
619
|
+
*/
|
|
620
|
+
export declare const deriveUnbondingOutputInfo: (scripts: {
|
|
621
|
+
unbondingTimelockScript: Buffer;
|
|
622
|
+
slashingScript: Buffer;
|
|
623
|
+
}, network: networks.Network) => {
|
|
624
|
+
outputAddress: string;
|
|
625
|
+
scriptPubKey: Buffer<ArrayBufferLike>;
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Derive the slashing output address and scriptPubKey from the staking scripts.
|
|
629
|
+
*
|
|
630
|
+
* @param {StakingScripts} scripts - The unbonding timelock scripts, we use the
|
|
631
|
+
* unbonding timelock script as the timelock of the slashing transaction.
|
|
632
|
+
* This is due to slashing tx timelock is the same as the unbonding timelock.
|
|
633
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
634
|
+
* @returns {OutputInfo} - The slashing output address and scriptPubKey.
|
|
635
|
+
* @throws {StakingError} - If the slashing output address cannot be derived.
|
|
636
|
+
*/
|
|
637
|
+
export declare const deriveSlashingOutput: (scripts: {
|
|
638
|
+
unbondingTimelockScript: Buffer;
|
|
639
|
+
}, network: networks.Network) => {
|
|
640
|
+
outputAddress: string;
|
|
641
|
+
scriptPubKey: Buffer<ArrayBufferLike>;
|
|
642
|
+
};
|
|
643
|
+
/**
|
|
644
|
+
* Find the matching output index for the given transaction.
|
|
645
|
+
*
|
|
646
|
+
* @param {Transaction} tx - The transaction.
|
|
647
|
+
* @param {string} outputAddress - The output address.
|
|
648
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
649
|
+
* @returns {number} - The output index.
|
|
650
|
+
* @throws {Error} - If the matching output is not found.
|
|
651
|
+
*/
|
|
652
|
+
export declare const findMatchingTxOutputIndex: (tx: Transaction, outputAddress: string, network: networks.Network) => number;
|
|
653
|
+
/**
|
|
654
|
+
* Validate the staking transaction input data.
|
|
655
|
+
*
|
|
656
|
+
* @param {number} stakingAmountSat - The staking amount in satoshis.
|
|
657
|
+
* @param {number} timelock - The staking time in blocks.
|
|
658
|
+
* @param {StakingParams} params - The staking parameters.
|
|
659
|
+
* @param {UTXO[]} inputUTXOs - The input UTXOs.
|
|
660
|
+
* @param {number} feeRate - The Bitcoin fee rate in sat/vbyte
|
|
661
|
+
* @throws {StakingError} - If the input data is invalid.
|
|
662
|
+
*/
|
|
663
|
+
export declare const validateStakingTxInputData: (stakingAmountSat: number, timelock: number, params: StakingParams, inputUTXOs: UTXO[], feeRate: number) => void;
|
|
664
|
+
/**
|
|
665
|
+
* Validate the staking parameters.
|
|
666
|
+
* Extend this method to add additional validation for staking parameters based
|
|
667
|
+
* on the staking type.
|
|
668
|
+
* @param {StakingParams} params - The staking parameters.
|
|
669
|
+
* @throws {StakingError} - If the parameters are invalid.
|
|
670
|
+
*/
|
|
671
|
+
export declare const validateParams: (params: StakingParams) => void;
|
|
672
|
+
/**
|
|
673
|
+
* Validate the staking timelock.
|
|
674
|
+
*
|
|
675
|
+
* @param {number} stakingTimelock - The staking timelock.
|
|
676
|
+
* @param {StakingParams} params - The staking parameters.
|
|
677
|
+
* @throws {StakingError} - If the staking timelock is invalid.
|
|
678
|
+
*/
|
|
679
|
+
export declare const validateStakingTimelock: (stakingTimelock: number, params: StakingParams) => void;
|
|
680
|
+
/**
|
|
681
|
+
* toBuffers converts an array of strings to an array of buffers.
|
|
682
|
+
*
|
|
683
|
+
* @param {string[]} inputs - The input strings.
|
|
684
|
+
* @returns {Buffer[]} - The buffers.
|
|
685
|
+
* @throws {StakingError} - If the values cannot be converted to buffers.
|
|
686
|
+
*/
|
|
687
|
+
export declare const toBuffers: (inputs: string[]) => Buffer[];
|
|
688
|
+
export declare const findInputUTXO: (inputUTXOs: UTXO[], input: Input) => UTXO;
|
|
689
|
+
/**
|
|
690
|
+
* Determines and constructs the correct PSBT input fields for a given UTXO based on its script type.
|
|
691
|
+
* This function handles different Bitcoin script types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) and returns
|
|
692
|
+
* the appropriate PSBT input fields required for that UTXO.
|
|
693
|
+
*
|
|
694
|
+
* @param {UTXO} utxo - The unspent transaction output to process
|
|
695
|
+
* @param {Buffer} [publicKeyNoCoord] - The public of the staker (optional).
|
|
696
|
+
* @returns {object} PSBT input fields object containing the necessary data
|
|
697
|
+
* @throws {Error} If required input data is missing or if an unsupported script type is provided
|
|
698
|
+
*/
|
|
699
|
+
export declare const getPsbtInputFields: (utxo: UTXO, publicKeyNoCoord?: Buffer) => PsbtInputExtended;
|
|
700
|
+
/**
|
|
701
|
+
* Supported Bitcoin script types
|
|
702
|
+
*/
|
|
703
|
+
export declare enum BitcoinScriptType {
|
|
704
|
+
P2PKH = "pubkeyhash",
|
|
705
|
+
P2SH = "scripthash",
|
|
706
|
+
P2WPKH = "witnesspubkeyhash",
|
|
707
|
+
P2WSH = "witnessscripthash",
|
|
708
|
+
P2TR = "taproot"
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Determines the type of Bitcoin script.
|
|
712
|
+
*
|
|
713
|
+
* This function tries to parse the script using different Bitcoin payment types and returns
|
|
714
|
+
* a string identifier for the script type.
|
|
715
|
+
*
|
|
716
|
+
* @param script - The raw script as a Buffer
|
|
717
|
+
* @returns {BitcoinScriptType} The identified script type
|
|
718
|
+
* @throws {Error} If the script cannot be identified as any known type
|
|
719
|
+
*/
|
|
720
|
+
export declare const getScriptType: (script: Buffer) => BitcoinScriptType;
|
|
721
|
+
export declare const getBabylonParamByBtcHeight: (height: number, babylonParamsVersions: VersionedStakingParams[]) => StakingParams;
|
|
722
|
+
export declare const getBabylonParamByVersion: (version: number, babylonParams: VersionedStakingParams[]) => StakingParams;
|
|
723
|
+
export interface BtcProvider {
|
|
724
|
+
signPsbt(signingStep: SigningStep, psbtHex: string): Promise<string>;
|
|
725
|
+
signMessage?: (signingStep: SigningStep, message: string, type: "ecdsa") => Promise<string>;
|
|
726
|
+
}
|
|
727
|
+
export interface BabylonProvider {
|
|
728
|
+
signTransaction: <T extends object>(signingStep: SigningStep, msg: {
|
|
729
|
+
typeUrl: string;
|
|
730
|
+
value: T;
|
|
731
|
+
}) => Promise<Uint8Array>;
|
|
732
|
+
}
|
|
733
|
+
export declare enum SigningStep {
|
|
734
|
+
STAKING_SLASHING = "staking-slashing",
|
|
735
|
+
UNBONDING_SLASHING = "unbonding-slashing",
|
|
736
|
+
PROOF_OF_POSSESSION = "proof-of-possession",
|
|
737
|
+
CREATE_BTC_DELEGATION_MSG = "create-btc-delegation-msg",
|
|
738
|
+
STAKING = "staking",
|
|
739
|
+
UNBONDING = "unbonding",
|
|
740
|
+
WITHDRAW_STAKING_EXPIRED = "withdraw-staking-expired",
|
|
741
|
+
WITHDRAW_EARLY_UNBONDED = "withdraw-early-unbonded",
|
|
742
|
+
WITHDRAW_SLASHING = "withdraw-slashing"
|
|
743
|
+
}
|
|
744
|
+
export interface StakingInputs {
|
|
745
|
+
finalityProviderPkNoCoordHex: string;
|
|
746
|
+
stakingAmountSat: number;
|
|
747
|
+
stakingTimelock: number;
|
|
748
|
+
}
|
|
749
|
+
export interface InclusionProof {
|
|
750
|
+
pos: number;
|
|
751
|
+
merkle: string[];
|
|
752
|
+
blockHashHex: string;
|
|
753
|
+
}
|
|
754
|
+
export declare class BabylonBtcStakingManager {
|
|
755
|
+
private stakingParams;
|
|
756
|
+
private btcProvider;
|
|
757
|
+
private network;
|
|
758
|
+
private babylonProvider;
|
|
759
|
+
constructor(network: networks.Network, stakingParams: VersionedStakingParams[], btcProvider: BtcProvider, babylonProvider: BabylonProvider);
|
|
760
|
+
/**
|
|
761
|
+
* Creates a signed Pre-Staking Registration transaction that is ready to be
|
|
762
|
+
* sent to the Babylon chain.
|
|
763
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
764
|
+
* and the no-coord public key in hex format.
|
|
765
|
+
* @param stakingInput - The staking inputs.
|
|
766
|
+
* @param babylonBtcTipHeight - The Babylon BTC tip height.
|
|
767
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
768
|
+
* transaction.
|
|
769
|
+
* @param feeRate - The fee rate in satoshis per byte.
|
|
770
|
+
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
771
|
+
* @returns The signed babylon pre-staking registration transaction in base64
|
|
772
|
+
* format.
|
|
773
|
+
*/
|
|
774
|
+
preStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, babylonBtcTipHeight: number, inputUTXOs: UTXO[], feeRate: number, babylonAddress: string): Promise<{
|
|
775
|
+
signedBabylonTx: Uint8Array;
|
|
776
|
+
stakingTx: Transaction;
|
|
777
|
+
}>;
|
|
778
|
+
/**
|
|
779
|
+
* Creates a signed post-staking registration transaction that is ready to be
|
|
780
|
+
* sent to the Babylon chain. This is used when a staking transaction is
|
|
781
|
+
* already created and included in a BTC block and we want to register it on
|
|
782
|
+
* the Babylon chain.
|
|
783
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
784
|
+
* and the no-coord public key in hex format.
|
|
785
|
+
* @param stakingTx - The staking transaction.
|
|
786
|
+
* @param stakingTxHeight - The BTC height in which the staking transaction
|
|
787
|
+
* is included.
|
|
788
|
+
* @param stakingInput - The staking inputs.
|
|
789
|
+
* @param inclusionProof - The inclusion proof of the staking transaction.
|
|
790
|
+
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
791
|
+
* @returns The signed babylon transaction in base64 format.
|
|
792
|
+
*/
|
|
793
|
+
postStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingTx: Transaction, stakingTxHeight: number, stakingInput: StakingInputs, inclusionProof: InclusionProof, babylonAddress: string): Promise<{
|
|
794
|
+
signedBabylonTx: Uint8Array;
|
|
795
|
+
}>;
|
|
796
|
+
/**
|
|
797
|
+
* Estimates the BTC fee required for staking.
|
|
798
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
799
|
+
* and the no-coord public key in hex format.
|
|
800
|
+
* @param babylonBtcTipHeight - The BTC tip height recorded on the Babylon
|
|
801
|
+
* chain.
|
|
802
|
+
* @param stakingInput - The staking inputs.
|
|
803
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
804
|
+
* transaction.
|
|
805
|
+
* @param feeRate - The fee rate in satoshis per byte.
|
|
806
|
+
* @returns The estimated BTC fee in satoshis.
|
|
807
|
+
*/
|
|
808
|
+
estimateBtcStakingFee(stakerBtcInfo: StakerInfo, babylonBtcTipHeight: number, stakingInput: StakingInputs, inputUTXOs: UTXO[], feeRate: number): number;
|
|
809
|
+
/**
|
|
810
|
+
* Creates a signed staking transaction that is ready to be sent to the BTC
|
|
811
|
+
* network.
|
|
812
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
813
|
+
* and the no-coord public key in hex format.
|
|
814
|
+
* @param stakingInput - The staking inputs.
|
|
815
|
+
* @param unsignedStakingTx - The unsigned staking transaction.
|
|
816
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
817
|
+
* transaction.
|
|
818
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
819
|
+
* delegation in Babylon chain
|
|
820
|
+
* @returns The signed staking transaction.
|
|
821
|
+
*/
|
|
822
|
+
createSignedBtcStakingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, unsignedStakingTx: Transaction, inputUTXOs: UTXO[], stakingParamsVersion: number): Promise<Transaction>;
|
|
823
|
+
/**
|
|
824
|
+
* Creates a partial signed unbonding transaction that is only signed by the
|
|
825
|
+
* staker. In order to complete the unbonding transaction, the covenant
|
|
826
|
+
* unbonding signatures need to be added to the transaction before sending it
|
|
827
|
+
* to the BTC network.
|
|
828
|
+
* NOTE: This method should only be used for Babylon phase-1 unbonding.
|
|
829
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
830
|
+
* and the no-coord public key in hex format.
|
|
831
|
+
* @param stakingInput - The staking inputs.
|
|
832
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
833
|
+
* delegation in Babylon chain
|
|
834
|
+
* @param stakingTx - The staking transaction.
|
|
835
|
+
* @returns The partial signed unbonding transaction and its fee.
|
|
836
|
+
*/
|
|
837
|
+
createPartialSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction): Promise<TransactionResult>;
|
|
838
|
+
/**
|
|
839
|
+
* Creates a signed unbonding transaction that is ready to be sent to the BTC
|
|
840
|
+
* network.
|
|
841
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
842
|
+
* and the no-coord public key in hex format.
|
|
843
|
+
* @param stakingInput - The staking inputs.
|
|
844
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
845
|
+
* delegation in Babylon chain
|
|
846
|
+
* @param stakingTx - The staking transaction.
|
|
847
|
+
* @param unsignedUnbondingTx - The unsigned unbonding transaction.
|
|
848
|
+
* @param covenantUnbondingSignatures - The covenant unbonding signatures.
|
|
849
|
+
* It can be retrieved from the Babylon chain or API.
|
|
850
|
+
* @returns The signed unbonding transaction and its fee.
|
|
851
|
+
*/
|
|
852
|
+
createSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, unsignedUnbondingTx: Transaction, covenantUnbondingSignatures: {
|
|
853
|
+
btcPkHex: string;
|
|
854
|
+
sigHex: string;
|
|
855
|
+
}[]): Promise<TransactionResult>;
|
|
856
|
+
/**
|
|
857
|
+
* Creates a signed withdrawal transaction on the unbodning output expiry path
|
|
858
|
+
* that is ready to be sent to the BTC network.
|
|
859
|
+
* @param stakingInput - The staking inputs.
|
|
860
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
861
|
+
* delegation in Babylon chain
|
|
862
|
+
* @param earlyUnbondingTx - The early unbonding transaction.
|
|
863
|
+
* @param feeRate - The fee rate in satoshis per byte.
|
|
864
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
865
|
+
*/
|
|
866
|
+
createSignedBtcWithdrawEarlyUnbondedTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, earlyUnbondingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
867
|
+
/**
|
|
868
|
+
* Creates a signed withdrawal transaction on the staking output expiry path
|
|
869
|
+
* that is ready to be sent to the BTC network.
|
|
870
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
871
|
+
* and the no-coord public key in hex format.
|
|
872
|
+
* @param stakingInput - The staking inputs.
|
|
873
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
874
|
+
* delegation in Babylon chain
|
|
875
|
+
* @param stakingTx - The staking transaction.
|
|
876
|
+
* @param feeRate - The fee rate in satoshis per byte.
|
|
877
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
878
|
+
*/
|
|
879
|
+
createSignedBtcWithdrawStakingExpiredTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
880
|
+
/**
|
|
881
|
+
* Creates a signed withdrawal transaction for the expired slashing output that
|
|
882
|
+
* is ready to be sent to the BTC network.
|
|
883
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
884
|
+
* and the no-coord public key in hex format.
|
|
885
|
+
* @param stakingInput - The staking inputs.
|
|
886
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
887
|
+
* delegation in Babylon chain
|
|
888
|
+
* @param slashingTx - The slashing transaction.
|
|
889
|
+
* @param feeRate - The fee rate in satoshis per byte.
|
|
890
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
891
|
+
*/
|
|
892
|
+
createSignedBtcWithdrawSlashingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, slashingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
893
|
+
/**
|
|
894
|
+
* Creates a proof of possession for the staker based on ECDSA signature.
|
|
895
|
+
* @param bech32Address - The staker's bech32 address.
|
|
896
|
+
* @returns The proof of possession.
|
|
897
|
+
*/
|
|
898
|
+
createProofOfPossession(bech32Address: string): Promise<ProofOfPossessionBTC>;
|
|
899
|
+
/**
|
|
900
|
+
* Creates the unbonding, slashing, and unbonding slashing transactions and
|
|
901
|
+
* PSBTs.
|
|
902
|
+
* @param stakingInstance - The staking instance.
|
|
903
|
+
* @param stakingTx - The staking transaction.
|
|
904
|
+
* @returns The unbonding, slashing, and unbonding slashing transactions and
|
|
905
|
+
* PSBTs.
|
|
906
|
+
*/
|
|
907
|
+
private createDelegationTransactionsAndPsbts;
|
|
908
|
+
/**
|
|
909
|
+
* Creates a protobuf message for the BTC delegation.
|
|
910
|
+
* @param stakingInstance - The staking instance.
|
|
911
|
+
* @param stakingInput - The staking inputs.
|
|
912
|
+
* @param stakingTx - The staking transaction.
|
|
913
|
+
* @param bech32Address - The staker's babylon chain bech32 address
|
|
914
|
+
* @param stakerBtcInfo - The staker's BTC information such as address and
|
|
915
|
+
* public key
|
|
916
|
+
* @param params - The staking parameters.
|
|
917
|
+
* @param inclusionProof - The inclusion proof of the staking transaction.
|
|
918
|
+
* @returns The protobuf message.
|
|
919
|
+
*/
|
|
920
|
+
private createBtcDelegationMsg;
|
|
921
|
+
/**
|
|
922
|
+
* Gets the inclusion proof for the staking transaction.
|
|
923
|
+
* See the type `InclusionProof` for more information
|
|
924
|
+
* @param inclusionProof - The inclusion proof.
|
|
925
|
+
* @returns The inclusion proof.
|
|
926
|
+
*/
|
|
927
|
+
private getInclusionProof;
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Get the staker signature from the unbonding transaction
|
|
931
|
+
* This is used mostly for unbonding transactions from phase-1(Observable)
|
|
932
|
+
* @param unbondingTx - The unbonding transaction
|
|
933
|
+
* @returns The staker signature
|
|
934
|
+
*/
|
|
935
|
+
export declare const getUnbondingTxStakerSignature: (unbondingTx: Transaction) => string;
|
|
936
|
+
|
|
937
|
+
export {};
|