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


Python Mnemonic.to_mnemonic方法代码示例

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

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

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

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

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

示例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) :
            
开发者ID:ngburke,项目名称:pollyaudit,代码行数:69,代码来源:audit.py


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