Beispiel #1
0
    def from_mnemonic(cls, mnemonic, is_testnet=False):
        """Create a bip32 key from a bip39 english mnemonic"""
        try:
            wally.bip39_mnemonic_validate(None, mnemonic)
        except ValueError:
            raise ValueError('Invalid mnemonic')

        _, seed = wally.bip39_mnemonic_to_seed512(mnemonic, None)
        return cls.from_seed(seed, is_testnet)
Beispiel #2
0
def mnemonic_to_seed(mnemonic: str, passphrase: str = None) -> bytes:
    """Derive a 512-bit seed from a BIP39 english mnemonic and passphrase"""

    try:
        wally.bip39_mnemonic_validate(None, mnemonic)
        _, seed = wally.bip39_mnemonic_to_seed512(mnemonic, passphrase)
        return seed
    except ValueError:
        raise InvalidMnemonic
Beispiel #3
0
def xpubs_from_mnemonic(mnemonic, subaccount, testnet):
    """Derive GreenAddress xpubs from a mnemonic"""
    if mnemonic is None:
        msg = 'You must either pass --ga-xpub or a mnemonic (not hex seed)'
        raise exceptions.NeedMnemonicOrGaXPub(msg)
    gait_path = gait_path_from_mnemonic(mnemonic)

    # Include the new derivations for newer wallets and hardware mnemonics
    written, seed = wally.bip39_mnemonic_to_seed512(mnemonic, None)
    assert written == wally.BIP39_SEED_LEN_512

    gait_paths = [gait_path] + gait_paths_from_seed(seed)
    return [derive_ga_xpub(gait_path, subaccount, testnet) for gait_path in gait_paths]
Beispiel #4
0
def seed_from_mnemonic(mnemonic_or_hex_seed):
    """Return seed, mnemonic given an input string

    mnemonic_or_hex_seed can either be:
    - A mnemonic
    - A hex seed, with an 'X' at the end, which needs to be stripped

    seed will always be returned, mnemonic may be None if a seed was passed
    """
    if mnemonic_or_hex_seed.endswith('X'):
        mnemonic = None
        seed = wally.hex_to_bytes(mnemonic_or_hex_seed[:-1])
    else:
        mnemonic = mnemonic_or_hex_seed
        written, seed = wally.bip39_mnemonic_to_seed512(mnemonic_or_hex_seed, None)
        assert written == wally.BIP39_SEED_LEN_512

    assert len(seed) == wally.BIP39_SEED_LEN_512
    return seed, mnemonic
Beispiel #5
0
 def seed(self):
     _, seed = wally.bip39_mnemonic_to_seed512(self._mnemonic, None)
     return seed
Beispiel #6
0
 def master_key(self):
     _, seed = wally.bip39_mnemonic_to_seed512(self._mnemonic, None)
     return wally.bip32_key_from_seed(seed, wally.BIP32_VER_TEST_PRIVATE,
                                      wally.BIP32_FLAG_KEY_PRIVATE)
Beispiel #7
0
import wallycore as wally
import os

address_prefix = wally.WALLY_CA_PREFIX_LIQUID_REGTEST
network = wally.WALLY_NETWORK_LIQUID_REGTEST
wif_prefix = wally.WALLY_ADDRESS_VERSION_WIF_TESTNET

mnemonic = "supreme layer police brand month october rather rack proud strike receive joy limit random hill inside brand depend giant success quarter brain butter mechanic"

# start-create_p2pkh_address
_, seed = wally.bip39_mnemonic_to_seed512(mnemonic, '')
wallet_master_key = wally.bip32_key_from_seed(seed,
                                              wally.BIP32_VER_TEST_PRIVATE, 0)
wallet_derived_key = wally.bip32_key_from_parent(wallet_master_key, 1,
                                                 wally.BIP32_FLAG_KEY_PRIVATE)
address = wally.bip32_key_to_address(
    wallet_derived_key, wally.WALLY_ADDRESS_TYPE_P2PKH,
    wally.WALLY_ADDRESS_VERSION_P2PKH_LIQUID_REGTEST)
# end-create_p2pkh_address

# start-derive_blinding_key
master_blinding_key = wally.asset_blinding_key_from_seed(seed)
script_pubkey = wally.address_to_scriptpubkey(
    address, wally.WALLY_NETWORK_LIQUID_REGTEST)
private_blinding_key = wally.asset_blinding_key_to_ec_private_key(
    master_blinding_key, script_pubkey)
public_blinding_key = wally.ec_public_key_from_private_key(
    private_blinding_key)
# end-derive_blinding_key

# start-create_conf_address