{"size": 518, "ext": "js", "max_stars_repo_path": "lib/checksum-address.js", "max_stars_repo_name": "hyperdivision/eth-multisig-wallet", "max_stars_repo_stars_event_min_datetime": "2020-05-14T19:42:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-21T11:58:38.000Z", "max_issues_repo_path": "lib/checksum-address.js", "max_issues_repo_name": "hyperdivision/eth-multisig-wallet", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/checksum-address.js", "max_forks_repo_name": "hyperdivision/eth-multisig-wallet", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.7777777778, "max_line_length": 87, "alphanum_fraction": 0.5907335907}
const hash = require('keccak')
module.exports = function toChecksumAddress (address, chainId = null) {
  const addr = address.toString('hex').toLowerCase().replace('0x', '')
  const prefix = chainId != null ? chainId.toString() + '0x' : ''
  var ret = '0x'
  const h = hash('keccak256').update(Buffer.from(prefix + addr, 'ascii')).digest('hex')

  for (var i = 0; i < addr.length; i++) {
    if (parseInt(h[i], 16) >= 8) {
      ret += addr[i].toUpperCase()
    } else {
      ret += addr[i]
    }
  }

  return ret
}
