buzzkillb

scripthash.py

Jul 18th, 2020
979
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import ecdsa
  3. import hashlib
  4. import base58
  5. import binascii
  6. import codecs
  7. import struct
  8.  
  9. denariusAddress= "DDD6SzCwXSEcTPHmNwEQX6xbUs2Rf3svNX"
  10. print("D Addy:" + denariusAddress)
  11.  
  12. #base58decode denarius address
  13. addrToBytes = base58.b58decode(denariusAddress)
  14. print(addrToBytes)
  15. decodedToHex = addrToBytes.hex()
  16. print(decodedToHex)
  17.  
  18. #remove prefix
  19. removeZeroBytes = 2
  20. decodedToHexnoPrefix = decodedToHex[removeZeroBytes:]
  21. print(decodedToHexnoPrefix)
  22.  
  23. #remove checksum
  24. removeChecksum = 40
  25. decodedNoPrefixnoChecksum = decodedToHexnoPrefix[:removeChecksum]
  26. print(decodedNoPrefixnoChecksum)
  27.  
  28. #Add OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG
  29. opDup = "76"
  30. opHash160 = "A9"
  31. opsBuffer = "14"
  32. opEqualVerify = "88"
  33. opChecksig = "AC"
  34.  
  35. scriptPubKey = opDup + opHash160 + opsBuffer + decodedNoPrefixnoChecksum + opEqualVerify + opChecksig
  36. print("scriptpubkey")
  37. print(scriptPubKey)
  38. print("scriptpubkey upper case")
  39. print(scriptPubKey.upper())
  40.  
  41.  
  42. hashedKey = codecs.decode(scriptPubKey.upper(), 'hex')
  43. s = hashlib.new('sha256', hashedKey).digest()
  44. r = hashlib.new('ripemd160', s).digest()
  45.  
  46. convertBigEndian = (codecs.encode(s, 'hex').decode("utf-8"))
  47. print(convertBigEndian)
  48.  
  49. scriptHash = codecs.encode(codecs.decode(convertBigEndian, 'hex')[::-1], 'hex').decode()
  50. print("----Scripthash Below----")
  51. print(scriptHash)
RAW Paste Data