How to use the bitcoinlib.keys.HDKey.from_seed function in bitcoinlib

To help you get started, we’ve selected a few bitcoinlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 1200wd / bitcoinlib / tests / test_wallets.py View on Github external
def test_wallet_key_import_and_sign_multisig(self):
        network = 'bitcoinlib_test'
        words = 'square innocent drama'
        seed = Mnemonic().to_seed(words, 'password')
        hdkey = HDKey.from_seed(seed, network=network)
        hdkey.key_type = 'single'

        key_list = [
            HDKey(network=network, multisig=True).public_master(),
            HDKey(network=network),
            hdkey.public()
        ]
        with HDWallet.create('Multisig-2-of-3-example', key_list, sigs_required=2,
                             db_uri=self.DATABASE_URI) as wlt:
            wlt.new_key()
            wlt.utxos_update()
            wt = wlt.send_to('21A6yyUPRL9hZZo1Rw4qP5G6h9idVVLUncE', 10000000)
            wt.sign(hdkey)
            wt.send()
            self.assertIsNone(wt.error)
github 1200wd / bitcoinlib / tests / test_wallets.py View on Github external
def test_wallet_multisig_sign_with_external_single_key(self):
        self.db_remove()
        network = 'bitcoinlib_test'
        words = 'square innocent drama'
        seed = Mnemonic().to_seed(words, 'password')
        hdkey = HDKey.from_seed(seed, network=network)
        hdkey.key_type = 'single'

        key_list = [
            HDKey(network=network, multisig=True).public_master(),
            HDKey(network=network),
            hdkey.public()
        ]
        wallet = HDWallet.create('Multisig-2-of-3-example', key_list, sigs_required=2, network=network,
                                 db_uri=self.DATABASE_URI)
        wallet.new_key()
        wallet.utxos_update()
        wt = wallet.send_to('21A6yyUPRL9hZZo1Rw4qP5G6h9idVVLUncE', 10000000)
        self.assertFalse(wt.verify())
        wt.sign(hdkey)
        self.assertTrue(wt.verify())
github 1200wd / bitcoinlib / bitcoinlib / tools / clw.py View on Github external
db_uri=db_uri, witness_type=args.witness_type)
    else:
        passphrase = args.passphrase
        if passphrase is None:
            passphrase = get_passphrase(args)
        elif not passphrase:
            passphrase = input("Enter Passphrase: ")
        if not isinstance(passphrase, list):
            passphrase = passphrase.split(' ')
        elif len(passphrase) == 1:
            passphrase = passphrase[0].split(' ')
        if len(passphrase) < 12:
            clw_exit("Please specify passphrase with 12 words or more")
        passphrase = ' '.join(passphrase)
        seed = binascii.hexlify(Mnemonic().to_seed(passphrase))
        hdkey = HDKey.from_seed(seed, network=args.network)
        return HDWallet.create(wallet_name, hdkey, network=args.network, witness_type=args.witness_type,
                               db_uri=db_uri)
github 1200wd / bitcoinlib / bitcoinlib / tools / clw.py View on Github external
def main():
    print("Command Line Wallet - BitcoinLib %s\n" % BITCOINLIB_VERSION)
    # --- Parse commandline arguments ---
    args = parse_args()

    db_uri = args.database

    if args.generate_key:
        passphrase = get_passphrase(args)
        passphrase = ' '.join(passphrase)
        seed = binascii.hexlify(Mnemonic().to_seed(passphrase))
        hdkey = HDKey.from_seed(seed, network=args.network)
        print("Private Master key, to create multisig wallet on this machine:\n%s" % hdkey.wif_private())
        print("Public Master key, to share with other cosigner multisig wallets:\n%s" %
              hdkey.public_master(witness_type=args.witness_type, multisig=True).wif())
        print("Network: %s" % hdkey.network.name)
        clw_exit()

    # List wallets, then exit
    if args.list_wallets:
        print("BitcoinLib wallets:")
        for w in wallets_list(db_uri=db_uri):
            if 'parent_id' in w and w['parent_id']:
                continue
            print("[%d] %s (%s) %s" % (w['id'], w['name'], w['network'], w['owner']))
        clw_exit()

    # Delete specified wallet, then exit
github 1200wd / bitcoinlib / bitcoinlib / tools / wallet_multisig_2of3.py View on Github external
"\n- With 1 private key a wallet on This PC is created"
          "\n- Use private key 2 to create a wallet on an Offline PC"
          "\n- Store key 3 on a Paper in a safe in case one of the PC's is not available anymore"
          "\nPLEASE NOTE: THIS IS AN EXAMPLE. In real life do not generate all private keys on a "
          "single instance"
          )
    key_list = []
    key_list_thispc = []
    for cosigner in cosigners:
        print("\n")
        words = Mnemonic().generate(KEY_STRENGTH)
        password = ''
        if cosigner[2] == 'password':
            password = input("Please give password for cosigner '%s': " % cosigner[0])
        seed = Mnemonic().to_seed(words, password)
        hdkey = HDKey.from_seed(seed, network=NETWORK, key_type=cosigner[1])
        if cosigner[1] == 'bip44':
            public_account = hdkey.account_multisig_key(witness_type=WITNESS_TYPE)
        else:
            public_account = hdkey
        print("Key for cosigner '%s' generated. Please store both passphrase and password carefully!" % cosigner[0])
        print("Passphrase: %s" % words)
        print("Password: %s" % ('*' * len(password)))
        print("Share this public key below with other cosigner")
        print("Public key: %s" % public_account.wif_public())

        if cosigner[3] == 'private':
            key_list.append(hdkey)
            key_list_thispc.append(hdkey)
        else:
            key_list.append(public_account)
            key_list_thispc.append(public_account.public())
github 1200wd / bitcoinlib / examples / mnemonic.py View on Github external
# Want some Chinese?
print("\nGenerate a key from a Chinese Mnemonic passphrase")
words = "信 收 曉 捐 炭 祖 瘋 原 強 則 岩 蓄"
print("Your Mnemonic is   %s" % words)
seed = Mnemonic().to_seed(words)
hdk = HDKey.from_seed(seed)
print("Seed for HD Key    %s" % to_hexstring(seed))
print("HD Key WIF is      %s" % hdk.wif())

# Spanish Unicode mnemonic sentence
print("\nGenerate a key from a Spanish UNICODE Mnemonic passphrase")
words = u"guion cruz envío papel otoño percha hazaña salir joya gorra íntimo actriz"
print("Your Mnemonic is   %s" % words)
seed = Mnemonic().to_seed(words, '1200 web development')
hdk = HDKey.from_seed(seed)
print("Seed for HD Key    %s" % to_hexstring(seed))
print("HD Key WIF is      %s" % hdk.wif())

# And Japanese
print("\nGenerate a key from a Japanese UNICODE Mnemonic passphrase")
words = "あじわう ちしき たわむれる おくさま しゃそう うんこう ひてい みほん たいほ てのひら りこう わかれる かいすいよく こもん ねもと"
print("Your Mnemonic is   %s" % words)
seed = Mnemonic().to_seed(words, '1200 web development')
hdk = HDKey.from_seed(seed)
print("Seed for HD Key    %s" % to_hexstring(seed))
print("HD Key WIF is      %s" % hdk.wif())
github 1200wd / bitcoinlib / bitcoinlib / tools / mnemonic_key_create.py View on Github external
#
#    © 2017 November - 1200 Web Development 
#

from bitcoinlib.mnemonic import Mnemonic
from bitcoinlib.keys import HDKey

NETWORK = 'testnet'
KEY_STRENGHT = 128

words = Mnemonic().generate(KEY_STRENGHT)
print("A Mnemonic passphrase has been generated. Please write down and store carefully: \n%s" % words)
password = input("\nEnter a password if you would like to protect passphrase []: ")

seed = Mnemonic().to_seed(words, password)
hdkey = HDKey.from_seed(seed, network=NETWORK)
public_account_wif = hdkey.public_master_multisig()
print("\nPrivate key: \n%s" % hdkey.wif_private())
# print("Public key: \n%s" % hdkey.wif_public())
print("Public account key to share with other cosigners for a multisig BIP45 wallet: \n%s" % public_account_wif.wif())