Merge pull request #2291 from saleemrashid/testnet-trezor
TREZOR Testnet support
This commit is contained in:
commit
b27aeadb71
|
@ -26,6 +26,7 @@
|
||||||
import os
|
import os
|
||||||
import bitcoin
|
import bitcoin
|
||||||
import keystore
|
import keystore
|
||||||
|
from keystore import bip44_derivation
|
||||||
from wallet import Wallet, Imported_Wallet, Standard_Wallet, Multisig_Wallet, wallet_types
|
from wallet import Wallet, Imported_Wallet, Standard_Wallet, Multisig_Wallet, wallet_types
|
||||||
from i18n import _
|
from i18n import _
|
||||||
from plugins import run_hook
|
from plugins import run_hook
|
||||||
|
@ -219,7 +220,6 @@ class BaseWizard(object):
|
||||||
# This is partially compatible with BIP45; assumes index=0
|
# This is partially compatible with BIP45; assumes index=0
|
||||||
self.on_hw_derivation(name, device_info, "m/45'/0")
|
self.on_hw_derivation(name, device_info, "m/45'/0")
|
||||||
else:
|
else:
|
||||||
from keystore import bip44_derivation
|
|
||||||
f = lambda x: self.run('on_hw_derivation', name, device_info, bip44_derivation(int(x)))
|
f = lambda x: self.run('on_hw_derivation', name, device_info, bip44_derivation(int(x)))
|
||||||
self.account_id_dialog(f)
|
self.account_id_dialog(f)
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ class BaseWizard(object):
|
||||||
def on_bip44(self, seed, passphrase, account_id):
|
def on_bip44(self, seed, passphrase, account_id):
|
||||||
k = keystore.BIP32_KeyStore({})
|
k = keystore.BIP32_KeyStore({})
|
||||||
bip32_seed = keystore.bip39_to_seed(seed, passphrase)
|
bip32_seed = keystore.bip39_to_seed(seed, passphrase)
|
||||||
derivation = "m/44'/0'/%d'"%account_id
|
derivation = bip44_derivation(account_id)
|
||||||
k.add_xprv_from_seed(bip32_seed, 0, derivation)
|
k.add_xprv_from_seed(bip32_seed, 0, derivation)
|
||||||
self.on_keystore(k)
|
self.on_keystore(k)
|
||||||
|
|
||||||
|
|
|
@ -650,7 +650,10 @@ is_private_key = lambda x: is_xprv(x) or is_private_key_list(x)
|
||||||
is_bip32_key = lambda x: is_xprv(x) or is_xpub(x)
|
is_bip32_key = lambda x: is_xprv(x) or is_xpub(x)
|
||||||
|
|
||||||
def bip44_derivation(account_id):
|
def bip44_derivation(account_id):
|
||||||
return "m/44'/0'/%d'"% int(account_id)
|
if TESTNET:
|
||||||
|
return "m/44'/1'/%d'"% int(account_id)
|
||||||
|
else:
|
||||||
|
return "m/44'/0'/%d'"% int(account_id)
|
||||||
|
|
||||||
def from_seed(seed, passphrase):
|
def from_seed(seed, passphrase):
|
||||||
t = seed_type(seed)
|
t = seed_type(seed)
|
||||||
|
|
|
@ -7,7 +7,8 @@ from functools import partial
|
||||||
|
|
||||||
from electrum.bitcoin import (bc_address_to_hash_160, xpub_from_pubkey,
|
from electrum.bitcoin import (bc_address_to_hash_160, xpub_from_pubkey,
|
||||||
public_key_to_p2pkh, EncodeBase58Check,
|
public_key_to_p2pkh, EncodeBase58Check,
|
||||||
TYPE_ADDRESS, TYPE_SCRIPT)
|
TYPE_ADDRESS, TYPE_SCRIPT,
|
||||||
|
TESTNET, ADDRTYPE_P2PKH, ADDRTYPE_P2SH)
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.plugins import BasePlugin, hook
|
from electrum.plugins import BasePlugin, hook
|
||||||
from electrum.transaction import deserialize, Transaction
|
from electrum.transaction import deserialize, Transaction
|
||||||
|
@ -41,7 +42,7 @@ class TrezorCompatibleKeyStore(Hardware_KeyStore):
|
||||||
client = self.get_client()
|
client = self.get_client()
|
||||||
address_path = self.get_derivation() + "/%d/%d"%sequence
|
address_path = self.get_derivation() + "/%d/%d"%sequence
|
||||||
address_n = client.expand_path(address_path)
|
address_n = client.expand_path(address_path)
|
||||||
msg_sig = client.sign_message('Bitcoin', address_n, message)
|
msg_sig = client.sign_message(self.get_coin_name(), address_n, message)
|
||||||
return msg_sig.signature
|
return msg_sig.signature
|
||||||
|
|
||||||
def sign_transaction(self, tx, password):
|
def sign_transaction(self, tx, password):
|
||||||
|
@ -143,6 +144,12 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||||
client.used()
|
client.used()
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
def get_coin_name(self):
|
||||||
|
if TESTNET:
|
||||||
|
return "Testnet"
|
||||||
|
else:
|
||||||
|
return "Bitcoin"
|
||||||
|
|
||||||
def initialize_device(self, device_id, wizard, handler):
|
def initialize_device(self, device_id, wizard, handler):
|
||||||
# Initialization method
|
# Initialization method
|
||||||
msg = _("Choose how you want to initialize your %s.\n\n"
|
msg = _("Choose how you want to initialize your %s.\n\n"
|
||||||
|
@ -233,7 +240,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||||
client = self.get_client(keystore)
|
client = self.get_client(keystore)
|
||||||
inputs = self.tx_inputs(tx, True)
|
inputs = self.tx_inputs(tx, True)
|
||||||
outputs = self.tx_outputs(keystore.get_derivation(), tx)
|
outputs = self.tx_outputs(keystore.get_derivation(), tx)
|
||||||
signed_tx = client.sign_tx('Bitcoin', inputs, outputs)[1]
|
signed_tx = client.sign_tx(self.get_coin_name(), inputs, outputs)[1]
|
||||||
raw = signed_tx.encode('hex')
|
raw = signed_tx.encode('hex')
|
||||||
tx.update_signatures(raw)
|
tx.update_signatures(raw)
|
||||||
|
|
||||||
|
@ -246,7 +253,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||||
derivation = wallet.keystore.derivation
|
derivation = wallet.keystore.derivation
|
||||||
address_path = "%s/%d/%d"%(derivation, change, index)
|
address_path = "%s/%d/%d"%(derivation, change, index)
|
||||||
address_n = client.expand_path(address_path)
|
address_n = client.expand_path(address_path)
|
||||||
client.get_address('Bitcoin', address_n, True)
|
client.get_address(self.get_coin_name(), address_n, True)
|
||||||
|
|
||||||
def tx_inputs(self, tx, for_sig=False):
|
def tx_inputs(self, tx, for_sig=False):
|
||||||
inputs = []
|
inputs = []
|
||||||
|
@ -319,14 +326,14 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||||
has_change = True # no more than one change address
|
has_change = True # no more than one change address
|
||||||
addrtype, hash_160 = bc_address_to_hash_160(address)
|
addrtype, hash_160 = bc_address_to_hash_160(address)
|
||||||
index, xpubs, m = info
|
index, xpubs, m = info
|
||||||
if addrtype == 0:
|
if addrtype == ADDRTYPE_P2PKH:
|
||||||
address_n = self.client_class.expand_path(derivation + "/%d/%d"%index)
|
address_n = self.client_class.expand_path(derivation + "/%d/%d"%index)
|
||||||
txoutputtype = self.types.TxOutputType(
|
txoutputtype = self.types.TxOutputType(
|
||||||
amount = amount,
|
amount = amount,
|
||||||
script_type = self.types.PAYTOADDRESS,
|
script_type = self.types.PAYTOADDRESS,
|
||||||
address_n = address_n,
|
address_n = address_n,
|
||||||
)
|
)
|
||||||
elif addrtype == 5:
|
elif addrtype == ADDRTYPE_P2SH:
|
||||||
address_n = self.client_class.expand_path("/%d/%d"%index)
|
address_n = self.client_class.expand_path("/%d/%d"%index)
|
||||||
nodes = map(self.ckd_public.deserialize, xpubs)
|
nodes = map(self.ckd_public.deserialize, xpubs)
|
||||||
pubkeys = [ self.types.HDNodePathType(node=node, address_n=address_n) for node in nodes]
|
pubkeys = [ self.types.HDNodePathType(node=node, address_n=address_n) for node in nodes]
|
||||||
|
@ -346,9 +353,9 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
||||||
txoutputtype.op_return_data = address[2:]
|
txoutputtype.op_return_data = address[2:]
|
||||||
elif _type == TYPE_ADDRESS:
|
elif _type == TYPE_ADDRESS:
|
||||||
addrtype, hash_160 = bc_address_to_hash_160(address)
|
addrtype, hash_160 = bc_address_to_hash_160(address)
|
||||||
if addrtype == 0:
|
if addrtype == ADDRTYPE_P2PKH:
|
||||||
txoutputtype.script_type = self.types.PAYTOADDRESS
|
txoutputtype.script_type = self.types.PAYTOADDRESS
|
||||||
elif addrtype == 5:
|
elif addrtype == ADDRTYPE_P2SH:
|
||||||
txoutputtype.script_type = self.types.PAYTOSCRIPTHASH
|
txoutputtype.script_type = self.types.PAYTOSCRIPTHASH
|
||||||
else:
|
else:
|
||||||
raise BaseException('addrtype')
|
raise BaseException('addrtype')
|
||||||
|
|
Loading…
Reference in New Issue