@bitgo-beta/babylonlabs-io-btc-staking-ts 0.4.0-beta.51 → 0.4.0-beta.511
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 +1353 -1099
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.cts +339 -269
- package/dist/index.js +1322 -1068
- package/dist/index.js.map +7 -0
- package/package.json +5 -4
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ import { ProofOfPossessionBTC } from '@babylonlabs-io/babylon-proto-ts/dist/gene
|
|
|
5
5
|
import { PsbtInputExtended } from 'bip174/src/lib/interfaces';
|
|
6
6
|
import { Psbt, Transaction, networks } from 'bitcoinjs-lib';
|
|
7
7
|
import { Input } from 'bitcoinjs-lib/src/transaction';
|
|
8
|
+
import { Emitter } from 'nanoevents';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Base interface for staking parameters that define the rules and constraints
|
|
@@ -25,6 +26,18 @@ export interface StakingParams {
|
|
|
25
26
|
minSlashingTxFeeSat: number;
|
|
26
27
|
};
|
|
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
|
+
};
|
|
28
41
|
/**
|
|
29
42
|
* Extension of StakingParams that includes activation height and version information.
|
|
30
43
|
* These parameters are used to identify and select the appropriate staking rules at
|
|
@@ -40,6 +53,20 @@ export interface VersionedStakingParams extends StakingParams {
|
|
|
40
53
|
export interface ObservableVersionedStakingParams extends VersionedStakingParams {
|
|
41
54
|
tag: string;
|
|
42
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
|
+
}
|
|
43
70
|
export interface UTXO {
|
|
44
71
|
txid: string;
|
|
45
72
|
vout: number;
|
|
@@ -144,20 +171,6 @@ export declare class StakingScriptData {
|
|
|
144
171
|
*/
|
|
145
172
|
buildMultiKeyScript(pks: Buffer[], threshold: number, withVerify: boolean): Buffer;
|
|
146
173
|
}
|
|
147
|
-
/**
|
|
148
|
-
* PsbtResult is an object containing a partially signed transaction and its fee
|
|
149
|
-
*/
|
|
150
|
-
export interface PsbtResult {
|
|
151
|
-
psbt: Psbt;
|
|
152
|
-
fee: number;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* TransactionResult is an object containing an unsigned transaction and its fee
|
|
156
|
-
*/
|
|
157
|
-
export interface TransactionResult {
|
|
158
|
-
transaction: Transaction;
|
|
159
|
-
fee: number;
|
|
160
|
-
}
|
|
161
174
|
export interface StakerInfo {
|
|
162
175
|
address: string;
|
|
163
176
|
publicKeyNoCoordHex: string;
|
|
@@ -166,9 +179,9 @@ export declare class Staking {
|
|
|
166
179
|
network: networks.Network;
|
|
167
180
|
stakerInfo: StakerInfo;
|
|
168
181
|
params: StakingParams;
|
|
169
|
-
|
|
182
|
+
finalityProviderPksNoCoordHex: string[];
|
|
170
183
|
stakingTimelock: number;
|
|
171
|
-
constructor(network: networks.Network, stakerInfo: StakerInfo, params: StakingParams,
|
|
184
|
+
constructor(network: networks.Network, stakerInfo: StakerInfo, params: StakingParams, finalityProviderPksNoCoordHex: string[], stakingTimelock: number);
|
|
172
185
|
/**
|
|
173
186
|
* buildScripts builds the staking scripts for the staking transaction.
|
|
174
187
|
* Note: different staking types may have different scripts.
|
|
@@ -269,6 +282,271 @@ export declare class Staking {
|
|
|
269
282
|
*/
|
|
270
283
|
createWithdrawSlashingPsbt(slashingTx: Transaction, feeRate: number): PsbtResult;
|
|
271
284
|
}
|
|
285
|
+
export type RegistrationStep = "staking-slashing" | "unbonding-slashing" | "proof-of-possession" | "create-btc-delegation-msg";
|
|
286
|
+
export type WithdrawalType = "staking-expired" | "early-unbonded" | "slashing";
|
|
287
|
+
export type EventData = Record<string, string | number | string[] | number[]>;
|
|
288
|
+
export interface ManagerEvents {
|
|
289
|
+
"delegation:create": (data?: EventData) => void;
|
|
290
|
+
"delegation:register": (data?: EventData) => void;
|
|
291
|
+
"delegation:stake": (data?: EventData) => void;
|
|
292
|
+
"delegation:unbond": (data?: EventData) => void;
|
|
293
|
+
"delegation:withdraw": (data?: EventData) => void;
|
|
294
|
+
}
|
|
295
|
+
export type DelegationEvent = keyof ManagerEvents;
|
|
296
|
+
export interface Action {
|
|
297
|
+
name: ActionName;
|
|
298
|
+
}
|
|
299
|
+
declare enum ActionName {
|
|
300
|
+
SIGN_BTC_STAKING_TRANSACTION = "sign-btc-staking-transaction",
|
|
301
|
+
SIGN_BTC_UNBONDING_TRANSACTION = "sign-btc-unbonding-transaction",
|
|
302
|
+
SIGN_BTC_WITHDRAW_TRANSACTION = "sign-btc-withdraw-transaction",
|
|
303
|
+
SIGN_BTC_SLASHING_TRANSACTION = "sign-btc-slashing-transaction",
|
|
304
|
+
SIGN_BTC_UNBONDING_SLASHING_TRANSACTION = "sign-btc-unbonding-slashing-transaction"
|
|
305
|
+
}
|
|
306
|
+
export interface Contract {
|
|
307
|
+
id: ContractId;
|
|
308
|
+
params: ContractData;
|
|
309
|
+
}
|
|
310
|
+
declare enum ContractId {
|
|
311
|
+
STAKING = "babylon:staking",
|
|
312
|
+
UNBONDING = "babylon:unbonding",
|
|
313
|
+
SLASHING = "babylon:slashing",
|
|
314
|
+
WITHDRAW = "babylon:withdraw",
|
|
315
|
+
SLASHING_BURN = "babylon:slashing-burn"
|
|
316
|
+
}
|
|
317
|
+
export type ContractData = Record<string, string | number | string[] | number[]>;
|
|
318
|
+
export interface SignPsbtOptions {
|
|
319
|
+
contracts: Contract[];
|
|
320
|
+
action: Action;
|
|
321
|
+
}
|
|
322
|
+
export interface BtcProvider {
|
|
323
|
+
signPsbt(psbtHex: string, options?: SignPsbtOptions): Promise<string>;
|
|
324
|
+
signMessage: (message: string, type: "ecdsa" | "bip322-simple") => Promise<string>;
|
|
325
|
+
}
|
|
326
|
+
export interface BabylonProvider {
|
|
327
|
+
/**
|
|
328
|
+
* Signs a Babylon chain transaction.
|
|
329
|
+
* This is primarily used for signing MsgCreateBTCDelegation transactions
|
|
330
|
+
* which register the BTC delegation on the Babylon Genesis chain.
|
|
331
|
+
*
|
|
332
|
+
* @param {object} msg - The Cosmos SDK transaction message to sign
|
|
333
|
+
* @param {string} msg.typeUrl - The Protobuf type URL identifying the message type
|
|
334
|
+
* @param {T} msg.value - The transaction message data matching the typeUrl
|
|
335
|
+
* @returns {Promise<Uint8Array>} The signed transaction bytes
|
|
336
|
+
*/
|
|
337
|
+
signTransaction: <T extends object>(msg: {
|
|
338
|
+
typeUrl: string;
|
|
339
|
+
value: T;
|
|
340
|
+
}) => Promise<Uint8Array>;
|
|
341
|
+
}
|
|
342
|
+
export interface StakingInputs {
|
|
343
|
+
finalityProviderPksNoCoordHex: string[];
|
|
344
|
+
stakingAmountSat: number;
|
|
345
|
+
stakingTimelock: number;
|
|
346
|
+
}
|
|
347
|
+
export interface InclusionProof {
|
|
348
|
+
pos: number;
|
|
349
|
+
merkle: string[];
|
|
350
|
+
blockHashHex: string;
|
|
351
|
+
}
|
|
352
|
+
export declare class BabylonBtcStakingManager {
|
|
353
|
+
protected network: networks.Network;
|
|
354
|
+
protected stakingParams: VersionedStakingParams[];
|
|
355
|
+
protected btcProvider: BtcProvider;
|
|
356
|
+
protected babylonProvider: BabylonProvider;
|
|
357
|
+
protected ee?: Emitter<ManagerEvents> | undefined;
|
|
358
|
+
constructor(network: networks.Network, stakingParams: VersionedStakingParams[], btcProvider: BtcProvider, babylonProvider: BabylonProvider, ee?: Emitter<ManagerEvents> | undefined);
|
|
359
|
+
/**
|
|
360
|
+
* Creates a signed Pre-Staking Registration transaction that is ready to be
|
|
361
|
+
* sent to the Babylon chain.
|
|
362
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
363
|
+
* and the no-coord public key in hex format.
|
|
364
|
+
* @param stakingInput - The staking inputs.
|
|
365
|
+
* @param babylonBtcTipHeight - The Babylon BTC tip height.
|
|
366
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
367
|
+
* transaction.
|
|
368
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
369
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
370
|
+
* be included in a block.
|
|
371
|
+
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
372
|
+
* @returns The signed babylon pre-staking registration transaction in base64
|
|
373
|
+
* format.
|
|
374
|
+
*/
|
|
375
|
+
preStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, babylonBtcTipHeight: number, inputUTXOs: UTXO[], feeRate: number, babylonAddress: string): Promise<{
|
|
376
|
+
signedBabylonTx: Uint8Array;
|
|
377
|
+
stakingTx: Transaction;
|
|
378
|
+
}>;
|
|
379
|
+
/**
|
|
380
|
+
* Creates a signed post-staking registration transaction that is ready to be
|
|
381
|
+
* sent to the Babylon chain. This is used when a staking transaction is
|
|
382
|
+
* already created and included in a BTC block and we want to register it on
|
|
383
|
+
* the Babylon chain.
|
|
384
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
385
|
+
* and the no-coord public key in hex format.
|
|
386
|
+
* @param stakingTx - The staking transaction.
|
|
387
|
+
* @param stakingTxHeight - The BTC height in which the staking transaction
|
|
388
|
+
* is included.
|
|
389
|
+
* @param stakingInput - The staking inputs.
|
|
390
|
+
* @param inclusionProof - Merkle Proof of Inclusion: Verifies transaction
|
|
391
|
+
* inclusion in a Bitcoin block that is k-deep.
|
|
392
|
+
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
393
|
+
* @returns The signed babylon transaction in base64 format.
|
|
394
|
+
*/
|
|
395
|
+
postStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingTx: Transaction, stakingTxHeight: number, stakingInput: StakingInputs, inclusionProof: InclusionProof, babylonAddress: string): Promise<{
|
|
396
|
+
signedBabylonTx: Uint8Array;
|
|
397
|
+
}>;
|
|
398
|
+
/**
|
|
399
|
+
* Estimates the BTC fee required for staking.
|
|
400
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
401
|
+
* and the no-coord public key in hex format.
|
|
402
|
+
* @param babylonBtcTipHeight - The BTC tip height recorded on the Babylon
|
|
403
|
+
* chain.
|
|
404
|
+
* @param stakingInput - The staking inputs.
|
|
405
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
406
|
+
* transaction.
|
|
407
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
408
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
409
|
+
* be included in a block.
|
|
410
|
+
* @returns The estimated BTC fee in satoshis.
|
|
411
|
+
*/
|
|
412
|
+
estimateBtcStakingFee(stakerBtcInfo: StakerInfo, babylonBtcTipHeight: number, stakingInput: StakingInputs, inputUTXOs: UTXO[], feeRate: number): number;
|
|
413
|
+
/**
|
|
414
|
+
* Creates a signed staking transaction that is ready to be sent to the BTC
|
|
415
|
+
* network.
|
|
416
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
417
|
+
* and the no-coord public key in hex format.
|
|
418
|
+
* @param stakingInput - The staking inputs.
|
|
419
|
+
* @param unsignedStakingTx - The unsigned staking transaction.
|
|
420
|
+
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
421
|
+
* transaction.
|
|
422
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
423
|
+
* delegation in Babylon chain
|
|
424
|
+
* @returns The signed staking transaction.
|
|
425
|
+
*/
|
|
426
|
+
createSignedBtcStakingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, unsignedStakingTx: Transaction, inputUTXOs: UTXO[], stakingParamsVersion: number): Promise<Transaction>;
|
|
427
|
+
/**
|
|
428
|
+
* Creates a partial signed unbonding transaction that is only signed by the
|
|
429
|
+
* staker. In order to complete the unbonding transaction, the covenant
|
|
430
|
+
* unbonding signatures need to be added to the transaction before sending it
|
|
431
|
+
* to the BTC network.
|
|
432
|
+
* NOTE: This method should only be used for Babylon phase-1 unbonding.
|
|
433
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
434
|
+
* and the no-coord public key in hex format.
|
|
435
|
+
* @param stakingInput - The staking inputs.
|
|
436
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
437
|
+
* delegation in Babylon chain
|
|
438
|
+
* @param stakingTx - The staking transaction.
|
|
439
|
+
* @returns The partial signed unbonding transaction and its fee.
|
|
440
|
+
*/
|
|
441
|
+
createPartialSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction): Promise<TransactionResult>;
|
|
442
|
+
/**
|
|
443
|
+
* Creates a signed unbonding transaction that is ready to be sent to the BTC
|
|
444
|
+
* network.
|
|
445
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
446
|
+
* and the no-coord public key in hex format.
|
|
447
|
+
* @param stakingInput - The staking inputs.
|
|
448
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
449
|
+
* delegation in Babylon chain
|
|
450
|
+
* @param stakingTx - The staking transaction.
|
|
451
|
+
* @param unsignedUnbondingTx - The unsigned unbonding transaction.
|
|
452
|
+
* @param covenantUnbondingSignatures - The covenant unbonding signatures.
|
|
453
|
+
* It can be retrieved from the Babylon chain or API.
|
|
454
|
+
* @returns The signed unbonding transaction and its fee.
|
|
455
|
+
*/
|
|
456
|
+
createSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, unsignedUnbondingTx: Transaction, covenantUnbondingSignatures: {
|
|
457
|
+
btcPkHex: string;
|
|
458
|
+
sigHex: string;
|
|
459
|
+
}[]): Promise<TransactionResult>;
|
|
460
|
+
/**
|
|
461
|
+
* Creates a signed withdrawal transaction on the unbodning output expiry path
|
|
462
|
+
* that is ready to be sent to the BTC network.
|
|
463
|
+
* @param stakingInput - The staking inputs.
|
|
464
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
465
|
+
* delegation in Babylon chain
|
|
466
|
+
* @param earlyUnbondingTx - The early unbonding transaction.
|
|
467
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
468
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
469
|
+
* be included in a block.
|
|
470
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
471
|
+
*/
|
|
472
|
+
createSignedBtcWithdrawEarlyUnbondedTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, earlyUnbondingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
473
|
+
/**
|
|
474
|
+
* Creates a signed withdrawal transaction on the staking output expiry path
|
|
475
|
+
* that is ready to be sent to the BTC network.
|
|
476
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
477
|
+
* and the no-coord public key in hex format.
|
|
478
|
+
* @param stakingInput - The staking inputs.
|
|
479
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
480
|
+
* delegation in Babylon chain
|
|
481
|
+
* @param stakingTx - The staking transaction.
|
|
482
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
483
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
484
|
+
* be included in a block.
|
|
485
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
486
|
+
*/
|
|
487
|
+
createSignedBtcWithdrawStakingExpiredTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
488
|
+
/**
|
|
489
|
+
* Creates a signed withdrawal transaction for the expired slashing output that
|
|
490
|
+
* is ready to be sent to the BTC network.
|
|
491
|
+
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
492
|
+
* and the no-coord public key in hex format.
|
|
493
|
+
* @param stakingInput - The staking inputs.
|
|
494
|
+
* @param stakingParamsVersion - The params version that was used to create the
|
|
495
|
+
* delegation in Babylon chain
|
|
496
|
+
* @param slashingTx - The slashing transaction.
|
|
497
|
+
* @param feeRate - The fee rate in satoshis per byte. Typical value for the
|
|
498
|
+
* fee rate is above 1. If the fee rate is too low, the transaction will not
|
|
499
|
+
* be included in a block.
|
|
500
|
+
* @returns The signed withdrawal transaction and its fee.
|
|
501
|
+
*/
|
|
502
|
+
createSignedBtcWithdrawSlashingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, slashingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
503
|
+
/**
|
|
504
|
+
* Creates a proof of possession for the staker based on ECDSA signature.
|
|
505
|
+
* @param bech32Address - The staker's bech32 address.
|
|
506
|
+
* @returns The proof of possession.
|
|
507
|
+
*/
|
|
508
|
+
createProofOfPossession(channel: "delegation:create" | "delegation:register", bech32Address: string, stakerBtcAddress: string): Promise<ProofOfPossessionBTC>;
|
|
509
|
+
/**
|
|
510
|
+
* Creates the unbonding, slashing, and unbonding slashing transactions and
|
|
511
|
+
* PSBTs.
|
|
512
|
+
* @param stakingInstance - The staking instance.
|
|
513
|
+
* @param stakingTx - The staking transaction.
|
|
514
|
+
* @returns The unbonding, slashing, and unbonding slashing transactions and
|
|
515
|
+
* PSBTs.
|
|
516
|
+
*/
|
|
517
|
+
private createDelegationTransactionsAndPsbts;
|
|
518
|
+
/**
|
|
519
|
+
* Creates a protobuf message for the BTC delegation.
|
|
520
|
+
* @param channel - The event channel to emit the message on.
|
|
521
|
+
* @param stakingInstance - The staking instance.
|
|
522
|
+
* @param stakingInput - The staking inputs.
|
|
523
|
+
* @param stakingTx - The staking transaction.
|
|
524
|
+
* @param bech32Address - The staker's babylon chain bech32 address
|
|
525
|
+
* @param stakerBtcInfo - The staker's BTC information such as address and
|
|
526
|
+
* public key
|
|
527
|
+
* @param params - The staking parameters.
|
|
528
|
+
* @param inclusionProof - The inclusion proof of the staking transaction.
|
|
529
|
+
* @returns The protobuf message.
|
|
530
|
+
*/
|
|
531
|
+
createBtcDelegationMsg(channel: "delegation:create" | "delegation:register", stakingInstance: Staking, stakingInput: StakingInputs, stakingTx: Transaction, bech32Address: string, stakerBtcInfo: StakerInfo, params: StakingParams, inclusionProof?: btcstaking.InclusionProof): Promise<{
|
|
532
|
+
typeUrl: string;
|
|
533
|
+
value: btcstakingtx.MsgCreateBTCDelegation;
|
|
534
|
+
}>;
|
|
535
|
+
/**
|
|
536
|
+
* Gets the inclusion proof for the staking transaction.
|
|
537
|
+
* See the type `InclusionProof` for more information
|
|
538
|
+
* @param inclusionProof - The inclusion proof.
|
|
539
|
+
* @returns The inclusion proof.
|
|
540
|
+
*/
|
|
541
|
+
private getInclusionProof;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Get the staker signature from the unbonding transaction
|
|
545
|
+
* This is used mostly for unbonding transactions from phase-1(Observable)
|
|
546
|
+
* @param unbondingTx - The unbonding transaction
|
|
547
|
+
* @returns The staker signature
|
|
548
|
+
*/
|
|
549
|
+
export declare const getUnbondingTxStakerSignature: (unbondingTx: Transaction) => string;
|
|
272
550
|
export interface ObservableStakingScripts extends StakingScripts {
|
|
273
551
|
dataEmbedScript: Buffer;
|
|
274
552
|
}
|
|
@@ -305,7 +583,7 @@ export declare class ObservableStakingScriptData extends StakingScriptData {
|
|
|
305
583
|
*/
|
|
306
584
|
export declare class ObservableStaking extends Staking {
|
|
307
585
|
params: ObservableVersionedStakingParams;
|
|
308
|
-
constructor(network: networks.Network, stakerInfo: StakerInfo, params: ObservableVersionedStakingParams,
|
|
586
|
+
constructor(network: networks.Network, stakerInfo: StakerInfo, params: ObservableVersionedStakingParams, finalityProviderPksNoCoordHex: string[], stakingTimelock: number);
|
|
309
587
|
/**
|
|
310
588
|
* Build the staking scripts for observable staking.
|
|
311
589
|
* This method overwrites the base method to include the OP_RETURN tag based
|
|
@@ -548,6 +826,14 @@ export declare const isValidBitcoinAddress: (btcAddress: string, network: networ
|
|
|
548
826
|
* @returns {boolean} - True if the address is a Taproot address, otherwise false.
|
|
549
827
|
*/
|
|
550
828
|
export declare const isTaproot: (taprootAddress: string, network: networks.Network) => boolean;
|
|
829
|
+
/**
|
|
830
|
+
* Check whether the given address is a Native SegWit address.
|
|
831
|
+
*
|
|
832
|
+
* @param {string} segwitAddress - The Bitcoin bech32 encoded address to check.
|
|
833
|
+
* @param {object} network - The Bitcoin network (e.g., bitcoin.networks.bitcoin).
|
|
834
|
+
* @returns {boolean} - True if the address is a Native SegWit address, otherwise false.
|
|
835
|
+
*/
|
|
836
|
+
export declare const isNativeSegwit: (segwitAddress: string, network: networks.Network) => boolean;
|
|
551
837
|
/**
|
|
552
838
|
* Check whether the given public key is a valid public key without a coordinate.
|
|
553
839
|
*
|
|
@@ -562,7 +848,7 @@ export declare const isValidNoCoordPublicKey: (pkWithNoCoord: string) => boolean
|
|
|
562
848
|
* @returns {string} - The public key without the coordinate in hex.
|
|
563
849
|
* @throws {Error} - If the public key is invalid.
|
|
564
850
|
*/
|
|
565
|
-
export declare const getPublicKeyNoCoord: (pkHex: string) =>
|
|
851
|
+
export declare const getPublicKeyNoCoord: (pkHex: string) => string;
|
|
566
852
|
/**
|
|
567
853
|
* Convert a transaction id to a hash. in buffer format.
|
|
568
854
|
*
|
|
@@ -570,6 +856,41 @@ export declare const getPublicKeyNoCoord: (pkHex: string) => String;
|
|
|
570
856
|
* @returns {Buffer} - The transaction hash.
|
|
571
857
|
*/
|
|
572
858
|
export declare const transactionIdToHash: (txId: string) => Buffer;
|
|
859
|
+
export declare const getBabylonParamByBtcHeight: (height: number, babylonParamsVersions: VersionedStakingParams[]) => StakingParams;
|
|
860
|
+
export declare const getBabylonParamByVersion: (version: number, babylonParams: VersionedStakingParams[]) => StakingParams;
|
|
861
|
+
export declare const findInputUTXO: (inputUTXOs: UTXO[], input: Input) => UTXO;
|
|
862
|
+
/**
|
|
863
|
+
* Determines and constructs the correct PSBT input fields for a given UTXO based on its script type.
|
|
864
|
+
* This function handles different Bitcoin script types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) and returns
|
|
865
|
+
* the appropriate PSBT input fields required for that UTXO.
|
|
866
|
+
*
|
|
867
|
+
* @param {UTXO} utxo - The unspent transaction output to process
|
|
868
|
+
* @param {Buffer} [publicKeyNoCoord] - The public of the staker (optional).
|
|
869
|
+
* @returns {object} PSBT input fields object containing the necessary data
|
|
870
|
+
* @throws {Error} If required input data is missing or if an unsupported script type is provided
|
|
871
|
+
*/
|
|
872
|
+
export declare const getPsbtInputFields: (utxo: UTXO, publicKeyNoCoord?: Buffer) => PsbtInputExtended;
|
|
873
|
+
/**
|
|
874
|
+
* Supported Bitcoin script types
|
|
875
|
+
*/
|
|
876
|
+
export declare enum BitcoinScriptType {
|
|
877
|
+
P2PKH = "pubkeyhash",
|
|
878
|
+
P2SH = "scripthash",
|
|
879
|
+
P2WPKH = "witnesspubkeyhash",
|
|
880
|
+
P2WSH = "witnessscripthash",
|
|
881
|
+
P2TR = "taproot"
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Determines the type of Bitcoin script.
|
|
885
|
+
*
|
|
886
|
+
* This function tries to parse the script using different Bitcoin payment types and returns
|
|
887
|
+
* a string identifier for the script type.
|
|
888
|
+
*
|
|
889
|
+
* @param script - The raw script as a Buffer
|
|
890
|
+
* @returns {BitcoinScriptType} The identified script type
|
|
891
|
+
* @throws {Error} If the script cannot be identified as any known type
|
|
892
|
+
*/
|
|
893
|
+
export declare const getScriptType: (script: Buffer) => BitcoinScriptType;
|
|
573
894
|
/**
|
|
574
895
|
* Validates a Babylon address. Babylon addresses are encoded in Bech32 format
|
|
575
896
|
* and have a prefix of "bbn".
|
|
@@ -693,256 +1014,5 @@ export declare const validateStakingTimelock: (stakingTimelock: number, params:
|
|
|
693
1014
|
* @throws {StakingError} - If the values cannot be converted to buffers.
|
|
694
1015
|
*/
|
|
695
1016
|
export declare const toBuffers: (inputs: string[]) => Buffer[];
|
|
696
|
-
export declare const findInputUTXO: (inputUTXOs: UTXO[], input: Input) => UTXO;
|
|
697
|
-
/**
|
|
698
|
-
* Determines and constructs the correct PSBT input fields for a given UTXO based on its script type.
|
|
699
|
-
* This function handles different Bitcoin script types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) and returns
|
|
700
|
-
* the appropriate PSBT input fields required for that UTXO.
|
|
701
|
-
*
|
|
702
|
-
* @param {UTXO} utxo - The unspent transaction output to process
|
|
703
|
-
* @param {Buffer} [publicKeyNoCoord] - The public of the staker (optional).
|
|
704
|
-
* @returns {object} PSBT input fields object containing the necessary data
|
|
705
|
-
* @throws {Error} If required input data is missing or if an unsupported script type is provided
|
|
706
|
-
*/
|
|
707
|
-
export declare const getPsbtInputFields: (utxo: UTXO, publicKeyNoCoord?: Buffer) => PsbtInputExtended;
|
|
708
|
-
/**
|
|
709
|
-
* Supported Bitcoin script types
|
|
710
|
-
*/
|
|
711
|
-
export declare enum BitcoinScriptType {
|
|
712
|
-
P2PKH = "pubkeyhash",
|
|
713
|
-
P2SH = "scripthash",
|
|
714
|
-
P2WPKH = "witnesspubkeyhash",
|
|
715
|
-
P2WSH = "witnessscripthash",
|
|
716
|
-
P2TR = "taproot"
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* Determines the type of Bitcoin script.
|
|
720
|
-
*
|
|
721
|
-
* This function tries to parse the script using different Bitcoin payment types and returns
|
|
722
|
-
* a string identifier for the script type.
|
|
723
|
-
*
|
|
724
|
-
* @param script - The raw script as a Buffer
|
|
725
|
-
* @returns {BitcoinScriptType} The identified script type
|
|
726
|
-
* @throws {Error} If the script cannot be identified as any known type
|
|
727
|
-
*/
|
|
728
|
-
export declare const getScriptType: (script: Buffer) => BitcoinScriptType;
|
|
729
|
-
export declare const getBabylonParamByBtcHeight: (height: number, babylonParamsVersions: VersionedStakingParams[]) => StakingParams;
|
|
730
|
-
export declare const getBabylonParamByVersion: (version: number, babylonParams: VersionedStakingParams[]) => StakingParams;
|
|
731
|
-
export interface BtcProvider {
|
|
732
|
-
signPsbt(signingStep: SigningStep, psbtHex: string): Promise<string>;
|
|
733
|
-
signMessage?: (signingStep: SigningStep, message: string, type: "ecdsa") => Promise<string>;
|
|
734
|
-
}
|
|
735
|
-
export interface BabylonProvider {
|
|
736
|
-
signTransaction: <T extends object>(signingStep: SigningStep, msg: {
|
|
737
|
-
typeUrl: string;
|
|
738
|
-
value: T;
|
|
739
|
-
}) => Promise<Uint8Array>;
|
|
740
|
-
}
|
|
741
|
-
export declare enum SigningStep {
|
|
742
|
-
STAKING_SLASHING = "staking-slashing",
|
|
743
|
-
UNBONDING_SLASHING = "unbonding-slashing",
|
|
744
|
-
PROOF_OF_POSSESSION = "proof-of-possession",
|
|
745
|
-
CREATE_BTC_DELEGATION_MSG = "create-btc-delegation-msg",
|
|
746
|
-
STAKING = "staking",
|
|
747
|
-
UNBONDING = "unbonding",
|
|
748
|
-
WITHDRAW_STAKING_EXPIRED = "withdraw-staking-expired",
|
|
749
|
-
WITHDRAW_EARLY_UNBONDED = "withdraw-early-unbonded",
|
|
750
|
-
WITHDRAW_SLASHING = "withdraw-slashing"
|
|
751
|
-
}
|
|
752
|
-
export interface StakingInputs {
|
|
753
|
-
finalityProviderPkNoCoordHex: string;
|
|
754
|
-
stakingAmountSat: number;
|
|
755
|
-
stakingTimelock: number;
|
|
756
|
-
}
|
|
757
|
-
export interface InclusionProof {
|
|
758
|
-
pos: number;
|
|
759
|
-
merkle: string[];
|
|
760
|
-
blockHashHex: string;
|
|
761
|
-
}
|
|
762
|
-
export declare class BabylonBtcStakingManager {
|
|
763
|
-
private stakingParams;
|
|
764
|
-
private btcProvider;
|
|
765
|
-
private network;
|
|
766
|
-
private babylonProvider;
|
|
767
|
-
constructor(network: networks.Network, stakingParams: VersionedStakingParams[], btcProvider: BtcProvider, babylonProvider: BabylonProvider);
|
|
768
|
-
/**
|
|
769
|
-
* Creates a signed Pre-Staking Registration transaction that is ready to be
|
|
770
|
-
* sent to the Babylon chain.
|
|
771
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
772
|
-
* and the no-coord public key in hex format.
|
|
773
|
-
* @param stakingInput - The staking inputs.
|
|
774
|
-
* @param babylonBtcTipHeight - The Babylon BTC tip height.
|
|
775
|
-
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
776
|
-
* transaction.
|
|
777
|
-
* @param feeRate - The fee rate in satoshis per byte.
|
|
778
|
-
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
779
|
-
* @returns The signed babylon pre-staking registration transaction in base64
|
|
780
|
-
* format.
|
|
781
|
-
*/
|
|
782
|
-
preStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, babylonBtcTipHeight: number, inputUTXOs: UTXO[], feeRate: number, babylonAddress: string): Promise<{
|
|
783
|
-
signedBabylonTx: Uint8Array;
|
|
784
|
-
stakingTx: Transaction;
|
|
785
|
-
}>;
|
|
786
|
-
/**
|
|
787
|
-
* Creates a signed post-staking registration transaction that is ready to be
|
|
788
|
-
* sent to the Babylon chain. This is used when a staking transaction is
|
|
789
|
-
* already created and included in a BTC block and we want to register it on
|
|
790
|
-
* the Babylon chain.
|
|
791
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
792
|
-
* and the no-coord public key in hex format.
|
|
793
|
-
* @param stakingTx - The staking transaction.
|
|
794
|
-
* @param stakingTxHeight - The BTC height in which the staking transaction
|
|
795
|
-
* is included.
|
|
796
|
-
* @param stakingInput - The staking inputs.
|
|
797
|
-
* @param inclusionProof - The inclusion proof of the staking transaction.
|
|
798
|
-
* @param babylonAddress - The Babylon bech32 encoded address of the staker.
|
|
799
|
-
* @returns The signed babylon transaction in base64 format.
|
|
800
|
-
*/
|
|
801
|
-
postStakeRegistrationBabylonTransaction(stakerBtcInfo: StakerInfo, stakingTx: Transaction, stakingTxHeight: number, stakingInput: StakingInputs, inclusionProof: InclusionProof, babylonAddress: string): Promise<{
|
|
802
|
-
signedBabylonTx: Uint8Array;
|
|
803
|
-
}>;
|
|
804
|
-
/**
|
|
805
|
-
* Estimates the BTC fee required for staking.
|
|
806
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
807
|
-
* and the no-coord public key in hex format.
|
|
808
|
-
* @param babylonBtcTipHeight - The BTC tip height recorded on the Babylon
|
|
809
|
-
* chain.
|
|
810
|
-
* @param stakingInput - The staking inputs.
|
|
811
|
-
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
812
|
-
* transaction.
|
|
813
|
-
* @param feeRate - The fee rate in satoshis per byte.
|
|
814
|
-
* @returns The estimated BTC fee in satoshis.
|
|
815
|
-
*/
|
|
816
|
-
estimateBtcStakingFee(stakerBtcInfo: StakerInfo, babylonBtcTipHeight: number, stakingInput: StakingInputs, inputUTXOs: UTXO[], feeRate: number): number;
|
|
817
|
-
/**
|
|
818
|
-
* Creates a signed staking transaction that is ready to be sent to the BTC
|
|
819
|
-
* network.
|
|
820
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
821
|
-
* and the no-coord public key in hex format.
|
|
822
|
-
* @param stakingInput - The staking inputs.
|
|
823
|
-
* @param unsignedStakingTx - The unsigned staking transaction.
|
|
824
|
-
* @param inputUTXOs - The UTXOs that will be used to pay for the staking
|
|
825
|
-
* transaction.
|
|
826
|
-
* @param stakingParamsVersion - The params version that was used to create the
|
|
827
|
-
* delegation in Babylon chain
|
|
828
|
-
* @returns The signed staking transaction.
|
|
829
|
-
*/
|
|
830
|
-
createSignedBtcStakingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, unsignedStakingTx: Transaction, inputUTXOs: UTXO[], stakingParamsVersion: number): Promise<Transaction>;
|
|
831
|
-
/**
|
|
832
|
-
* Creates a partial signed unbonding transaction that is only signed by the
|
|
833
|
-
* staker. In order to complete the unbonding transaction, the covenant
|
|
834
|
-
* unbonding signatures need to be added to the transaction before sending it
|
|
835
|
-
* to the BTC network.
|
|
836
|
-
* NOTE: This method should only be used for Babylon phase-1 unbonding.
|
|
837
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
838
|
-
* and the no-coord public key in hex format.
|
|
839
|
-
* @param stakingInput - The staking inputs.
|
|
840
|
-
* @param stakingParamsVersion - The params version that was used to create the
|
|
841
|
-
* delegation in Babylon chain
|
|
842
|
-
* @param stakingTx - The staking transaction.
|
|
843
|
-
* @returns The partial signed unbonding transaction and its fee.
|
|
844
|
-
*/
|
|
845
|
-
createPartialSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction): Promise<TransactionResult>;
|
|
846
|
-
/**
|
|
847
|
-
* Creates a signed unbonding transaction that is ready to be sent to the BTC
|
|
848
|
-
* network.
|
|
849
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
850
|
-
* and the no-coord public key in hex format.
|
|
851
|
-
* @param stakingInput - The staking inputs.
|
|
852
|
-
* @param stakingParamsVersion - The params version that was used to create the
|
|
853
|
-
* delegation in Babylon chain
|
|
854
|
-
* @param stakingTx - The staking transaction.
|
|
855
|
-
* @param unsignedUnbondingTx - The unsigned unbonding transaction.
|
|
856
|
-
* @param covenantUnbondingSignatures - The covenant unbonding signatures.
|
|
857
|
-
* It can be retrieved from the Babylon chain or API.
|
|
858
|
-
* @returns The signed unbonding transaction and its fee.
|
|
859
|
-
*/
|
|
860
|
-
createSignedBtcUnbondingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, unsignedUnbondingTx: Transaction, covenantUnbondingSignatures: {
|
|
861
|
-
btcPkHex: string;
|
|
862
|
-
sigHex: string;
|
|
863
|
-
}[]): Promise<TransactionResult>;
|
|
864
|
-
/**
|
|
865
|
-
* Creates a signed withdrawal transaction on the unbodning output expiry path
|
|
866
|
-
* that is ready to be sent to the BTC network.
|
|
867
|
-
* @param stakingInput - The staking inputs.
|
|
868
|
-
* @param stakingParamsVersion - The params version that was used to create the
|
|
869
|
-
* delegation in Babylon chain
|
|
870
|
-
* @param earlyUnbondingTx - The early unbonding transaction.
|
|
871
|
-
* @param feeRate - The fee rate in satoshis per byte.
|
|
872
|
-
* @returns The signed withdrawal transaction and its fee.
|
|
873
|
-
*/
|
|
874
|
-
createSignedBtcWithdrawEarlyUnbondedTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, earlyUnbondingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
875
|
-
/**
|
|
876
|
-
* Creates a signed withdrawal transaction on the staking output expiry path
|
|
877
|
-
* that is ready to be sent to the BTC network.
|
|
878
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
879
|
-
* and the no-coord public key in hex format.
|
|
880
|
-
* @param stakingInput - The staking inputs.
|
|
881
|
-
* @param stakingParamsVersion - The params version that was used to create the
|
|
882
|
-
* delegation in Babylon chain
|
|
883
|
-
* @param stakingTx - The staking transaction.
|
|
884
|
-
* @param feeRate - The fee rate in satoshis per byte.
|
|
885
|
-
* @returns The signed withdrawal transaction and its fee.
|
|
886
|
-
*/
|
|
887
|
-
createSignedBtcWithdrawStakingExpiredTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, stakingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
888
|
-
/**
|
|
889
|
-
* Creates a signed withdrawal transaction for the expired slashing output that
|
|
890
|
-
* is ready to be sent to the BTC network.
|
|
891
|
-
* @param stakerBtcInfo - The staker BTC info which includes the BTC address
|
|
892
|
-
* and the no-coord public key in hex format.
|
|
893
|
-
* @param stakingInput - The staking inputs.
|
|
894
|
-
* @param stakingParamsVersion - The params version that was used to create the
|
|
895
|
-
* delegation in Babylon chain
|
|
896
|
-
* @param slashingTx - The slashing transaction.
|
|
897
|
-
* @param feeRate - The fee rate in satoshis per byte.
|
|
898
|
-
* @returns The signed withdrawal transaction and its fee.
|
|
899
|
-
*/
|
|
900
|
-
createSignedBtcWithdrawSlashingTransaction(stakerBtcInfo: StakerInfo, stakingInput: StakingInputs, stakingParamsVersion: number, slashingTx: Transaction, feeRate: number): Promise<TransactionResult>;
|
|
901
|
-
/**
|
|
902
|
-
* Creates a proof of possession for the staker based on ECDSA signature.
|
|
903
|
-
* @param bech32Address - The staker's bech32 address.
|
|
904
|
-
* @returns The proof of possession.
|
|
905
|
-
*/
|
|
906
|
-
createProofOfPossession(bech32Address: string): Promise<ProofOfPossessionBTC>;
|
|
907
|
-
/**
|
|
908
|
-
* Creates the unbonding, slashing, and unbonding slashing transactions and
|
|
909
|
-
* PSBTs.
|
|
910
|
-
* @param stakingInstance - The staking instance.
|
|
911
|
-
* @param stakingTx - The staking transaction.
|
|
912
|
-
* @returns The unbonding, slashing, and unbonding slashing transactions and
|
|
913
|
-
* PSBTs.
|
|
914
|
-
*/
|
|
915
|
-
private createDelegationTransactionsAndPsbts;
|
|
916
|
-
/**
|
|
917
|
-
* Creates a protobuf message for the BTC delegation.
|
|
918
|
-
* @param stakingInstance - The staking instance.
|
|
919
|
-
* @param stakingInput - The staking inputs.
|
|
920
|
-
* @param stakingTx - The staking transaction.
|
|
921
|
-
* @param bech32Address - The staker's babylon chain bech32 address
|
|
922
|
-
* @param stakerBtcInfo - The staker's BTC information such as address and
|
|
923
|
-
* public key
|
|
924
|
-
* @param params - The staking parameters.
|
|
925
|
-
* @param inclusionProof - The inclusion proof of the staking transaction.
|
|
926
|
-
* @returns The protobuf message.
|
|
927
|
-
*/
|
|
928
|
-
createBtcDelegationMsg(stakingInstance: Staking, stakingInput: StakingInputs, stakingTx: Transaction, bech32Address: string, stakerBtcInfo: StakerInfo, params: StakingParams, inclusionProof?: btcstaking.InclusionProof): Promise<{
|
|
929
|
-
typeUrl: string;
|
|
930
|
-
value: btcstakingtx.MsgCreateBTCDelegation;
|
|
931
|
-
}>;
|
|
932
|
-
/**
|
|
933
|
-
* Gets the inclusion proof for the staking transaction.
|
|
934
|
-
* See the type `InclusionProof` for more information
|
|
935
|
-
* @param inclusionProof - The inclusion proof.
|
|
936
|
-
* @returns The inclusion proof.
|
|
937
|
-
*/
|
|
938
|
-
private getInclusionProof;
|
|
939
|
-
}
|
|
940
|
-
/**
|
|
941
|
-
* Get the staker signature from the unbonding transaction
|
|
942
|
-
* This is used mostly for unbonding transactions from phase-1(Observable)
|
|
943
|
-
* @param unbondingTx - The unbonding transaction
|
|
944
|
-
* @returns The staker signature
|
|
945
|
-
*/
|
|
946
|
-
export declare const getUnbondingTxStakerSignature: (unbondingTx: Transaction) => string;
|
|
947
1017
|
|
|
948
1018
|
export {};
|