本文整理汇总了Python中mnemonic.Mnemonic.to_mnemonic方法的典型用法代码示例。如果您正苦于以下问题:Python Mnemonic.to_mnemonic方法的具体用法?Python Mnemonic.to_mnemonic怎么用?Python Mnemonic.to_mnemonic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mnemonic.Mnemonic
的用法示例。
在下文中一共展示了Mnemonic.to_mnemonic方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_list
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_mnemonic [as 别名]
def _check_list(self, language, vectors):
mnemo = Mnemonic(language)
for v in vectors:
code = mnemo.to_mnemonic(unhexlify(v[0]))
seed = hexlify(Mnemonic.to_seed(code, passphrase = 'TREZOR'))
self.assertIs(mnemo.check(v[1]), True)
self.assertEqual(v[1], code)
self.assertEqual(v[2], seed)
示例2: test_to_entropy
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_mnemonic [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)
示例3: test_to_entropy
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_mnemonic [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)
示例4: _check_list
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_mnemonic [as 别名]
def _check_list(self, language, vectors):
mnemo = Mnemonic(language)
for v in vectors:
code = mnemo.to_mnemonic(unhexlify(v[0]))
seed = hexlify(Mnemonic.to_seed(code, passphrase="TREZOR"))
xprv = Mnemonic.to_hd_master_key(unhexlify(seed))
if sys.version >= "3":
seed = seed.decode("utf8")
self.assertIs(mnemo.check(v[1]), True)
self.assertEqual(v[1], code)
self.assertEqual(v[2], seed)
self.assertEqual(v[3], xprv)
示例5: Shamir
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_mnemonic [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)
示例6: PollyAudit
# 需要导入模块: from mnemonic import Mnemonic [as 别名]
# 或者: from mnemonic.Mnemonic import to_mnemonic [as 别名]
#.........这里部分代码省略.........
# Append the new fake source
spend = Spendable(satoshi_per_tx, script, rand_hash, rand_output_index)
spendables.append(spend)
satoshi_left -= satoshi_per_tx
assert satoshi_left == 0, "incorrect funding"
return spendables
def get_tx_bytes(self, tx):
"""
Takes a Tx object and returns a bytes object containing the tx bytes.
"""
s = io.BytesIO()
tx.stream(s)
return s.getvalue()
def gen_wordlist(self, seed):
"""
Generates a polly mnemonic wordlist from a seed, including the checksum.
seed - a string of 24 hex bytes (for a strength of 192 bits)
Returns a space separated string of 18 words from the wordlist.
"""
assert len(seed) == 24, "incorrect seed length, expecting 24 bytes"
return self.mnemonic.to_mnemonic(seed)
def hexstr(self, data):
"""
Takes a bytes object and returns a packed hex string.
"""
# Hexlify the bytes object and strip off the leading b' and trailing '
return str(binascii.hexlify(data))[2:-1]
def txstr(self, tx):
"""
Takes a tx bytes object and prints out its details field by field.
"""
def hexy(tag, data):
print ("{0:<20s} : {1}".format(tag, self.hexstr(data)))
print("\n[tx details]\n")
s = 0
hexy("version", tx[s:s + 4])
s += 4
in_count = ord(tx[s:s + 1])
hexy("in count", tx[s:s + 1])
s += 1
for _ in range(0, in_count) :