Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. const ecc = require('eosjs-ecc');
  2. const base58 = require('bs58');
  3. const ripemd160 = require('ripemd160')
  4.  
  5. const wif = process.argv[2];
  6. console.log("WIF: ", wif);
  7.  
  8. const privkey = ecc.PrivateKey.fromString(wif);
  9. console.log("Private Key: ", privkey.toBuffer().toString('hex'));
  10.  
  11. const compressed_pubkey = privkey.toPublic();
  12. const uncompressed_pubkey = compressed_pubkey.toUncompressed();
  13. console.log("Public key (compressed): ", compressed_pubkey.toHex());
  14. console.log("Public key: ", uncompressed_pubkey.toHex());
  15.  
  16. const hash1 = ecc.sha256(compressed_pubkey.toBuffer());
  17. const hash2 = new ripemd160().update(Buffer.from(hash1, 'hex')).digest('hex');
  18. const hash3 = ecc.sha256(uncompressed_pubkey.toBuffer());
  19. const hash4 = new ripemd160().update(Buffer.from(hash3, 'hex')).digest('hex');
  20. const with_prefix_compressed = '00' + hash2;
  21. const with_prefix_uncompressed = '00' + hash4;
  22.  
  23. const hash5 = ecc.sha256(Buffer.from(with_prefix_compressed, 'hex'));
  24. const hash6 = ecc.sha256(Buffer.from(hash5, 'hex'));
  25. const hash7 = ecc.sha256(Buffer.from(with_prefix_uncompressed, 'hex'));
  26. const hash8 = ecc.sha256(Buffer.from(hash7, 'hex'));
  27. const binary_address_compressed = with_prefix_compressed + hash6.slice(0,8);
  28. const binary_address_uncompressed = with_prefix_uncompressed + hash8.slice(0,8);
  29. console.log("Binary address (compressed): ", binary_address_compressed);
  30. console.log("Binary address: ", binary_address_uncompressed);
  31.  
  32. const bitcoin_address_compressed = base58.encode(Buffer.from(binary_address_compressed, 'hex'));
  33. const bitcoin_address_uncompressed = base58.encode(Buffer.from(binary_address_uncompressed, 'hex'));
  34. console.log("Bitcoin address (compressed): ", bitcoin_address_compressed);
  35. console.log("Bitcoin address: ", bitcoin_address_uncompressed);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement