def test_electrum_multisig_seed_standard(self):
        seed_words = 'blast uniform dragon fiscal ensure vast young utility dinosaur abandon rookie sure'
        self.assertEqual(seed_type(seed_words), 'standard')

        ks1 = keystore.from_seed(seed_words, '', True)
        self._check_seeded_keystore_sanity(ks1)
        self.assertTrue(isinstance(ks1, keystore.BIP32_KeyStore))
        self.assertEqual(
            ks1.xpub,
            'xpub661MyMwAqRbcGNEPu3aJQqXTydqR9t49Tkwb4Esrj112kw8xLthv8uybxvaki4Ygt9xiwZUQGeFTG7T2TUzR3eA4Zp3aq5RXsABHFBUrq4c'
        )

        ks2 = keystore.from_xpub(
            'xpub661MyMwAqRbcGfCPEkkyo5WmcrhTq8mi3xuBS7VEZ3LYvsgY1cCFDbenT33bdD12axvrmXhuX3xkAbKci3yZY9ZEk8vhLic7KNhLjqdh5ec'
        )
        self._check_xpub_keystore_sanity(ks2)
        self.assertTrue(isinstance(ks2, keystore.BIP32_KeyStore))

        w = self._create_multisig_wallet(ks1, ks2)

        self.assertEqual(
            w.get_receiving_addresses()[0],
            address_from_string('32ji3QkAgXNz6oFoRfakyD3ys1XXiERQYN'))
        self.assertEqual(
            w.get_change_addresses()[0],
            address_from_string('36XWwEHrrVCLnhjK5MrVVGmUHghr9oWTN1'))
    def test_old(self, tmp_storage) -> None:
        seed_words = ('powerful random nobody notice nothing important ' +
                      'anyway look away hidden message over')
        child_keystore = from_seed(seed_words, '', False)
        assert isinstance(child_keystore, Old_KeyStore)

        parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage)
        keystore_usage = parent_wallet.add_keystore(child_keystore.dump())
        child_wallet = Standard_Wallet.create_within_parent(
            parent_wallet, keystore_usage=[keystore_usage])

        parent_keystores = parent_wallet.get_keystores()
        assert len(parent_keystores) == 1
        child_keystores = child_wallet.get_keystores()
        assert len(child_keystores) == 1
        assert parent_keystores[0] is child_keystores[0]

        keystore_data = parent_keystores[0].dump()
        assert len(keystore_data) == 3
        assert keystore_data['type'] == 'old'
        assert 'mpk' in keystore_data
        assert 'seed' in keystore_data

        child_wallet_data = child_wallet.dump()
        assert len(child_wallet_data) == 3
        assert child_wallet_data['id'] == 0
        assert child_wallet_data['wallet_type'] == 'standard'
        keystore_usage = child_wallet_data['keystore_usage']
        assert len(keystore_usage) == 1
        assert len(keystore_usage[0]) == 1
        assert keystore_usage[0]['index'] == 0
示例#3
0
 def test_from_seed(self, seed_text):
     hex_seed = 'acb740e454c3134901d7c8f16497cc1c'
     keystore = from_seed(seed_text, None, False)
     assert isinstance(keystore, Old_KeyStore)
     assert keystore.seed == hex_seed
     assert keystore.mpk == ('e9d4b7866dd1e91c862aebf62a49548c7dbf7bcc6e4b7b8c9da820c7737968df9'
                             'c09d5a3e271dc814a29981f81b3faaf2737b551ef5dcc6189cf0f8252c442b3')
示例#4
0
    def test_old(self, tmp_storage) -> None:
        seed_words = ('powerful random nobody notice nothing important '+
            'anyway look away hidden message over')
        child_keystore = from_seed(seed_words, '')
        assert isinstance(child_keystore, Old_KeyStore)

        wallet = Wallet(tmp_storage)
        masterkey_row = wallet.create_masterkey_from_keystore(child_keystore)
        account_row = AccountRow(1, masterkey_row.masterkey_id, ScriptType.P2PKH, '...')
        account = StandardAccount(wallet, account_row, [], [])
        wallet.register_account(account.get_id(), account)

        parent_keystores = wallet.get_keystores()
        assert len(parent_keystores) == 1
        child_keystores = account.get_keystores()
        assert len(child_keystores) == 1
        assert parent_keystores[0] is child_keystores[0]

        masterkey_row = parent_keystores[0].to_masterkey_row()
        assert masterkey_row.derivation_type == DerivationType.ELECTRUM_OLD
        keystore_data = parent_keystores[0].to_derivation_data()
        assert len(keystore_data) == 3
        assert 'mpk' in keystore_data
        assert 'seed' in keystore_data
        assert 'subpaths' in keystore_data

        check_create_keys(wallet, account_row.default_script_type)
示例#5
0
    def test_multisig(self, tmp_storage) -> None:
        wallet = Wallet(tmp_storage)

        seed_words = (
            'blast uniform dragon fiscal ensure vast young utility dinosaur abandon '
            + 'rookie sure')
        ks1 = from_seed(seed_words, '')
        ks2 = from_xpub(
            'xpub661MyMwAqRbcGfCPEkkyo5WmcrhTq8mi3xuBS7VEZ3LYvsgY1cCFDben' +
            'T33bdD12axvrmXhuX3xkAbKci3yZY9ZEk8vhLic7KNhLjqdh5ec')

        keystore = Multisig_KeyStore({'m': 2, 'n': 2, "cosigner-keys": []})
        keystore.add_cosigner_keystore(ks1)
        keystore.add_cosigner_keystore(ks2)

        assert not keystore.is_watching_only()
        assert 2 == len(keystore.get_cosigner_keystores())

        masterkey_row = wallet.create_masterkey_from_keystore(keystore)

        account_row = AccountRow(1, masterkey_row.masterkey_id,
                                 ScriptType.MULTISIG_BARE, 'text')
        account = MultisigAccount(wallet, account_row, [], [])
        wallet.register_account(account.get_id(), account)

        check_legacy_parent_of_multisig_wallet(wallet)
        check_create_keys(wallet, account_row.default_script_type)
示例#6
0
    def _create_account(self, password: str) -> None:
        from electrumsv import mnemonic
        seed_phrase = mnemonic.Mnemonic('en').make_seed('standard')
        k = keystore.from_seed(seed_phrase, '')
        k.update_password(password)

        wizard: AccountWizard = self.wizard()
        wizard._wallet.create_account_from_keystore(k)
    def test_standard_electrum(self, tmp_storage) -> None:
        seed_words = 'cycle rocket west magnet parrot shuffle foot correct salt library feed song'
        child_keystore = from_seed(seed_words, '', False)

        parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage)
        keystore_usage = parent_wallet.add_keystore(child_keystore.dump())
        child_wallet = Standard_Wallet.create_within_parent(
            parent_wallet, keystore_usage=[keystore_usage])

        check_legacy_parent_of_standard_wallet(parent_wallet)
示例#8
0
    def test_standard_electrum(self, tmp_storage) -> None:
        password = '******'
        seed_words = 'cycle rocket west magnet parrot shuffle foot correct salt library feed song'
        child_keystore = from_seed(seed_words, '')

        wallet = Wallet(tmp_storage)
        masterkey_row = wallet.create_masterkey_from_keystore(child_keystore)
        wallet.update_password(password)

        account_row = AccountRow(1, masterkey_row.masterkey_id, ScriptType.P2PKH, '...')
        account = StandardAccount(wallet, account_row, [], [])
        wallet.register_account(account.get_id(), account)

        check_legacy_parent_of_standard_wallet(wallet, password=password)
        check_create_keys(wallet, account_row.default_script_type)
    def test_electrum_seed_old(self, mock_write):
        seed_words = 'powerful random nobody notice nothing important anyway look away hidden message over'
        self.assertEqual(bitcoin.seed_type(seed_words), 'old')

        ks = keystore.from_seed(seed_words, '', False)

        self._check_seeded_keystore_sanity(ks)
        self.assertTrue(isinstance(ks, keystore.Old_KeyStore))

        self.assertEqual(ks.mpk, 'e9d4b7866dd1e91c862aebf62a49548c7dbf7bcc6e4b7b8c9da820c7737968df9c09d5a3e271dc814a29981f81b3faaf2737b551ef5dcc6189cf0f8252c442b3')

        w = self._create_standard_wallet(ks)

        self.assertEqual(w.get_receiving_addresses()[0],
                         Address.from_string('1FJEEB8ihPMbzs2SkLmr37dHyRFzakqUmo'))
        self.assertEqual(w.get_change_addresses()[0],
                         Address.from_string('1KRW8pH6HFHZh889VDq6fEKvmrsmApwNfe'))
    def test_electrum_seed_standard(self, mock_write):
        seed_words = 'cycle rocket west magnet parrot shuffle foot correct salt library feed song'
        self.assertEqual(bitcoin.seed_type(seed_words), 'standard')

        ks = keystore.from_seed(seed_words, '', False)

        self._check_seeded_keystore_sanity(ks)
        self.assertTrue(isinstance(ks, keystore.BIP32_KeyStore))

        self.assertEqual(ks.xpub, 'xpub661MyMwAqRbcFWohJWt7PHsFEJfZAvw9ZxwQoDa4SoMgsDDM1T7WK3u9E4edkC4ugRnZ8E4xDZRpk8Rnts3Nbt97dPwT52CwBdDWroaZf8U')

        w = self._create_standard_wallet(ks)

        self.assertEqual(w.get_receiving_addresses()[0],
                         Address.from_string('1NNkttn1YvVGdqBW4PR6zvc3Zx3H5owKRf'))
        self.assertEqual(w.get_change_addresses()[0],
                         Address.from_string('1KSezYMhAJMWqFbVFB2JshYg69UpmEXR4D'))
示例#11
0
    def test_electrum_seed_standard(self):
        seed_words = 'cycle rocket west magnet parrot shuffle foot correct salt library feed song'
        self.assertEqual(seed_type(seed_words), 'standard')

        ks = keystore.from_seed(seed_words, '')

        self._check_seeded_keystore_sanity(ks)
        self.assertTrue(isinstance(ks, keystore.BIP32_KeyStore))

        self.assertEqual(ks.xpub, 'xpub661MyMwAqRbcFWohJWt7PHsFEJfZAvw9ZxwQoDa4SoMgsDDM1T7WK3u'
            '9E4edkC4ugRnZ8E4xDZRpk8Rnts3Nbt97dPwT52CwBdDWroaZf8U')

        w = self._create_standard_wallet(ks)

        self.assertEqual(w.derive_script_template((0, 0)),
                         address_from_string('1NNkttn1YvVGdqBW4PR6zvc3Zx3H5owKRf'))
        self.assertEqual(w.derive_script_template((1, 0)),
                         address_from_string('1KSezYMhAJMWqFbVFB2JshYg69UpmEXR4D'))
示例#12
0
    def test_multisig(self, tmp_storage) -> None:
        parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage)
        seed_words = (
            'blast uniform dragon fiscal ensure vast young utility dinosaur abandon '
            + 'rookie sure')
        ks1 = from_seed(seed_words, '', True)
        ks2 = from_xpub(
            'xpub661MyMwAqRbcGfCPEkkyo5WmcrhTq8mi3xuBS7VEZ3LYvsgY1cCFDben' +
            'T33bdD12axvrmXhuX3xkAbKci3yZY9ZEk8vhLic7KNhLjqdh5ec')
        keystores = [ks1, ks2]
        keystore_usages = []
        for i, k in enumerate(keystores):
            keystore_usage = parent_wallet.add_keystore(k.dump())
            keystore_usage['name'] = f'x{i+1}/'
            keystore_usages.append(keystore_usage)
        child_wallet = Multisig_Wallet.create_within_parent(
            parent_wallet, keystore_usage=keystore_usages, wallet_type="2of2")

        check_legacy_parent_of_multisig_wallet(parent_wallet)
示例#13
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)
示例#14
0
文件: main.py 项目: Zwilla/electrumsv
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)