当前位置: 首页>>代码示例>>Python>>正文


Python Mnemonic.to_entropy方法代码示例

本文整理汇总了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)
开发者ID:trezor,项目名称:python-mnemonic,代码行数:10,代码来源:test_mnemonic.py

示例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)
开发者ID:ghtdak,项目名称:python-mnemonic,代码行数:12,代码来源:test_mnemonic.py

示例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())
开发者ID:RCasatta,项目名称:ew-core,代码行数:17,代码来源:ewcore.py

示例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)
开发者ID:bip39JP,项目名称:python-mnemonic,代码行数:40,代码来源:shamir.py

示例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
开发者ID:RCasatta,项目名称:ew-api-python,代码行数:38,代码来源:ew_hash_api_call.py

示例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())

开发者ID:RCasatta,项目名称:ew-core,代码行数:21,代码来源:excluding_mnemonic.py


注:本文中的mnemonic.Mnemonic.to_entropy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。