@rsksmart/powpeg-sdk 1.2.0 → 2.0.0-beta.0

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
@@ -13,12 +13,11 @@ pnpm add @rsksmart/powpeg-sdk
13
13
  ## Quick Start
14
14
 
15
15
  ```ts
16
- import { PowPegSDK, LedgerSigner } from '@rsksmart/powpeg-sdk'
16
+ import { PowPegSDK, Network } from '@rsksmart/powpeg-sdk'
17
17
 
18
- const sdk = new PowPegSDK(null, null, 'TEST')
18
+ const sdk = new PowPegSDK({ network: Network.TEST })
19
19
 
20
- // Peg-in: BTC -> RBTC
21
- const signer = await LedgerSigner.init('TEST')
20
+ // Peg-in: BTC -> RBTC. `signer` is your own BitcoinSigner implementation.
22
21
  const unsignedPegin = await sdk.createAndFundPegin(500_000n, '0xRecipientRskAddress', signer)
23
22
  const txId = await sdk.signAndBroadcastPegin(unsignedPegin.psbt, unsignedPegin.inputs, unsignedPegin.transactions)
24
23
 
@@ -27,11 +26,11 @@ const { tx, bitcoinFee, rootstockFee } = await sdk.createPegout('0.01', '0xSende
27
26
  await sdk.signAndBroadcastPegout(tx, someEthersSigner)
28
27
  ```
29
28
 
30
- See [`docs/bitcoin-signers.md`](./docs/bitcoin-signers.md) for other ways to supply a `BitcoinSigner` (e.g. `TrezorSigner`, or your own implementation).
29
+ The SDK ships no signer implementations — see [`docs/bitcoin-signers.md`](./docs/bitcoin-signers.md) for the `BitcoinSigner` contract and how to supply one.
31
30
 
32
31
  ## API Reference
33
32
 
34
- See [`docs/api.md`](./docs/api.md) for the full table of public exports (`PowPegSDK`, the bundled signers, and every exported type/error).
33
+ See [`docs/api.md`](./docs/api.md) for the full table of public exports (`PowPegSDK` and every exported type/error).
35
34
 
36
35
  ## Testing
37
36
 
package/dist/index.d.mts CHANGED
@@ -1,12 +1,54 @@
1
- import { Psbt, networks as networks$1 } from 'bitcoinjs-lib';
1
+ import { networks as networks$1, Psbt } from 'bitcoinjs-lib';
2
2
  import { isBtcTestnetAddress, isBtcMainnetAddress, ethers } from '@rsksmart/bridges-core-sdk';
3
- import TrezorConnect from '@trezor/connect-web';
4
- import { CreateTransactionArg } from '@ledgerhq/hw-app-btc/lib/createTransaction';
5
3
 
4
+ declare const networks: {
5
+ readonly TEST: {
6
+ readonly lib: networks$1.Network;
7
+ readonly isBtcAddress: typeof isBtcTestnetAddress;
8
+ };
9
+ readonly MAIN: {
10
+ readonly lib: networks$1.Network;
11
+ readonly isBtcAddress: typeof isBtcMainnetAddress;
12
+ };
13
+ };
14
+ type Network = keyof typeof networks;
15
+ /**
16
+ * The network names as values, so callers can write `Network.TEST` instead of the bare string. Shares
17
+ * its name with the type above: TypeScript keeps values and types in separate declaration spaces, so
18
+ * `Network` is both. The mapped annotation keeps it in step with `networks` — adding a network there
19
+ * fails to compile until it is added here too.
20
+ */
21
+ declare const Network: {
22
+ [K in Network]: K;
23
+ };
24
+
25
+ /** Configuration for {@link PowPegSDK}. Only `network` is required. */
26
+ interface PowPegSDKOptions {
27
+ /** `'MAIN'` or `'TEST'` — selects the Bitcoin network params, the Rootstock chain id and the default endpoints. */
28
+ network: Network;
29
+ /** Signs peg-in transactions and derives the addresses they are funded from. Needed only for operations that sign. */
30
+ bitcoinSigner?: BitcoinSigner;
31
+ /** Fee rates, UTXOs, raw transactions, broadcast and transaction status. Defaults to the built-in 2WP API-backed source. */
32
+ bitcoinDataSource?: BitcoinDataSource;
33
+ /** Rootstock JSON-RPC endpoint. Defaults to the public node for `network`. */
34
+ rpcProviderUrl?: string;
35
+ /** 2WP API endpoint. Defaults to the production API for `network`. */
36
+ apiUrl?: string;
37
+ /** Addresses to derive per `BitcoinSigner` call while creating a peg-in. Defaults to 10. */
38
+ maxBundleSize?: number;
39
+ /** Change below this many satoshis is dropped into the fee instead of added as an output. Defaults to 2000. */
40
+ burnDustValue?: number;
41
+ /** Upper bound, in sat/B, for a fee rate coming from the configured `BitcoinDataSource`. Defaults to 1000. */
42
+ maxFeeRateSatPerByte?: number;
43
+ /** Upper bound for the ratio of total fee to peg-in amount. Defaults to 0.5. */
44
+ maxFeeToAmountRatio?: number;
45
+ /** Milliseconds before a request to the API is aborted. Defaults to 10000. */
46
+ requestTimeoutMs?: number;
47
+ }
6
48
  /** Priority level used to look up a Bitcoin network fee rate. */
7
49
  type FeeLevel = 'slow' | 'average' | 'fast';
8
50
  /**
9
- * Contract that a Bitcoin signing backend (e.g. {@link TrezorSigner}, {@link LedgerSigner}) must implement
51
+ * Contract that a Bitcoin signing backend must implement
10
52
  * so {@link PowPegSDK} can derive addresses and sign peg-in transactions with it.
11
53
  */
12
54
  interface BitcoinSigner {
@@ -19,6 +61,7 @@ interface BitcoinSigner {
19
61
  * {@link PowPegSDK} falls back to its built-in 2WP API-backed implementation when none is supplied.
20
62
  */
21
63
  interface BitcoinDataSource {
64
+ /** Fee rate in sat/B. Must be a positive integer: a fractional rate is rejected as implausible. */
22
65
  getFeeRate(level: FeeLevel): Promise<number>;
23
66
  getTxHex(txId: string): Promise<string>;
24
67
  getOutputs(address: string): Promise<Utxo[]>;
@@ -141,6 +184,19 @@ interface PeginStatusData {
141
184
  }
142
185
  /** Discriminated union of the two possible {@link PowPegSDK.getTransactionStatus} payloads. */
143
186
  type StatusData = PegoutStatusData | PeginStatusData;
187
+ /**
188
+ * An unsigned peg-out transaction request, as returned by {@link PowPegSDK.createPegout}.
189
+ * Extends ethers' own request type, so gas, nonce and fee fields a caller sets are carried through to the
190
+ * signer. `customData` and `ccipReadEnabled` are excluded because neither survives ethers' own transaction
191
+ * serialization, on either signer type.
192
+ */
193
+ interface UnsignedPegout extends Omit<ethers.providers.TransactionRequest, 'customData' | 'ccipReadEnabled'> {
194
+ from: string;
195
+ to: string;
196
+ value: string;
197
+ /** Chain the request targets. Filled in with the SDK's configured chain when omitted, and rejected when it names another chain. */
198
+ chainId?: number;
199
+ }
144
200
  /** An unsigned, fee-funded peg-in PSBT ready to be signed, as returned by {@link PowPegSDK.createAndFundPegin}. */
145
201
  interface UnsignedPegin {
146
202
  psbt: Psbt;
@@ -149,51 +205,11 @@ interface UnsignedPegin {
149
205
  fee: number;
150
206
  }
151
207
 
152
- declare const supportedAddressTypes: {
153
- readonly 'NATIVE SEGWIT': {
154
- readonly path: "84";
155
- readonly format: "bech32";
156
- };
157
- readonly SEGWIT: {
158
- readonly path: "49";
159
- readonly format: "p2sh";
160
- };
161
- readonly LEGACY: {
162
- readonly path: "44";
163
- readonly format: "legacy";
164
- };
165
- };
166
- declare const networks: {
167
- readonly TEST: {
168
- readonly currency: "bitcoin_testnet";
169
- readonly coin: "1";
170
- readonly lib: networks$1.Network;
171
- readonly xpubVersion: 70617039;
172
- readonly isBtcAddress: typeof isBtcTestnetAddress;
173
- };
174
- readonly MAIN: {
175
- readonly currency: "bitcoin";
176
- readonly coin: "0";
177
- readonly lib: networks$1.Network;
178
- readonly xpubVersion: 76067358;
179
- readonly isBtcAddress: typeof isBtcMainnetAddress;
180
- };
181
- };
182
- type AddressType = keyof typeof supportedAddressTypes;
183
- type Network = keyof typeof networks;
184
-
185
208
  /**
186
209
  * SDK for creating, funding, signing and broadcasting native PowPeg peg-in (BTC -> RBTC)
187
210
  * and peg-out (RBTC -> BTC) transactions.
188
211
  */
189
212
  declare class PowPegSDK {
190
- private _bitcoinSigner;
191
- private _bitcoinDataSource;
192
- private network;
193
- private maxBundleSize;
194
- private burnDustValue;
195
- private maxFeeRateSatPerByte;
196
- private maxFeeToAmountRatio;
197
213
  private txHeaderSizeInBytes;
198
214
  private txOutputSizeInBytes;
199
215
  private txInputSizeInBytes;
@@ -204,30 +220,40 @@ declare class PowPegSDK {
204
220
  private psbtSigner;
205
221
  private minPeginAmount;
206
222
  private peginFeeEstimationInputs;
207
- private minPegoutAmount;
223
+ private minPegoutSatoshis;
224
+ private pegoutFeeGapPercentage;
225
+ private pegoutSimulationInputs;
226
+ private pegoutSimulationOutputs;
227
+ private pegoutScriptSigSize;
228
+ private maxScriptSigRedeemScriptSize;
229
+ private pegoutSignatureSize;
230
+ private pegoutDeployedSignatureSize;
231
+ private weiPerSatoshi;
232
+ private pegoutRejectionReasons;
208
233
  private btcNetworkConfig;
209
234
  private bridge;
210
235
  private api;
211
236
  private rskProvider;
212
- private publicNodes;
237
+ private rskNetworks;
238
+ private network;
239
+ private _bitcoinSigner;
240
+ private _bitcoinDataSource;
241
+ private maxBundleSize;
242
+ private burnDustValue;
243
+ private maxFeeRateSatPerByte;
244
+ private maxFeeToAmountRatio;
213
245
  /**
214
- * @param {BitcoinSigner | null} _bitcoinSigner - An instance of a class that implements the BitcoinSigner interface.
215
- * @param {BitcoinDataSource | null} _bitcoinDataSource - An instance of a class that implements the BitcoinDataSource interface or null if you won't use peg-in operations.
216
- * @param {Network} network - The network to use. Either 'MAIN' or 'TEST'.
217
- * @param {string} rpcProviderUrl - URL of either your own Rootstock node, the Rootstock RPC API or a third-party node provider. If not provided, it will default to the Rootstock public node for the specified network.
218
- * @param {string} apiUrl - The URL of the API to use. If not provided, it will default to the production 2WP API URL for the specified network and use it as BitcoinDataSource.
219
- * @param {number} maxBundleSize - The maximum number of addresses to ask for while creating a peg-in transaction. Defaults to 10.
220
- * @param {number} burnDustValue - The value in satoshis to consider as dust to burn. Defaults to 2000.
221
- * @param {number} maxFeeRateSatPerByte - Upper bound, in sat/B, for a fee rate coming from the configured BitcoinDataSource. Defaults to 1000.
222
- * @param {number} maxFeeToAmountRatio - Upper bound for the ratio of total fee to peg-in amount. Defaults to 0.5.
246
+ * @param {PowPegSDKOptions} options - SDK configuration. Only `network` is required; every other field
247
+ * falls back to the default documented on {@link PowPegSDKOptions}.
223
248
  */
224
- constructor(_bitcoinSigner: BitcoinSigner | null, _bitcoinDataSource: BitcoinDataSource | null, network: Network, rpcProviderUrl?: string, apiUrl?: string, maxBundleSize?: number, burnDustValue?: number, maxFeeRateSatPerByte?: number, maxFeeToAmountRatio?: number);
249
+ constructor(options: PowPegSDKOptions);
225
250
  private get bitcoinSigner();
226
251
  private set bitcoinSigner(value);
227
252
  private get bitcoinDataSource();
228
253
  private getUtxos;
229
254
  private getAddressesWithDetails;
230
255
  private groupAddressesByUsage;
256
+ private isSpendableAddress;
231
257
  private groupAddressesByBalance;
232
258
  private getAddressesGroupedByUsage;
233
259
  private validateRskRecipient;
@@ -281,7 +307,7 @@ declare class PowPegSDK {
281
307
  * @param {BitcoinSigner} signer - Bitcoin signer used to derive the addresses funding this peg-in.
282
308
  * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
283
309
  * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
284
- * @param {number} [feeRate] - Fee rate, in sat/B, to fund with. When omitted, a fresh rate is fetched from the configured `BitcoinDataSource` and validated. Pass a rate obtained independently (e.g. from a prior `estimatePeginFee` call) to pin funding to that exact value instead of risking a second, possibly different, fetch.
310
+ * @param {number} [feeRate] - Fee rate, in sat/B, to fund with. When omitted, a fresh rate is fetched from the configured `BitcoinDataSource` and validated. Pass a rate obtained independently to pin funding to that exact value instead of risking a second, possibly different, fetch.
285
311
  * @returns {Promise<UnsignedPegin>} The funded, unsigned peg-in PSBT along with its inputs, raw transactions, and total fee.
286
312
  */
287
313
  createAndFundPegin(amount: bigint, recipientAddress: string, signer: BitcoinSigner, feeLevel?: FeeLevel, selectedUtxos?: Utxo[], feeRate?: number): Promise<UnsignedPegin>;
@@ -300,11 +326,48 @@ declare class PowPegSDK {
300
326
  /**
301
327
  * Signs a peg-in PSBT with the configured Bitcoin signer and broadcasts it via the configured data source.
302
328
  * @param {Psbt} psbt - The funded peg-in PSBT to sign and broadcast.
303
- * @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.
304
- * @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.
329
+ * @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 signers that must verify each input against its funding transaction; optional only for signers that can sign directly from the PSBT.
330
+ * @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 signers that must verify each input against its funding transaction; optional only for signers that can sign directly from the PSBT.
305
331
  * @returns {Promise<string>} The broadcast transaction's ID.
332
+ * @throws {SigningError} If the signer returns no signed transaction.
306
333
  */
307
334
  signAndBroadcastPegin(psbt: Psbt, inputs?: Utxo[], transactions?: string[]): Promise<string>;
335
+ private varIntSize;
336
+ /**
337
+ * Witness bytes each input contributes once signed: the stack item count, the two empty elements the
338
+ * federation's script pushes, one signature per required signer, and the redeem script itself.
339
+ */
340
+ private estimateSigningSizePerInput;
341
+ /**
342
+ * Resolves the federation's output script from its redeem script, and with it the transaction format
343
+ * the Bridge builds. The address is required to derive from the redeem script: a P2SH wrapping the
344
+ * witness program means P2SH-P2WSH, a P2SH wrapping the redeem script itself means a legacy multisig.
345
+ */
346
+ private resolveFederationOutput;
347
+ private buildPegoutSimulation;
348
+ /**
349
+ * Size the Bridge computes for a P2SH-P2WSH federation: the transaction is serialized without its
350
+ * inputs and a fixed script-sig size is added per input instead.
351
+ */
352
+ private pegoutVSizeSegwit;
353
+ /**
354
+ * Size the Bridge computes for a federation that is not P2SH-P2WSH: plain serialized bytes, with the
355
+ * redeem script spent through each input's script sig and no witness discount.
356
+ */
357
+ private pegoutVSizeNonSegwit;
358
+ /**
359
+ * Size the Bridge computes once RSKIP378 is active: every input is serialized, and its witness carries
360
+ * one signature per required signer plus the redeem script, weighted as per BIP141.
361
+ */
362
+ private pegoutVSizeAfterRskip378;
363
+ /**
364
+ * Virtual size of the transaction the Bridge would build for a regular peg-out, taken as the larger of
365
+ * what it computes today and what it will compute once RSKIP378 activates, so the derived minimum is
366
+ * never below the one the Bridge enforces under either rule.
367
+ */
368
+ private simulatePegoutVSize;
369
+ private getMinimumPegoutSatoshis;
370
+ private assertAtLeastMinimumPegout;
308
371
  private validateMinimumPegoutAmount;
309
372
  private createPegoutTransaction;
310
373
  /**
@@ -312,6 +375,7 @@ declare class PowPegSDK {
312
375
  * @param {string} amount - Amount to peg out, in RBTC (18 decimals).
313
376
  * @param {string} [fromAddress] - Rootstock sender address used to estimate gas. Defaults to the zero address.
314
377
  * @returns {Promise<PegoutFeeEstimation>} The estimated Bitcoin fee (satoshis) and Rootstock gas fee (wei).
378
+ * @throws {AmountBelowMinError} If `amount` is below the minimum the Bridge currently enforces, derived from its fee per kb and the active federation.
315
379
  */
316
380
  estimatePegoutFees(amount: string, fromAddress?: string): Promise<PegoutFeeEstimation>;
317
381
  /**
@@ -321,9 +385,11 @@ declare class PowPegSDK {
321
385
  * @param {string} senderAccount - Rootstock address that will send the peg-out.
322
386
  * @returns The unsigned transaction request and its estimated Bitcoin/Rootstock fees.
323
387
  * @throws {NotEnoughFundsError} If `senderAccount`'s balance is lower than `amount`.
388
+ * @throws {UnsupportedSenderError} If `senderAccount` is a contract account.
324
389
  */
325
390
  createPegout(amount: string, senderAccount: string): Promise<{
326
391
  tx: {
392
+ chainId: number;
327
393
  from: string;
328
394
  to: string;
329
395
  value: string;
@@ -334,15 +400,14 @@ declare class PowPegSDK {
334
400
  /**
335
401
  * Sends a peg-out transaction (as returned by {@link createPegout}) using the given ethers signer
336
402
  * and waits for it to be mined.
337
- * @param {{ from: string, to: string, value: string }} tx - The peg-out transaction request.
403
+ * @param {UnsignedPegout} tx - The peg-out transaction request, as returned by {@link createPegout}. Forwarded to the signer as given, so gas, nonce and fee fields set by the caller are honoured; only an absent chain id is filled in.
338
404
  * @param {ethers.Signer} signer - Ethers signer used to send the transaction.
339
405
  * @returns The mined transaction receipt, if the signer's provider is set.
406
+ * @throws {WrongNetworkError} If the transaction's chain id, or the signer's chain, doesn't match the network the SDK was configured for.
407
+ * @throws {TransactionRevertedError} If the transaction was mined but reverted.
408
+ * @throws {PegoutRejectedError} If the transaction was mined but the Bridge rejected and refunded the release request.
340
409
  */
341
- signAndBroadcastPegout(tx: {
342
- from: string;
343
- to: string;
344
- value: string;
345
- }, signer: ethers.Signer): Promise<ethers.providers.TransactionReceipt | undefined>;
410
+ signAndBroadcastPegout(tx: UnsignedPegout, signer: ethers.Signer): Promise<ethers.providers.TransactionReceipt | undefined>;
346
411
  /**
347
412
  * Fetches the current status of a peg-in or peg-out transaction from the configured API.
348
413
  * @param {string} txHash - The Bitcoin or Rootstock transaction hash to look up.
@@ -368,111 +433,6 @@ declare class PowPegSDK {
368
433
  getAvailableUtxos(addresses: string | string[]): Promise<Utxo[]>;
369
434
  }
370
435
 
371
- /** {@link BitcoinSigner} backed by a Trezor hardware wallet, connected via `@trezor/connect-web`. */
372
- declare class TrezorSigner implements BitcoinSigner {
373
- private readonly network;
374
- private _addressType;
375
- private readonly bitcoinTxVersion;
376
- private readonly addresses;
377
- private constructor();
378
- /**
379
- * Initializes the Trezor connection and returns a ready-to-use signer.
380
- * @param {Network} [network] - The network to derive addresses for. Defaults to `'TEST'`.
381
- * @param {Partial<Parameters<typeof TrezorConnect.init>[0]>} [initOptions] - Extra options merged into the `TrezorConnect.init` call.
382
- * @returns {Promise<TrezorSigner>} The initialized signer.
383
- */
384
- static init(network?: Network, initOptions?: Partial<Parameters<typeof TrezorConnect.init>[0]>): Promise<TrezorSigner>;
385
- /**
386
- * Disposes the current Trezor connection and re-initializes it.
387
- * @returns {Promise<TrezorSigner>} A freshly initialized signer for the default (`'TEST'`) network.
388
- */
389
- static reinit(): Promise<TrezorSigner>;
390
- /** The Bitcoin address type used to derive addresses (`'LEGACY'`, `'SEGWIT'` or `'NATIVE SEGWIT'`). */
391
- set addressType(addressType: AddressType);
392
- get addressType(): AddressType;
393
- private getPathPurpose;
394
- private getPathCoin;
395
- private getAddresses;
396
- /**
397
- * @param {number} bundleSize - Number of change addresses to derive.
398
- * @returns {Promise<string[]>} `bundleSize` change addresses derived from the Trezor device.
399
- */
400
- getChangeAddresses(bundleSize: number): Promise<string[]>;
401
- /**
402
- * @param {number} bundleSize - Number of receive addresses to derive.
403
- * @returns {Promise<string[]>} `bundleSize` receive (non-change) addresses derived from the Trezor device.
404
- */
405
- getNonChangeAddresses(bundleSize: number): Promise<string[]>;
406
- private getScriptType;
407
- private getInputs;
408
- private getOutputScriptType;
409
- private isChangePath;
410
- private getOutputs;
411
- /**
412
- * Signs the given PSBT's inputs/outputs on the Trezor device.
413
- * @param {Psbt} psbt - The PSBT to sign.
414
- * @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.
415
- * @returns {Promise<string>} The serialized signed transaction, or an empty string if signing didn't succeed.
416
- */
417
- signTransaction(psbt: Psbt, utxos?: Utxo[]): Promise<string>;
418
- }
419
-
420
- /**
421
- * {@link BitcoinSigner} backed by a Ledger hardware wallet, connected over WebUSB.
422
- * Device operations are queued so only one runs against the transport at a time.
423
- */
424
- declare class LedgerSigner implements BitcoinSigner {
425
- private readonly connection;
426
- private readonly transport;
427
- private readonly network;
428
- private _addressType;
429
- private readonly addresses;
430
- private readonly transportService;
431
- private constructor();
432
- /**
433
- * Opens a WebUSB transport to a connected Ledger device and returns a ready-to-use signer.
434
- * @param {Network} [network] - The network to derive addresses for. Defaults to `'TEST'`.
435
- * @returns {Promise<LedgerSigner>} The initialized signer.
436
- */
437
- static init(network?: Network): Promise<LedgerSigner>;
438
- /**
439
- * Closes and reopens the WebUSB transport to the Ledger device, queued behind any in-flight operation.
440
- * @returns {Promise<LedgerSigner>} A freshly initialized signer for the default (`'TEST'`) network.
441
- */
442
- reinit(): Promise<LedgerSigner>;
443
- /** The Bitcoin address type used to derive addresses (`'LEGACY'`, `'SEGWIT'` or `'NATIVE SEGWIT'`). */
444
- set addressType(addressType: AddressType);
445
- get addressType(): AddressType;
446
- private getPathPurpose;
447
- private getPathCoin;
448
- private getAddressFormat;
449
- private getXpubVersion;
450
- private isSegwit;
451
- getAddresses(bundleSize: number, change?: boolean): Promise<string[]>;
452
- /**
453
- * @param {number} bundleSize - Number of change addresses to derive.
454
- * @returns {Promise<string[]>} `bundleSize` change addresses derived from the Ledger device.
455
- */
456
- getChangeAddresses(bundleSize: number): Promise<string[]>;
457
- /**
458
- * @param {number} bundleSize - Number of receive addresses to derive.
459
- * @returns {Promise<string[]>} `bundleSize` receive (non-change) addresses derived from the Ledger device.
460
- */
461
- getNonChangeAddresses(bundleSize: number): Promise<string[]>;
462
- getInputs(inputs: Utxo[], transactions: string[]): CreateTransactionArg['inputs'];
463
- private isChangePath;
464
- private getChangePath;
465
- getOutputScriptHex(psbt: Psbt): string;
466
- /**
467
- * Signs the given PSBT on the Ledger device, queued behind any in-flight operation.
468
- * @param {Psbt} psbt - The PSBT to sign.
469
- * @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.
470
- * @param {string[]} [transactions] - Raw hex transactions for `inputs`, required by the Ledger app to verify each input.
471
- * @returns {Promise<string>} The signed, serialized transaction.
472
- */
473
- signTransaction(psbt: Psbt, inputs?: Utxo[], transactions?: string[]): Promise<string>;
474
- }
475
-
476
436
  /** Thrown when a requested peg-in or peg-out amount is below the protocol's minimum allowed amount. */
477
437
  declare class AmountBelowMinError extends Error {
478
438
  constructor(message?: string);
@@ -496,9 +456,58 @@ declare class InvalidAddressError extends Error {
496
456
  readonly invalidAddresses: string[];
497
457
  constructor(invalidAddresses: string[], message?: string);
498
458
  }
459
+ /** Thrown when the configured BitcoinSigner doesn't return what the SDK asked it for: no derived addresses, or no signed transaction to broadcast. */
460
+ declare class SigningError extends Error {
461
+ constructor(message?: string);
462
+ }
499
463
  /** Thrown when a fee rate from the configured BitcoinDataSource is missing, non-numeric, non-positive, exceeds the configured bound, or produces a fee disproportionate to the amount being sent. */
500
464
  declare class InvalidFeeRateError extends Error {
501
465
  constructor(message?: string);
502
466
  }
467
+ /** Thrown when the signer's chain doesn't match the network the SDK was configured for. */
468
+ declare class WrongNetworkError extends Error {
469
+ constructor(message?: string);
470
+ }
471
+ /**
472
+ * Thrown when the peg-out transaction was mined but the Bridge rejected the release request instead of
473
+ * queueing it. `reason` carries the Bridge's own code: 1 the amount was below its minimum, 2 the caller
474
+ * is a contract, 3 the fee would exceed the amount. Reasons 1 and 3 refund the amount; **reason 2 does
475
+ * not** — the Bridge keeps it. `txHash` is the mined transaction, kept on the error because it is the
476
+ * only handle to an on-chain transaction the caller has already paid for.
477
+ */
478
+ declare class PegoutRejectedError extends Error {
479
+ readonly reason: number;
480
+ readonly txHash: string;
481
+ readonly amount: bigint;
482
+ constructor(reason: number, txHash: string, amount: bigint, message?: string);
483
+ }
484
+ /**
485
+ * Thrown when the account asked to send a peg-out cannot receive BTC for it. The Bridge only releases
486
+ * BTC for release requests that arrive from an externally owned account, so a contract account is
487
+ * refused before any value is sent.
488
+ */
489
+ declare class UnsupportedSenderError extends Error {
490
+ constructor(message?: string);
491
+ }
492
+ /**
493
+ * Thrown when the peg-out transaction was mined but reverted, so the Bridge never recorded a release
494
+ * request and no BTC will be released. This is distinct from {@link PegoutRejectedError}, which the
495
+ * Bridge raises from a transaction that succeeded. `txHash` and `receipt` are kept on the error because
496
+ * the caller has already paid the gas and needs both to account for it without a second round trip.
497
+ */
498
+ declare class TransactionRevertedError extends Error {
499
+ readonly txHash: string;
500
+ readonly receipt: ethers.providers.TransactionReceipt;
501
+ constructor(txHash: string, receipt: ethers.providers.TransactionReceipt, message?: string);
502
+ }
503
+ /**
504
+ * Thrown when a UTXO is held by an address whose type the SDK cannot build a signable PSBT input for.
505
+ * A P2SH input needs a redeem script derived from the public key behind the address, and `BitcoinSigner`
506
+ * exposes addresses only.
507
+ */
508
+ declare class UnsupportedAddressTypeError extends Error {
509
+ readonly address: string;
510
+ constructor(address: string, message?: string);
511
+ }
503
512
 
504
- export { APIError, type AddressWithDetails, AmountBelowMinError, type BitcoinDataSource, type BitcoinSigner, type Feature, FederationAddressError, type FeeLevel, InvalidAddressError, InvalidFeeRateError, 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 };
513
+ export { APIError, type AddressWithDetails, AmountBelowMinError, type BitcoinDataSource, type BitcoinSigner, type Feature, FederationAddressError, type FeeLevel, InvalidAddressError, InvalidFeeRateError, Network, NotEnoughFundsError, type PeginStatusData, PeginStatuses, type PeginTxDetails, type PegoutFeeEstimation, PegoutRejectedError, type PegoutStatusData, PegoutStatuses, type PegoutTxDetails, PowPegSDK, type PowPegSDKOptions, type RejectedPegoutReason, RejectedPegoutReasons, SigningError, type StatusData, type SupportedBrowsers, TransactionRevertedError, TxType, type UnsignedPegin, type UnsignedPegout, UnsupportedAddressTypeError, UnsupportedSenderError, type Utxo, WrongNetworkError };