URI: 
       ttrustedcoin: use 12-word seeds with separate derivations - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 296f30b92468ccd19ec8ea9bed0998b9f036256d
   DIR parent 997dd17933feb5c5ac2afd2fada7d4af0674f444
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Tue, 27 Sep 2016 13:21:25 +0200
       
       ttrustedcoin: use 12-word seeds with separate derivations
       
       Diffstat:
         M lib/bitcoin.py                      |       7 +++++++
         M lib/keystore.py                     |      10 ----------
         M plugins/trustedcoin/trustedcoin.py  |      30 +++++++++++++++++++++---------
       
       3 files changed, 28 insertions(+), 19 deletions(-)
       ---
   DIR diff --git a/lib/bitcoin.py b/lib/bitcoin.py
       t@@ -814,3 +814,10 @@ def bip32_private_key(sequence, k, chain):
            for i in sequence:
                k, chain = CKD_priv(k, chain, i)
            return SecretToASecret(k, True)
       +
       +
       +def xkeys_from_seed(seed, derivation):
       +    from mnemonic import Mnemonic
       +    xprv, xpub = bip32_root(Mnemonic.mnemonic_to_seed(seed, ''))
       +    xprv, xpub = bip32_private_derivation(xprv, "m/", derivation)
       +    return xprv, xpub
   DIR diff --git a/lib/keystore.py b/lib/keystore.py
       t@@ -710,16 +710,6 @@ def from_xprv(xprv):
            k.xpub = xpub
            return k
        
       -def xprv_from_seed(seed):
       -    # do not store the seed, only the master xprv
       -    xprv, xpub = bip32_root(Mnemonic.mnemonic_to_seed(seed, ''))
       -    return from_xprv(xprv)
       -
       -def xpub_from_seed(seed):
       -    # store only master xpub
       -    xprv, xpub = bip32_root(Mnemonic.mnemonic_to_seed(seed,''))
       -    return from_xpub(xpub)
       -
        def from_keys(text):
            if is_xprv(text):
                k = from_xprv(text)
   DIR diff --git a/plugins/trustedcoin/trustedcoin.py b/plugins/trustedcoin/trustedcoin.py
       t@@ -330,7 +330,7 @@ class TrustedCoinPlugin(BasePlugin):
                return True
        
            def make_seed(self):
       -        return Mnemonic('english').make_seed(num_bits=256, prefix=SEED_PREFIX)
       +        return Mnemonic('english').make_seed(num_bits=128, prefix=SEED_PREFIX)
        
            @hook
            def do_clear(self, window):
       t@@ -357,13 +357,26 @@ class TrustedCoinPlugin(BasePlugin):
                f = lambda x: wizard.confirm_seed(seed, '')
                wizard.show_seed_dialog(run_next=f, seed_text=seed)
        
       +    def xkeys_from_seed(self, seed):
       +        words = seed.split()
       +        n = len(words)
       +        # old version use long seed phrases
       +        if n == 24:
       +            xprv1, xpub1 = keystore.xkeys_from_seed(' '.join(words[0:12]), "m/")
       +            xprv2, xpub2 = keystore.xkeys_from_seed(' '.join(words[12:]), "m/")
       +        elif n==12:
       +            xprv1, xpub1 = keystore.xkeys_from_seed(seed, "m/0'/")
       +            xprv2, xpub2 = keystore.xkeys_from_seed(seed, "m/1'/")
       +        else:
       +            raise BaseException('unrecognized seed length')
       +        return xprv1, xpub1, xprv2, xpub2
       +
            def create_keystore(self, wizard, seed, passphrase):
                assert passphrase == ''
                # this overloads the wizard's method
       -        words = seed.split()
       -        n = len(words)/2
       -        k1 = keystore.xprv_from_seed(' '.join(words[0:n]))
       -        k2 = keystore.xpub_from_seed(' '.join(words[n:]))
       +        xprv1, xpub1, xprv2, xpub2 = self.xkeys_from_seed(seed)
       +        k1 = keystore.from_xprv(xprv1)
       +        k2 = keystore.from_xpub(xpub2)
                wizard.request_password(run_next=lambda pw: self.on_password(wizard, pw, k1, k2))
        
            def on_password(self, wizard, password, k1, k2):
       t@@ -396,10 +409,9 @@ class TrustedCoinPlugin(BasePlugin):
        
            def on_restore_pw(self, wizard, seed, password):
                storage = wizard.storage
       -        words = seed.split()
       -        n = len(words)/2
       -        k1 = keystore.xprv_from_seed(' '.join(words[0:n]))
       -        k2 = keystore.xprv_from_seed(' '.join(words[n:]))
       +        xprv1, xpub1, xprv2, xpub2 = self.xkeys_from_seed(seed)
       +        k1 = keystore.from_xprv(xprv1)
       +        k2 = keystore.from_xprv(xprv2)
                k1.add_seed(seed)
                k1.update_password(None, password)
                k2.update_password(None, password)