Exemple #1
0
    def test_wallet_multisig_reopen_wallet(self):

        def _open_all_wallets():
            wl1 = wallet_create_or_open_multisig(
                'multisigmulticur1_tst', sigs_required=2, network=network,
                databasefile=DATABASEFILE_UNITTESTS,
                key_list=[pk1, pk2.account_multisig_key().wif_public(), pk3.account_multisig_key().wif_public()])
            wl2 = wallet_create_or_open_multisig(
                'multisigmulticur2_tst', sigs_required=2, network=network,
                databasefile=DATABASEFILE_UNITTESTS,
                key_list=[pk1.account_multisig_key().wif_public(), pk2, pk3.account_multisig_key().wif_public()])
            wl3 = wallet_create_or_open_multisig(
                'multisigmulticur3_tst', sigs_required=2, network=network,
                databasefile=DATABASEFILE_UNITTESTS,
                key_list=[pk1.account_multisig_key().wif_public(), pk2.account_multisig_key().wif_public(), pk3])
            return wl1, wl2, wl3

        if os.path.isfile(DATABASEFILE_UNITTESTS):
            os.remove(DATABASEFILE_UNITTESTS)
        network = 'litecoin'
        phrase1 = 'shop cloth bench traffic vintage security hour engage omit almost episode fragile'
        phrase2 = 'exclude twice mention orchard grit ignore display shine cheap exercise same apart'
        phrase3 = 'citizen obscure tribe index little welcome deer wine exile possible pizza adjust'
        pk1 = HDKey.from_passphrase(phrase1, network=network)
        pk2 = HDKey.from_passphrase(phrase2, network=network)
        pk3 = HDKey.from_passphrase(phrase3, network=network)
        wallets = _open_all_wallets()
        for wlt in wallets:
            self.assertEqual(wlt.get_key().address, '354bZpUpeaUEwsRn5Le5BymTvqPHf9jZkS')
        del wallets
        wallets2 = _open_all_wallets()
        for wlt in wallets2:
            self.assertEqual(wlt.get_key().address, '354bZpUpeaUEwsRn5Le5BymTvqPHf9jZkS')
            wlt._session.close_all()
Exemple #2
0
 def test_wallet_multisig_network_mixups(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     network = 'litecoin_testnet'
     phrase1 = 'shop cloth bench traffic vintage security hour engage omit almost episode fragile'
     phrase2 = 'exclude twice mention orchard grit ignore display shine cheap exercise same apart'
     phrase3 = 'citizen obscure tribe index little welcome deer wine exile possible pizza adjust'
     pk2 = HDKey.from_passphrase(phrase2, network=network)
     pk3 = HDKey.from_passphrase(phrase3, network=network)
     wlt = wallet_create_or_open_multisig(
         'multisig_network_mixups', sigs_required=2, network=network, databasefile=DATABASEFILE_UNITTESTS,
         key_list=[phrase1, pk2.account_multisig_key().wif_public(), pk3.account_multisig_key().wif_public()])
     self.assertEqual(wlt.get_key().address, 'QeBprfDJNadgqJV4R5d7e9i6duVK8HFgAN')
     self.assertEqual(wlt.get_key().network.network_name, network)
Exemple #3
0
print("Seed for HD Key    %s" %
      to_hexstring(Mnemonic().to_seed(words, 'test')))
print("Back to Entropy    %s" % to_hexstring(Mnemonic().to_entropy(words)))

# Generate a random Mnemonic HD Key
print("\nGenerate a random Mnemonic HD Key")
entsize = 128
words = Mnemonic('english').generate(entsize)
print("Your Mnemonic is   %s" % words)
print("  (An avarage of %d tries is needed to brute-force this password)" %
      ((2**entsize) // 2))
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())
print("HD Key WIF is      %s (method 2)" % HDKey.from_passphrase(words).wif())

# Generate a key from a Mnemonic passphrase
print("\nGenerate a key from a Mnemonic passphrase")
words = "type fossil omit food supply enlist move perfect direct grape clean diamond"
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())

# Let's talk Spanish
print("\nGenerate a key from a Spanish Mnemonic passphrase")
words = "laguna afirmar talón resto peldaño deuda guerra dorado catorce avance oasis barniz"
print("Your Mnemonic is   %s" % words)
seed = Mnemonic().to_seed(words)
COSIGNER_NAME_THIS_WALLET = 'Chris'

# wallet_delete_if_exists(WALLET_NAME)
if not wallet_exists(WALLET_NAME):
    # This wallets key list, use tools/mnemonic_key_create.py to create your own.
    #
    cosigners_private = []
    key_list = []
    for cosigner in cosigners:
        if not cosigner['key']:
            raise ValueError(
                "Please create private keys with mnemonic_key_create.py and add to COSIGNERS definitions"
            )
        if len(cosigner['key'].split(" ")) > 1:
            hdkey = HDKey.from_passphrase(cosigner['key'],
                                          key_type=cosigner['key_type'],
                                          witness_type=WITNESS_TYPE,
                                          network=NETWORK)
        else:
            hdkey = HDKey(cosigner['key'],
                          key_type=cosigner['key_type'],
                          witness_type=WITNESS_TYPE,
                          network=NETWORK)
        if cosigner['name'] != COSIGNER_NAME_THIS_WALLET:
            if hdkey.key_type == 'single':
                hdkey = hdkey.public()
            else:
                hdkey = hdkey.public_master_multisig()
        cosigner['hdkey'] = hdkey
        key_list.append(hdkey)

    if len(key_list) != SIGS_N: