commit a220932711f2bdc015d698ef67510fbfcd533d54
parent 62fe3a411b2e052c2d17d1d330879e11e4b03c9c
Author: ThomasV <thomasv@electrum.org>
Date: Wed, 25 Oct 2017 17:33:49 +0200
serialize txin-type in xpub/xprv
Diffstat:
4 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/lib/base_wizard.py b/lib/base_wizard.py
@@ -299,7 +299,7 @@ class BaseWizard(object):
self.derivation_dialog(f)
def create_keystore(self, seed, passphrase):
- k = keystore.from_seed(seed, passphrase)
+ k = keystore.from_seed(seed, passphrase, self.wallet_type == 'multisig')
self.on_keystore(k)
def on_bip43(self, seed, passphrase, derivation):
diff --git a/lib/bitcoin.py b/lib/bitcoin.py
@@ -47,19 +47,25 @@ def read_json_dict(filename):
return r
+
+
# Version numbers for BIP32 extended keys
# standard: xprv, xpub
# segwit in p2sh: yprv, ypub
# native segwit: zprv, zpub
XPRV_HEADERS = {
'standard': 0x0488ade4,
- 'segwit_p2sh': 0x049d7878,
- 'segwit': 0x4b2430c
+ 'p2wpkh-p2sh': 0x049d7878,
+ 'p2wsh-p2sh': 0x295b004,
+ 'p2wpkh': 0x4b2430c,
+ 'p2wsh': 0x2aa7a99
}
XPUB_HEADERS = {
'standard': 0x0488b21e,
- 'segwit_p2sh': 0x049d7cb2,
- 'segwit': 0x4b24746
+ 'p2wpkh-p2sh': 0x049d7cb2,
+ 'p2wsh-p2sh': 0x295b43e,
+ 'p2wpkh': 0x4b24746,
+ 'p2wsh': 0x2aa7ed3
}
diff --git a/lib/keystore.py b/lib/keystore.py
@@ -681,7 +681,7 @@ def bip44_derivation(account_id, segwit=False):
coin = 1 if bitcoin.TESTNET else 0
return "m/%d'/%d'/%d'" % (bip, coin, int(account_id))
-def from_seed(seed, passphrase):
+def from_seed(seed, passphrase, is_p2sh):
t = seed_type(seed)
if t == 'old':
keystore = Old_KeyStore({})
@@ -691,7 +691,13 @@ def from_seed(seed, passphrase):
keystore.add_seed(seed)
keystore.passphrase = passphrase
bip32_seed = Mnemonic.mnemonic_to_seed(seed, passphrase)
- keystore.add_xprv_from_seed(bip32_seed, t, "m/")
+ if t == 'standard':
+ der = "m/"
+ xtype = 'standard'
+ else:
+ der = "m/1'/" if is_p2sh else "m/0'/"
+ xtype = 'p2wsh' if is_p2sh else 'p2wpkh'
+ keystore.add_xprv_from_seed(bip32_seed, xtype, der)
else:
raise BaseException(t)
return keystore
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -1662,14 +1662,7 @@ class Simple_Deterministic_Wallet(Simple_Wallet, Deterministic_Wallet):
xtype = deserialize_xpub(self.keystore.xpub)[0]
except:
xtype = 'standard'
- if xtype == 'standard':
- self.txin_type = 'p2pkh'
- elif xtype == 'segwit':
- self.txin_type = 'p2wpkh'
- elif xtype == 'segwit_p2sh':
- self.txin_type = 'p2wpkh-p2sh'
- else:
- raise BaseException('unknown txin_type', xtype)
+ self.txin_type = 'p2pkh' if xtype == 'standard' else xtype
def get_pubkey(self, c, i):
return self.derive_pubkeys(c, i)
@@ -1731,14 +1724,7 @@ class Multisig_Wallet(Deterministic_Wallet):
self.keystores[name] = load_keystore(self.storage, name)
self.keystore = self.keystores['x1/']
xtype = deserialize_xpub(self.keystore.xpub)[0]
- if xtype == 'standard':
- self.txin_type = 'p2sh'
- elif xtype == 'segwit':
- self.txin_type = 'p2wsh'
- elif xtype == 'segwit_p2sh':
- self.txin_type = 'p2wsh-p2sh'
- else:
- raise BaseException('unknown txin_type', xtype)
+ self.txin_type = 'p2sh' if xtype == 'standard' else 'xtype'
def save_keystore(self):
for name, k in self.keystores.items():