Пример #1
0
 def make_seed(self, num_bits=128, prefix=version.SEED_PREFIX, custom_entropy=1):
     n = int(math.ceil(math.log(custom_entropy,2)))
     # bits of entropy used by the prefix
     k = len(prefix)*4
     # we add at least 16 bits
     n_added = max(16, k + num_bits - n)
     print_error("make_seed", prefix, "adding %d bits"%n_added)
     my_entropy = ecdsa.util.randrange( pow(2, n_added) )
     nonce = 0
     while True:
         nonce += 1
         i = custom_entropy * (my_entropy + nonce)
         seed = self.mnemonic_encode(i)
         assert i == self.mnemonic_decode(seed)
         if is_old_seed(seed):
             continue
         if is_new_seed(seed, prefix):
             break
     print_error('%d words'%len(seed.split()))
     return seed
Пример #2
0
 def make_seed(self,
               num_bits=128,
               prefix=version.SEED_PREFIX,
               custom_entropy=1):
     # increase num_bits in order to obtain a uniform distibution for the last word
     bpw = math.log(len(self.wordlist), 2)
     num_bits = int(math.ceil(num_bits / bpw)) * bpw
     # handle custom entropy; make sure we add at least 16 bits
     n_custom = int(math.ceil(math.log(custom_entropy, 2)))
     n = max(16, num_bits - n_custom)
     print_error("make_seed", prefix, "adding %d bits" % n)
     my_entropy = ecdsa.util.randrange(pow(2, n))
     nonce = 0
     while True:
         nonce += 1
         i = custom_entropy * (my_entropy + nonce)
         seed = self.mnemonic_encode(i)
         assert i == self.mnemonic_decode(seed)
         if is_old_seed(seed):
             continue
         if is_new_seed(seed, prefix):
             break
     print_error('%d words' % len(seed.split()))
     return seed
Пример #3
0
 def check_seed(self, seed, custom_entropy):
     assert is_new_seed(seed)
     i = self.mnemonic_decode(seed)
     return i % custom_entropy == 0
Пример #4
0
 def check_seed(self, seed, custom_entropy):
     assert is_new_seed(seed)
     i = self.mnemonic_decode(seed)
     return i % custom_entropy == 0