@rsksmart/powpeg-sdk 1.1.0-beta.1 → 1.2.0-beta
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 +40 -0
- package/dist/index.d.mts +193 -4
- package/dist/index.d.ts +193 -4
- package/dist/index.js +147 -0
- package/dist/index.mjs +147 -0
- package/docs/api.md +51 -0
- package/docs/bitcoin-signers.md +36 -0
- package/docs/setup.md +61 -0
- package/package.json +12 -3
- /package/{.pnpm-workspace.yaml → pnpm-workspace.yaml} +0 -0
package/README.md
CHANGED
|
@@ -4,6 +4,46 @@
|
|
|
4
4
|
# powpeg-sdk
|
|
5
5
|
SDK for creating native peg-in and peg-out transactions following the PowPeg protocol.
|
|
6
6
|
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @rsksmart/powpeg-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { PowPegSDK, LedgerSigner } from '@rsksmart/powpeg-sdk'
|
|
17
|
+
|
|
18
|
+
const sdk = new PowPegSDK(null, null, 'TEST')
|
|
19
|
+
|
|
20
|
+
// Peg-in: BTC -> RBTC
|
|
21
|
+
const signer = await LedgerSigner.init('TEST')
|
|
22
|
+
const unsignedPegin = await sdk.createAndFundPegin(500_000n, '0xRecipientRskAddress', signer)
|
|
23
|
+
const txId = await sdk.signAndBroadcastPegin(unsignedPegin.psbt, unsignedPegin.inputs, unsignedPegin.transactions)
|
|
24
|
+
|
|
25
|
+
// Peg-out: RBTC -> BTC
|
|
26
|
+
const { tx, bitcoinFee, rootstockFee } = await sdk.createPegout('0.01', '0xSenderRskAddress')
|
|
27
|
+
await sdk.signAndBroadcastPegout(tx, someEthersSigner)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
See [`docs/bitcoin-signers.md`](./docs/bitcoin-signers.md) for other ways to supply a `BitcoinSigner` (e.g. `TrezorSigner`, or your own implementation).
|
|
31
|
+
|
|
32
|
+
## API Reference
|
|
33
|
+
|
|
34
|
+
See [`docs/api.md`](./docs/api.md) for the full table of public exports (`PowPegSDK`, the bundled signers, and every exported type/error).
|
|
35
|
+
|
|
36
|
+
## Testing
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pnpm test # run once
|
|
40
|
+
pnpm coverage # with coverage report
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Documentation
|
|
44
|
+
|
|
45
|
+
See [`docs/`](./docs/) for setup details, the full API reference, and the `BitcoinSigner` extension point (`docs/setup.md`, `docs/api.md`, `docs/bitcoin-signers.md`).
|
|
46
|
+
|
|
7
47
|
# How to publish a beta package?
|
|
8
48
|
|
|
9
49
|
* Update `package.json` `version` field to the format `<version>-beta.<i++>` (eg: 1.0.1-beta.0).
|
package/dist/index.d.mts
CHANGED
|
@@ -3,12 +3,21 @@ import { isBtcTestnetAddress, isBtcMainnetAddress, ethers } from '@rsksmart/brid
|
|
|
3
3
|
import TrezorConnect from '@trezor/connect-web';
|
|
4
4
|
import { CreateTransactionArg } from '@ledgerhq/hw-app-btc/lib/createTransaction';
|
|
5
5
|
|
|
6
|
+
/** Priority level used to look up a Bitcoin network fee rate. */
|
|
6
7
|
type FeeLevel = 'slow' | 'average' | 'fast';
|
|
8
|
+
/**
|
|
9
|
+
* Contract that a Bitcoin signing backend (e.g. {@link TrezorSigner}, {@link LedgerSigner}) must implement
|
|
10
|
+
* so {@link PowPegSDK} can derive addresses and sign peg-in transactions with it.
|
|
11
|
+
*/
|
|
7
12
|
interface BitcoinSigner {
|
|
8
13
|
getNonChangeAddresses(bundleSize: number): Promise<string[]>;
|
|
9
14
|
getChangeAddresses(bundleSize: number): Promise<string[]>;
|
|
10
15
|
signTransaction(psbt: Psbt, inputs?: Utxo[], transactions?: string[]): Promise<string>;
|
|
11
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Contract for a Bitcoin data provider (fee rates, UTXOs, raw transactions, broadcasting).
|
|
19
|
+
* {@link PowPegSDK} falls back to its built-in 2WP API-backed implementation when none is supplied.
|
|
20
|
+
*/
|
|
12
21
|
interface BitcoinDataSource {
|
|
13
22
|
getFeeRate(level: FeeLevel): Promise<number>;
|
|
14
23
|
getTxHex(txId: string): Promise<string>;
|
|
@@ -16,25 +25,47 @@ interface BitcoinDataSource {
|
|
|
16
25
|
broadcast(hexTx: string): Promise<string>;
|
|
17
26
|
getAddressDetails(address: string): Promise<AddressWithDetails>;
|
|
18
27
|
}
|
|
28
|
+
/** A Bitcoin address together with its current balance and transaction count. */
|
|
19
29
|
interface AddressWithDetails {
|
|
20
30
|
address: string;
|
|
21
31
|
balance: number;
|
|
22
32
|
txCount: number;
|
|
23
33
|
}
|
|
34
|
+
/** A spendable Bitcoin unspent transaction output. */
|
|
24
35
|
interface Utxo {
|
|
25
36
|
address: string;
|
|
26
37
|
txid: string;
|
|
27
38
|
amount: bigint;
|
|
28
39
|
vout: number;
|
|
29
40
|
}
|
|
41
|
+
/** Estimated Bitcoin and Rootstock fees for a peg-out. */
|
|
30
42
|
interface PegoutFeeEstimation {
|
|
31
43
|
bitcoinFee: bigint;
|
|
32
44
|
rootstockFee: bigint;
|
|
33
45
|
}
|
|
46
|
+
/** Browser support flags for a feature, as reported by the 2WP API. */
|
|
47
|
+
interface SupportedBrowsers {
|
|
48
|
+
chrome: boolean;
|
|
49
|
+
firefox: boolean;
|
|
50
|
+
safari: boolean;
|
|
51
|
+
edge: boolean;
|
|
52
|
+
brave: boolean;
|
|
53
|
+
chromium: boolean;
|
|
54
|
+
opera: boolean;
|
|
55
|
+
}
|
|
56
|
+
/** A feature flag entry returned by the 2WP API `/features` endpoint. */
|
|
57
|
+
interface Feature {
|
|
58
|
+
name: string;
|
|
59
|
+
value: string;
|
|
60
|
+
version: number;
|
|
61
|
+
supportedBrowsers?: SupportedBrowsers;
|
|
62
|
+
}
|
|
63
|
+
/** Distinguishes a peg-in (BTC -> RBTC) from a peg-out (RBTC -> BTC) transaction. */
|
|
34
64
|
declare enum TxType {
|
|
35
65
|
PEGIN = "PEGIN",
|
|
36
66
|
PEGOUT = "PEGOUT"
|
|
37
67
|
}
|
|
68
|
+
/** Lifecycle status of a peg-out transaction, as reported by the 2WP API. */
|
|
38
69
|
declare enum PegoutStatuses {
|
|
39
70
|
RECEIVED = "RECEIVED",
|
|
40
71
|
REJECTED = "REJECTED",
|
|
@@ -46,6 +77,7 @@ declare enum PegoutStatuses {
|
|
|
46
77
|
NOT_PEGOUT_TX = "NOT_PEGOUT_TX",
|
|
47
78
|
RELEASE_BTC = "RELEASE_BTC"
|
|
48
79
|
}
|
|
80
|
+
/** Lifecycle status of a peg-in transaction, as reported by the 2WP API. */
|
|
49
81
|
declare enum PeginStatuses {
|
|
50
82
|
NOT_IN_BTC_YET = "NOT_IN_BTC_YET",
|
|
51
83
|
WAITING_CONFIRMATIONS = "WAITING_CONFIRMATIONS",
|
|
@@ -57,12 +89,15 @@ declare enum PeginStatuses {
|
|
|
57
89
|
ERROR_BELOW_MIN = "ERROR_BELOW_MIN",
|
|
58
90
|
ERROR_UNEXPECTED = "ERROR_UNEXPECTED"
|
|
59
91
|
}
|
|
92
|
+
/** Maps the bridge's numeric rejection codes to a human-readable peg-out rejection reason. */
|
|
60
93
|
declare const RejectedPegoutReasons: {
|
|
61
94
|
readonly 1: "LOW_AMOUNT";
|
|
62
95
|
readonly 2: "CALLER_CONTRACT";
|
|
63
96
|
readonly 3: "FEE_ABOVE_VALUE";
|
|
64
97
|
};
|
|
98
|
+
/** A human-readable reason a peg-out was rejected, as reported by the 2WP API. */
|
|
65
99
|
type RejectedPegoutReason = (typeof RejectedPegoutReasons)[keyof typeof RejectedPegoutReasons];
|
|
100
|
+
/** Bitcoin and Rootstock-side details of a peg-in transaction. */
|
|
66
101
|
interface PeginTxDetails {
|
|
67
102
|
btc: {
|
|
68
103
|
txId: string;
|
|
@@ -81,6 +116,7 @@ interface PeginTxDetails {
|
|
|
81
116
|
};
|
|
82
117
|
status: PeginStatuses;
|
|
83
118
|
}
|
|
119
|
+
/** Details of a peg-out transaction, including its Bitcoin release once processed. */
|
|
84
120
|
interface PegoutTxDetails {
|
|
85
121
|
originatingRskTxHash: string;
|
|
86
122
|
rskTxHash: string;
|
|
@@ -93,15 +129,19 @@ interface PegoutTxDetails {
|
|
|
93
129
|
btcRawTransaction: string;
|
|
94
130
|
reason?: RejectedPegoutReason;
|
|
95
131
|
}
|
|
132
|
+
/** Status payload for a peg-out transaction, as returned by {@link PowPegSDK.getTransactionStatus}. */
|
|
96
133
|
interface PegoutStatusData {
|
|
97
134
|
type: TxType.PEGOUT;
|
|
98
135
|
txDetails: PegoutTxDetails;
|
|
99
136
|
}
|
|
137
|
+
/** Status payload for a peg-in transaction, as returned by {@link PowPegSDK.getTransactionStatus}. */
|
|
100
138
|
interface PeginStatusData {
|
|
101
139
|
type: TxType.PEGIN;
|
|
102
140
|
txDetails: PeginTxDetails;
|
|
103
141
|
}
|
|
142
|
+
/** Discriminated union of the two possible {@link PowPegSDK.getTransactionStatus} payloads. */
|
|
104
143
|
type StatusData = PegoutStatusData | PeginStatusData;
|
|
144
|
+
/** An unsigned, fee-funded peg-in PSBT ready to be signed, as returned by {@link PowPegSDK.createAndFundPegin}. */
|
|
105
145
|
interface UnsignedPegin {
|
|
106
146
|
psbt: Psbt;
|
|
107
147
|
inputs: Utxo[];
|
|
@@ -142,6 +182,10 @@ declare const networks: {
|
|
|
142
182
|
type AddressType = keyof typeof supportedAddressTypes;
|
|
143
183
|
type Network = keyof typeof networks;
|
|
144
184
|
|
|
185
|
+
/**
|
|
186
|
+
* SDK for creating, funding, signing and broadcasting native PowPeg peg-in (BTC -> RBTC)
|
|
187
|
+
* and peg-out (RBTC -> BTC) transactions.
|
|
188
|
+
*/
|
|
145
189
|
declare class PowPegSDK {
|
|
146
190
|
private _bitcoinSigner;
|
|
147
191
|
private _bitcoinDataSource;
|
|
@@ -183,25 +227,87 @@ declare class PowPegSDK {
|
|
|
183
227
|
private groupAddressesByBalance;
|
|
184
228
|
private getAddressesGroupedByUsage;
|
|
185
229
|
private getRskOutput;
|
|
230
|
+
/**
|
|
231
|
+
* Estimates the Bitcoin network fee (in satoshis) to pay for a peg-in transaction of the given amount.
|
|
232
|
+
* @param {bigint} amount - Amount to peg in, in satoshis.
|
|
233
|
+
* @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
|
|
234
|
+
* @returns {Promise<number>} The estimated total fee in satoshis.
|
|
235
|
+
*/
|
|
186
236
|
estimatePeginFee(amount: bigint, feeLevel?: FeeLevel): Promise<number>;
|
|
237
|
+
/**
|
|
238
|
+
* Builds an unsigned peg-in PSBT that sends `amount` satoshis to the federation's Bitcoin address,
|
|
239
|
+
* encoding `recipientAddress` (and an unused refund address, if available) in an OP_RETURN output.
|
|
240
|
+
* Also records the UTXOs and change address {@link fundPegin} will use to fund the transaction.
|
|
241
|
+
* @param {bigint} amount - Amount to peg in, in satoshis.
|
|
242
|
+
* @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
|
|
243
|
+
* @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
|
|
244
|
+
* @returns {Promise<Psbt>} The unsigned, unfunded peg-in PSBT.
|
|
245
|
+
*/
|
|
187
246
|
createPegin(amount: bigint, recipientAddress: string, selectedUtxos?: Utxo[]): Promise<Psbt>;
|
|
188
247
|
private selectInputs;
|
|
189
248
|
private validatePeginAmount;
|
|
190
249
|
private calculatePeginFee;
|
|
191
250
|
private calculateFeeAndSelectedInputs;
|
|
251
|
+
/**
|
|
252
|
+
* Adds funding inputs (and a change output, if above the dust threshold) to an existing peg-in PSBT,
|
|
253
|
+
* using the UTXOs previously selected by {@link createPegin} or {@link createAndFundPsbt}.
|
|
254
|
+
* @param {Psbt} psbt - The peg-in PSBT to fund.
|
|
255
|
+
* @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
|
|
256
|
+
* @param {bigint} [value] - Amount being sent, in satoshis. Defaults to the PSBT's second output value.
|
|
257
|
+
* @returns {Promise<UnsignedPegin>} The funded PSBT along with its inputs, their raw transactions, and the total fee.
|
|
258
|
+
*/
|
|
192
259
|
fundPegin(psbt: Psbt, feeLevel?: FeeLevel, value?: bigint): Promise<{
|
|
193
260
|
psbt: Psbt;
|
|
194
261
|
inputs: Utxo[];
|
|
195
262
|
transactions: string[];
|
|
196
263
|
fee: number;
|
|
197
264
|
}>;
|
|
265
|
+
/**
|
|
266
|
+
* Convenience method that creates and funds a peg-in PSBT in one call.
|
|
267
|
+
* @param {bigint} amount - Amount to peg in, in satoshis.
|
|
268
|
+
* @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
|
|
269
|
+
* @param {BitcoinSigner} signer - Bitcoin signer used to derive the addresses funding this peg-in.
|
|
270
|
+
* @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
|
|
271
|
+
* @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
|
|
272
|
+
* @returns {Promise<UnsignedPegin>} The funded, unsigned peg-in PSBT along with its inputs, raw transactions, and total fee.
|
|
273
|
+
*/
|
|
198
274
|
createAndFundPegin(amount: bigint, recipientAddress: string, signer: BitcoinSigner, feeLevel?: FeeLevel, selectedUtxos?: Utxo[]): Promise<UnsignedPegin>;
|
|
275
|
+
/**
|
|
276
|
+
* Builds and funds a generic PSBT paying `amount` satoshis to `recipientAddress` using the given UTXOs,
|
|
277
|
+
* without routing through the federation address (unlike {@link createPegin}).
|
|
278
|
+
* @param {bigint} amount - Amount to send, in satoshis.
|
|
279
|
+
* @param {string} recipientAddress - Bitcoin address to receive the payment.
|
|
280
|
+
* @param {Utxo[]} utxos - UTXOs to fund the transaction with.
|
|
281
|
+
* @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
|
|
282
|
+
* @returns {Promise<UnsignedPegin>} The funded, unsigned PSBT along with its inputs, raw transactions, and total fee.
|
|
283
|
+
*/
|
|
199
284
|
createAndFundPsbt(amount: bigint, recipientAddress: string, utxos: Utxo[], feeLevel?: FeeLevel): Promise<UnsignedPegin>;
|
|
200
285
|
private signPegin;
|
|
286
|
+
/**
|
|
287
|
+
* Signs a peg-in PSBT with the configured Bitcoin signer and broadcasts it via the configured data source.
|
|
288
|
+
* @param {Psbt} psbt - The funded peg-in PSBT to sign and broadcast.
|
|
289
|
+
* @param {Utxo[]} [inputs] - The PSBT's funding UTXOs (the `inputs` field returned by `fundPegin`/`createAndFundPegin`), forwarded to the signer if it needs them. Required for the bundled hardware-wallet signers (Ledger, Trezor); optional only for signers that can sign directly from the PSBT.
|
|
290
|
+
* @param {string[]} [transactions] - Raw hex transactions for `inputs` (the `transactions` field returned by `fundPegin`/`createAndFundPegin`), forwarded to the signer if it needs them. Required for the bundled hardware-wallet signers (Ledger, Trezor); optional only for signers that can sign directly from the PSBT.
|
|
291
|
+
* @returns {Promise<string>} The broadcast transaction's ID.
|
|
292
|
+
*/
|
|
201
293
|
signAndBroadcastPegin(psbt: Psbt, inputs?: Utxo[], transactions?: string[]): Promise<string>;
|
|
202
294
|
private validateMinimumPegoutAmount;
|
|
203
295
|
private createPegoutTransaction;
|
|
296
|
+
/**
|
|
297
|
+
* Estimates the Bitcoin and Rootstock fees for a peg-out of the given RBTC amount.
|
|
298
|
+
* @param {string} amount - Amount to peg out, in RBTC (18 decimals).
|
|
299
|
+
* @param {string} [fromAddress] - Rootstock sender address used to estimate gas. Defaults to the zero address.
|
|
300
|
+
* @returns {Promise<PegoutFeeEstimation>} The estimated Bitcoin fee (satoshis) and Rootstock gas fee (wei).
|
|
301
|
+
*/
|
|
204
302
|
estimatePegoutFees(amount: string, fromAddress?: string): Promise<PegoutFeeEstimation>;
|
|
303
|
+
/**
|
|
304
|
+
* Validates the requested amount and the sender's balance, then builds an unsigned peg-out
|
|
305
|
+
* transaction (a value-transfer call to the bridge precompile) together with its estimated fees.
|
|
306
|
+
* @param {string} amount - Amount to peg out, in RBTC (18 decimals).
|
|
307
|
+
* @param {string} senderAccount - Rootstock address that will send the peg-out.
|
|
308
|
+
* @returns The unsigned transaction request and its estimated Bitcoin/Rootstock fees.
|
|
309
|
+
* @throws {NotEnoughFundsError} If `senderAccount`'s balance is lower than `amount`.
|
|
310
|
+
*/
|
|
205
311
|
createPegout(amount: string, senderAccount: string): Promise<{
|
|
206
312
|
tx: {
|
|
207
313
|
from: string;
|
|
@@ -211,40 +317,94 @@ declare class PowPegSDK {
|
|
|
211
317
|
rootstockFee: bigint;
|
|
212
318
|
bitcoinFee: bigint;
|
|
213
319
|
}>;
|
|
320
|
+
/**
|
|
321
|
+
* Sends a peg-out transaction (as returned by {@link createPegout}) using the given ethers signer
|
|
322
|
+
* and waits for it to be mined.
|
|
323
|
+
* @param {{ from: string, to: string, value: string }} tx - The peg-out transaction request.
|
|
324
|
+
* @param {ethers.Signer} signer - Ethers signer used to send the transaction.
|
|
325
|
+
* @returns The mined transaction receipt, if the signer's provider is set.
|
|
326
|
+
*/
|
|
214
327
|
signAndBroadcastPegout(tx: {
|
|
215
328
|
from: string;
|
|
216
329
|
to: string;
|
|
217
330
|
value: string;
|
|
218
331
|
}, signer: ethers.Signer): Promise<ethers.providers.TransactionReceipt | undefined>;
|
|
332
|
+
/**
|
|
333
|
+
* Fetches the current status of a peg-in or peg-out transaction from the configured API.
|
|
334
|
+
* @param {string} txHash - The Bitcoin or Rootstock transaction hash to look up.
|
|
335
|
+
* @param {T} txType - Whether `txHash` is a peg-in or a peg-out transaction.
|
|
336
|
+
* @returns {Promise<Extract<StatusData, { type: T }>>} The transaction's type-narrowed status details.
|
|
337
|
+
*/
|
|
219
338
|
getTransactionStatus<T extends TxType>(txHash: string, txType: T): Promise<Extract<PegoutStatusData, {
|
|
220
339
|
type: T;
|
|
221
340
|
}> | Extract<PeginStatusData, {
|
|
222
341
|
type: T;
|
|
223
342
|
}>>;
|
|
343
|
+
/**
|
|
344
|
+
* Retrieves the feature flags from the 2WP API `/features` endpoint.
|
|
345
|
+
* @returns {Promise<Feature[]>} The feature flags as returned by the API.
|
|
346
|
+
*/
|
|
347
|
+
getFeatures(): Promise<Feature[]>;
|
|
348
|
+
/**
|
|
349
|
+
* Returns the spendable UTXOs for the given Bitcoin address(es).
|
|
350
|
+
* @param {string | string[]} addresses - One or more Bitcoin addresses to fetch UTXOs for.
|
|
351
|
+
* @returns {Promise<Utxo[]>} The UTXOs available across the given address(es).
|
|
352
|
+
* @throws {InvalidAddressError} If any address doesn't belong to the SDK's configured network.
|
|
353
|
+
*/
|
|
224
354
|
getAvailableUtxos(addresses: string | string[]): Promise<Utxo[]>;
|
|
225
355
|
}
|
|
226
356
|
|
|
357
|
+
/** {@link BitcoinSigner} backed by a Trezor hardware wallet, connected via `@trezor/connect-web`. */
|
|
227
358
|
declare class TrezorSigner implements BitcoinSigner {
|
|
228
359
|
private readonly network;
|
|
229
360
|
private _addressType;
|
|
230
361
|
private readonly bitcoinTxVersion;
|
|
231
362
|
private readonly addresses;
|
|
232
363
|
private constructor();
|
|
233
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Initializes the Trezor connection and returns a ready-to-use signer.
|
|
366
|
+
* @param {Network} [network] - The network to derive addresses for. Defaults to `'TEST'`.
|
|
367
|
+
* @param {Partial<Parameters<typeof TrezorConnect.init>[0]>} [initOptions] - Extra options merged into the `TrezorConnect.init` call.
|
|
368
|
+
* @returns {Promise<TrezorSigner>} The initialized signer.
|
|
369
|
+
*/
|
|
370
|
+
static init(network?: Network, initOptions?: Partial<Parameters<typeof TrezorConnect.init>[0]>): Promise<TrezorSigner>;
|
|
371
|
+
/**
|
|
372
|
+
* Disposes the current Trezor connection and re-initializes it.
|
|
373
|
+
* @returns {Promise<TrezorSigner>} A freshly initialized signer for the default (`'TEST'`) network.
|
|
374
|
+
*/
|
|
234
375
|
static reinit(): Promise<TrezorSigner>;
|
|
376
|
+
/** The Bitcoin address type used to derive addresses (`'LEGACY'`, `'SEGWIT'` or `'NATIVE SEGWIT'`). */
|
|
235
377
|
set addressType(addressType: AddressType);
|
|
236
378
|
get addressType(): AddressType;
|
|
237
379
|
private getPathPurpose;
|
|
238
380
|
private getPathCoin;
|
|
239
381
|
private getAddresses;
|
|
382
|
+
/**
|
|
383
|
+
* @param {number} bundleSize - Number of change addresses to derive.
|
|
384
|
+
* @returns {Promise<string[]>} `bundleSize` change addresses derived from the Trezor device.
|
|
385
|
+
*/
|
|
240
386
|
getChangeAddresses(bundleSize: number): Promise<string[]>;
|
|
387
|
+
/**
|
|
388
|
+
* @param {number} bundleSize - Number of receive addresses to derive.
|
|
389
|
+
* @returns {Promise<string[]>} `bundleSize` receive (non-change) addresses derived from the Trezor device.
|
|
390
|
+
*/
|
|
241
391
|
getNonChangeAddresses(bundleSize: number): Promise<string[]>;
|
|
242
392
|
private getScriptType;
|
|
243
393
|
private getInputs;
|
|
244
394
|
private getOutputs;
|
|
245
|
-
|
|
395
|
+
/**
|
|
396
|
+
* Signs the given PSBT's inputs/outputs on the Trezor device.
|
|
397
|
+
* @param {Psbt} psbt - The PSBT to sign.
|
|
398
|
+
* @param {Utxo[]} [utxos] - The PSBT's inputs, used to look up each input's derivation path and script type. Required — TrezorSigner cannot sign from the PSBT alone.
|
|
399
|
+
* @returns {Promise<string>} The serialized signed transaction, or an empty string if signing didn't succeed.
|
|
400
|
+
*/
|
|
401
|
+
signTransaction(psbt: Psbt, utxos?: Utxo[]): Promise<string>;
|
|
246
402
|
}
|
|
247
403
|
|
|
404
|
+
/**
|
|
405
|
+
* {@link BitcoinSigner} backed by a Ledger hardware wallet, connected over WebUSB.
|
|
406
|
+
* Device operations are queued so only one runs against the transport at a time.
|
|
407
|
+
*/
|
|
248
408
|
declare class LedgerSigner implements BitcoinSigner {
|
|
249
409
|
private readonly connection;
|
|
250
410
|
private readonly transport;
|
|
@@ -253,8 +413,18 @@ declare class LedgerSigner implements BitcoinSigner {
|
|
|
253
413
|
private readonly addresses;
|
|
254
414
|
private readonly transportService;
|
|
255
415
|
private constructor();
|
|
416
|
+
/**
|
|
417
|
+
* Opens a WebUSB transport to a connected Ledger device and returns a ready-to-use signer.
|
|
418
|
+
* @param {Network} [network] - The network to derive addresses for. Defaults to `'TEST'`.
|
|
419
|
+
* @returns {Promise<LedgerSigner>} The initialized signer.
|
|
420
|
+
*/
|
|
256
421
|
static init(network?: Network): Promise<LedgerSigner>;
|
|
422
|
+
/**
|
|
423
|
+
* Closes and reopens the WebUSB transport to the Ledger device, queued behind any in-flight operation.
|
|
424
|
+
* @returns {Promise<LedgerSigner>} A freshly initialized signer for the default (`'TEST'`) network.
|
|
425
|
+
*/
|
|
257
426
|
reinit(): Promise<LedgerSigner>;
|
|
427
|
+
/** The Bitcoin address type used to derive addresses (`'LEGACY'`, `'SEGWIT'` or `'NATIVE SEGWIT'`). */
|
|
258
428
|
set addressType(addressType: AddressType);
|
|
259
429
|
get addressType(): AddressType;
|
|
260
430
|
private getPathPurpose;
|
|
@@ -263,27 +433,46 @@ declare class LedgerSigner implements BitcoinSigner {
|
|
|
263
433
|
private getXpubVersion;
|
|
264
434
|
private isSegwit;
|
|
265
435
|
getAddresses(bundleSize: number, change?: boolean): Promise<string[]>;
|
|
436
|
+
/**
|
|
437
|
+
* @param {number} bundleSize - Number of change addresses to derive.
|
|
438
|
+
* @returns {Promise<string[]>} `bundleSize` change addresses derived from the Ledger device.
|
|
439
|
+
*/
|
|
266
440
|
getChangeAddresses(bundleSize: number): Promise<string[]>;
|
|
441
|
+
/**
|
|
442
|
+
* @param {number} bundleSize - Number of receive addresses to derive.
|
|
443
|
+
* @returns {Promise<string[]>} `bundleSize` receive (non-change) addresses derived from the Ledger device.
|
|
444
|
+
*/
|
|
267
445
|
getNonChangeAddresses(bundleSize: number): Promise<string[]>;
|
|
268
446
|
getInputs(inputs: Utxo[], transactions: string[]): CreateTransactionArg['inputs'];
|
|
269
447
|
getOutputScriptHex(psbt: Psbt): string;
|
|
270
|
-
|
|
448
|
+
/**
|
|
449
|
+
* Signs the given PSBT on the Ledger device, queued behind any in-flight operation.
|
|
450
|
+
* @param {Psbt} psbt - The PSBT to sign.
|
|
451
|
+
* @param {Utxo[]} [inputs] - The PSBT's inputs, used to look up each input's previously derived address path. Required — LedgerSigner cannot sign from the PSBT alone.
|
|
452
|
+
* @param {string[]} [transactions] - Raw hex transactions for `inputs`, required by the Ledger app to verify each input.
|
|
453
|
+
* @returns {Promise<string>} The signed, serialized transaction.
|
|
454
|
+
*/
|
|
455
|
+
signTransaction(psbt: Psbt, inputs?: Utxo[], transactions?: string[]): Promise<string>;
|
|
271
456
|
}
|
|
272
457
|
|
|
458
|
+
/** Thrown when a requested peg-in or peg-out amount is below the protocol's minimum allowed amount. */
|
|
273
459
|
declare class AmountBelowMinError extends Error {
|
|
274
460
|
constructor(message?: string);
|
|
275
461
|
}
|
|
462
|
+
/** Thrown when the available UTXOs/balance can't cover the requested amount plus fees. */
|
|
276
463
|
declare class NotEnoughFundsError extends Error {
|
|
277
464
|
constructor(message?: string);
|
|
278
465
|
}
|
|
466
|
+
/** Thrown when the 2WP API responds with an error, a failed request, or an unexpected failure. */
|
|
279
467
|
declare class APIError extends Error {
|
|
280
468
|
readonly statusCode?: number;
|
|
281
469
|
readonly data?: unknown;
|
|
282
470
|
constructor(message: string, statusCode?: number, data?: unknown);
|
|
283
471
|
}
|
|
472
|
+
/** Thrown when one or more Bitcoin addresses don't belong to the SDK's configured network. */
|
|
284
473
|
declare class InvalidAddressError extends Error {
|
|
285
474
|
readonly invalidAddresses: string[];
|
|
286
475
|
constructor(invalidAddresses: string[], message?: string);
|
|
287
476
|
}
|
|
288
477
|
|
|
289
|
-
export { APIError, type AddressWithDetails, AmountBelowMinError, type BitcoinDataSource, type BitcoinSigner, type FeeLevel, InvalidAddressError, LedgerSigner, NotEnoughFundsError, type PeginStatusData, PeginStatuses, type PeginTxDetails, type PegoutFeeEstimation, type PegoutStatusData, PegoutStatuses, type PegoutTxDetails, PowPegSDK, type RejectedPegoutReason, RejectedPegoutReasons, type StatusData, TrezorSigner, TxType, type UnsignedPegin, type Utxo };
|
|
478
|
+
export { APIError, type AddressWithDetails, AmountBelowMinError, type BitcoinDataSource, type BitcoinSigner, type Feature, type FeeLevel, InvalidAddressError, LedgerSigner, NotEnoughFundsError, type PeginStatusData, PeginStatuses, type PeginTxDetails, type PegoutFeeEstimation, type PegoutStatusData, PegoutStatuses, type PegoutTxDetails, PowPegSDK, type RejectedPegoutReason, RejectedPegoutReasons, type StatusData, type SupportedBrowsers, TrezorSigner, TxType, type UnsignedPegin, type Utxo };
|