Client-side Bitcoin JavaScript library for node.js and browsers with comprehensive Bitcoin protocol support
Overall
score
99%
Build a Bitcoin address utility that can generate P2PKH (Pay-to-Public-Key-Hash) addresses from public keys and validate whether given addresses are valid P2PKH addresses. The utility should support multiple Bitcoin networks (mainnet, testnet, and regtest).
Create a function generateP2PKHAddress(publicKeyBuffer, network) that:
Create a function isValidP2PKHAddress(address, network) that:
Create a function getP2PKHOutputScript(address) that:
Create a test file address-utils.test.js with the following test cases:
const publicKey = Buffer.from('03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd', 'hex');
const address = generateP2PKHAddress(publicKey, 'mainnet');
// Expected address should start with '1' (mainnet P2PKH prefix)
// Verify it's a valid mainnet addressconst publicKey = Buffer.from('02d0de0aaeaefad02b8bdc8a01a1b8b11c696bd3d66a2c5f10780d95b7df42645c', 'hex');
const address = generateP2PKHAddress(publicKey, 'testnet');
// Expected address should start with 'm' or 'n' (testnet P2PKH prefix)
// Verify it's a valid testnet address// Mainnet P2PKH address
assert(isValidP2PKHAddress('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 'mainnet') === true);
// Invalid address (Bech32, not P2PKH)
assert(isValidP2PKHAddress('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4', 'mainnet') === false);
// Wrong network
assert(isValidP2PKHAddress('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 'testnet') === false);const address = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa';
const script = getP2PKHOutputScript(address);
// Verify the script is a Buffer
// Verify the script length is appropriate for P2PKH (25 bytes)Provides Bitcoin protocol support including address generation, script creation, and network configuration.
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