client/src/utils/encodings.js
// Extract a raw script hash from an address
Extract a raw script hash from an address
Extract a raw script hash from an address
function addressToSPK (address) {
  if (address.startsWith('bc1')) {
    const result = bech32.BitcoinAddress.decode(address)
    let prefix
    if (result.scriptVersion == 1) prefix = '5120' 
    else if (address.length == 62) prefix = '0020' 
    else prefix = '0014' 
    return prefix + Buffer.from(result.data).toString('hex')
  } else {
    const result = base58_to_binary(address)
    let prefix, postfix
    if (address.charAt(0) === '1') {
      prefix = '76a914' 
      postfix = '88ac' 
    } else {
      prefix = 'a914' 
      postfix = '87' 
    }
    return prefix + Buffer.from(result).toString('hex').slice(2, -8) + postfix
  }
}
function addressToSPK ( address ) { if ( address . startsWith ( 'bc1' ) ) { const result = bech32 . BitcoinAddress . decode ( address ) let prefix if ( result . scriptVersion == 1 ) prefix = '5120' else if ( address . length == 62 ) prefix = '0020' else prefix = '0014' return prefix + Buffer . from ( result . data ) . toString ( 'hex' ) } else { const result = base58_to_binary ( address ) let prefix , postfix if ( address . charAt ( 0 ) === '1' ) { prefix = '76a914' postfix = '88ac' } else { prefix = 'a914' postfix = '87' } return prefix + Buffer . from ( result ) . toString ( 'hex' ) . slice ( 2 , - 8 ) + postfix } }
Extract a raw script hash from an address
Extract a raw script hash from an address
// taproot (OP_PUSHNUM_1 OP_PUSHBYTES_32) // p2wsh (OP_0 OP_PUSHBYTES_32) // p2wpkh (OP_0 OP_PUSHBYTES_20) // p2pkh (OP_DUP OP_HASH160 OP_PUSHBYTES_20) // p2pkh (OP_EQUALVERIFY OP_CHECKSIG) // p2sh (OP_HASH160 OP_PUSHBYTES_20) // p2sh (OP_EQUAL)