CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-bitcoinjs-lib

Client-side Bitcoin JavaScript library for node.js and browsers with comprehensive Bitcoin protocol support

Overall
score

99%

Overview
Eval results
Files

task.mdevals/scenario-5/

PSBT Transaction Fee Validator

Build a Bitcoin transaction fee validation tool that analyzes and validates fees for Partially Signed Bitcoin Transactions (PSBTs) before they are broadcast to the network.

Requirements

Create a module that validates transaction fees for PSBTs to prevent accidentally overpaying fees. The validator should:

  1. Parse PSBT data from Base64 format
  2. Calculate the absolute transaction fee in satoshis
  3. Calculate the fee rate in satoshis per virtual byte (sat/vB)
  4. Validate that the fee rate doesn't exceed a configurable maximum threshold
  5. Provide detailed fee information for user review

Input

The validator should accept:

  • A Base64-encoded PSBT string
  • A maximum fee rate threshold in satoshis per virtual byte (default: 100 sat/vB)

Output

The validator should return an object containing:

  • fee: The absolute fee amount in satoshis
  • feeRate: The calculated fee rate in sat/vB
  • isValid: Boolean indicating whether the fee rate is within acceptable limits
  • maxFeeRate: The maximum fee rate threshold used for validation

Error Handling

The validator should handle these error cases:

  • Invalid PSBT format (throw an error with descriptive message)
  • Missing input/output data required for fee calculation (throw an error)

Test Cases

  • Given a valid PSBT with a reasonable fee rate (under 100 sat/vB), the validator returns the correct fee, fee rate, and marks it as valid. @test

  • Given a valid PSBT with a high fee rate (over 100 sat/vB), the validator calculates the correct fee and fee rate, and marks it as invalid when using the default threshold. @test

  • Given a valid PSBT with a high fee rate that is validated with a custom maximum threshold above that rate, the validator marks it as valid. @test

  • Given an invalid Base64 string that is not a valid PSBT format, the validator throws an error. @test

@generates

API

/**
 * Validates PSBT transaction fees and calculates fee rates
 *
 * @param {string} psbtBase64 - Base64-encoded PSBT string
 * @param {number} [maxFeeRate=100] - Maximum acceptable fee rate in sat/vB
 * @returns {{fee: number, feeRate: number, isValid: boolean, maxFeeRate: number}}
 * @throws {Error} If PSBT is invalid or missing required data
 */
function validatePsbtFee(psbtBase64, maxFeeRate = 100) {
  // IMPLEMENTATION HERE
}

module.exports = {
  validatePsbtFee
};

Dependencies { .dependencies }

bitcoinjs-lib { .dependency }

Provides PSBT parsing, fee calculation, and transaction handling functionality.

Install with Tessl CLI

npx tessl i tessl/npm-bitcoinjs-lib

tile.json