@rsksmart/powpeg-sdk 1.2.0-beta.6 → 1.2.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/dist/index.d.mts CHANGED
@@ -249,9 +249,10 @@ declare class PowPegSDK {
249
249
  * @param {bigint} amount - Amount to peg in, in satoshis.
250
250
  * @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
251
251
  * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
252
+ * @param {BitcoinSigner} [signer] - Signer to bind this PSBT to. Defaults to the signer configured in the constructor.
252
253
  * @returns {Promise<Psbt>} The unsigned, unfunded peg-in PSBT.
253
254
  */
254
- createPegin(amount: bigint, recipientAddress: string, selectedUtxos?: Utxo[]): Promise<Psbt>;
255
+ createPegin(amount: bigint, recipientAddress: string, selectedUtxos?: Utxo[], signer?: BitcoinSigner): Promise<Psbt>;
255
256
  private selectInputs;
256
257
  private validatePeginAmount;
257
258
  private validateFeeRate;
@@ -280,9 +281,10 @@ declare class PowPegSDK {
280
281
  * @param {BitcoinSigner} signer - Bitcoin signer used to derive the addresses funding this peg-in.
281
282
  * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
282
283
  * @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.
283
285
  * @returns {Promise<UnsignedPegin>} The funded, unsigned peg-in PSBT along with its inputs, raw transactions, and total fee.
284
286
  */
285
- createAndFundPegin(amount: bigint, recipientAddress: string, signer: BitcoinSigner, feeLevel?: FeeLevel, selectedUtxos?: Utxo[]): Promise<UnsignedPegin>;
287
+ createAndFundPegin(amount: bigint, recipientAddress: string, signer: BitcoinSigner, feeLevel?: FeeLevel, selectedUtxos?: Utxo[], feeRate?: number): Promise<UnsignedPegin>;
286
288
  /**
287
289
  * Builds and funds a generic PSBT paying `amount` satoshis to `recipientAddress` using the given UTXOs,
288
290
  * without routing through the federation address (unlike {@link createPegin}).
package/dist/index.d.ts CHANGED
@@ -249,9 +249,10 @@ declare class PowPegSDK {
249
249
  * @param {bigint} amount - Amount to peg in, in satoshis.
250
250
  * @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
251
251
  * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
252
+ * @param {BitcoinSigner} [signer] - Signer to bind this PSBT to. Defaults to the signer configured in the constructor.
252
253
  * @returns {Promise<Psbt>} The unsigned, unfunded peg-in PSBT.
253
254
  */
254
- createPegin(amount: bigint, recipientAddress: string, selectedUtxos?: Utxo[]): Promise<Psbt>;
255
+ createPegin(amount: bigint, recipientAddress: string, selectedUtxos?: Utxo[], signer?: BitcoinSigner): Promise<Psbt>;
255
256
  private selectInputs;
256
257
  private validatePeginAmount;
257
258
  private validateFeeRate;
@@ -280,9 +281,10 @@ declare class PowPegSDK {
280
281
  * @param {BitcoinSigner} signer - Bitcoin signer used to derive the addresses funding this peg-in.
281
282
  * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
282
283
  * @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.
283
285
  * @returns {Promise<UnsignedPegin>} The funded, unsigned peg-in PSBT along with its inputs, raw transactions, and total fee.
284
286
  */
285
- createAndFundPegin(amount: bigint, recipientAddress: string, signer: BitcoinSigner, feeLevel?: FeeLevel, selectedUtxos?: Utxo[]): Promise<UnsignedPegin>;
287
+ createAndFundPegin(amount: bigint, recipientAddress: string, signer: BitcoinSigner, feeLevel?: FeeLevel, selectedUtxos?: Utxo[], feeRate?: number): Promise<UnsignedPegin>;
286
288
  /**
287
289
  * Builds and funds a generic PSBT paying `amount` satoshis to `recipientAddress` using the given UTXOs,
288
290
  * without routing through the federation address (unlike {@link createPegin}).
package/dist/index.js CHANGED
@@ -514,10 +514,10 @@ var PowPegSDK = class {
514
514
  * @param {bigint} amount - Amount to peg in, in satoshis.
515
515
  * @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
516
516
  * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
517
+ * @param {BitcoinSigner} [signer] - Signer to bind this PSBT to. Defaults to the signer configured in the constructor.
517
518
  * @returns {Promise<Psbt>} The unsigned, unfunded peg-in PSBT.
518
519
  */
519
- async createPegin(amount, recipientAddress, selectedUtxos) {
520
- const signer = this.bitcoinSigner;
520
+ async createPegin(amount, recipientAddress, selectedUtxos, signer = this.bitcoinSigner) {
521
521
  const addresses = await this.getAddressesGroupedByUsage(signer);
522
522
  const psbt = new import_bitcoinjs_lib4.Psbt({ network: this.btcNetworkConfig.lib });
523
523
  const refundAddress = addresses.nonChange.unused[0]?.address;
@@ -612,8 +612,17 @@ var PowPegSDK = class {
612
612
  const { inputs, change, totalFee } = await this.calculateFeeAndSelectedInputs(amount, funding.utxos, resolvedFeeRate);
613
613
  const hexTransactions = await Promise.all(inputs.map((input) => this.bitcoinDataSource.getTxHex(input.txid)));
614
614
  const parsedOutputs = hexTransactions.map((hex, index) => {
615
- const output = import_bitcoinjs_lib4.Transaction.fromHex(hex).outs[inputs[index].vout];
615
+ const tx = import_bitcoinjs_lib4.Transaction.fromHex(hex);
616
+ (0, import_bridges_core_sdk4.assertTruthy)(
617
+ tx.getId() === inputs[index].txid,
618
+ `Fetched transaction for UTXO ${inputs[index].txid}:${inputs[index].vout} does not match the requested txid (got ${tx.getId()}).`
619
+ );
620
+ const output = tx.outs[inputs[index].vout];
616
621
  (0, import_bridges_core_sdk4.assertTruthy)(output, `UTXO ${inputs[index].txid}:${inputs[index].vout} was not found in the fetched transaction.`);
622
+ (0, import_bridges_core_sdk4.assertTruthy)(
623
+ BigInt(output.value) === inputs[index].amount,
624
+ `UTXO ${inputs[index].txid}:${inputs[index].vout} value mismatch: fetched transaction reports ${output.value}, expected ${inputs[index].amount}.`
625
+ );
617
626
  return output;
618
627
  });
619
628
  const initialInputCount = psbt.txInputs.length;
@@ -654,13 +663,13 @@ var PowPegSDK = class {
654
663
  * @param {BitcoinSigner} signer - Bitcoin signer used to derive the addresses funding this peg-in.
655
664
  * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
656
665
  * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
666
+ * @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.
657
667
  * @returns {Promise<UnsignedPegin>} The funded, unsigned peg-in PSBT along with its inputs, raw transactions, and total fee.
658
668
  */
659
- async createAndFundPegin(amount, recipientAddress, signer, feeLevel = "fast", selectedUtxos) {
660
- this.bitcoinSigner = signer;
669
+ async createAndFundPegin(amount, recipientAddress, signer, feeLevel = "fast", selectedUtxos, feeRate) {
661
670
  this.validatePeginAmount(amount);
662
- const psbt = await this.createPegin(amount, recipientAddress, selectedUtxos);
663
- return this.fundPegin(psbt, feeLevel);
671
+ const psbt = await this.createPegin(amount, recipientAddress, selectedUtxos, signer);
672
+ return this.fundPegin(psbt, feeLevel, void 0, feeRate);
664
673
  }
665
674
  /**
666
675
  * Builds and funds a generic PSBT paying `amount` satoshis to `recipientAddress` using the given UTXOs,
package/dist/index.mjs CHANGED
@@ -466,10 +466,10 @@ var PowPegSDK = class {
466
466
  * @param {bigint} amount - Amount to peg in, in satoshis.
467
467
  * @param {string} recipientAddress - Rootstock address that will receive the pegged-in RBTC.
468
468
  * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
469
+ * @param {BitcoinSigner} [signer] - Signer to bind this PSBT to. Defaults to the signer configured in the constructor.
469
470
  * @returns {Promise<Psbt>} The unsigned, unfunded peg-in PSBT.
470
471
  */
471
- async createPegin(amount, recipientAddress, selectedUtxos) {
472
- const signer = this.bitcoinSigner;
472
+ async createPegin(amount, recipientAddress, selectedUtxos, signer = this.bitcoinSigner) {
473
473
  const addresses = await this.getAddressesGroupedByUsage(signer);
474
474
  const psbt = new Psbt2({ network: this.btcNetworkConfig.lib });
475
475
  const refundAddress = addresses.nonChange.unused[0]?.address;
@@ -564,8 +564,17 @@ var PowPegSDK = class {
564
564
  const { inputs, change, totalFee } = await this.calculateFeeAndSelectedInputs(amount, funding.utxos, resolvedFeeRate);
565
565
  const hexTransactions = await Promise.all(inputs.map((input) => this.bitcoinDataSource.getTxHex(input.txid)));
566
566
  const parsedOutputs = hexTransactions.map((hex, index) => {
567
- const output = Transaction.fromHex(hex).outs[inputs[index].vout];
567
+ const tx = Transaction.fromHex(hex);
568
+ assertTruthy(
569
+ tx.getId() === inputs[index].txid,
570
+ `Fetched transaction for UTXO ${inputs[index].txid}:${inputs[index].vout} does not match the requested txid (got ${tx.getId()}).`
571
+ );
572
+ const output = tx.outs[inputs[index].vout];
568
573
  assertTruthy(output, `UTXO ${inputs[index].txid}:${inputs[index].vout} was not found in the fetched transaction.`);
574
+ assertTruthy(
575
+ BigInt(output.value) === inputs[index].amount,
576
+ `UTXO ${inputs[index].txid}:${inputs[index].vout} value mismatch: fetched transaction reports ${output.value}, expected ${inputs[index].amount}.`
577
+ );
569
578
  return output;
570
579
  });
571
580
  const initialInputCount = psbt.txInputs.length;
@@ -606,13 +615,13 @@ var PowPegSDK = class {
606
615
  * @param {BitcoinSigner} signer - Bitcoin signer used to derive the addresses funding this peg-in.
607
616
  * @param {FeeLevel} feeLevel - Fee priority level used to look up the current network fee rate. Defaults to `'fast'`.
608
617
  * @param {Utxo[]} [selectedUtxos] - UTXOs to fund the transaction with. If omitted, they're derived from the signer's used addresses.
618
+ * @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.
609
619
  * @returns {Promise<UnsignedPegin>} The funded, unsigned peg-in PSBT along with its inputs, raw transactions, and total fee.
610
620
  */
611
- async createAndFundPegin(amount, recipientAddress, signer, feeLevel = "fast", selectedUtxos) {
612
- this.bitcoinSigner = signer;
621
+ async createAndFundPegin(amount, recipientAddress, signer, feeLevel = "fast", selectedUtxos, feeRate) {
613
622
  this.validatePeginAmount(amount);
614
- const psbt = await this.createPegin(amount, recipientAddress, selectedUtxos);
615
- return this.fundPegin(psbt, feeLevel);
623
+ const psbt = await this.createPegin(amount, recipientAddress, selectedUtxos, signer);
624
+ return this.fundPegin(psbt, feeLevel, void 0, feeRate);
616
625
  }
617
626
  /**
618
627
  * Builds and funds a generic PSBT paying `amount` satoshis to `recipientAddress` using the given UTXOs,
package/docs/setup.md CHANGED
@@ -50,7 +50,7 @@ pnpm add @rsksmart/powpeg-sdk
50
50
  | `bitcoinDataSource` | `BitcoinDataSource` used for fee rates, UTXOs, tx broadcast and tx status | `null` — falls back to the built-in `apiUrl`-backed source |
51
51
  | `network` | `'MAIN'` or `'TEST'` — selects Bitcoin network params and address validation rules | required |
52
52
  | `rpcProviderUrl` | Rootstock JSON-RPC endpoint used to read the bridge precompile and send peg-outs | RSK public node for the given network (`https://public-node.rsk.co` / `https://public-node.testnet.rsk.co`) |
53
- | `apiUrl` | 2WP API used as the default `BitcoinDataSource` (fee rates, UTXOs, tx broadcast, tx status) when no custom `BitcoinDataSource` is supplied | production 2WP API for the given network (`https://api.2wp.rootstock.io` / `https://api.2wp.testnet.rootstock.io`) |
53
+ | `apiUrl` | 2WP API endpoint. Used as the default `BitcoinDataSource` when no custom one is supplied, and always used for federation-address verification during peg-in creation regardless of `bitcoinDataSource` — see External dependencies below | production 2WP API for the given network (`https://api.2wp.rootstock.io` / `https://api.2wp.testnet.rootstock.io`) |
54
54
  | `maxBundleSize` | Number of addresses to derive per `BitcoinSigner` call while creating a peg-in | `10` |
55
55
  | `burnDustValue` | Change amount, in satoshis, below which it's dropped into the fee instead of added as an output | `2000` |
56
56
  | `maxFeeRateSatPerByte` | Upper bound, in sat/B, for a fee rate coming from the configured `BitcoinDataSource`; a higher value throws `InvalidFeeRateError` | `1000` |
@@ -59,7 +59,7 @@ pnpm add @rsksmart/powpeg-sdk
59
59
  ## External dependencies
60
60
 
61
61
  - **Rootstock RPC node** — read via `ethers.providers.JsonRpcProvider`, used for the bridge precompile (`Bridge` in `src/bridge.ts`) and to send peg-out transactions.
62
- - **2WP API** — the SDK's built-in `BitcoinDataSource` implementation (`src/api/api.ts`); can be replaced with your own `BitcoinDataSource` for fee rates, UTXOs, tx broadcasting and address details.
62
+ - **2WP API** — the SDK's built-in `BitcoinDataSource` implementation (`src/api/api.ts`); the fee-rate/UTXO/broadcast/address-details methods can be replaced with your own `BitcoinDataSource`, but `createPegin` always calls the 2WP API's `/pegin-configuration` endpoint directly (via the internal `ApiService`, independent of `bitcoinDataSource`) to verify the federation address against the Bridge contract — this call cannot be substituted, so the 2WP API stays a required dependency even when every other data source is custom.
63
63
  - **Hardware wallets** (only needed if you use the bundled signers — see [`bitcoin-signers.md`](./bitcoin-signers.md)):
64
64
  - **Ledger** — via `@ledgerhq/hw-transport-webusb`, requires a browser environment with WebUSB support.
65
65
  - **Trezor** — via `@trezor/connect-web`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsksmart/powpeg-sdk",
3
- "version": "1.2.0-beta.6",
3
+ "version": "1.2.0",
4
4
  "description": "SDK for creating native peg-in and peg-out transactions following the PowPeg protocol.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",