Client-side Bitcoin JavaScript library for node.js and browsers with comprehensive Bitcoin protocol support
Overall
score
99%
Build a utility that analyzes Bitcoin scripts by converting between different representations and extracting key information about script structure and operations.
Your utility should provide the following functionality:
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.
Analyze a script to determine:
Handle numeric values encoded within scripts. Bitcoin scripts use a special encoding format for numbers. Your utility should:
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
/**
* 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
};Provides Bitcoin protocol support and script operations.
Install with Tessl CLI
npx tessl i tessl/npm-bitcoinjs-libdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10