<commit_before>//if (process.versions.node<'0.12') {
    require('buffertools').extend();
// } else {
//     require('./mock-buffertools');
// }
var crypto = require('crypto');
var bignum = require('bignum');
var Binary = require('./binary');
var logger = require('./logger');
var ccmodule = require('./binding');

exports.ccmodule = ccmodule;

exports.BitcoinKey = ccmodule.BitcoinKey;

var sha256 = exports.sha256 = function (data) {
  return new Buffer(crypto.createHash('sha256').update(data).digest('binary'), 'binary');
};

var ripe160 = exports.ripe160 = function (data) {
  return new Buffer(crypto.createHash('rmd160').update(data).digest('binary'), 'binary');
};

var sha1 = exports.sha1 = function (data) {
  return new Buffer(crypto.createHash('sha1').update(data).digest('binary'), 'binary');
};

var twoSha256 = exports.twoSha256 = function (data) {
  return sha256(sha256(data));
};

var sha256ripe160 = exports.sha256ripe160 = function (data) {
  return ripe160(sha256(data));
};

var sha256midstate = exports.sha256midstate = ccmodule.sha256_midstate;

var encodeHex = exports.encodeHex = function (buffer) {
  return buffer.slice(0).toHex().toString('ascii');
};

var decodeHex = exports.decodeHex = function (hex) {
  // Note that we copy (slice) at the end to convert from SlowBuffer to Buffer
  return new Buffer(hex, 'hex');
};

var encodeBase58 = exports.encodeBase58 = ccmodule.base58_encode;

var decodeBase58 = exports.decodeBase58 = ccmodule.base58_decode;

// DEPRECATED, use BitcoinKey
var verifySig = exports.verifySig = function (sig, pubkey, hash) {
  var key = new ccmodule.BitcoinKey();
  key.public = pubkey;
  return key.verifySignatureSync(hash, sig);
};

/**
 * Format a block hash like the official client does.
 */
var formatHash = exports.formatHash = function (hash) {
  // Make a copy, because reverse() and toHex() are destructive.
  var hashEnd = new Buffer(10);
  hash.copy(hashEnd, 0, 22, 32);
  return hashEnd.reverse().toHex();
};

/**
 * Display the whole hash, as hex, in correct endian order.
 */
var formatHashFull = exports.formatHashFull = function (hash) {
  // Make a copy, because reverse() and toHex() are destructive.
  var copy = new Buffer(hash.length);
  hash.copy(copy);
  var hex = copy.reverse().toHex();
  return hex;
};

/**
 * Format a block hash like Block Explorer does.
 *
 * Formats a block hash by removing leading zeros and truncating to 10 characters.
 */
var formatHashAlt = exports.formatHashAlt = function (hash) {
  var hex = formatHashFull(hash);
  hex = hex.replace(/^0*/, '');
  return hex.substr(0, 10);
};

var formatBuffer = exports.formatBuffer = function (buffer, maxLen) {
  // Calculate amount of bytes to display
  if (maxLen === null) {
    maxLen = 10;
  }
  if (maxLen > buffer.length || maxLen === 0) {
    maxLen = buffer.length;
  }

  // Copy those bytes into a temporary buffer
  var temp = new Buffer(maxLen);
  buffer.copy(temp, 0, 0, maxLen);

  // Format as string
  var output = temp.toHex();
  if (temp.length < buffer.length) {
    output += "...";
  }
  return output;
};

var valueToBigInt = exports.valueToBigInt = function (valueBuffer) {
  if (Buffer.isBuffer(valueBuffer)) {
    return bignum.fromBuffer(valueBuffer, {endian: 'little', size: 8});
  } else {<commit_msg>use full hash for debugging<commit_after>//if (process.versions.node<'0.12') {
    require('buffertools').extend();
// } else {
//     require('./mock-buffertools');
// }
var crypto = require('crypto');
var bignum = require('bignum');
var Binary = require('./binary');
var logger = require('./logger');
var ccmodule = require('./binding');

exports.ccmodule = ccmodule;

exports.BitcoinKey = ccmodule.BitcoinKey;

var sha256 = exports.sha256 = function (data) {
  return new Buffer(crypto.createHash('sha256').update(data).digest('binary'), 'binary');
};

var ripe160 = exports.ripe160 = function (data) {
  return new Buffer(crypto.createHash('rmd160').update(data).digest('binary'), 'binary');
};

var sha1 = exports.sha1 = function (data) {
  return new Buffer(crypto.createHash('sha1').update(data).digest('binary'), 'binary');
};

var twoSha256 = exports.twoSha256 = function (data) {
  return sha256(sha256(data));
};

var sha256ripe160 = exports.sha256ripe160 = function (data) {
  return ripe160(sha256(data));
};

var sha256midstate = exports.sha256midstate = ccmodule.sha256_midstate;

var encodeHex = exports.encodeHex = function (buffer) {
  return buffer.slice(0).toHex().toString('ascii');
};

var decodeHex = exports.decodeHex = function (hex) {
  // Note that we copy (slice) at the end to convert from SlowBuffer to Buffer
  return new Buffer(hex, 'hex');
};

var encodeBase58 = exports.encodeBase58 = ccmodule.base58_encode;

var decodeBase58 = exports.decodeBase58 = ccmodule.base58_decode;

// DEPRECATED, use BitcoinKey
var verifySig = exports.verifySig = function (sig, pubkey, hash) {
  var key = new ccmodule.BitcoinKey();
  key.public = pubkey;
  return key.verifySignatureSync(hash, sig);
};

/**
 * Format a block hash like the official client does.
 */
var formatHash = exports.formatHash = function (hash) {
  // Make a copy, because reverse() and toHex() are destructive.
  var hashEnd = new Buffer(10);
  hash.copy(hashEnd, 0, 22, 32);
  return hashEnd.reverse().toHex();
};

/**
 * Display the whole hash, as hex, in correct endian order.
 */
var formatHashFull = exports.formatHashFull = function (hash) {
  // Make a copy, because reverse() and toHex() are destructive.
  var copy = new Buffer(hash.length);
  hash.copy(copy);
  var hex = copy.reverse().toHex();
  return hex;
};

/**
 * Format a block hash like Block Explorer does.
 *
 * Formats a block hash by removing leading zeros and truncating to 10 characters.
 */
var formatHashAlt = exports.formatHashAlt = function (hash) {
  var hex = formatHashFull(hash);
  hex = hex.replace(/^0*/, '');
return hex; 
// return hex.substr(0, 10);
};

var formatBuffer = exports.formatBuffer = function (buffer, maxLen) {
  // Calculate amount of bytes to display
  if (maxLen === null) {
    maxLen = 10;
  }
  if (maxLen > buffer.length || maxLen === 0) {
    maxLen = buffer.length;
  }

  // Copy those bytes into a temporary buffer
  var temp = new Buffer(maxLen);
  buffer.copy(temp, 0, 0, maxLen);

  // Format as string
  var output = temp.toHex();
  if (temp.length < buffer.length) {
    output += "...";
  }
  return output;
};

var valueToBigInt = exports.valueToBigInt = function (valueBuffer) {
  if (Buffer.isBuffer(valueBuffer)) {
    return bignum.fromBuffer(valueBuffer, {endian: 'little', size: 8});
  } else {
{'fraction_non_alphanumeric': 0.14825493171471926, 'fraction_numerical': 0.028831562974203338, 'mean_word_length': 4.0974477958236655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2581488', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2075, 'n_words': 590}