Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a multiple of 32 between 128 and 256.
passphrase (str): An optional passphrase for the generated
mnemonic string.
Returns:
HDPrivateKey, str:
a tuple consisting of the master
private key and a mnemonic string from which the seed
can be recovered.
"""
if strength % 32 != 0:
raise ValueError("strength must be a multiple of 32")
if strength < 128 or strength > 256:
raise ValueError("strength should be >= 128 and <= 256")
entropy = rand_bytes(strength // 8)
m = Mnemonic(language='english')
n = m.to_mnemonic(entropy)
return HDPrivateKey.master_key_from_seed(
Mnemonic.to_seed(n, passphrase)), n
a multiple of 32 between 128 and 256.
passphrase (str): An optional passphrase for the generated
mnemonic string.
Returns:
HDPrivateKey, str:
a tuple consisting of the master
private key and a mnemonic string from which the seed
can be recovered.
"""
if strength % 32 != 0:
raise ValueError("strength must be a multiple of 32")
if strength < 128 or strength > 256:
raise ValueError("strength should be >= 128 and <= 256")
entropy = rand_bytes(strength // 8)
m = Mnemonic(language='english')
n = m.to_mnemonic(entropy)
return HDPrivateKey.master_key_from_seed(
Mnemonic.to_seed(n, passphrase)), n
a multiple of 32 between 128 and 256.
passphrase (str): An optional passphrase for the generated
mnemonic string.
Returns:
HDPrivateKey, str:
a tuple consisting of the master
private key and a mnemonic string from which the seed
can be recovered.
"""
if strength % 32 != 0:
raise ValueError("strength must be a multiple of 32")
if strength < 128 or strength > 256:
raise ValueError("strength should be >= 128 and <= 256")
entropy = rand_bytes(strength // 8)
m = Mnemonic(language='english')
n = m.to_mnemonic(entropy)
return HDPrivateKey.master_key_from_seed(
Mnemonic.to_seed(n, passphrase)), n
def master_key_from_mnemonic(mnemonic, passphrase=''):
""" Generates a master key from a mnemonic.
Args:
mnemonic (str): The mnemonic sentence representing
the seed from which to generate the master key.
passphrase (str): Password if one was used.
Returns:
HDPrivateKey: the master private key.
"""
return HDPrivateKey.master_key_from_seed(
Mnemonic.to_seed(mnemonic, passphrase))
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 main():
import binascii
import sys
if len(sys.argv) > 1:
data = sys.argv[1]
else:
data = sys.stdin.readline().strip()
data = binascii.unhexlify(data)
m = Mnemonic("english")
print(m.to_mnemonic(data))
def master_key_from_mnemonic(mnemonic, passphrase=''):
""" Generates a master key from a mnemonic.
Args:
mnemonic (str): The mnemonic sentence representing
the seed from which to generate the master key.
passphrase (str): Password if one was used.
Returns:
HDPrivateKey: the master private key.
"""
return HDPrivateKey.master_key_from_seed(
Mnemonic.to_seed(mnemonic, passphrase))