2018-09-17 17:13:30 -03:00
|
|
|
import hashlib
|
|
|
|
|
|
|
|
|
|
|
|
def sha256(x):
|
2018-11-22 22:24:21 -06:00
|
|
|
if isinstance(x, str):
|
2018-09-17 17:13:30 -03:00
|
|
|
x = x.encode('utf-8')
|
|
|
|
return hashlib.sha256(x).digest()
|
|
|
|
|
|
|
|
|
|
|
|
def double_sha256(x):
|
|
|
|
return sha256(sha256(x))
|
|
|
|
|
|
|
|
|
|
|
|
def ripemd160(x):
|
2018-11-22 22:24:21 -06:00
|
|
|
if isinstance(x, str):
|
2018-09-17 17:13:30 -03:00
|
|
|
x = x.encode('utf-8')
|
|
|
|
md = hashlib.new('ripemd160')
|
|
|
|
md.update(x)
|
|
|
|
return md.digest()
|
|
|
|
|
|
|
|
|
|
|
|
def hash160(x):
|
|
|
|
return ripemd160(sha256(x))
|