Example #1
0
 def derivation_dialog(self, f):
     default = bip44_derivation(0)
     message = '\n'.join([
         _('Enter your wallet derivation here.'),
         _('If you are not sure what this is, leave this field unchanged.')
     ])
     self.line_dialog(run_next=f, title=_('Derivation'), message=message, default=default, test=bitcoin.is_bip32_derivation)
Example #2
0
 def derivation_dialog(self, f):
     default = bip44_derivation(0)
     message = '\n'.join([
         _('Enter your wallet derivation here.'),
         _('If you are not sure what this is, leave this field unchanged.')
     ])
     self.line_dialog(run_next=f, title=_('Derivation'), message=message, default=default, test=bitcoin.is_bip32_derivation)
Example #3
0
 def on_device(self, name, device_info):
     self.plugin = self.plugins.get_plugin(name)
     self.plugin.setup_device(device_info, self)
     if self.wallet_type=='multisig':
         # There is no general standard for HD multisig.
         # This is partially compatible with BIP45; assumes index=0
         self.on_hw_derivation(name, device_info, "m/45'/0")
     else:
         from keystore import bip44_derivation
         f = lambda x: self.run('on_hw_derivation', name, device_info, bip44_derivation(int(x)))
         self.account_id_dialog(f)
Example #4
0
 def on_hardware_account_id(self, hw_type, device_info, account_id):
     from keystore import hardware_keystore, bip44_derivation
     derivation = bip44_derivation(int(account_id))
     plugin = self.plugins.get_plugin(hw_type)
     xpub = plugin.setup_device(device_info, derivation, self)
     # create keystore
     d = {
         'type': 'hardware',
         'hw_type': hw_type,
         'derivation': derivation,
         'xpub': xpub,
     }
     k = hardware_keystore(hw_type, d)
     self.on_keystore(k, None)
Example #5
0
 def split_accounts(storage):
     result = []
     # backward compatibility with old wallets
     d = storage.get('accounts', {})
     if len(d) < 2:
         return
     wallet_type = storage.get('wallet_type')
     if wallet_type == 'old':
         assert len(d) == 2
         storage1 = WalletStorage(storage.path + '.deterministic')
         storage1.data = copy.deepcopy(storage.data)
         storage1.put('accounts', {'0': d['0']})
         storage1.upgrade()
         storage1.write()
         storage2 = WalletStorage(storage.path + '.imported')
         storage2.data = copy.deepcopy(storage.data)
         storage2.put('accounts', {'/x': d['/x']})
         storage2.put('seed', None)
         storage2.put('seed_version', None)
         storage2.put('master_public_key', None)
         storage2.put('wallet_type', 'imported')
         storage2.upgrade()
         storage2.write()
         result = [storage1.path, storage2.path]
     elif wallet_type in [
             'bip44', 'trezor', 'keepkey', 'ledger', 'btchip',
             'digitalbitbox'
     ]:
         mpk = storage.get('master_public_keys')
         for k in d.keys():
             i = int(k)
             x = d[k]
             if x.get("pending"):
                 continue
             xpub = mpk["x/%d'" % i]
             new_path = storage.path + '.' + k
             storage2 = WalletStorage(new_path)
             storage2.data = copy.deepcopy(storage.data)
             # save account, derivation and xpub at index 0
             storage2.put('accounts', {'0': x})
             storage2.put('master_public_keys', {"x/0'": xpub})
             storage2.put('derivation', bip44_derivation(k))
             storage2.upgrade()
             storage2.write()
             result.append(new_path)
     else:
         raise BaseException(
             "This wallet has multiple accounts and must be split")
     return result
Example #6
0
 def derivation_dialog(self, f):
     default = bip44_derivation(0)
     message = '\n'.join([
         _('Enter your wallet derivation here.'),
         _('If you are not sure what this is, leave this field unchanged.'),
         _("If you want the wallet to use legacy Bitcoin addresses use m/44'/0'/0'"
           ),
         _("If you want the wallet to use Bitcoin Cash addresses use m/44'/145'/0'"
           )
     ])
     self.line_dialog(run_next=f,
                      title=_('Derivation'),
                      message=message,
                      default=default,
                      test=bitcoin.is_bip32_derivation)
Example #7
0
 def on_device(self, name, device_info):
     self.plugin = self.plugins.get_plugin(name)
     try:
         self.plugin.setup_device(device_info, self)
     except BaseException as e:
         self.show_error(str(e))
         self.choose_hw_device()
         return
     if self.wallet_type=='multisig':
         # There is no general standard for HD multisig.
         # This is partially compatible with BIP45; assumes index=0
         self.on_hw_derivation(name, device_info, "m/45'/0")
     else:
         f = lambda x: self.run('on_hw_derivation', name, device_info, bip44_derivation(int(x)))
         self.account_id_dialog(f)
Example #8
0
 def on_device(self, name, device_info):
     self.plugin = self.plugins.get_plugin(name)
     try:
         self.plugin.setup_device(device_info, self)
     except BaseException as e:
         self.show_error(str(e))
         self.choose_hw_device()
         return
     if self.wallet_type=='multisig':
         # There is no general standard for HD multisig.
         # This is partially compatible with BIP45; assumes index=0
         self.on_hw_derivation(name, device_info, "m/45'/0")
     else:
         f = lambda x: self.run('on_hw_derivation', name, device_info, bip44_derivation(int(x)))
         self.account_id_dialog(f)
Example #9
0
 def on_hardware_account_id(self, name, device_info, account_id):
     from keystore import hardware_keystore, bip44_derivation
     derivation = bip44_derivation(int(account_id))
     xpub = self.plugin.get_xpub(device_info.device.id_, derivation, self)
     if xpub is None:
         self.show_error('Cannot read xpub from device')
         return
     d = {
         'type': 'hardware',
         'hw_type': name,
         'derivation': derivation,
         'xpub': xpub,
         'label': device_info.label,
     }
     k = hardware_keystore(d)
     self.on_keystore(k)
Example #10
0
 def split_accounts(storage):
     result = []
     # backward compatibility with old wallets
     d = storage.get('accounts', {})
     if len(d) < 2:
         return
     wallet_type = storage.get('wallet_type')
     if wallet_type == 'old':
         assert len(d) == 2
         storage1 = WalletStorage(storage.path + '.deterministic')
         storage1.data = copy.deepcopy(storage.data)
         storage1.put('accounts', {'0': d['0']})
         storage1.upgrade()
         storage1.write()
         storage2 = WalletStorage(storage.path + '.imported')
         storage2.data = copy.deepcopy(storage.data)
         storage2.put('accounts', {'/x': d['/x']})
         storage2.put('seed', None)
         storage2.put('seed_version', None)
         storage2.put('master_public_key', None)
         storage2.put('wallet_type', 'imported')
         storage2.upgrade()
         storage2.write()
         result = [storage1.path, storage2.path]
     elif wallet_type in ['bip44', 'trezor', 'keepkey', 'ledger', 'btchip', 'digitalbitbox']:
         mpk = storage.get('master_public_keys')
         for k in d.keys():
             i = int(k)
             x = d[k]
             if x.get("pending"):
                 continue
             xpub = mpk["x/%d'"%i]
             new_path = storage.path + '.' + k
             storage2 = WalletStorage(new_path)
             storage2.data = copy.deepcopy(storage.data)
             # save account, derivation and xpub at index 0
             storage2.put('accounts', {'0': x})
             storage2.put('master_public_keys', {"x/0'": xpub})
             storage2.put('derivation', bip44_derivation(k))
             storage2.upgrade()
             storage2.write()
             result.append(new_path)
     else:
         raise BaseException("This wallet has multiple accounts and must be split")
     return result
Example #11
0
 def on_bip44(self, seed, passphrase, account_id):
     k = keystore.BIP32_KeyStore({})
     bip32_seed = keystore.bip39_to_seed(seed, passphrase)
     derivation = bip44_derivation(account_id)
     k.add_xprv_from_seed(bip32_seed, 0, derivation)
     self.on_keystore(k)
Example #12
0
    def convert_wallet_type(self):
        wallet_type = self.get('wallet_type')
        if wallet_type == 'btchip': wallet_type = 'ledger'
        if self.get('keystore') or self.get(
                'x1/') or wallet_type == 'imported':
            return False
        assert not self.requires_split()
        seed_version = self.get_seed_version()
        seed = self.get('seed')
        xpubs = self.get('master_public_keys')
        xprvs = self.get('master_private_keys', {})
        mpk = self.get('master_public_key')
        keypairs = self.get('keypairs')
        key_type = self.get('key_type')
        if seed_version == OLD_SEED_VERSION or wallet_type == 'old':
            d = {
                'type': 'old',
                'seed': seed,
                'mpk': mpk,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif key_type == 'imported':
            d = {
                'type': 'imported',
                'keypairs': keypairs,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in ['xpub', 'standard']:
            xpub = xpubs["x/"]
            xprv = xprvs.get("x/")
            d = {
                'type': 'bip32',
                'xpub': xpub,
                'xprv': xprv,
                'seed': seed,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in ['bip44']:
            xpub = xpubs["x/0'"]
            xprv = xprvs.get("x/0'")
            d = {
                'type': 'bip32',
                'xpub': xpub,
                'xprv': xprv,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in ['trezor', 'keepkey', 'ledger', 'digitalbitbox']:
            xpub = xpubs["x/0'"]
            derivation = self.get('derivation', bip44_derivation(0))
            d = {
                'type': 'hardware',
                'hw_type': wallet_type,
                'xpub': xpub,
                'derivation': derivation,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif multisig_type(wallet_type):
            for key in xpubs.keys():
                d = {
                    'type': 'bip32',
                    'xpub': xpubs[key],
                    'xprv': xprvs.get(key),
                }
                if key == 'x1/' and seed:
                    d['seed'] = seed
                self.put(key, d)
        else:
            raise
        # remove junk
        self.put('master_public_key', None)
        self.put('master_public_keys', None)
        self.put('master_private_keys', None)
        self.put('derivation', None)
        self.put('seed', None)
        self.put('keypairs', None)
        self.put('key_type', None)
Example #13
0
 def on_bip44(self, seed, passphrase, account_id):
     k = keystore.BIP32_KeyStore({})
     bip32_seed = keystore.bip39_to_seed(seed, passphrase)
     derivation = bip44_derivation(account_id)
     k.add_xprv_from_seed(bip32_seed, 0, derivation)
     self.on_keystore(k)
Example #14
0
    def convert_wallet_type(self, is_test):
        assert not self.requires_split()
        if self.get('keystore') or self.get('x1/'):
            return False
        if is_test:
            return True
        wallet_type = self.get('wallet_type')
        seed_version = self.get_seed_version()
        seed = self.get('seed')
        xpubs = self.get('master_public_keys')
        xprvs = self.get('master_private_keys')
        mpk = self.get('master_public_key')
        keypairs = self.get('keypairs')
        key_type = self.get('key_type')
        if seed_version == OLD_SEED_VERSION or wallet_type == 'old':
            d = {
                'type': 'old',
                'seed': seed,
                'mpk': mpk,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif key_type == 'imported':
            d = {
                'type': 'imported',
                'keypairs': keypairs,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in['xpub', 'standard']:
            xpub = xpubs["x/"]
            xprv = xprvs["x/"]
            d = {
                'type': 'bip32',
                'xpub': xpub,
                'xprv': xprv,
                'seed': seed,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in ['trezor', 'keepkey']:
            xpub = xpubs["x/0'"]
            d = {
                'type': 'hardware',
                'hardware_type': wallet_type,
                'xpub': xpub,
                'derivation': bip44_derivation(0),
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif (wallet_type == '2fa') or multisig_type(wallet_type):
            for key in xpubs.keys():
                d = {
                    'type': 'bip32',
                    'xpub': xpubs[key],
                    'xprv': xprvs.get(key),
                }
                if key == 'x1/' and seed:
                    d['seed'] = seed
                self.put(key, d)
        else:
            raise

        self.put('master_public_key', None)
        self.put('master_public_keys', None)
        self.put('master_private_keys', None)
        self.put('seed', None)
        self.put('keypairs', None)
        self.put('key_type', None)
Example #15
0
    def convert_wallet_type(self):
        wallet_type = self.get('wallet_type')
        if wallet_type == 'btchip': wallet_type = 'ledger'
        if self.get('keystore') or self.get('x1/') or wallet_type=='imported':
            return False
        assert not self.requires_split()
        seed_version = self.get_seed_version()
        seed = self.get('seed')
        xpubs = self.get('master_public_keys')
        xprvs = self.get('master_private_keys', {})
        mpk = self.get('master_public_key')
        keypairs = self.get('keypairs')
        key_type = self.get('key_type')
        if seed_version == OLD_SEED_VERSION or wallet_type == 'old':
            d = {
                'type': 'old',
                'seed': seed,
                'mpk': mpk,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif key_type == 'imported':
            d = {
                'type': 'imported',
                'keypairs': keypairs,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in ['xpub', 'standard']:
            xpub = xpubs["x/"]
            xprv = xprvs.get("x/")
            d = {
                'type': 'bip32',
                'xpub': xpub,
                'xprv': xprv,
                'seed': seed,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in ['bip44']:
            xpub = xpubs["x/0'"]
            xprv = xprvs.get("x/0'")
            d = {
                'type': 'bip32',
                'xpub': xpub,
                'xprv': xprv,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif wallet_type in ['trezor', 'keepkey', 'ledger', 'digitalbitbox']:
            xpub = xpubs["x/0'"]
            derivation = self.get('derivation', bip44_derivation(0))
            d = {
                'type': 'hardware',
                'hw_type': wallet_type,
                'xpub': xpub,
                'derivation': derivation,
            }
            self.put('wallet_type', 'standard')
            self.put('keystore', d)

        elif (wallet_type == '2fa') or multisig_type(wallet_type):
            for key in xpubs.keys():
                d = {
                    'type': 'bip32',
                    'xpub': xpubs[key],
                    'xprv': xprvs.get(key),
                }
                if key == 'x1/' and seed:
                    d['seed'] = seed
                self.put(key, d)
        else:
            raise
        # remove junk
        self.put('master_public_key', None)
        self.put('master_public_keys', None)
        self.put('master_private_keys', None)
        self.put('derivation', None)
        self.put('seed', None)
        self.put('keypairs', None)
        self.put('key_type', None)