@rsksmart/powpeg-sdk 1.2.0-beta.2 → 1.2.0-beta.3

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 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/SECURITY.md CHANGED
@@ -1,140 +1,15 @@
1
- # PowPeg SDK Security Process
1
+ # Reporting Security Issues
2
2
 
3
- We are committed to conduct our security process in a professional and civil manner. Public shaming, under-reporting or misrepresentation of vulnerabilities will not be tolerated.
3
+ The Rootstock team and community take security bugs in rootstock seriously. Beside this project is out of our Bug Bounty Program scope, we appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions.
4
4
 
5
5
  ## Responsible Disclosure
6
6
 
7
- For all security related issues, RootstockLabs has two main points of contact. Reach us at <security@rootstocklabs.com> or refer to our [Bug Bounty Program](https://www.rootstocklabs.com/bug-bounty-program). **Do not open up a GitHub issue if the bug is a security vulnerability**
8
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/rsksmart/powpeg-sdk/issues).
9
-
10
- ## Vulnerability Handling
11
-
12
- ### Response Time
13
-
14
- RootstockLabs will make a best effort to meet the following response times for reported vulnerabilities:
15
- * Time to first response (from report submit) - 5 business days
16
- * Time to triage (from report submit) - 7 business days
17
- * Time to bounty (from triage) - 15 business days
7
+ For all security related issues, the powpeg-sdk team has two main points of contact. Reach us at <security@rootstocklabs.com> or use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/rsksmart/powpeg-sdk/security/advisories/new) tab.
18
8
 
19
- We’ll try to keep you informed about our progress throughout the process.
9
+ The Rootstock team will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance.
20
10
 
21
- ### Disclosure Policy
22
-
23
- * Follow HackerOne's [disclosure guidelines](https://www.hackerone.com/disclosure-guidelines).
24
- * Public disclosure of a vulnerability makes it ineligible for a bounty. If the user reports the vulnerability to other security teams (e.g. Ethereum or ETC) but reports to RootstockLabs with considerable delay, then RootstockLabs may reduce or cancel the bounty.
25
-
26
- For more information check RootstockLabs bounty program policy at [HackerOne](https://hackerone.com/rootstocklabs)
27
-
28
- ## Public Keys
11
+ **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/rsksmart/powpeg-sdk/issues).
29
12
 
30
- ### Security
13
+ ## Disclose Policy
31
14
 
32
- ```gpg
33
- -----BEGIN PGP PUBLIC KEY BLOCK-----
34
- Version: GnuPG v2
35
- mQINBFoF+z0BEADJNtu4DjEqH3+TzdwNwPfRmHo7hhSBR08wnLfkWmsm3IxgEqdB
36
- wYU8rMNXpnsiToTjDnCYYacxQR5uUN4MbYvtnKqGbiapZ5EgCDoRMKYKhJwTuAjH
37
- ju9cPfblwuIG9eLJ7NJ9t/C+07JQQzDolPo3JBzXjeNDMS21YNqiUfHRCIKcTC45
38
- /ksfX0q5UG0KM0FgYiAYJer0OQp/A2KETzzweXdNTs+KXDuA1ChafQ/3x3efDG+D
39
- HekfQULToISKMq36Fh2icjMDY4I93iDXGa8xDoGYt1OIGuPS37XVdNjudlvsybgU
40
- 8Y6vnw3xp9r5dP3Dvb43yYNXAiTErLiU6jkufUj1Jo85nwJDMSiaXwFfAeiiv1WO
41
- ThdRwrEOKYLVIAb0mhT1Gcqf4PC0nVX/RyPsF8OztgiJBAp/4jY/8POmGi7KdDKG
42
- Fa/r1eV/Tuk8yfh+GYq7LkdT92up5uUxPACCGvkP3+5vLu9R8ttO6DDl3eYGIpla
43
- mP4JTGaFWmVi/Fq+7u2JTZI3CpVsx7CBH5Loluof6Yp6ijqtrzDwGPsD6a/qqQpx
44
- hPwO0jYhrCFgRl369gkavlT4y2IodNw8D1Hx1MtIYLVwS7PD7XIcfLwsOl5I0Bc5
45
- SKbW4hJ8VPj/Qv+I5tDu1G/GbTmE5wSly7SbVMSvtSOUzIlbczONKi+mrQARAQAB
46
- tB9TZWMgQ2hhbm5lbCA8c2VjY2hhbm5lbEByc2suY28+iQI9BBMBCgAnBQJaBfs9
47
- AhsDBQkJZgGABQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJEFjSJg1ZmGdY6tYP
48
- /A3P75RTZdl37JzHEWh6kfNJ6LdmCBTxbtwUxCmhKKKtgl1lSamt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9gcD5BGZSLakwummLVKEJyFlgZW3Tc2p9C
128
- 5PyqukuEHLjep3UNYiQLX4rupeqovfEI8q3cJJrEa30svDmNO+kQYlPVemjsNo7l
129
- XmWm+LM281Ycg4ZYFpUIsDGupNFiQyLbKizXEICkhrBs8NaTCyp4yHJVuo75z/w5
130
- /p8HndVR4u62Qmxn06XZICjd8nQXK9bPen5OZ6O42yOL4/zCGJgQzrshMiBZwPUf
131
- Q6hjQJkgD/PttjL32SeIAGC6ca4uVR5MqPub1RDaIe6CZJ/Go8lZX+dxQzCJbdv+
132
- DcdNL7HHw9EVTR3wRdI7DwJbH1vJCEO1i1RTZBJd3sKhwHtdSXkdOwIWYgnUF2fx
133
- ermtX1AKDpAKkMumwMMvAFA6ntevmNmdc35LCCq5rMX4ClKVn5+0n5YeAdxH7teZ
134
- 0FzlNBDmYtdeYWnMXut/ukHO2GWZyXkbfXXXQhezeUQaWuyCfsAuocqHvEtRYoVx
135
- iZ1WSLgU34q1rcX2abQsHUWRxZmBfKD6RZ15bvlIM99ne2/bDSBETz4KUCIa2WIV
136
- v0FjOkVKB3PSHj1q4fogldX0Yb55tUa3rX0Rb8QEKInQj8FFPd44XHclv9PTv0OL
137
- IfHtYt8huvu34FA85HR8wAOPiqvyJ7Oj
138
- =r7Yf
139
- -----END PGP PUBLIC KEY BLOCK-----
140
- ```
15
+ Follow our [disclosure guidelines](https://www.rootstocklabs.com/bounty-program/).
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;
@@ -154,8 +198,7 @@ declare class PowPegSDK {
154
198
  private pegInOutputs;
155
199
  private powpegRsktHeader;
156
200
  private burnDustMaxValue;
157
- private utxos;
158
- private changeAddress?;
201
+ private funding;
159
202
  private minPeginAmount;
160
203
  private peginFeeEstimationInputs;
161
204
  private minPegoutAmount;
@@ -182,26 +225,92 @@ declare class PowPegSDK {
182
225
  private groupAddressesByUsage;
183
226
  private groupAddressesByBalance;
184
227
  private getAddressesGroupedByUsage;
228
+ private validateRskRecipient;
229
+ private getVerifiedFederationAddress;
185
230
  private getRskOutput;
186
- estimatePeginFee(amount: bigint, feeLevel?: FeeLevel): Promise<number>;
231
+ /**
232
+ * Estimates the Bitcoin network fee (in satoshis) to pay for a peg-in transaction of the given amount.
233
+ * @param {bigint} amount - Amount to peg in, in satoshis.
234
+ * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
235
+ * @param {Utxo[]} [utxos] - UTXOs available to fund the peg-in. When provided, the estimate runs the
236
+ * same input selection used to fund the transaction; otherwise it assumes a fixed number of inputs.
237
+ * @returns {Promise<number>} The estimated total fee in satoshis.
238
+ */
239
+ estimatePeginFee(amount: bigint, feeLevel?: FeeLevel, utxos?: Utxo[]): Promise<number>;
240
+ /**
241
+ * Builds an unsigned peg-in PSBT that sends `amount` satoshis to the federation's Bitcoin address,
242
+ * encoding `recipientAddress` (and an unused refund address, if available) in an OP_RETURN output.
243
+ * Also records the UTXOs and change address {@link fundPegin} will use to fund the transaction.
244
+ * @param {bigint} amount - Amount to peg in, in satoshis.
245
+ * @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
246
+ * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
247
+ * @returns {Promise<Psbt>} The unsigned, unfunded peg-in PSBT.
248
+ */
187
249
  createPegin(amount: bigint, recipientAddress: string, selectedUtxos?: Utxo[]): Promise<Psbt>;
188
250
  private selectInputs;
189
251
  private validatePeginAmount;
190
252
  private calculatePeginFee;
191
253
  private calculateFeeAndSelectedInputs;
254
+ /**
255
+ * Adds funding inputs (and a change output, if above the dust threshold) to an existing peg-in PSBT,
256
+ * using the UTXOs previously selected by {@link createPegin} or {@link createAndFundPsbt}.
257
+ * @param {Psbt} psbt - The peg-in PSBT to fund.
258
+ * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
259
+ * @param {bigint} [value] - Amount being sent, in satoshis. Defaults to the PSBT's second output value.
260
+ * @returns {Promise<UnsignedPegin>} The funded PSBT along with its inputs, their raw transactions, and the total fee.
261
+ */
192
262
  fundPegin(psbt: Psbt, feeLevel?: FeeLevel, value?: bigint): Promise<{
193
263
  psbt: Psbt;
194
264
  inputs: Utxo[];
195
265
  transactions: string[];
196
266
  fee: number;
197
267
  }>;
268
+ /**
269
+ * Convenience method that creates and funds a peg-in PSBT in one call.
270
+ * @param {bigint} amount - Amount to peg in, in satoshis.
271
+ * @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
272
+ * @param {BitcoinSigner} signer - Bitcoin signer used to derive the addresses funding this peg-in.
273
+ * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
274
+ * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
275
+ * @returns {Promise<UnsignedPegin>} The funded, unsigned peg-in PSBT along with its inputs, raw transactions, and total fee.
276
+ */
198
277
  createAndFundPegin(amount: bigint, recipientAddress: string, signer: BitcoinSigner, feeLevel?: FeeLevel, selectedUtxos?: Utxo[]): Promise<UnsignedPegin>;
278
+ /**
279
+ * Builds and funds a generic PSBT paying `amount` satoshis to `recipientAddress` using the given UTXOs,
280
+ * without routing through the federation address (unlike {@link createPegin}).
281
+ * @param {bigint} amount - Amount to send, in satoshis.
282
+ * @param {string} recipientAddress - Bitcoin address to receive the payment.
283
+ * @param {Utxo[]} utxos - UTXOs to fund the transaction with.
284
+ * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
285
+ * @returns {Promise<UnsignedPegin>} The funded, unsigned PSBT along with its inputs, raw transactions, and total fee.
286
+ */
199
287
  createAndFundPsbt(amount: bigint, recipientAddress: string, utxos: Utxo[], feeLevel?: FeeLevel): Promise<UnsignedPegin>;
200
288
  private signPegin;
289
+ /**
290
+ * Signs a peg-in PSBT with the configured Bitcoin signer and broadcasts it via the configured data source.
291
+ * @param {Psbt} psbt - The funded peg-in PSBT to sign and broadcast.
292
+ * @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.
293
+ * @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.
294
+ * @returns {Promise<string>} The broadcast transaction's ID.
295
+ */
201
296
  signAndBroadcastPegin(psbt: Psbt, inputs?: Utxo[], transactions?: string[]): Promise<string>;
202
297
  private validateMinimumPegoutAmount;
203
298
  private createPegoutTransaction;
299
+ /**
300
+ * Estimates the Bitcoin and Rootstock fees for a peg-out of the given RBTC amount.
301
+ * @param {string} amount - Amount to peg out, in RBTC (18 decimals).
302
+ * @param {string} [fromAddress] - Rootstock sender address used to estimate gas. Defaults to the zero address.
303
+ * @returns {Promise<PegoutFeeEstimation>} The estimated Bitcoin fee (satoshis) and Rootstock gas fee (wei).
304
+ */
204
305
  estimatePegoutFees(amount: string, fromAddress?: string): Promise<PegoutFeeEstimation>;
306
+ /**
307
+ * Validates the requested amount and the sender's balance, then builds an unsigned peg-out
308
+ * transaction (a value-transfer call to the bridge precompile) together with its estimated fees.
309
+ * @param {string} amount - Amount to peg out, in RBTC (18 decimals).
310
+ * @param {string} senderAccount - Rootstock address that will send the peg-out.
311
+ * @returns The unsigned transaction request and its estimated Bitcoin/Rootstock fees.
312
+ * @throws {NotEnoughFundsError} If `senderAccount`'s balance is lower than `amount`.
313
+ */
205
314
  createPegout(amount: string, senderAccount: string): Promise<{
206
315
  tx: {
207
316
  from: string;
@@ -211,40 +320,96 @@ declare class PowPegSDK {
211
320
  rootstockFee: bigint;
212
321
  bitcoinFee: bigint;
213
322
  }>;
323
+ /**
324
+ * Sends a peg-out transaction (as returned by {@link createPegout}) using the given ethers signer
325
+ * and waits for it to be mined.
326
+ * @param {{ from: string, to: string, value: string }} tx - The peg-out transaction request.
327
+ * @param {ethers.Signer} signer - Ethers signer used to send the transaction.
328
+ * @returns The mined transaction receipt, if the signer's provider is set.
329
+ */
214
330
  signAndBroadcastPegout(tx: {
215
331
  from: string;
216
332
  to: string;
217
333
  value: string;
218
334
  }, signer: ethers.Signer): Promise<ethers.providers.TransactionReceipt | undefined>;
335
+ /**
336
+ * Fetches the current status of a peg-in or peg-out transaction from the configured API.
337
+ * @param {string} txHash - The Bitcoin or Rootstock transaction hash to look up.
338
+ * @param {T} txType - Whether `txHash` is a peg-in or a peg-out transaction.
339
+ * @returns {Promise<Extract<StatusData, { type: T }>>} The transaction's type-narrowed status details.
340
+ */
219
341
  getTransactionStatus<T extends TxType>(txHash: string, txType: T): Promise<Extract<PegoutStatusData, {
220
342
  type: T;
221
343
  }> | Extract<PeginStatusData, {
222
344
  type: T;
223
345
  }>>;
346
+ /**
347
+ * Retrieves the feature flags from the 2WP API `/features` endpoint.
348
+ * @returns {Promise<Feature[]>} The feature flags as returned by the API.
349
+ */
350
+ getFeatures(): Promise<Feature[]>;
351
+ /**
352
+ * Returns the spendable UTXOs for the given Bitcoin address(es).
353
+ * @param {string | string[]} addresses - One or more Bitcoin addresses to fetch UTXOs for.
354
+ * @returns {Promise<Utxo[]>} The UTXOs available across the given address(es).
355
+ * @throws {InvalidAddressError} If any address doesn't belong to the SDK's configured network.
356
+ */
224
357
  getAvailableUtxos(addresses: string | string[]): Promise<Utxo[]>;
225
358
  }
226
359
 
360
+ /** {@link BitcoinSigner} backed by a Trezor hardware wallet, connected via `@trezor/connect-web`. */
227
361
  declare class TrezorSigner implements BitcoinSigner {
228
362
  private readonly network;
229
363
  private _addressType;
230
364
  private readonly bitcoinTxVersion;
231
365
  private readonly addresses;
232
366
  private constructor();
233
- static init(network?: Network, initOptions?: typeof TrezorConnect.init): Promise<TrezorSigner>;
367
+ /**
368
+ * Initializes the Trezor connection and returns a ready-to-use signer.
369
+ * @param {Network} [network] - The network to derive addresses for. Defaults to `'TEST'`.
370
+ * @param {Partial<Parameters<typeof TrezorConnect.init>[0]>} [initOptions] - Extra options merged into the `TrezorConnect.init` call.
371
+ * @returns {Promise<TrezorSigner>} The initialized signer.
372
+ */
373
+ static init(network?: Network, initOptions?: Partial<Parameters<typeof TrezorConnect.init>[0]>): Promise<TrezorSigner>;
374
+ /**
375
+ * Disposes the current Trezor connection and re-initializes it.
376
+ * @returns {Promise<TrezorSigner>} A freshly initialized signer for the default (`'TEST'`) network.
377
+ */
234
378
  static reinit(): Promise<TrezorSigner>;
379
+ /** The Bitcoin address type used to derive addresses (`'LEGACY'`, `'SEGWIT'` or `'NATIVE SEGWIT'`). */
235
380
  set addressType(addressType: AddressType);
236
381
  get addressType(): AddressType;
237
382
  private getPathPurpose;
238
383
  private getPathCoin;
239
384
  private getAddresses;
385
+ /**
386
+ * @param {number} bundleSize - Number of change addresses to derive.
387
+ * @returns {Promise<string[]>} `bundleSize` change addresses derived from the Trezor device.
388
+ */
240
389
  getChangeAddresses(bundleSize: number): Promise<string[]>;
390
+ /**
391
+ * @param {number} bundleSize - Number of receive addresses to derive.
392
+ * @returns {Promise<string[]>} `bundleSize` receive (non-change) addresses derived from the Trezor device.
393
+ */
241
394
  getNonChangeAddresses(bundleSize: number): Promise<string[]>;
242
395
  private getScriptType;
243
396
  private getInputs;
397
+ private getOutputScriptType;
398
+ private isChangePath;
244
399
  private getOutputs;
245
- signTransaction(psbt: Psbt, utxos: Utxo[]): Promise<string>;
400
+ /**
401
+ * Signs the given PSBT's inputs/outputs on the Trezor device.
402
+ * @param {Psbt} psbt - The PSBT to sign.
403
+ * @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.
404
+ * @returns {Promise<string>} The serialized signed transaction, or an empty string if signing didn't succeed.
405
+ */
406
+ signTransaction(psbt: Psbt, utxos?: Utxo[]): Promise<string>;
246
407
  }
247
408
 
409
+ /**
410
+ * {@link BitcoinSigner} backed by a Ledger hardware wallet, connected over WebUSB.
411
+ * Device operations are queued so only one runs against the transport at a time.
412
+ */
248
413
  declare class LedgerSigner implements BitcoinSigner {
249
414
  private readonly connection;
250
415
  private readonly transport;
@@ -253,8 +418,18 @@ declare class LedgerSigner implements BitcoinSigner {
253
418
  private readonly addresses;
254
419
  private readonly transportService;
255
420
  private constructor();
421
+ /**
422
+ * Opens a WebUSB transport to a connected Ledger device and returns a ready-to-use signer.
423
+ * @param {Network} [network] - The network to derive addresses for. Defaults to `'TEST'`.
424
+ * @returns {Promise<LedgerSigner>} The initialized signer.
425
+ */
256
426
  static init(network?: Network): Promise<LedgerSigner>;
427
+ /**
428
+ * Closes and reopens the WebUSB transport to the Ledger device, queued behind any in-flight operation.
429
+ * @returns {Promise<LedgerSigner>} A freshly initialized signer for the default (`'TEST'`) network.
430
+ */
257
431
  reinit(): Promise<LedgerSigner>;
432
+ /** The Bitcoin address type used to derive addresses (`'LEGACY'`, `'SEGWIT'` or `'NATIVE SEGWIT'`). */
258
433
  set addressType(addressType: AddressType);
259
434
  get addressType(): AddressType;
260
435
  private getPathPurpose;
@@ -263,27 +438,52 @@ declare class LedgerSigner implements BitcoinSigner {
263
438
  private getXpubVersion;
264
439
  private isSegwit;
265
440
  getAddresses(bundleSize: number, change?: boolean): Promise<string[]>;
441
+ /**
442
+ * @param {number} bundleSize - Number of change addresses to derive.
443
+ * @returns {Promise<string[]>} `bundleSize` change addresses derived from the Ledger device.
444
+ */
266
445
  getChangeAddresses(bundleSize: number): Promise<string[]>;
446
+ /**
447
+ * @param {number} bundleSize - Number of receive addresses to derive.
448
+ * @returns {Promise<string[]>} `bundleSize` receive (non-change) addresses derived from the Ledger device.
449
+ */
267
450
  getNonChangeAddresses(bundleSize: number): Promise<string[]>;
268
451
  getInputs(inputs: Utxo[], transactions: string[]): CreateTransactionArg['inputs'];
452
+ private isChangePath;
453
+ private getChangePath;
269
454
  getOutputScriptHex(psbt: Psbt): string;
270
- signTransaction(psbt: Psbt, inputs: Utxo[], transactions: string[]): Promise<string>;
455
+ /**
456
+ * Signs the given PSBT on the Ledger device, queued behind any in-flight operation.
457
+ * @param {Psbt} psbt - The PSBT to sign.
458
+ * @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.
459
+ * @param {string[]} [transactions] - Raw hex transactions for `inputs`, required by the Ledger app to verify each input.
460
+ * @returns {Promise<string>} The signed, serialized transaction.
461
+ */
462
+ signTransaction(psbt: Psbt, inputs?: Utxo[], transactions?: string[]): Promise<string>;
271
463
  }
272
464
 
465
+ /** Thrown when a requested peg-in or peg-out amount is below the protocol's minimum allowed amount. */
273
466
  declare class AmountBelowMinError extends Error {
274
467
  constructor(message?: string);
275
468
  }
469
+ /** Thrown when the available UTXOs/balance can't cover the requested amount plus fees. */
276
470
  declare class NotEnoughFundsError extends Error {
277
471
  constructor(message?: string);
278
472
  }
473
+ /** Thrown when the 2WP API responds with an error, a failed request, or an unexpected failure. */
279
474
  declare class APIError extends Error {
280
475
  readonly statusCode?: number;
281
476
  readonly data?: unknown;
282
477
  constructor(message: string, statusCode?: number, data?: unknown);
283
478
  }
479
+ /** Thrown when the federation address can't be retrieved from the pegin configuration endpoint or doesn't match the Bridge contract's value. */
480
+ declare class FederationAddressError extends Error {
481
+ constructor(message?: string);
482
+ }
483
+ /** Thrown when one or more Bitcoin addresses don't belong to the SDK's configured network. */
284
484
  declare class InvalidAddressError extends Error {
285
485
  readonly invalidAddresses: string[];
286
486
  constructor(invalidAddresses: string[], message?: string);
287
487
  }
288
488
 
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 };
489
+ export { APIError, type AddressWithDetails, AmountBelowMinError, type BitcoinDataSource, type BitcoinSigner, type Feature, FederationAddressError, 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 };