@bitgo-beta/babylonlabs-io-btc-staking-ts 0.4.0-beta.73 → 0.4.0-beta.731
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/README.md +1 -1
- package/dist/index.cjs +2219 -1477
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.cts +777 -490
- package/dist/index.d.ts +1235 -0
- package/dist/index.js +2196 -1452
- package/dist/index.js.map +7 -0
- package/package.json +9 -6
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1235 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { btcstaking, btcstakingtx } from '@babylonlabs-io/babylon-proto-ts';
|
|
4
|
+
import { ProofOfPossessionBTC } from '@babylonlabs-io/babylon-proto-ts/dist/generated/babylon/btcstaking/v1/pop';
|
|
5
|
+
import { PsbtInputExtended } from 'bip174/src/lib/interfaces';
|
|
6
|
+
import { Psbt, Transaction, networks } from 'bitcoinjs-lib';
|
|
7
|
+
import { Input } from 'bitcoinjs-lib/src/transaction';
|
|
8
|
+
import { Emitter } from 'nanoevents';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Base interface for staking parameters that define the rules and constraints
|
|
12
|
+
* for staking operations.
|
|
13
|
+
*/
|
|
14
|
+
export interface StakingParams {
|
|
15
|
+
covenantNoCoordPks: string[];
|
|
16
|
+
covenantQuorum: number;
|
|
17
|
+
unbondingTime: number;
|
|
18
|
+
unbondingFeeSat: number;
|
|
19
|
+
maxStakingAmountSat: number;
|
|
20
|
+
minStakingAmountSat: number;
|
|
21
|
+
maxStakingTimeBlocks: number;
|
|
22
|
+
minStakingTimeBlocks: number;
|
|
23
|
+
slashing?: {
|
|
24
|
+
slashingPkScriptHex: string;
|
|
25
|
+
slashingRate: number;
|
|
26
|
+
minSlashingTxFeeSat: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Type for StakingParams where slashing is required
|
|
31
|
+
*/
|
|
32
|
+
export type StakingParamsWithSlashing = StakingParams & {
|
|
33
|
+
slashing: NonNullable<StakingParams["slashing"]>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Type guard to check if slashing exists in StakingParams
|
|
37
|
+
*/
|
|
38
|
+
export declare function hasSlashing(params: StakingParams): params is StakingParams & {
|
|
39
|
+
slashing: NonNullable<StakingParams["slashing"]>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Extension of StakingParams that includes activation height and version information.
|
|
43
|
+
* These parameters are used to identify and select the appropriate staking rules at
|
|
44
|
+
* different blockchain heights, but do not affect the actual staking transaction content.
|
|
45
|
+
*/
|
|
46
|
+
export interface VersionedStakingParams extends StakingParams {
|
|
47
|
+
btcActivationHeight: number;
|
|
48
|
+
version: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Extension of VersionedStakingParams that includes a tag field for observability.
|
|
52
|
+
*/
|
|
53
|
+
export interface ObservableVersionedStakingParams extends VersionedStakingParams {
|
|
54
|
+
tag: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* PsbtResult is an object containing a partially signed transaction and its fee
|
|
58
|
+
*/
|
|
59
|
+
export interface PsbtResult {
|
|
60
|
+
psbt: Psbt;
|
|
61
|
+
fee: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* TransactionResult is an object containing an unsigned transaction and its fee
|
|
65
|
+
*/
|
|
66
|
+
export interface TransactionResult {
|
|
67
|
+
transaction: Transaction;
|
|
68
|
+
fee: number;
|
|
69
|
+
}
|
|
70
|
+
export interface UTXO {
|
|
71
|
+
txid: string;
|
|
72
|
+
vout: number;
|
|
73
|
+
value: number;
|
|
74
|
+
scriptPubKey: string;
|
|
75
|
+
rawTxHex?: string;
|
|
76
|
+
redeemScript?: string;
|
|
77
|
+
witnessScript?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface StakingScripts {
|
|
80
|
+
timelockScript: Buffer;
|
|
81
|
+
unbondingScript: Buffer;
|
|
82
|
+
slashingScript: Buffer;
|
|
83
|
+
unbondingTimelockScript: Buffer;
|
|
84
|
+
}
|
|
85
|
+
export declare class StakingScriptData {
|
|
86
|
+
stakerKey: Buffer;
|
|
87
|
+
finalityProviderKeys: Buffer[];
|
|
88
|
+
covenantKeys: Buffer[];
|
|
89
|
+
covenantThreshold: number;
|
|
90
|
+
stakingTimeLock: number;
|
|
91
|
+
unbondingTimeLock: number;
|
|
92
|
+
constructor(stakerKey: Buffer, finalityProviderKeys: Buffer[], covenantKeys: Buffer[], covenantThreshold: number, stakingTimelock: number, unbondingTimelock: number);
|
|
93
|
+
/**
|
|
94
|
+
* Validates the staking script.
|
|
95
|
+
* @returns {boolean} Returns true if the staking script is valid, otherwise false.
|
|
96
|
+
*/
|
|
97
|
+
validate(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Builds a timelock script.
|
|
100
|
+
* @param timelock - The timelock value to encode in the script.
|
|
101
|
+
* @returns {Buffer} containing the compiled timelock script.
|
|
102
|
+
*/
|
|
103
|
+
buildTimelockScript(timelock: number): Buffer;
|
|
104
|
+
/**
|
|
105
|
+
* Builds the staking timelock script.
|
|
106
|
+
* Only holder of private key for given pubKey can spend after relative lock time
|
|
107
|
+
* Creates the timelock script in the form:
|
|
108
|
+
* <stakerPubKey>
|
|
109
|
+
* OP_CHECKSIGVERIFY
|
|
110
|
+
* <stakingTimeBlocks>
|
|
111
|
+
* OP_CHECKSEQUENCEVERIFY
|
|
112
|
+
* @returns {Buffer} The staking timelock script.
|
|
113
|
+
*/
|
|
114
|
+
buildStakingTimelockScript(): Buffer;
|
|
115
|
+
/**
|
|
116
|
+
* Builds the unbonding timelock script.
|
|
117
|
+
* Creates the unbonding timelock script in the form:
|
|
118
|
+
* <stakerPubKey>
|
|
119
|
+
* OP_CHECKSIGVERIFY
|
|
120
|
+
* <unbondingTimeBlocks>
|
|
121
|
+
* OP_CHECKSEQUENCEVERIFY
|
|
122
|
+
* @returns {Buffer} The unbonding timelock script.
|
|
123
|
+
*/
|
|
124
|
+
buildUnbondingTimelockScript(): Buffer;
|
|
125
|
+
/**
|
|
126
|
+
* Builds the unbonding script in the form:
|
|
127
|
+
* buildSingleKeyScript(stakerPk, true) ||
|
|
128
|
+
* buildMultiKeyScript(covenantPks, covenantThreshold, false)
|
|
129
|
+
* || means combining the scripts
|
|
130
|
+
* @returns {Buffer} The unbonding script.
|
|
131
|
+
*/
|
|
132
|
+
buildUnbondingScript(): Buffer;
|
|
133
|
+
/**
|
|
134
|
+
* Builds the slashing script for staking in the form:
|
|
135
|
+
* buildSingleKeyScript(stakerPk, true) ||
|
|
136
|
+
* buildMultiKeyScript(finalityProviderPKs, 1, true) ||
|
|
137
|
+
* buildMultiKeyScript(covenantPks, covenantThreshold, false)
|
|
138
|
+
* || means combining the scripts
|
|
139
|
+
* The slashing script is a combination of single-key and multi-key scripts.
|
|
140
|
+
* The single-key script is used for staker key verification.
|
|
141
|
+
* The multi-key script is used for finality provider key verification and covenant key verification.
|
|
142
|
+
* @returns {Buffer} The slashing script as a Buffer.
|
|
143
|
+
*/
|
|
144
|
+
buildSlashingScript(): Buffer;
|
|
145
|
+
/**
|
|
146
|
+
* Builds the staking scripts.
|
|
147
|
+
* @returns {StakingScripts} The staking scripts.
|
|
148
|
+
*/
|
|
149
|
+
buildScripts(): StakingScripts;
|
|
150
|
+
/**
|
|
151
|
+
* Builds a single key script in the form:
|
|
152
|
+
* buildSingleKeyScript creates a single key script
|
|
153
|
+
* <pk> OP_CHECKSIGVERIFY (if withVerify is true)
|
|
154
|
+
* <pk> OP_CHECKSIG (if withVerify is false)
|
|
155
|
+
* @param pk - The public key buffer.
|
|
156
|
+
* @param withVerify - A boolean indicating whether to include the OP_CHECKSIGVERIFY opcode.
|
|
157
|
+
* @returns The compiled script buffer.
|
|
158
|
+
*/
|
|
159
|
+
buildSingleKeyScript(pk: Buffer, withVerify: boolean): Buffer;
|
|
160
|
+
/**
|
|
161
|
+
* Builds a multi-key script in the form:
|
|
162
|
+
* <pk1> OP_CHEKCSIG <pk2> OP_CHECKSIGADD <pk3> OP_CHECKSIGADD ... <pkN> OP_CHECKSIGADD <threshold> OP_NUMEQUAL
|
|
163
|
+
* <withVerify -> OP_NUMEQUALVERIFY>
|
|
164
|
+
* It validates whether provided keys are unique and the threshold is not greater than number of keys
|
|
165
|
+
* If there is only one key provided it will return single key sig script
|
|
166
|
+
* @param pks - An array of public keys.
|
|
167
|
+
* @param threshold - The required number of valid signers.
|
|
168
|
+
* @param withVerify - A boolean indicating whether to include the OP_VERIFY opcode.
|
|
169
|
+
* @returns The compiled multi-key script as a Buffer.
|
|
170
|
+
* @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.
|
|
171
|
+
*/
|
|
172
|
+
buildMultiKeyScript(pks: Buffer[], threshold: number, withVerify: boolean): Buffer;
|
|
173
|
+
}
|
|
174
|
+
export interface StakerInfo {
|
|
175
|
+
address: string;
|
|
176
|
+
publicKeyNoCoordHex: string;
|
|
177
|
+
}
|
|
178
|
+
export declare class Staking {
|
|
179
|
+
network: networks.Network;
|
|
180
|
+
stakerInfo: StakerInfo;
|
|
181
|
+
params: StakingParams;
|
|
182
|
+
finalityProviderPksNoCoordHex: string[];
|
|
183
|
+
stakingTimelock: number;
|
|
184
|
+
constructor(network: networks.Network, stakerInfo: StakerInfo, params: StakingParams, finalityProviderPksNoCoordHex: string[], stakingTimelock: number);
|
|
185
|
+
/**
|
|
186
|
+
* buildScripts builds the staking scripts for the staking transaction.
|
|
187
|
+
* Note: different staking types may have different scripts.
|
|
188
|
+
* e.g the observable staking script has a data embed script.
|
|
189
|
+
*
|
|
190
|
+
* @returns {StakingScripts} - The staking scripts.
|
|
191
|
+
*/
|
|
192
|
+
buildScripts(): StakingScripts;
|
|
193
|
+
/**
|
|
194
|
+
* Create a staking transaction for staking.
|
|
195
|
+
*
|
|
196
|
+
* @param {number} stakingAmountSat - The amount to stake in satoshis.
|
|
197
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
198
|
+
* transaction.
|
|
199
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
200
|
+
* @returns {TransactionResult} - An object containing the unsigned
|
|
201
|
+
* transaction, and fee
|
|
202
|
+
* @throws {StakingError} - If the transaction cannot be built
|
|
203
|
+
*/
|
|
204
|
+
createStakingTransaction(stakingAmountSat: number, inputUTXOs: UTXO[], feeRate: number): TransactionResult;
|
|
205
|
+
/**
|
|
206
|
+
* Creates a staking expansion transaction that extends an existing BTC stake
|
|
207
|
+
* to new finality providers or renews the timelock.
|
|
208
|
+
*
|
|
209
|
+
* This method implements RFC 037 BTC Stake Expansion,
|
|
210
|
+
* allowing existing active BTC staking transactions
|
|
211
|
+
* to extend their delegation to new finality providers without going through
|
|
212
|
+
* the full unbonding process.
|
|
213
|
+
*
|
|
214
|
+
* The expansion transaction:
|
|
215
|
+
* 1. Spends the previous staking transaction output as the first input
|
|
216
|
+
* 2. Uses funding UTXO as additional input to cover transaction fees or
|
|
217
|
+
* to increase the staking amount
|
|
218
|
+
* 3. Creates a new staking output with expanded finality provider coverage or
|
|
219
|
+
* renews the timelock
|
|
220
|
+
* 4. Has an output returning the remaining funds as change (if any) to the
|
|
221
|
+
* staker BTC address
|
|
222
|
+
*
|
|
223
|
+
* @param {number} stakingAmountSat - The total staking amount in satoshis
|
|
224
|
+
* (The amount had to be equal to the previous staking amount for now, this
|
|
225
|
+
* lib does not yet support increasing the staking amount at this stage)
|
|
226
|
+
* @param {UTXO[]} inputUTXOs - Available UTXOs to use for funding the
|
|
227
|
+
* expansion transaction fees. Only one will be selected for the expansion
|
|
228
|
+
* @param {number} feeRate - Fee rate in satoshis per byte for the
|
|
229
|
+
* expansion transaction
|
|
230
|
+
* @param {StakingParams} paramsForPreviousStakingTx - Staking parameters
|
|
231
|
+
* used in the previous staking transaction
|
|
232
|
+
* @param {Object} previousStakingTxInfo - Necessary information to spend the
|
|
233
|
+
* previous staking transaction.
|
|
234
|
+
* @returns {TransactionResult & { fundingUTXO: UTXO }} - An object containing
|
|
235
|
+
* the unsigned expansion transaction and calculated fee, and the funding UTXO
|
|
236
|
+
* @throws {StakingError} - If the transaction cannot be built or validation
|
|
237
|
+
* fails
|
|
238
|
+
*/
|
|
239
|
+
createStakingExpansionTransaction(stakingAmountSat: number, inputUTXOs: UTXO[], feeRate: number, paramsForPreviousStakingTx: StakingParams, previousStakingTxInfo: {
|
|
240
|
+
stakingTx: Transaction;
|
|
241
|
+
stakingInput: {
|
|
242
|
+
finalityProviderPksNoCoordHex: string[];
|
|
243
|
+
stakingTimelock: number;
|
|
244
|
+
};
|
|
245
|
+
}): TransactionResult & {
|
|
246
|
+
fundingUTXO: UTXO;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Create a staking psbt based on the existing staking transaction.
|
|
250
|
+
*
|
|
251
|
+
* @param {Transaction} stakingTx - The staking transaction.
|
|
252
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
253
|
+
* transaction. The UTXOs that were used to create the staking transaction should
|
|
254
|
+
* be included in this array.
|
|
255
|
+
* @returns {Psbt} - The psbt.
|
|
256
|
+
*/
|
|
257
|
+
toStakingPsbt(stakingTx: Transaction, inputUTXOs: UTXO[]): Psbt;
|
|
258
|
+
/**
|
|
259
|
+
* Convert a staking expansion transaction to a PSBT.
|
|
260
|
+
*
|
|
261
|
+
* @param {Transaction} stakingExpansionTx - The staking expansion
|
|
262
|
+
* transaction to convert
|
|
263
|
+
* @param {UTXO[]} inputUTXOs - Available UTXOs for the
|
|
264
|
+
* funding input (second input)
|
|
265
|
+
* @param {StakingParams} paramsForPreviousStakingTx - Staking parameters
|
|
266
|
+
* used for the previous staking transaction
|
|
267
|
+
* @param {Object} previousStakingTxInfo - Information about the previous
|
|
268
|
+
* staking transaction
|
|
269
|
+
* @returns {Psbt} The PSBT for the staking expansion transaction
|
|
270
|
+
* @throws {Error} If the previous staking output cannot be found or
|
|
271
|
+
* validation fails
|
|
272
|
+
*/
|
|
273
|
+
toStakingExpansionPsbt(stakingExpansionTx: Transaction, inputUTXOs: UTXO[], paramsForPreviousStakingTx: StakingParams, previousStakingTxInfo: {
|
|
274
|
+
stakingTx: Transaction;
|
|
275
|
+
stakingInput: {
|
|
276
|
+
finalityProviderPksNoCoordHex: string[];
|
|
277
|
+
stakingTimelock: number;
|
|
278
|
+
};
|
|
279
|
+
}): Psbt;
|
|
280
|
+
/**
|
|
281
|
+
* Create an unbonding transaction for staking.
|
|
282
|
+
*
|
|
283
|
+
* @param {Transaction} stakingTx - The staking transaction to unbond.
|
|
284
|
+
* @returns {TransactionResult} - An object containing the unsigned
|
|
285
|
+
* transaction, and fee
|
|
286
|
+
* @throws {StakingError} - If the transaction cannot be built
|
|
287
|
+
*/
|
|
288
|
+
createUnbondingTransaction(stakingTx: Transaction): TransactionResult;
|
|
289
|
+
/**
|
|
290
|
+
* Create an unbonding psbt based on the existing unbonding transaction and
|
|
291
|
+
* staking transaction.
|
|
292
|
+
*
|
|
293
|
+
* @param {Transaction} unbondingTx - The unbonding transaction.
|
|
294
|
+
* @param {Transaction} stakingTx - The staking transaction.
|
|
295
|
+
*
|
|
296
|
+
* @returns {Psbt} - The psbt.
|
|
297
|
+
*/
|
|
298
|
+
toUnbondingPsbt(unbondingTx: Transaction, stakingTx: Transaction): Psbt;
|
|
299
|
+
/**
|
|
300
|
+
* Creates a withdrawal transaction that spends from an unbonding or slashing
|
|
301
|
+
* transaction. The timelock on the input transaction must have expired before
|
|
302
|
+
* this withdrawal can be valid.
|
|
303
|
+
*
|
|
304
|
+
* @param {Transaction} earlyUnbondedTx - The unbonding or slashing
|
|
305
|
+
* transaction to withdraw from
|
|
306
|
+
* @param {number} feeRate - Fee rate in satoshis per byte for the withdrawal
|
|
307
|
+
* transaction
|
|
308
|
+
* @returns {PsbtResult} - Contains the unsigned PSBT and fee amount
|
|
309
|
+
* @throws {StakingError} - If the input transaction is invalid or withdrawal
|
|
310
|
+
* transaction cannot be built
|
|
311
|
+
*/
|
|
312
|
+
createWithdrawEarlyUnbondedTransaction(earlyUnbondedTx: Transaction, feeRate: number): PsbtResult;
|
|
313
|
+
/**
|
|
314
|
+
* Create a withdrawal psbt that spends a naturally expired staking
|
|
315
|
+
* transaction.
|
|
316
|
+
*
|
|
317
|
+
* @param {Transaction} stakingTx - The staking transaction to withdraw from.
|
|
318
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
319
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
320
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
321
|
+
*/
|
|
322
|
+
createWithdrawStakingExpiredPsbt(stakingTx: Transaction, feeRate: number): PsbtResult;
|
|
323
|
+
/**
|
|
324
|
+
* Create a slashing psbt spending from the staking output.
|
|
325
|
+
*
|
|
326
|
+
* @param {Transaction} stakingTx - The staking transaction to slash.
|
|
327
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
328
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
329
|
+
*/
|
|
330
|
+
createStakingOutputSlashingPsbt(stakingTx: Transaction): PsbtResult;
|
|
331
|
+
/**
|
|
332
|
+
* Create a slashing psbt for an unbonding output.
|
|
333
|
+
*
|
|
334
|
+
* @param {Transaction} unbondingTx - The unbonding transaction to slash.
|
|
335
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
336
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
337
|
+
*/
|
|
338
|
+
createUnbondingOutputSlashingPsbt(unbondingTx: Transaction): PsbtResult;
|
|
339
|
+
/**
|
|
340
|
+
* Create a withdraw slashing psbt that spends a slashing transaction from the
|
|
341
|
+
* staking output.
|
|
342
|
+
*
|
|
343
|
+
* @param {Transaction} slashingTx - The slashing transaction.
|
|
344
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
345
|
+
* @returns {PsbtResult} - An object containing the unsigned psbt and fee
|
|
346
|
+
* @throws {StakingError} - If the delegation is invalid or the transaction cannot be built
|
|
347
|
+
*/
|
|
348
|
+
createWithdrawSlashingPsbt(slashingTx: Transaction, feeRate: number): PsbtResult;
|
|
349
|
+
}
|
|
350
|
+
export type RegistrationStep = "staking-slashing" | "unbonding-slashing" | "proof-of-possession" | "create-btc-delegation-msg";
|
|
351
|
+
export type WithdrawalType = "staking-expired" | "early-unbonded" | "slashing";
|
|
352
|
+
export type EventData = Record<string, string | number | string[] | number[]>;
|
|
353
|
+
export interface ManagerEvents {
|
|
354
|
+
"delegation:create": (data?: EventData) => void;
|
|
355
|
+
"delegation:register": (data?: EventData) => void;
|
|
356
|
+
"delegation:stake": (data?: EventData) => void;
|
|
357
|
+
"delegation:unbond": (data?: EventData) => void;
|
|
358
|
+
"delegation:withdraw": (data?: EventData) => void;
|
|
359
|
+
"delegation:expand": (data?: EventData) => void;
|
|
360
|
+
}
|
|
361
|
+
export type DelegationEvent = keyof ManagerEvents;
|
|
362
|
+
export interface Action {
|
|
363
|
+
name: ActionName;
|
|
364
|
+
}
|
|
365
|
+
declare enum ActionName {
|
|
366
|
+
SIGN_BTC_STAKING_TRANSACTION = "sign-btc-staking-transaction",
|
|
367
|
+
SIGN_BTC_UNBONDING_TRANSACTION = "sign-btc-unbonding-transaction",
|
|
368
|
+
SIGN_BTC_WITHDRAW_TRANSACTION = "sign-btc-withdraw-transaction",
|
|
369
|
+
SIGN_BTC_SLASHING_TRANSACTION = "sign-btc-slashing-transaction",
|
|
370
|
+
SIGN_BTC_UNBONDING_SLASHING_TRANSACTION = "sign-btc-unbonding-slashing-transaction"
|
|
371
|
+
}
|
|
372
|
+
export interface Contract {
|
|
373
|
+
id: ContractId;
|
|
374
|
+
params: ContractData;
|
|
375
|
+
}
|
|
376
|
+
declare enum ContractId {
|
|
377
|
+
STAKING = "babylon:staking",
|
|
378
|
+
UNBONDING = "babylon:unbonding",
|
|
379
|
+
SLASHING = "babylon:slashing",
|
|
380
|
+
WITHDRAW = "babylon:withdraw",
|
|
381
|
+
SLASHING_BURN = "babylon:slashing-burn"
|
|
382
|
+
}
|
|
383
|
+
export type ContractData = Record<string, string | number | string[] | number[]>;
|
|
384
|
+
export interface SignPsbtOptions {
|
|
385
|
+
contracts: Contract[];
|
|
386
|
+
action: Action;
|
|
387
|
+
}
|
|
388
|
+
export interface BtcProvider {
|
|
389
|
+
signPsbt(psbtHex: string, options?: SignPsbtOptions): Promise<string>;
|
|
390
|
+
signMessage: (message: string, type: "ecdsa" | "bip322-simple") => Promise<string>;
|
|
391
|
+
getTransactionHex(txid: string): Promise<string>;
|
|
392
|
+
}
|
|
393
|
+
export interface BabylonProvider {
|
|
394
|
+
/**
|
|
395
|
+
* Signs a Babylon chain transaction.
|
|
396
|
+
* This is primarily used for signing MsgCreateBTCDelegation transactions
|
|
397
|
+
* which register the BTC delegation on the Babylon Genesis chain.
|
|
398
|
+
*
|
|
399
|
+
* @param {object} msg - The Cosmos SDK transaction message to sign
|
|
400
|
+
* @param {string} msg.typeUrl - The Protobuf type URL identifying the message type
|
|
401
|
+
* @param {T} msg.value - The transaction message data matching the typeUrl
|
|
402
|
+
* @returns {Promise<Uint8Array>} The signed transaction bytes
|
|
403
|
+
*/
|
|
404
|
+
signTransaction: <T extends object>(msg: {
|
|
405
|
+
typeUrl: string;
|
|
406
|
+
value: T;
|
|
407
|
+
}) => Promise<Uint8Array>;
|
|
408
|
+
/**
|
|
409
|
+
* Gets the current height of the Babylon Genesis chain.
|
|
410
|
+
*
|
|
411
|
+
* @returns {Promise<number>} The current Babylon chain height
|
|
412
|
+
*/
|
|
413
|
+
getCurrentHeight?: () => Promise<number>;
|
|
414
|
+
/**
|
|
415
|
+
* Gets the chain ID of the Babylon Genesis chain.
|
|
416
|
+
*
|
|
417
|
+
* @returns {Promise<string>} The Babylon chain ID
|
|
418
|
+
*/
|
|
419
|
+
getChainId?: () => Promise<string>;
|
|
420
|
+
}
|
|
421
|
+
export interface StakingInputs {
|
|
422
|
+
finalityProviderPksNoCoordHex: string[];
|
|
423
|
+
stakingAmountSat: number;
|
|
424
|
+
stakingTimelock: number;
|
|
425
|
+
}
|
|
426
|
+
export interface InclusionProof {
|
|
427
|
+
pos: number;
|
|
428
|
+
merkle: string[];
|
|
429
|
+
blockHashHex: string;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Upgrade configuration for Babylon POP (Proof of Possession) context.
|
|
433
|
+
* This is used to determine when to switch to the new POP context format
|
|
434
|
+
* based on the Babylon chain height and version.
|
|
435
|
+
*/
|
|
436
|
+
export interface UpgradeConfig {
|
|
437
|
+
/**
|
|
438
|
+
* POP context upgrade configuration.
|
|
439
|
+
*/
|
|
440
|
+
pop?: PopUpgradeConfig;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Configuration for POP context upgrade.
|
|
444
|
+
* - upgradeHeight: The Babylon chain height at which the POP context upgrade is activated.
|
|
445
|
+
* - version: The version of the POP context to use after the upgrade.
|
|
446
|
+
*/
|
|
447
|
+
export interface PopUpgradeConfig {
|
|
448
|
+
/**
|
|
449
|
+
* The Babylon chain height at which the POP context upgrade is activated.
|
|
450
|
+
*/
|
|
451
|
+
upgradeHeight: number;
|
|
452
|
+
/**
|
|
453
|
+
* The version of the POP context to use after the upgrade.
|
|
454
|
+
*/
|
|
455
|
+
version: number;
|
|
456
|
+
}
|
|
457
|
+
export declare class BabylonBtcStakingManager {
|
|
458
|
+
protected network: networks.Network;
|
|
459
|
+
protected stakingParams: VersionedStakingParams[];
|
|
460
|
+
protected btcProvider: BtcProvider;
|
|
461
|
+
protected babylonProvider: BabylonProvider;
|
|
462
|
+
protected ee?: Emitter<ManagerEvents> | undefined;
|
|
463
|
+
private upgradeConfig?;
|
|
464
|
+
constructor(network: networks.Network, stakingParams: VersionedStakingParams[], btcProvider: BtcProvider, babylonProvider: BabylonProvider, ee?: Emitter<ManagerEvents> | undefined, upgradeConfig?: UpgradeConfig);
|
|
465
|
+
/**
|
|
466
|
+
* Creates a signed Pre-Staking Registration transaction that is ready to be
|
|
467
|
+
* sent to the Babylon chain.
|
|
468
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
469
|
+
* and the no-coord public key in hex format.
|
|
470
|
+
* @param stakingInput - The staking inputs.
|
|
471
|
+
* @param babylonBtcTipHeight - The Babylon BTC tip height.
|
|
472
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
473
|
+
* transaction.
|
|
474
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
475
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
476
|
+
* be included in a block.
|
|
477
|
+
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
478
|
+
* @returns The signed babylon pre-staking registration transaction in base64
|
|
479
|
+
* format.
|
|
480
|
+
*/
|
|
481
|
+
preStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, babylonBtcTipHeight: number, inputUTXOs: UTXO[], feeRate: number, babylonAddress: string): Promise<{
|
|
482
|
+
signedBabylonTx: Uint8Array;
|
|
483
|
+
stakingTx: Transaction;
|
|
484
|
+
}>;
|
|
485
|
+
/**
|
|
486
|
+
* Create a signed staking expansion transaction that is ready to be sent to
|
|
487
|
+
* the Babylon chain.
|
|
488
|
+
*/
|
|
489
|
+
stakingExpansionRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, babylonBtcTipHeight: number, inputUTXOs: UTXO[], feeRate: number, babylonAddress: string, previousStakingTxInfo: {
|
|
490
|
+
stakingTx: Transaction;
|
|
491
|
+
paramVersion: number;
|
|
492
|
+
stakingInput: StakingInputs;
|
|
493
|
+
}): Promise<{
|
|
494
|
+
signedBabylonTx: Uint8Array;
|
|
495
|
+
stakingTx: Transaction;
|
|
496
|
+
}>;
|
|
497
|
+
/**
|
|
498
|
+
* Estimates the transaction fee for a BTC staking expansion transaction.
|
|
499
|
+
*
|
|
500
|
+
* @param {StakerInfo} stakerBtcInfo - The staker's Bitcoin information
|
|
501
|
+
* including address and public key
|
|
502
|
+
* @param {number} babylonBtcTipHeight - The current Babylon BTC tip height
|
|
503
|
+
* used to determine staking parameters
|
|
504
|
+
* @param {StakingInputs} stakingInput - The new staking input parameters for
|
|
505
|
+
* the expansion
|
|
506
|
+
* @param {UTXO[]} inputUTXOs - Available UTXOs that can be used for funding
|
|
507
|
+
* the expansion transaction
|
|
508
|
+
* @param {number} feeRate - Fee rate in satoshis per byte for the expansion
|
|
509
|
+
* transaction
|
|
510
|
+
* @param {Object} previousStakingTxInfo - Information about the previous
|
|
511
|
+
* staking transaction being expanded
|
|
512
|
+
* @returns {number} - The estimated transaction fee in satoshis
|
|
513
|
+
* @throws {Error} - If validation fails or the fee cannot be calculated
|
|
514
|
+
*/
|
|
515
|
+
estimateBtcStakingExpansionFee(stakerBtcInfo: StakerInfo, babylonBtcTipHeight: number, stakingInput: StakingInputs, inputUTXOs: UTXO[], feeRate: number, previousStakingTxInfo: {
|
|
516
|
+
stakingTx: Transaction;
|
|
517
|
+
paramVersion: number;
|
|
518
|
+
stakingInput: StakingInputs;
|
|
519
|
+
}): number;
|
|
520
|
+
/**
|
|
521
|
+
* Creates a signed post-staking registration transaction that is ready to be
|
|
522
|
+
* sent to the Babylon chain. This is used when a staking transaction is
|
|
523
|
+
* already created and included in a BTC block and we want to register it on
|
|
524
|
+
* the Babylon chain.
|
|
525
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
526
|
+
* and the no-coord public key in hex format.
|
|
527
|
+
* @param stakingTx - The staking transaction.
|
|
528
|
+
* @param stakingTxHeight - The BTC height in which the staking transaction
|
|
529
|
+
* is included.
|
|
530
|
+
* @param stakingInput - The staking inputs.
|
|
531
|
+
* @param inclusionProof - Merkle Proof of Inclusion: Verifies transaction
|
|
532
|
+
* inclusion in a Bitcoin block that is k-deep.
|
|
533
|
+
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
534
|
+
* @returns The signed babylon transaction in base64 format.
|
|
535
|
+
*/
|
|
536
|
+
postStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingTx: Transaction, stakingTxHeight: number, stakingInput: StakingInputs, inclusionProof: InclusionProof, babylonAddress: string): Promise<{
|
|
537
|
+
signedBabylonTx: Uint8Array;
|
|
538
|
+
}>;
|
|
539
|
+
/**
|
|
540
|
+
* Estimates the BTC fee required for staking.
|
|
541
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
542
|
+
* and the no-coord public key in hex format.
|
|
543
|
+
* @param babylonBtcTipHeight - The BTC tip height recorded on the Babylon
|
|
544
|
+
* chain.
|
|
545
|
+
* @param stakingInput - The staking inputs.
|
|
546
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
547
|
+
* transaction.
|
|
548
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
549
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
550
|
+
* be included in a block.
|
|
551
|
+
* @returns The estimated BTC fee in satoshis.
|
|
552
|
+
*/
|
|
553
|
+
estimateBtcStakingFee(stakerBtcInfo: StakerInfo, babylonBtcTipHeight: number, stakingInput: StakingInputs, inputUTXOs: UTXO[], feeRate: number): number;
|
|
554
|
+
/**
|
|
555
|
+
* Creates a signed staking transaction that is ready to be sent to the BTC
|
|
556
|
+
* network.
|
|
557
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
558
|
+
* and the no-coord public key in hex format.
|
|
559
|
+
* @param stakingInput - The staking inputs.
|
|
560
|
+
* @param unsignedStakingTx - The unsigned staking transaction.
|
|
561
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
562
|
+
* transaction.
|
|
563
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
564
|
+
* delegation in Babylon chain
|
|
565
|
+
* @returns The signed staking transaction.
|
|
566
|
+
*/
|
|
567
|
+
createSignedBtcStakingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, unsignedStakingTx: Transaction, inputUTXOs: UTXO[], stakingParamsVersion: number): Promise<Transaction>;
|
|
568
|
+
/**
|
|
569
|
+
* Creates a signed staking expansion transaction that is ready to be sent to
|
|
570
|
+
* the BTC network.
|
|
571
|
+
*
|
|
572
|
+
* @param {StakerInfo} stakerBtcInfo - The staker's BTC information including
|
|
573
|
+
* address and public key
|
|
574
|
+
* @param {StakingInputs} stakingInput - The staking inputs for the expansion
|
|
575
|
+
* @param {Transaction} unsignedStakingExpansionTx - The unsigned staking
|
|
576
|
+
* expansion transaction
|
|
577
|
+
* @param {UTXO[]} inputUTXOs - Available UTXOs for the funding input
|
|
578
|
+
* @param {number} stakingParamsVersion - The version of staking parameters
|
|
579
|
+
* that was used when registering the staking expansion delegation.
|
|
580
|
+
* @param {Object} previousStakingTxInfo - Information about the previous
|
|
581
|
+
* staking transaction
|
|
582
|
+
* @param {Array} covenantStakingExpansionSignatures - Covenant committee
|
|
583
|
+
* signatures for the expansion
|
|
584
|
+
* @returns {Promise<Transaction>} The fully signed staking expansion
|
|
585
|
+
* transaction
|
|
586
|
+
* @throws {Error} If signing fails, validation fails, or required data is
|
|
587
|
+
* missing
|
|
588
|
+
*/
|
|
589
|
+
createSignedBtcStakingExpansionTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, unsignedStakingExpansionTx: Transaction, inputUTXOs: UTXO[], stakingParamsVersion: number, previousStakingTxInfo: {
|
|
590
|
+
stakingTx: Transaction;
|
|
591
|
+
paramVersion: number;
|
|
592
|
+
stakingInput: StakingInputs;
|
|
593
|
+
}, covenantStakingExpansionSignatures: {
|
|
594
|
+
btcPkHex: string;
|
|
595
|
+
sigHex: string;
|
|
596
|
+
}[]): Promise<Transaction>;
|
|
597
|
+
/**
|
|
598
|
+
* Creates a partial signed unbonding transaction that is only signed by the
|
|
599
|
+
* staker. In order to complete the unbonding transaction, the covenant
|
|
600
|
+
* unbonding signatures need to be added to the transaction before sending it
|
|
601
|
+
* to the BTC network.
|
|
602
|
+
* NOTE: This method should only be used for Babylon phase-1 unbonding.
|
|
603
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
604
|
+
* and the no-coord public key in hex format.
|
|
605
|
+
* @param stakingInput - The staking inputs.
|
|
606
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
607
|
+
* delegation in Babylon chain
|
|
608
|
+
* @param stakingTx - The staking transaction.
|
|
609
|
+
* @returns The partial signed unbonding transaction and its fee.
|
|
610
|
+
*/
|
|
611
|
+
createPartialSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction): Promise<TransactionResult>;
|
|
612
|
+
/**
|
|
613
|
+
* Creates a signed unbonding transaction that is ready to be sent to the BTC
|
|
614
|
+
* network.
|
|
615
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
616
|
+
* and the no-coord public key in hex format.
|
|
617
|
+
* @param stakingInput - The staking inputs.
|
|
618
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
619
|
+
* delegation in Babylon chain
|
|
620
|
+
* @param stakingTx - The staking transaction.
|
|
621
|
+
* @param unsignedUnbondingTx - The unsigned unbonding transaction.
|
|
622
|
+
* @param covenantUnbondingSignatures - The covenant unbonding signatures.
|
|
623
|
+
* It can be retrieved from the Babylon chain or API.
|
|
624
|
+
* @returns The signed unbonding transaction and its fee.
|
|
625
|
+
*/
|
|
626
|
+
createSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, unsignedUnbondingTx: Transaction, covenantUnbondingSignatures: {
|
|
627
|
+
btcPkHex: string;
|
|
628
|
+
sigHex: string;
|
|
629
|
+
}[]): Promise<TransactionResult>;
|
|
630
|
+
/**
|
|
631
|
+
* Creates a signed withdrawal transaction on the unbodning output expiry path
|
|
632
|
+
* that is ready to be sent to the BTC network.
|
|
633
|
+
* @param stakingInput - The staking inputs.
|
|
634
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
635
|
+
* delegation in Babylon chain
|
|
636
|
+
* @param earlyUnbondingTx - The early unbonding transaction.
|
|
637
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
638
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
639
|
+
* be included in a block.
|
|
640
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
641
|
+
*/
|
|
642
|
+
createSignedBtcWithdrawEarlyUnbondedTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, earlyUnbondingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
643
|
+
/**
|
|
644
|
+
* Creates a signed withdrawal transaction on the staking output expiry path
|
|
645
|
+
* that is ready to be sent to the BTC network.
|
|
646
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
647
|
+
* and the no-coord public key in hex format.
|
|
648
|
+
* @param stakingInput - The staking inputs.
|
|
649
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
650
|
+
* delegation in Babylon chain
|
|
651
|
+
* @param stakingTx - The staking transaction.
|
|
652
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
653
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
654
|
+
* be included in a block.
|
|
655
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
656
|
+
*/
|
|
657
|
+
createSignedBtcWithdrawStakingExpiredTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
658
|
+
/**
|
|
659
|
+
* Creates a signed withdrawal transaction for the expired slashing output that
|
|
660
|
+
* is ready to be sent to the BTC network.
|
|
661
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
662
|
+
* and the no-coord public key in hex format.
|
|
663
|
+
* @param stakingInput - The staking inputs.
|
|
664
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
665
|
+
* delegation in Babylon chain
|
|
666
|
+
* @param slashingTx - The slashing transaction.
|
|
667
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
668
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
669
|
+
* be included in a block.
|
|
670
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
671
|
+
*/
|
|
672
|
+
createSignedBtcWithdrawSlashingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, slashingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
673
|
+
/**
|
|
674
|
+
* Creates a proof of possession for the staker based on ECDSA signature.
|
|
675
|
+
* @param bech32Address - The staker's bech32 address.
|
|
676
|
+
* @returns The proof of possession.
|
|
677
|
+
*/
|
|
678
|
+
createProofOfPossession(channel: "delegation:create" | "delegation:register" | "delegation:expand", bech32Address: string, stakerBtcAddress: string): Promise<ProofOfPossessionBTC>;
|
|
679
|
+
/**
|
|
680
|
+
* Creates the unbonding, slashing, and unbonding slashing transactions and
|
|
681
|
+
* PSBTs.
|
|
682
|
+
* @param stakingInstance - The staking instance.
|
|
683
|
+
* @param stakingTx - The staking transaction.
|
|
684
|
+
* @returns The unbonding, slashing, and unbonding slashing transactions and
|
|
685
|
+
* PSBTs.
|
|
686
|
+
*/
|
|
687
|
+
private createDelegationTransactionsAndPsbts;
|
|
688
|
+
/**
|
|
689
|
+
* Creates a protobuf message for the BTC delegation.
|
|
690
|
+
* @param channel - The event channel to emit the message on.
|
|
691
|
+
* @param stakingInstance - The staking instance.
|
|
692
|
+
* @param stakingInput - The staking inputs.
|
|
693
|
+
* @param stakingTx - The staking transaction.
|
|
694
|
+
* @param bech32Address - The staker's babylon chain bech32 address
|
|
695
|
+
* @param stakerBtcInfo - The staker's BTC information such as address and
|
|
696
|
+
* public key
|
|
697
|
+
* @param params - The staking parameters.
|
|
698
|
+
* @param options - The options for the BTC delegation.
|
|
699
|
+
* @param options.inclusionProof - The inclusion proof of the staking
|
|
700
|
+
* transaction.
|
|
701
|
+
* @param options.delegationExpansionInfo - The information for the BTC
|
|
702
|
+
* delegation expansion.
|
|
703
|
+
* @returns The protobuf message.
|
|
704
|
+
*/
|
|
705
|
+
createBtcDelegationMsg(channel: "delegation:create" | "delegation:register" | "delegation:expand", stakingInstance: Staking, stakingInput: StakingInputs, stakingTx: Transaction, bech32Address: string, stakerBtcInfo: StakerInfo, params: StakingParams, options?: {
|
|
706
|
+
inclusionProof?: btcstaking.InclusionProof;
|
|
707
|
+
delegationExpansionInfo?: {
|
|
708
|
+
previousStakingTx: Transaction;
|
|
709
|
+
fundingTx: Transaction;
|
|
710
|
+
};
|
|
711
|
+
}): Promise<{
|
|
712
|
+
typeUrl: string;
|
|
713
|
+
value: btcstakingtx.MsgCreateBTCDelegation | btcstakingtx.MsgBtcStakeExpand;
|
|
714
|
+
}>;
|
|
715
|
+
/**
|
|
716
|
+
* Gets the inclusion proof for the staking transaction.
|
|
717
|
+
* See the type `InclusionProof` for more information
|
|
718
|
+
* @param inclusionProof - The inclusion proof.
|
|
719
|
+
* @returns The inclusion proof.
|
|
720
|
+
*/
|
|
721
|
+
private getInclusionProof;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Get the staker signature from the unbonding transaction
|
|
725
|
+
* This is used mostly for unbonding transactions from phase-1(Observable)
|
|
726
|
+
* @param unbondingTx - The unbonding transaction
|
|
727
|
+
* @returns The staker signature
|
|
728
|
+
*/
|
|
729
|
+
export declare const getUnbondingTxStakerSignature: (unbondingTx: Transaction) => string;
|
|
730
|
+
export interface ObservableStakingScripts extends StakingScripts {
|
|
731
|
+
dataEmbedScript: Buffer;
|
|
732
|
+
}
|
|
733
|
+
export declare class ObservableStakingScriptData extends StakingScriptData {
|
|
734
|
+
magicBytes: Buffer;
|
|
735
|
+
constructor(stakerKey: Buffer, finalityProviderKeys: Buffer[], covenantKeys: Buffer[], covenantThreshold: number, stakingTimelock: number, unbondingTimelock: number, magicBytes: Buffer);
|
|
736
|
+
/**
|
|
737
|
+
* Builds a data embed script for staking in the form:
|
|
738
|
+
* OP_RETURN || <serializedStakingData>
|
|
739
|
+
* where serializedStakingData is the concatenation of:
|
|
740
|
+
* MagicBytes || Version || StakerPublicKey || FinalityProviderPublicKey || StakingTimeLock
|
|
741
|
+
* Note: Only a single finality provider key is supported for now in phase 1
|
|
742
|
+
* @throws {Error} If the number of finality provider keys is not equal to 1.
|
|
743
|
+
* @returns {Buffer} The compiled data embed script.
|
|
744
|
+
*/
|
|
745
|
+
buildDataEmbedScript(): Buffer;
|
|
746
|
+
/**
|
|
747
|
+
* Builds the staking scripts.
|
|
748
|
+
* @returns {ObservableStakingScripts} The staking scripts that can be used to stake.
|
|
749
|
+
* contains the timelockScript, unbondingScript, slashingScript,
|
|
750
|
+
* unbondingTimelockScript, and dataEmbedScript.
|
|
751
|
+
* @throws {Error} If script data is invalid.
|
|
752
|
+
*/
|
|
753
|
+
buildScripts(): ObservableStakingScripts;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* ObservableStaking is a class that provides an interface to create observable
|
|
757
|
+
* staking transactions for the Babylon Staking protocol.
|
|
758
|
+
*
|
|
759
|
+
* The class requires a network and staker information to create staking
|
|
760
|
+
* transactions.
|
|
761
|
+
* The staker information includes the staker's address and
|
|
762
|
+
* public key(without coordinates).
|
|
763
|
+
*/
|
|
764
|
+
export declare class ObservableStaking extends Staking {
|
|
765
|
+
params: ObservableVersionedStakingParams;
|
|
766
|
+
constructor(network: networks.Network, stakerInfo: StakerInfo, params: ObservableVersionedStakingParams, finalityProviderPksNoCoordHex: string[], stakingTimelock: number);
|
|
767
|
+
/**
|
|
768
|
+
* Build the staking scripts for observable staking.
|
|
769
|
+
* This method overwrites the base method to include the OP_RETURN tag based
|
|
770
|
+
* on the tag provided in the parameters.
|
|
771
|
+
*
|
|
772
|
+
* @returns {ObservableStakingScripts} - The staking scripts for observable staking.
|
|
773
|
+
* @throws {StakingError} - If the scripts cannot be built.
|
|
774
|
+
*/
|
|
775
|
+
buildScripts(): ObservableStakingScripts;
|
|
776
|
+
/**
|
|
777
|
+
* Create a staking transaction for observable staking.
|
|
778
|
+
* This overwrites the method from the Staking class with the addtion
|
|
779
|
+
* of the
|
|
780
|
+
* 1. OP_RETURN tag in the staking scripts
|
|
781
|
+
* 2. lockHeight parameter
|
|
782
|
+
*
|
|
783
|
+
* @param {number} stakingAmountSat - The amount to stake in satoshis.
|
|
784
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
785
|
+
* transaction.
|
|
786
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
787
|
+
* @returns {TransactionResult} - An object containing the unsigned transaction,
|
|
788
|
+
* and fee
|
|
789
|
+
*/
|
|
790
|
+
createStakingTransaction(stakingAmountSat: number, inputUTXOs: UTXO[], feeRate: number): TransactionResult;
|
|
791
|
+
/**
|
|
792
|
+
* Create a staking psbt for observable staking.
|
|
793
|
+
*
|
|
794
|
+
* @param {Transaction} stakingTx - The staking transaction.
|
|
795
|
+
* @param {UTXO[]} inputUTXOs - The UTXOs to use as inputs for the staking
|
|
796
|
+
* transaction.
|
|
797
|
+
* @returns {Psbt} - The psbt.
|
|
798
|
+
*/
|
|
799
|
+
toStakingPsbt(stakingTx: Transaction, inputUTXOs: UTXO[]): Psbt;
|
|
800
|
+
}
|
|
801
|
+
export interface CovenantSignature {
|
|
802
|
+
btcPkHex: string;
|
|
803
|
+
sigHex: string;
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Constructs an unsigned BTC Staking transaction in psbt format.
|
|
807
|
+
*
|
|
808
|
+
* Outputs:
|
|
809
|
+
* - psbt:
|
|
810
|
+
* - The first output corresponds to the staking script with the specified amount.
|
|
811
|
+
* - The second output corresponds to the change from spending the amount and the transaction fee.
|
|
812
|
+
* - If a data embed script is provided, it will be added as the second output, and the fee will be the third output.
|
|
813
|
+
* - fee: The total fee amount for the transaction.
|
|
814
|
+
*
|
|
815
|
+
* Inputs:
|
|
816
|
+
* - scripts:
|
|
817
|
+
* - timelockScript, unbondingScript, slashingScript: Scripts for different transaction types.
|
|
818
|
+
* - dataEmbedScript: Optional data embed script.
|
|
819
|
+
* - amount: Amount to stake.
|
|
820
|
+
* - changeAddress: Address to send the change to.
|
|
821
|
+
* - inputUTXOs: All available UTXOs from the wallet.
|
|
822
|
+
* - network: Bitcoin network.
|
|
823
|
+
* - feeRate: Fee rate in satoshis per byte.
|
|
824
|
+
* - publicKeyNoCoord: Public key if the wallet is in taproot mode.
|
|
825
|
+
* - lockHeight: Optional block height locktime to set for the transaction (i.e., not mined until the block height).
|
|
826
|
+
*
|
|
827
|
+
* @param {Object} scripts - Scripts used to construct the taproot output.
|
|
828
|
+
* such as timelockScript, unbondingScript, slashingScript, and dataEmbedScript.
|
|
829
|
+
* @param {number} amount - The amount to stake.
|
|
830
|
+
* @param {string} changeAddress - The address to send the change to.
|
|
831
|
+
* @param {UTXO[]} inputUTXOs - All available UTXOs from the wallet.
|
|
832
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
833
|
+
* @param {number} feeRate - The fee rate in satoshis per byte.
|
|
834
|
+
* @param {number} [lockHeight] - The optional block height locktime.
|
|
835
|
+
* @returns {TransactionResult} - An object containing the unsigned transaction and fee
|
|
836
|
+
* @throws Will throw an error if the amount or fee rate is less than or equal
|
|
837
|
+
* to 0, if the change address is invalid, or if the public key is invalid.
|
|
838
|
+
*/
|
|
839
|
+
export declare function stakingTransaction(scripts: {
|
|
840
|
+
timelockScript: Buffer;
|
|
841
|
+
unbondingScript: Buffer;
|
|
842
|
+
slashingScript: Buffer;
|
|
843
|
+
dataEmbedScript?: Buffer;
|
|
844
|
+
}, amount: number, changeAddress: string, inputUTXOs: UTXO[], network: networks.Network, feeRate: number, lockHeight?: number): TransactionResult;
|
|
845
|
+
/**
|
|
846
|
+
* Expand an existing staking transaction with additional finality providers
|
|
847
|
+
* or renew timelock.
|
|
848
|
+
*
|
|
849
|
+
* This function builds a Bitcoin transaction that:
|
|
850
|
+
* 1. Spends the previous staking transaction output as the first input
|
|
851
|
+
* 2. Uses a funding UTXO as the second input to cover transaction fees
|
|
852
|
+
* 3. Creates new staking outputs where the timelock is renewed or FPs added
|
|
853
|
+
* 4. Returns any remaining funds as change
|
|
854
|
+
*
|
|
855
|
+
* @param network - Bitcoin network (mainnet, testnet, etc.)
|
|
856
|
+
* @param scripts - Scripts for the new staking outputs
|
|
857
|
+
* @param amount - Total staking amount (must equal previous staking amount,
|
|
858
|
+
* we only support equal amounts for now)
|
|
859
|
+
* @param changeAddress - Bitcoin address to receive change from funding UTXO
|
|
860
|
+
* @param feeRate - Fee rate in satoshis per byte
|
|
861
|
+
* @param inputUTXOs - Available UTXOs to use for funding the expansion
|
|
862
|
+
* @param previousStakingTxInfo - Details of the previous staking transaction
|
|
863
|
+
* being expanded
|
|
864
|
+
* @returns {TransactionResult & { fundingUTXO: UTXO }} containing the built
|
|
865
|
+
* transaction and calculated fee, and the funding UTXO
|
|
866
|
+
*/
|
|
867
|
+
export declare function stakingExpansionTransaction(network: networks.Network, scripts: {
|
|
868
|
+
timelockScript: Buffer;
|
|
869
|
+
unbondingScript: Buffer;
|
|
870
|
+
slashingScript: Buffer;
|
|
871
|
+
}, amount: number, changeAddress: string, feeRate: number, inputUTXOs: UTXO[], previousStakingTxInfo: {
|
|
872
|
+
stakingTx: Transaction;
|
|
873
|
+
scripts: {
|
|
874
|
+
timelockScript: Buffer;
|
|
875
|
+
unbondingScript: Buffer;
|
|
876
|
+
slashingScript: Buffer;
|
|
877
|
+
};
|
|
878
|
+
}): TransactionResult & {
|
|
879
|
+
fundingUTXO: UTXO;
|
|
880
|
+
};
|
|
881
|
+
/**
|
|
882
|
+
* Constructs a withdrawal transaction for manually unbonded delegation.
|
|
883
|
+
*
|
|
884
|
+
* This transaction spends the unbonded output from the staking transaction.
|
|
885
|
+
*
|
|
886
|
+
* Inputs:
|
|
887
|
+
* - scripts: Scripts used to construct the taproot output.
|
|
888
|
+
* - unbondingTimelockScript: Script for the unbonding timelock condition.
|
|
889
|
+
* - slashingScript: Script for the slashing condition.
|
|
890
|
+
* - unbondingTx: The unbonding transaction.
|
|
891
|
+
* - withdrawalAddress: The address to send the withdrawn funds to.
|
|
892
|
+
* - network: The Bitcoin network.
|
|
893
|
+
* - feeRate: The fee rate for the transaction in satoshis per byte.
|
|
894
|
+
*
|
|
895
|
+
* Returns:
|
|
896
|
+
* - psbt: The partially signed transaction (PSBT).
|
|
897
|
+
*
|
|
898
|
+
* @param {Object} scripts - The scripts used in the transaction.
|
|
899
|
+
* @param {Transaction} unbondingTx - The unbonding transaction.
|
|
900
|
+
* @param {string} withdrawalAddress - The address to send the withdrawn funds to.
|
|
901
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
902
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
903
|
+
* @returns {PsbtResult} An object containing the partially signed transaction (PSBT).
|
|
904
|
+
*/
|
|
905
|
+
export declare function withdrawEarlyUnbondedTransaction(scripts: {
|
|
906
|
+
unbondingTimelockScript: Buffer;
|
|
907
|
+
slashingScript: Buffer;
|
|
908
|
+
}, unbondingTx: Transaction, withdrawalAddress: string, network: networks.Network, feeRate: number): PsbtResult;
|
|
909
|
+
/**
|
|
910
|
+
* Constructs a withdrawal transaction for naturally unbonded delegation.
|
|
911
|
+
*
|
|
912
|
+
* This transaction spends the unbonded output from the staking transaction when the timelock has expired.
|
|
913
|
+
*
|
|
914
|
+
* Inputs:
|
|
915
|
+
* - scripts: Scripts used to construct the taproot output.
|
|
916
|
+
* - timelockScript: Script for the timelock condition.
|
|
917
|
+
* - slashingScript: Script for the slashing condition.
|
|
918
|
+
* - unbondingScript: Script for the unbonding condition.
|
|
919
|
+
* - tx: The original staking transaction.
|
|
920
|
+
* - withdrawalAddress: The address to send the withdrawn funds to.
|
|
921
|
+
* - network: The Bitcoin network.
|
|
922
|
+
* - feeRate: The fee rate for the transaction in satoshis per byte.
|
|
923
|
+
* - outputIndex: The index of the output to be spent in the original transaction (default is 0).
|
|
924
|
+
*
|
|
925
|
+
* Returns:
|
|
926
|
+
* - psbt: The partially signed transaction (PSBT).
|
|
927
|
+
*
|
|
928
|
+
* @param {Object} scripts - The scripts used in the transaction.
|
|
929
|
+
* @param {Transaction} tx - The original staking transaction.
|
|
930
|
+
* @param {string} withdrawalAddress - The address to send the withdrawn funds to.
|
|
931
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
932
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
933
|
+
* @param {number} [outputIndex=0] - The index of the output to be spent in the original transaction.
|
|
934
|
+
* @returns {PsbtResult} An object containing the partially signed transaction (PSBT).
|
|
935
|
+
*/
|
|
936
|
+
export declare function withdrawTimelockUnbondedTransaction(scripts: {
|
|
937
|
+
timelockScript: Buffer;
|
|
938
|
+
slashingScript: Buffer;
|
|
939
|
+
unbondingScript: Buffer;
|
|
940
|
+
}, tx: Transaction, withdrawalAddress: string, network: networks.Network, feeRate: number, outputIndex?: number): PsbtResult;
|
|
941
|
+
/**
|
|
942
|
+
* Constructs a withdrawal transaction for a slashing transaction.
|
|
943
|
+
*
|
|
944
|
+
* This transaction spends the output from the slashing transaction.
|
|
945
|
+
*
|
|
946
|
+
* @param {Object} scripts - The unbondingTimelockScript
|
|
947
|
+
* We use the unbonding timelock script as the timelock of the slashing transaction.
|
|
948
|
+
* This is due to slashing tx timelock is the same as the unbonding timelock.
|
|
949
|
+
* @param {Transaction} slashingTx - The slashing transaction.
|
|
950
|
+
* @param {string} withdrawalAddress - The address to send the withdrawn funds to.
|
|
951
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
952
|
+
* @param {number} feeRate - The fee rate for the transaction in satoshis per byte.
|
|
953
|
+
* @param {number} outputIndex - The index of the output to be spent in the original transaction.
|
|
954
|
+
* @returns {PsbtResult} An object containing the partially signed transaction (PSBT).
|
|
955
|
+
*/
|
|
956
|
+
export declare function withdrawSlashingTransaction(scripts: {
|
|
957
|
+
unbondingTimelockScript: Buffer;
|
|
958
|
+
}, slashingTx: Transaction, withdrawalAddress: string, network: networks.Network, feeRate: number, outputIndex: number): PsbtResult;
|
|
959
|
+
/**
|
|
960
|
+
* Constructs a slashing transaction for a staking output without prior unbonding.
|
|
961
|
+
*
|
|
962
|
+
* This transaction spends the staking output of the staking transaction and distributes the funds
|
|
963
|
+
* according to the specified slashing rate.
|
|
964
|
+
*
|
|
965
|
+
* Outputs:
|
|
966
|
+
* - The first output sends `input * slashing_rate` funds to the slashing address.
|
|
967
|
+
* - The second output sends `input * (1 - slashing_rate) - fee` funds back to the user's address.
|
|
968
|
+
*
|
|
969
|
+
* Inputs:
|
|
970
|
+
* - scripts: Scripts used to construct the taproot output.
|
|
971
|
+
* - slashingScript: Script for the slashing condition.
|
|
972
|
+
* - timelockScript: Script for the timelock condition.
|
|
973
|
+
* - unbondingScript: Script for the unbonding condition.
|
|
974
|
+
* - unbondingTimelockScript: Script for the unbonding timelock condition.
|
|
975
|
+
* - transaction: The original staking transaction.
|
|
976
|
+
* - slashingAddress: The address to send the slashed funds to.
|
|
977
|
+
* - slashingRate: The rate at which the funds are slashed (0 < slashingRate < 1).
|
|
978
|
+
* - minimumFee: The minimum fee for the transaction in satoshis.
|
|
979
|
+
* - network: The Bitcoin network.
|
|
980
|
+
* - outputIndex: The index of the output to be spent in the original transaction (default is 0).
|
|
981
|
+
*
|
|
982
|
+
* @param {Object} scripts - The scripts used in the transaction.
|
|
983
|
+
* @param {Transaction} stakingTransaction - The original staking transaction.
|
|
984
|
+
* @param {string} slashingPkScriptHex - The public key script to send the slashed funds to.
|
|
985
|
+
* @param {number} slashingRate - The rate at which the funds are slashed.
|
|
986
|
+
* @param {number} minimumFee - The minimum fee for the transaction in satoshis.
|
|
987
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
988
|
+
* @param {number} [outputIndex=0] - The index of the output to be spent in the original transaction.
|
|
989
|
+
* @returns {{ psbt: Psbt }} An object containing the partially signed transaction (PSBT).
|
|
990
|
+
*/
|
|
991
|
+
export declare function slashTimelockUnbondedTransaction(scripts: {
|
|
992
|
+
slashingScript: Buffer;
|
|
993
|
+
timelockScript: Buffer;
|
|
994
|
+
unbondingScript: Buffer;
|
|
995
|
+
unbondingTimelockScript: Buffer;
|
|
996
|
+
}, stakingTransaction: Transaction, slashingPkScriptHex: string, slashingRate: number, minimumFee: number, network: networks.Network, outputIndex?: number): {
|
|
997
|
+
psbt: Psbt;
|
|
998
|
+
};
|
|
999
|
+
/**
|
|
1000
|
+
* Constructs a slashing transaction for an early unbonded transaction.
|
|
1001
|
+
*
|
|
1002
|
+
* This transaction spends the staking output of the staking transaction and distributes the funds
|
|
1003
|
+
* according to the specified slashing rate.
|
|
1004
|
+
*
|
|
1005
|
+
* Transaction outputs:
|
|
1006
|
+
* - The first output sends `input * slashing_rate` funds to the slashing address.
|
|
1007
|
+
* - The second output sends `input * (1 - slashing_rate) - fee` funds back to the user's address.
|
|
1008
|
+
*
|
|
1009
|
+
* @param {Object} scripts - The scripts used in the transaction. e.g slashingScript, unbondingTimelockScript
|
|
1010
|
+
* @param {Transaction} unbondingTx - The unbonding transaction.
|
|
1011
|
+
* @param {string} slashingPkScriptHex - The public key script to send the slashed funds to.
|
|
1012
|
+
* @param {number} slashingRate - The rate at which the funds are slashed.
|
|
1013
|
+
* @param {number} minimumSlashingFee - The minimum fee for the transaction in satoshis.
|
|
1014
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
1015
|
+
* @returns {{ psbt: Psbt }} An object containing the partially signed transaction (PSBT).
|
|
1016
|
+
*/
|
|
1017
|
+
export declare function slashEarlyUnbondedTransaction(scripts: {
|
|
1018
|
+
slashingScript: Buffer;
|
|
1019
|
+
unbondingTimelockScript: Buffer;
|
|
1020
|
+
}, unbondingTx: Transaction, slashingPkScriptHex: string, slashingRate: number, minimumSlashingFee: number, network: networks.Network): {
|
|
1021
|
+
psbt: Psbt;
|
|
1022
|
+
};
|
|
1023
|
+
export declare function unbondingTransaction(scripts: {
|
|
1024
|
+
unbondingTimelockScript: Buffer;
|
|
1025
|
+
slashingScript: Buffer;
|
|
1026
|
+
}, stakingTx: Transaction, unbondingFee: number, network: networks.Network, outputIndex?: number): TransactionResult;
|
|
1027
|
+
export declare const createCovenantWitness: (originalWitness: Buffer[], paramsCovenants: Buffer[], covenantSigs: CovenantSignature[], covenantQuorum: number) => Buffer<ArrayBufferLike>[];
|
|
1028
|
+
export declare const initBTCCurve: () => void;
|
|
1029
|
+
/**
|
|
1030
|
+
* Check whether the given address is a valid Bitcoin address.
|
|
1031
|
+
*
|
|
1032
|
+
* @param {string} btcAddress - The Bitcoin address to check.
|
|
1033
|
+
* @param {object} network - The Bitcoin network (e.g., bitcoin.networks.bitcoin).
|
|
1034
|
+
* @returns {boolean} - True if the address is valid, otherwise false.
|
|
1035
|
+
*/
|
|
1036
|
+
export declare const isValidBitcoinAddress: (btcAddress: string, network: networks.Network) => boolean;
|
|
1037
|
+
/**
|
|
1038
|
+
* Check whether the given address is a Taproot address.
|
|
1039
|
+
*
|
|
1040
|
+
* @param {string} taprootAddress - The Bitcoin bech32 encoded address to check.
|
|
1041
|
+
* @param {object} network - The Bitcoin network (e.g., bitcoin.networks.bitcoin).
|
|
1042
|
+
* @returns {boolean} - True if the address is a Taproot address, otherwise false.
|
|
1043
|
+
*/
|
|
1044
|
+
export declare const isTaproot: (taprootAddress: string, network: networks.Network) => boolean;
|
|
1045
|
+
/**
|
|
1046
|
+
* Check whether the given address is a Native SegWit address.
|
|
1047
|
+
*
|
|
1048
|
+
* @param {string} segwitAddress - The Bitcoin bech32 encoded address to check.
|
|
1049
|
+
* @param {object} network - The Bitcoin network (e.g., bitcoin.networks.bitcoin).
|
|
1050
|
+
* @returns {boolean} - True if the address is a Native SegWit address, otherwise false.
|
|
1051
|
+
*/
|
|
1052
|
+
export declare const isNativeSegwit: (segwitAddress: string, network: networks.Network) => boolean;
|
|
1053
|
+
/**
|
|
1054
|
+
* Check whether the given public key is a valid public key without a coordinate.
|
|
1055
|
+
*
|
|
1056
|
+
* @param {string} pkWithNoCoord - public key without the coordinate.
|
|
1057
|
+
* @returns {boolean} - True if the public key without the coordinate is valid, otherwise false.
|
|
1058
|
+
*/
|
|
1059
|
+
export declare const isValidNoCoordPublicKey: (pkWithNoCoord: string) => boolean;
|
|
1060
|
+
/**
|
|
1061
|
+
* Get the public key without the coordinate.
|
|
1062
|
+
*
|
|
1063
|
+
* @param {string} pkHex - The public key in hex, with or without the coordinate.
|
|
1064
|
+
* @returns {string} - The public key without the coordinate in hex.
|
|
1065
|
+
* @throws {Error} - If the public key is invalid.
|
|
1066
|
+
*/
|
|
1067
|
+
export declare const getPublicKeyNoCoord: (pkHex: string) => string;
|
|
1068
|
+
/**
|
|
1069
|
+
* Convert a transaction id to a hash. in buffer format.
|
|
1070
|
+
*
|
|
1071
|
+
* @param {string} txId - The transaction id.
|
|
1072
|
+
* @returns {Buffer} - The transaction hash.
|
|
1073
|
+
*/
|
|
1074
|
+
export declare const transactionIdToHash: (txId: string) => Buffer;
|
|
1075
|
+
export declare const getBabylonParamByBtcHeight: (height: number, babylonParamsVersions: VersionedStakingParams[]) => StakingParams;
|
|
1076
|
+
export declare const getBabylonParamByVersion: (version: number, babylonParams: VersionedStakingParams[]) => StakingParams;
|
|
1077
|
+
export declare const findInputUTXO: (inputUTXOs: UTXO[], input: Input) => UTXO;
|
|
1078
|
+
/**
|
|
1079
|
+
* Determines and constructs the correct PSBT input fields for a given UTXO based on its script type.
|
|
1080
|
+
* This function handles different Bitcoin script types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) and returns
|
|
1081
|
+
* the appropriate PSBT input fields required for that UTXO.
|
|
1082
|
+
*
|
|
1083
|
+
* @param {UTXO} utxo - The unspent transaction output to process
|
|
1084
|
+
* @param {Buffer} [publicKeyNoCoord] - The public of the staker (optional).
|
|
1085
|
+
* @returns {object} PSBT input fields object containing the necessary data
|
|
1086
|
+
* @throws {Error} If required input data is missing or if an unsupported script type is provided
|
|
1087
|
+
*/
|
|
1088
|
+
export declare const getPsbtInputFields: (utxo: UTXO, publicKeyNoCoord?: Buffer) => PsbtInputExtended;
|
|
1089
|
+
/**
|
|
1090
|
+
* Supported Bitcoin script types
|
|
1091
|
+
*/
|
|
1092
|
+
export declare enum BitcoinScriptType {
|
|
1093
|
+
P2PKH = "pubkeyhash",
|
|
1094
|
+
P2SH = "scripthash",
|
|
1095
|
+
P2WPKH = "witnesspubkeyhash",
|
|
1096
|
+
P2WSH = "witnessscripthash",
|
|
1097
|
+
P2TR = "taproot"
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Determines the type of Bitcoin script.
|
|
1101
|
+
*
|
|
1102
|
+
* This function tries to parse the script using different Bitcoin payment types and returns
|
|
1103
|
+
* a string identifier for the script type.
|
|
1104
|
+
*
|
|
1105
|
+
* @param script - The raw script as a Buffer
|
|
1106
|
+
* @returns {BitcoinScriptType} The identified script type
|
|
1107
|
+
* @throws {Error} If the script cannot be identified as any known type
|
|
1108
|
+
*/
|
|
1109
|
+
export declare const getScriptType: (script: Buffer) => BitcoinScriptType;
|
|
1110
|
+
/**
|
|
1111
|
+
* Validates a Babylon address. Babylon addresses are encoded in Bech32 format
|
|
1112
|
+
* and have a prefix of "bbn".
|
|
1113
|
+
* @param address - The address to validate.
|
|
1114
|
+
* @returns True if the address is valid, false otherwise.
|
|
1115
|
+
*/
|
|
1116
|
+
export declare const isValidBabylonAddress: (address: string) => boolean;
|
|
1117
|
+
export type TransactionOutput = {
|
|
1118
|
+
scriptPubKey: Buffer;
|
|
1119
|
+
value: number;
|
|
1120
|
+
};
|
|
1121
|
+
export interface OutputInfo {
|
|
1122
|
+
scriptPubKey: Buffer;
|
|
1123
|
+
outputAddress: string;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Build the staking output for the transaction which contains p2tr output
|
|
1127
|
+
* with staking scripts.
|
|
1128
|
+
*
|
|
1129
|
+
* @param {StakingScripts} scripts - The staking scripts.
|
|
1130
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
1131
|
+
* @param {number} amount - The amount to stake.
|
|
1132
|
+
* @returns {TransactionOutput[]} - The staking transaction outputs.
|
|
1133
|
+
* @throws {Error} - If the staking output cannot be built.
|
|
1134
|
+
*/
|
|
1135
|
+
export declare const buildStakingTransactionOutputs: (scripts: {
|
|
1136
|
+
timelockScript: Buffer;
|
|
1137
|
+
unbondingScript: Buffer;
|
|
1138
|
+
slashingScript: Buffer;
|
|
1139
|
+
dataEmbedScript?: Buffer;
|
|
1140
|
+
}, network: networks.Network, amount: number) => TransactionOutput[];
|
|
1141
|
+
/**
|
|
1142
|
+
* Derive the staking output address from the staking scripts.
|
|
1143
|
+
*
|
|
1144
|
+
* @param {StakingScripts} scripts - The staking scripts.
|
|
1145
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
1146
|
+
* @returns {StakingOutput} - The staking output address and scriptPubKey.
|
|
1147
|
+
* @throws {StakingError} - If the staking output address cannot be derived.
|
|
1148
|
+
*/
|
|
1149
|
+
export declare const deriveStakingOutputInfo: (scripts: {
|
|
1150
|
+
timelockScript: Buffer;
|
|
1151
|
+
unbondingScript: Buffer;
|
|
1152
|
+
slashingScript: Buffer;
|
|
1153
|
+
}, network: networks.Network) => {
|
|
1154
|
+
outputAddress: string;
|
|
1155
|
+
scriptPubKey: Buffer<ArrayBufferLike>;
|
|
1156
|
+
};
|
|
1157
|
+
/**
|
|
1158
|
+
* Derive the unbonding output address and scriptPubKey from the staking scripts.
|
|
1159
|
+
*
|
|
1160
|
+
* @param {StakingScripts} scripts - The staking scripts.
|
|
1161
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
1162
|
+
* @returns {OutputInfo} - The unbonding output address and scriptPubKey.
|
|
1163
|
+
* @throws {StakingError} - If the unbonding output address cannot be derived.
|
|
1164
|
+
*/
|
|
1165
|
+
export declare const deriveUnbondingOutputInfo: (scripts: {
|
|
1166
|
+
unbondingTimelockScript: Buffer;
|
|
1167
|
+
slashingScript: Buffer;
|
|
1168
|
+
}, network: networks.Network) => {
|
|
1169
|
+
outputAddress: string;
|
|
1170
|
+
scriptPubKey: Buffer<ArrayBufferLike>;
|
|
1171
|
+
};
|
|
1172
|
+
/**
|
|
1173
|
+
* Derive the slashing output address and scriptPubKey from the staking scripts.
|
|
1174
|
+
*
|
|
1175
|
+
* @param {StakingScripts} scripts - The unbonding timelock scripts, we use the
|
|
1176
|
+
* unbonding timelock script as the timelock of the slashing transaction.
|
|
1177
|
+
* This is due to slashing tx timelock is the same as the unbonding timelock.
|
|
1178
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
1179
|
+
* @returns {OutputInfo} - The slashing output address and scriptPubKey.
|
|
1180
|
+
* @throws {StakingError} - If the slashing output address cannot be derived.
|
|
1181
|
+
*/
|
|
1182
|
+
export declare const deriveSlashingOutput: (scripts: {
|
|
1183
|
+
unbondingTimelockScript: Buffer;
|
|
1184
|
+
}, network: networks.Network) => {
|
|
1185
|
+
outputAddress: string;
|
|
1186
|
+
scriptPubKey: Buffer<ArrayBufferLike>;
|
|
1187
|
+
};
|
|
1188
|
+
/**
|
|
1189
|
+
* Find the matching output index for the given transaction.
|
|
1190
|
+
*
|
|
1191
|
+
* @param {Transaction} tx - The transaction.
|
|
1192
|
+
* @param {string} outputAddress - The output address.
|
|
1193
|
+
* @param {networks.Network} network - The Bitcoin network.
|
|
1194
|
+
* @returns {number} - The output index.
|
|
1195
|
+
* @throws {Error} - If the matching output is not found.
|
|
1196
|
+
*/
|
|
1197
|
+
export declare const findMatchingTxOutputIndex: (tx: Transaction, outputAddress: string, network: networks.Network) => number;
|
|
1198
|
+
/**
|
|
1199
|
+
* toBuffers converts an array of strings to an array of buffers.
|
|
1200
|
+
*
|
|
1201
|
+
* @param {string[]} inputs - The input strings.
|
|
1202
|
+
* @returns {Buffer[]} - The buffers.
|
|
1203
|
+
* @throws {StakingError} - If the values cannot be converted to buffers.
|
|
1204
|
+
*/
|
|
1205
|
+
export declare const toBuffers: (inputs: string[]) => Buffer[];
|
|
1206
|
+
/**
|
|
1207
|
+
* Strips all signatures from a transaction by clearing both the script and
|
|
1208
|
+
* witness data. This is due to the fact that we only need the raw unsigned
|
|
1209
|
+
* transaction structure. The signatures are sent in a separate protobuf field
|
|
1210
|
+
* when creating the delegation message in the Babylon.
|
|
1211
|
+
* @param tx - The transaction to strip signatures from
|
|
1212
|
+
* @returns A copy of the transaction with all signatures removed
|
|
1213
|
+
*/
|
|
1214
|
+
export declare const clearTxSignatures: (tx: Transaction) => Transaction;
|
|
1215
|
+
/**
|
|
1216
|
+
* Derives the merkle proof from the list of hex strings. Note the
|
|
1217
|
+
* sibling hashes are reversed from hex before concatenation.
|
|
1218
|
+
* @param merkle - The merkle proof hex strings.
|
|
1219
|
+
* @returns The merkle proof in hex string format.
|
|
1220
|
+
*/
|
|
1221
|
+
export declare const deriveMerkleProof: (merkle: string[]) => string;
|
|
1222
|
+
/**
|
|
1223
|
+
* Extracts the first valid Schnorr signature from a signed transaction.
|
|
1224
|
+
*
|
|
1225
|
+
* Since we only handle transactions with a single input and request a signature
|
|
1226
|
+
* for one public key, there can be at most one signature from the Bitcoin node.
|
|
1227
|
+
* A valid Schnorr signature is exactly 64 bytes in length.
|
|
1228
|
+
*
|
|
1229
|
+
* @param singedTransaction - The signed Bitcoin transaction to extract the signature from
|
|
1230
|
+
* @returns The first valid 64-byte Schnorr signature found in the transaction witness data,
|
|
1231
|
+
* or undefined if no valid signature exists
|
|
1232
|
+
*/
|
|
1233
|
+
export declare const extractFirstSchnorrSignatureFromTransaction: (singedTransaction: Transaction) => Buffer | undefined;
|
|
1234
|
+
|
|
1235
|
+
export {};
|