Beispiel #1
0
 def create(self, session_obj):
     """Create and register a new wallet"""
     entropy = secrets.token_bytes(wally.BIP39_ENTROPY_LEN_256)
     wordlist = wally.bip39_get_wordlist('en')
     mnemonic = wally.bip39_mnemonic_from_bytes(wordlist, entropy)
     assert len(mnemonic.split()) == 24
     self._mnemonic = mnemonic
     return self.register(session_obj)
Beispiel #2
0
def entropy_to_mnemonic(entropy: bytes) -> str:
    """Convert entropy bytes to a BIP39 english mnemonic

    Entropy can be 16, 20, 24, 28, 32, 36 or 40 bytes"""

    try:
        return wally.bip39_mnemonic_from_bytes(None, entropy)
    except ValueError:
        raise InvalidEntropy
Beispiel #3
0
    def create(self, session_obj, words):
        """Create and register a new wallet"""
        entropy_len = int(words * 4 / 3)
        entropy = secrets.token_bytes(entropy_len)

        wordlist = wally.bip39_get_wordlist('en')
        mnemonic = wally.bip39_mnemonic_from_bytes(wordlist, entropy)
        assert len(mnemonic.split()) == words

        self._mnemonic = mnemonic
        return self.register(session_obj)
Beispiel #4
0
def _decrypt_mnemonic(mnemonic, password):
    """Decrypt a 27 word encrypted mnemonic to a 24 word mnemonic"""
    mnemonic = ' '.join(mnemonic.split())
    entropy = bytearray(wally.BIP39_ENTROPY_LEN_288)
    assert wally.bip39_mnemonic_to_bytes(None, mnemonic, entropy) == len(entropy)
    salt, encrypted = entropy[32:], entropy[:32]
    derived = bytearray(64)
    wally.scrypt(password.encode('utf-8'), salt, 16384, 8, 8, derived)
    key, decrypted = derived[32:], bytearray(32)
    wally.aes(key, encrypted, wally.AES_FLAG_DECRYPT, decrypted)
    for i in range(len(decrypted)):
        decrypted[i] ^= derived[i]
    if wally.sha256d(decrypted)[:4] != salt:
        raise exceptions.InvalidMnemonicOrPasswordError('Incorrect password')
    return wally.bip39_mnemonic_from_bytes(None, decrypted)
Beispiel #5
0
 def to_mnemonic(self, data):
     return wallycore.bip39_mnemonic_from_bytes(self.wordlist, data)
Beispiel #6
0
hardened_notation = ''
if args.hardened == True:
    hardened_notation = '\''

pattern = re.compile(args.pattern)
i = 0
start = time.time()

while(True):
    i = i + 1

    # get entropy
    entropy = os.urandom(32)

    # calculate mnemonic
    mnemonic = wally.bip39_mnemonic_from_bytes(None, entropy)

    # calculate the seed
    seed = bytearray(64)
    password = ''
    wally.bip39_mnemonic_to_seed(mnemonic, password, seed)

    # calculate master key
    master_key = wally.bip32_key_from_seed(seed, master_key_flags, wally.BIP32_FLAG_SKIP_HASH)
    if args.verbose > 1:
        print('::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::')
        print('Seed:                  {}'.format(seed.hex()))
        print('Mnemonic:              {}'.format(mnemonic))
        print('Master key:            {}'.format(wally.bip32_key_to_base58(master_key, 0)))
        print('::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::')
""" Create a mnemonic for testing GreenAddress """
from os import urandom
from wallycore import bip39_get_wordlist, bip39_mnemonic_from_bytes, \
        BIP39_ENTROPY_LEN_256

if __name__ == "__main__":

    # Only english wordlists are supported by GreenAddress wallets
    wordlist = bip39_get_wordlist('en')
    entropy = urandom(BIP39_ENTROPY_LEN_256)
    mnemonic = bip39_mnemonic_from_bytes(wordlist, entropy)
    print(mnemonic)