lib/utility.js
function stringValue2Buffer(stringValue, byteLength) {
    if ((stringValue).slice(0, 2) === '0x') {
        var input = stringValue.slice(2);
        var length = input.length;
        var buffers = [];
        var j = 0;
        for (var i = length; i > 0 && j < byteLength; i -= 2) {
            buffers.push(new Buffer(input.slice(i - 2, i), 'hex'));
            j++;
        }
        var buffer = Buffer.concat(buffers);
        var paddingLength = byteLength - buffer.length;
        if (paddingLength > 0) {
            var padding = new Buffer(paddingLength);
            padding.fill(0);
            buffer = Buffer.concat([buffer, padding]);
        }
        return buffer;
    }
    else {
        return bigInt2Buffer(new BigInteger(stringValue), byteLength);
    }
}
function stringValue2Buffer(stringValue, byteLength) {
    if ((stringValue).slice(0, 2) === '0x') {
        var input = stringValue.slice(2);
        var length = input.length;
        var buffers = [];
        var j = 0;
        for (var i = length; i > 0 && j < byteLength; i -= 2) {
            buffers.push(new Buffer(input.slice(i - 2, i), 'hex'));
            j++;
        }
        var buffer = Buffer.concat(buffers);
        var paddingLength = byteLength - buffer.length;
        if (paddingLength > 0) {
            var padding = new Buffer(paddingLength);
            padding.fill(0);
            buffer = Buffer.concat([buffer, padding]);
        }
        return buffer;
    }
    else {
        return bigInt2Buffer(new BigInteger(stringValue), byteLength);
    }
}
function stringValue2Buffer ( stringValue , byteLength ) { if ( ( stringValue ) . slice ( 0 , 2 ) === '0x' ) { var input = stringValue . slice ( 2 ) ; var length = input . length ; var buffers = [ ] ; var j = 0 ; for ( var i = length ; i > 0 && j < byteLength ; i -= 2 ) { buffers . push ( new Buffer ( input . slice ( i - 2 , i ) , 'hex' ) ) ; j ++ ; } var buffer = Buffer . concat ( buffers ) ; var paddingLength = byteLength - buffer . length ; if ( paddingLength > 0 ) { var padding = new Buffer ( paddingLength ) ; padding . fill ( 0 ) ; buffer = Buffer . concat ( [ buffer , padding ] ) ; } return buffer ; } else { return bigInt2Buffer ( new BigInteger ( stringValue ) , byteLength ) ; } }
Convert a string value to buffer
Convert a string value to buffer