src/encoder.js
function writeScriptLockedPayToPubKeyHash(address, locktime, buffer, offset) {
    let locktime_buffer = Buffer.from(locktime, 'hex');
    offset = buffer.writeUInt8(27 + locktime_buffer.length, offset); //Script length
    offset = buffer.writeUInt8(locktime_buffer.length, offset); //Length of locktime
    offset += locktime_buffer.copy(buffer, offset);
    offset = buffer.writeUInt8(OPS.OP_NUMEQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_DUP, offset);
    offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
    //Write previous output address
    offset = buffer.writeUInt8(20, offset); //Address length
    offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
    offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
    return offset;
}
function writeScriptLockedPayToPubKeyHash(address, locktime, buffer, offset) {
    let locktime_buffer = Buffer.from(locktime, 'hex');
    offset = buffer.writeUInt8(27 + locktime_buffer.length, offset); //Script length
    offset = buffer.writeUInt8(locktime_buffer.length, offset); //Length of locktime
    offset += locktime_buffer.copy(buffer, offset);
    offset = buffer.writeUInt8(OPS.OP_NUMEQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_DUP, offset);
    offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
    //Write previous output address
    offset = buffer.writeUInt8(20, offset); //Address length
    offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
    offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
    return offset;
}
function writeScriptLockedPayToPubKeyHash ( address , locktime , buffer , offset ) { let locktime_buffer = Buffer . from ( locktime , 'hex' ) ; offset = buffer . writeUInt8 ( 27 + locktime_buffer . length , offset ) ; //Script length offset = buffer . writeUInt8 ( locktime_buffer . length , offset ) ; //Length of locktime offset += locktime_buffer . copy ( buffer , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_NUMEQUALVERIFY , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_DUP , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_HASH160 , offset ) ; //Write previous output address offset = buffer . writeUInt8 ( 20 , offset ) ; //Address length offset += Buffer . from ( base58check . decode ( address , 'hex' ) . data , 'hex' ) . copy ( buffer , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_EQUALVERIFY , offset ) ; offset = buffer . writeUInt8 ( OPS . OP_CHECKSIG , offset ) ; return offset ; }
Write locked p2pkh to the given buffer.
@param {String} address
@param {String} locktime little endian hex
@param {Buffer} buffer
@param {Number} offset
@returns {Number} new offset
Write locked p2pkh to the given buffer .