Exemple #1
0
 def test_pubkeys_to_address(self, tmp_storage, network):
     coin = network.COIN
     privkey = PrivateKey.from_random()
     WIF = privkey.to_WIF(coin=coin)
     wallet = ImportedPrivkeyWallet.from_text(tmp_storage, WIF, None)
     public_key = privkey.public_key
     pubkey_hex = public_key.to_hex()
     address = public_key.to_address(coin=coin).to_string()
     assert wallet.pubkeys_to_address(pubkey_hex) == Address.from_string(address)
 def test_pubkeys_to_address(self, tmp_storage, network):
     coin = network.COIN
     privkey = PrivateKey.from_random()
     WIF = privkey.to_WIF(coin=coin)
     parent_wallet = _TestableParentWallet.as_legacy_wallet_container(
         tmp_storage)
     wallet = ImportedPrivkeyWallet.from_text(parent_wallet, WIF)
     public_key = privkey.public_key
     pubkey_hex = public_key.to_hex()
     address = public_key.to_address(coin=coin).to_string()
     assert wallet.pubkeys_to_address(pubkey_hex) == address_from_string(
         address)
    def test_imported_privkey(self, tmp_storage) -> None:
        text = """
        KzMFjMC2MPadjvX5Cd7b8AKKjjpBSoRKUTpoAtN6B3J9ezWYyXS6
        """
        parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage)
        child_wallet = ImportedPrivkeyWallet.from_text(parent_wallet, text)

        keypairs = {
            '02c6467b7e621144105ed3e4835b0b4ab7e35266a2ae1c4f8baa19e9ca93452997':
            'KzMFjMC2MPadjvX5Cd7b8AKKjjpBSoRKUTpoAtN6B3J9ezWYyXS6'
        }
        check_legacy_parent_of_imported_privkey_wallet(parent_wallet,
                                                       keypairs=keypairs)
Exemple #4
0
def run_non_RPC(config):
    cmdname = config.get('cmd')

    storage = WalletStorage(config.get_wallet_path())
    if storage.file_exists():
        sys.exit("Error: Remove the existing wallet first!")

    def password_dialog():
        return prompt_password(
            "Password (hit return if you do not wish to encrypt your wallet):")

    if cmdname == 'restore':
        text = config.get('text').strip()
        passphrase = config.get('passphrase', '')
        password = password_dialog() if keystore.is_private(text) else None
        if keystore.is_address_list(text):
            wallet = ImportedAddressWallet.from_text(storage, text)
        elif keystore.is_private_key_list(text):
            wallet = ImportedPrivkeyWallet.from_text(storage, text, password)
        else:
            if keystore.is_seed(text):
                k = keystore.from_seed(text, passphrase, False)
            elif keystore.is_master_key(text):
                k = keystore.from_master_key(text)
            else:
                sys.exit("Error: Seed or key not recognized")
            if password:
                k.update_password(None, password)
            storage.put('keystore', k.dump())
            storage.put('wallet_type', 'standard')
            storage.put('use_encryption', bool(password))
            storage.write()
            wallet = Wallet(storage)
        if not config.get('offline'):
            network = Network(config)
            network.start()
            wallet.start_threads(network)
            print("Recovering wallet...")
            wallet.synchronize()
            wallet.wait_until_synchronized()
            msg = ("Recovery successful" if wallet.is_found() else
                   "Found no history for this wallet")
        else:
            msg = ("This wallet was restored offline. "
                   "It may contain more addresses than displayed.")
        print(msg)

    elif cmdname == 'create':
        password = password_dialog()
        passphrase = config.get('passphrase', '')
        seed_type = 'standard'
        seed = Mnemonic('en').make_seed(seed_type)
        k = keystore.from_seed(seed, passphrase, False)
        storage.put('keystore', k.dump())
        storage.put('wallet_type', 'standard')
        wallet = Wallet(storage)
        wallet.update_password(None, password, True)
        wallet.synchronize()
        print("Your wallet generation seed is:\n\"%s\"" % seed)
        print("Please keep it in a safe place; if you lose it, "
              "you will not be able to restore your wallet.")

    wallet.storage.write()
    print("Wallet saved in '%s'" % wallet.storage.path)
    sys.exit(0)
Exemple #5
0
def run_non_RPC(config):
    cmdname = config.get('cmd')

    storage = WalletStorage(config.get_wallet_path())
    if storage.file_exists():
        sys.exit("Error: Remove the existing wallet first!")

    def password_dialog():
        return prompt_password(
            "Password (hit return if you do not wish to encrypt your wallet):")

    if cmdname == 'restore':
        text = config.get('text').strip()
        passphrase = config.get('passphrase', '')
        password = password_dialog() if keystore.is_private(text) else None

        parent_wallet = ParentWallet.as_legacy_wallet_container(storage)
        if keystore.is_address_list(text):
            legacy_wallet = ImportedAddressWallet.from_text(
                parent_wallet, text)
        elif keystore.is_private_key_list(text):
            legacy_wallet = ImportedPrivkeyWallet.from_text(
                parent_wallet, text)
        else:
            if keystore.is_seed(text):
                k = keystore.from_seed(text, passphrase, False)
            elif keystore.is_master_key(text):
                k = keystore.from_master_key(text)
            else:
                sys.exit("Error: Seed or key not recognized")

            keystore_usage = parent_wallet.add_keystore(k.dump())
            Standard_Wallet.create_within_parent(
                parent_wallet, keystore_usage=[keystore_usage])

        if password:
            parent_wallet.update_password(None, password)

        if not config.get('offline'):
            network = Network()
            network.add_wallet(parent_wallet)
            print("Recovering wallet...")
            parent_wallet.synchronize()
            msg = ("Recovery successful" if parent_wallet.has_usage() else
                   "Found no history for this wallet")
        else:
            msg = ("This wallet was restored offline. "
                   "It may contain more addresses than displayed.")
        print(msg)

    elif cmdname == 'create':
        password = password_dialog()
        passphrase = config.get('passphrase', '')
        seed_type = 'standard'
        seed = Mnemonic('en').make_seed(seed_type)
        k = keystore.from_seed(seed, passphrase, False)

        parent_wallet = ParentWallet.as_legacy_wallet_container(storage)
        keystore_usage = parent_wallet.add_keystore(k.dump())
        Standard_Wallet.create_within_parent(parent_wallet,
                                             keystore_usage=[keystore_usage])

        parent_wallet.update_password(None, password)
        parent_wallet.synchronize()
        print("Your wallet generation seed is:\n\"%s\"" % seed)
        print("Please keep it in a safe place; if you lose it, "
              "you will not be able to restore your wallet.")

    parent_wallet.save_storage()
    print("Wallet saved in '%s'" % parent_wallet.get_storage_path())
    sys.exit(0)