本文整理汇总了Python中mnemonic.Mnemonic.to_entropy方法的典型用法代码示例。如果您正苦于以下问题:Python Mnemonic.to_entropy方法的具体用法?Python Mnemonic.to_entropy怎么用?Python Mnemonic.to_entropy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mnemonic.Mnemonic
的用法示例。
在下文中一共展示了Mnemonic.to_entropy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_entropy
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_entropy [as 别名]
def test_to_entropy(self):
data = [
bytearray((random.getrandbits(8) for _ in range(32))) for _ in range(1024)
]
data.append(b"Lorem ipsum dolor sit amet amet.")
m = Mnemonic("english")
for d in data:
self.assertEqual(m.to_entropy(m.to_mnemonic(d).split()), d)
示例2: test_to_entropy
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_entropy [as 别名]
def test_to_entropy(self):
data = [bytearray((random.getrandbits(8) for _ in range(32))) for _ in
range(1024)]
data.append(
b" I'm a little teapot, short and stout. Here is my handle. "
b"Here is my spout. When I get all steamed up, hear me shout. "
b"Tip me over and pour me out!! ")
m = Mnemonic('english')
for d in data:
self.assertEqual(m.to_entropy(m.to_mnemonic(d).split()), d)
示例3: __init__
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_entropy [as 别名]
def __init__(self):
conf = read_config_file("ew.conf")
if conf['entropy']:
entropy = binascii.unhexlify(conf['entropy'])
else:
mnemo = Mnemonic('english')
entropy = mnemo.to_entropy(conf['passphrase'])
print("entropy=" + entropy.hex())
master = BIP32Node.from_master_secret(entropy, 'BTC')
print("master address=" + master.address())
# /m/4544288'/0'/0'/0/0 alias
alias = master.subkey(i=EW_DERIVATION, is_hardened=True).subkey(i=0, is_hardened=True).subkey(i=0, is_hardened=True).subkey(i=0, is_hardened=False).subkey(i=0, is_hardened=False)
self.address = alias.address()
print("alias address=" + self.address)
self.key = CBitcoinSecret(alias.wif())
示例4: Shamir
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_entropy [as 别名]
class Shamir(object):
def __init__(self, language):
self.mnemo = Mnemonic(language)
# see https://primes.utm.edu/lists/2small/ for biggest primes that fit into X bits
self.primes = {
15: (2**120 - 119),
19: (2**152 - 17),
23: (2**184 - 33),
27: (2**216 - 377),
31: (2**248 - 237)
}
def split(self, data, m, n):
if not len(data) in self.primes.keys():
raise Exception('Unknown data length')
if m < 2 or m > 15:
raise Exception('Invalid M provided')
if n < 2 or n > 15:
raise Exception('Invalid N provided')
prime = self.primes[len(data)]
s = secret_int_to_points(int(binascii.hexlify(data), 16), m, n, prime)
s = [ '%x%x%s' % (m, x[0], ('%x' % x[1]).zfill(len(data) * 2)) for x in s ]
return [ self.mnemo.to_mnemonic(binascii.unhexlify(x)) for x in s ]
def combine(self, shares):
words = set([ len(x.split(' ')) for x in shares ])
if len(words) != 1:
raise Exception('Inconsistent number of words')
datalen = list(words)[0] * 4 / 3 - 1
shares = [ binascii.hexlify(self.mnemo.to_entropy(x)) for x in shares ]
if set([ int(x[0], 16) for x in shares ]) != set([len(shares)]):
raise Exception('Number of shares does not match the threshold')
points = [ ( int(x[1], 16), int(x[2:], 16) ) for x in shares ]
prime = self.primes[datalen]
r = points_to_secret_int(points, prime)
r = hex(r)[2:-1].zfill(datalen * 2)
return binascii.unhexlify(r)
示例5: test_ew_derivation
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_entropy [as 别名]
def test_ew_derivation(self):
code = 'this passphrase will not work' # passphrase of an Eternity Wall account with a defined alias (you could use Eternity Wall android app to obtain one or create by your own with the same rules)
mnemo = Mnemonic('english')
entropy = mnemo.to_entropy(code)
# /m/4544288'/0'/0'/0/0 alias
alias = master.subkey(i=EW_DERIVATION, is_hardened=True).subkey(i=0, is_hardened=True).subkey(i=0, is_hardened=True).subkey(i=0, is_hardened=False).subkey(i=0, is_hardened=False)
challenge = str(random.random())
print "challenge= " + challenge
hashvalue = b2h(hashlib.sha256(challenge).digest())
print "hash= " + hashvalue
compressed = True
account = alias.bitcoin_address()
signature = sign_and_verify(alias.wif() , challenge, account, compressed)
print "signature:" + signature
# http://eternitywall.it/v1/auth/hash/[hash]?account=[account]&signature=[signature]&challenge=[challenge]
# for https use https://eternitywall.appspot.com/v1/auth/hash/[hash]?account=[account]&signature=[signature]&challenge=[challenge]
params = { 'account' : account, 'signature' : signature, "challenge" : challenge }
url = "http://eternitywall.it/v1/auth/hash/" + hashvalue + "?" + urllib.urlencode(params)
# returns http code
# 400 if bad missing unrecognized parameter
# 401 if unauthorized (invalid signature or not existing account)
# 200 if OK
print url
conn = httplib.HTTPConnection('eternitywall.it', 80)
conn.connect()
conn.request('POST', url , "")
resp = conn.getresponse()
conn.close()
print resp.status, resp.reason
示例6: Mnemonic
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_entropy [as 别名]
from mnemonic import Mnemonic
from pycoin.key.BIP32Node import BIP32Node
import binascii
EW_DERIVATION = 4544288
mnemo = Mnemonic('english')
entropy_from_pass = mnemo.to_entropy('your passphrase')
entropy_hex = binascii.hexlify(entropy_from_pass)
print(entropy_hex) # save this in conf
######
entropy = binascii.unhexlify(entropy_hex)
master = BIP32Node.from_master_secret(entropy, 'BTC')
print("master address=" + master.address())
alias = master.subkey(i=EW_DERIVATION, is_hardened=True).subkey(i=0, is_hardened=True).subkey(i=0, is_hardened=True).subkey(i=0, is_hardened=False).subkey(i=0, is_hardened=False)
print("alias address=" + alias.address())