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-4/

Taproot Key Spend Transaction Builder

Build a utility that creates and signs Bitcoin transactions using Taproot key-path spending. The utility handles creating Taproot payment outputs and signing transactions with Schnorr signatures.

Capabilities

Create Taproot payment output

  • Given an internal public key (x-only 32-byte format), create a P2TR payment object with the correct witness program and address @test
  • The P2TR address should be properly encoded in Bech32m format for the specified network @test

Sign Taproot key-path spend

  • Given a transaction with a Taproot input, private key, and input value, produce a valid Schnorr signature for key-path spending @test
  • The signature commits to all transaction inputs and outputs using SIGHASH_ALL @test

Build complete Taproot transaction

  • Create a complete transaction that spends from a Taproot output to a new Taproot output, including proper witness data @test
  • The transaction should serialize correctly and have valid witness structure for Taproot key spend @test

Implementation

@generates

API

/**
 * Creates a P2TR (Pay-to-Taproot) payment object from an internal public key.
 *
 * @param {Buffer} internalPubkey - The 32-byte x-only internal public key
 * @param {Object} options - Configuration options
 * @param {Object} options.network - Bitcoin network (mainnet, testnet, regtest)
 * @returns {Object} Payment object with address, output script, and witness program
 */
function createTaprootPayment(internalPubkey, options) {
  // IMPLEMENTATION HERE
}

/**
 * Signs a Taproot input using key-path spending with a Schnorr signature.
 *
 * @param {Object} transaction - The transaction builder or PSBT object
 * @param {number} inputIndex - Index of the input to sign
 * @param {Buffer} privateKey - The 32-byte private key for signing
 * @param {number} prevOutValue - The value in satoshis of the output being spent
 * @param {number} sighashType - The signature hash type (default: SIGHASH_ALL)
 * @returns {Buffer} The Schnorr signature
 */
function signTaprootKeyPath(transaction, inputIndex, privateKey, prevOutValue, sighashType) {
  // IMPLEMENTATION HERE
}

/**
 * Builds a complete transaction spending from a Taproot output to a new Taproot output.
 *
 * @param {Object} input - Input UTXO details
 * @param {Buffer} input.txid - Transaction ID of the UTXO
 * @param {number} input.vout - Output index
 * @param {number} input.value - Value in satoshis
 * @param {Buffer} input.internalPubkey - Internal public key of the input
 * @param {Object} output - Output details
 * @param {Buffer} output.internalPubkey - Internal public key for the output
 * @param {number} output.value - Value in satoshis
 * @param {Buffer} signingKey - Private key for signing the input
 * @param {Object} network - Bitcoin network configuration
 * @returns {Object} Complete transaction with witness data
 */
function buildTaprootTransaction(input, output, signingKey, network) {
  // IMPLEMENTATION HERE
}

module.exports = {
  createTaprootPayment,
  signTaprootKeyPath,
  buildTaprootTransaction,
};

Dependencies { .dependencies }

bitcoinjs-lib { .dependency }

Provides Bitcoin transaction creation, Taproot support, and cryptographic operations.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-bitcoinjs-lib

tile.json