const jsSHA = require('jssha'); const bytes = require('./bytes'); const code = require('./code'); const base58 = require('./base58'); module.exports.getBase58CheckAddress = function (addressBytes) { const hash0 = SHA256(addressBytes); const hash1 = SHA256(hash0); let checkSum = hash1.slice(0, 4); checkSum = addressBytes.concat(checkSum); return base58.encode58(checkSum); }; function SHA256(msgBytes) { const shaObj = new jsSHA('SHA-256', 'HEX'); const msgHex = bytes.byteArray2hexStr(msgBytes); shaObj.update(msgHex); const hashHex = shaObj.getHash('HEX'); return code.hexStr2byteArray(hashHex); }