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

Bitcoin Script Analyzer

Build a utility that analyzes Bitcoin scripts by converting between different representations and extracting key information about script structure and operations.

Requirements

Your utility should provide the following functionality:

Script Format Conversion

Convert Bitcoin scripts between their binary and human-readable text representations. The binary format should be handled as hexadecimal strings or buffers, while the text format should display operation names and data in a readable assembly-like syntax.

Script Structure Analysis

Analyze a script to determine:

  • The total number of elements in the script
  • Whether the script contains only data push operations (no executable opcodes)
  • The count of executable operations (excluding data pushes)

Numeric Data Handling

Handle numeric values encoded within scripts. Bitcoin scripts use a special encoding format for numbers. Your utility should:

  • Extract numeric values from their encoded binary format
  • Convert regular numbers into the script-compatible binary format

Test Cases

  • Given a P2PKH locking script in hex format 76a914d291ebe8c5cb3d9539e735641b8e220050bb7e6788ac, convert it to readable text format and verify it contains 5 elements. @test

  • Given the text representation OP_DUP OP_HASH160 d291ebe8c5cb3d9539e735641b8e220050bb7e67 OP_EQUALVERIFY OP_CHECKSIG, convert it back to hex format and verify the result matches the original hex. @test

  • Given a script containing only a signature and public key (typical scriptSig), verify that it is identified as containing only data pushes with 0 non-push operations. @test

  • Given the number 42 encoded as 2a in hex, decode it to verify it equals 42. Then encode 100 and verify the result can be decoded back to 100. @test

@generates

API

/**
 * Converts a script buffer to human-readable text format
 * @param {Buffer|string} script - Script as buffer or hex string
 * @returns {string} Human-readable text representation
 */
function scriptToText(script) {
  // IMPLEMENTATION HERE
}

/**
 * Converts human-readable text format to script buffer
 * @param {string} text - Text representation of script
 * @returns {Buffer} Script buffer
 */
function textToScript(text) {
  // IMPLEMENTATION HERE
}

/**
 * Analyzes script structure
 * @param {Buffer|string} script - Script as buffer or hex string
 * @returns {Object} Analysis result with elementCount, isPushOnly, nonPushOpCount
 */
function analyzeScript(script) {
  // IMPLEMENTATION HERE
}

/**
 * Decodes a script number from buffer
 * @param {Buffer} buffer - Encoded number buffer
 * @returns {number} Decoded number
 */
function decodeNumber(buffer) {
  // IMPLEMENTATION HERE
}

/**
 * Encodes a number into script number format
 * @param {number} num - Number to encode
 * @returns {Buffer} Encoded number buffer
 */
function encodeNumber(num) {
  // IMPLEMENTATION HERE
}

module.exports = {
  scriptToText,
  textToScript,
  analyzeScript,
  decodeNumber,
  encodeNumber
};

Dependencies { .dependencies }

bitcoinjs-lib { .dependency }

Provides Bitcoin protocol support and script operations.

Install with Tessl CLI

npx tessl i tessl/npm-bitcoinjs-lib

tile.json