crypto.js 644 B

123456789101112131415161718192021222324
  1. const jsSHA = require('jssha');
  2. const bytes = require('./bytes');
  3. const code = require('./code');
  4. const base58 = require('./base58');
  5. module.exports.getBase58CheckAddress = function (addressBytes) {
  6. const hash0 = SHA256(addressBytes);
  7. const hash1 = SHA256(hash0);
  8. let checkSum = hash1.slice(0, 4);
  9. checkSum = addressBytes.concat(checkSum);
  10. return base58.encode58(checkSum);
  11. };
  12. function SHA256(msgBytes) {
  13. const shaObj = new jsSHA('SHA-256', 'HEX');
  14. const msgHex = bytes.byteArray2hexStr(msgBytes);
  15. shaObj.update(msgHex);
  16. const hashHex = shaObj.getHash('HEX');
  17. return code.hexStr2byteArray(hashHex);
  18. }