digitalbitbox: some Python backwards compat fixes
This commit is contained in:
@@ -91,7 +91,7 @@ class DigitalBitbox_Client():
|
|||||||
|
|
||||||
def _get_xpub(self, bip32_path):
|
def _get_xpub(self, bip32_path):
|
||||||
if self.check_device_dialog():
|
if self.check_device_dialog():
|
||||||
return self.hid_send_encrypt(b'{"xpub": "%s"}' % bip32_path.encode('utf8'))
|
return self.hid_send_encrypt(('{"xpub": "%s"}' % bip32_path).encode('utf8'))
|
||||||
|
|
||||||
|
|
||||||
def get_xpub(self, bip32_path, xtype):
|
def get_xpub(self, bip32_path, xtype):
|
||||||
@@ -121,7 +121,7 @@ class DigitalBitbox_Client():
|
|||||||
|
|
||||||
def stretch_key(self, key):
|
def stretch_key(self, key):
|
||||||
import pbkdf2, hmac
|
import pbkdf2, hmac
|
||||||
return binascii.hexlify(pbkdf2.PBKDF2(key, b'Digital Bitbox', iterations = 20480, macmodule = hmac, digestmodule = hashlib.sha512).read(64))
|
return to_hexstr(pbkdf2.PBKDF2(key, b'Digital Bitbox', iterations = 20480, macmodule = hmac, digestmodule = hashlib.sha512).read(64))
|
||||||
|
|
||||||
|
|
||||||
def backup_password_dialog(self):
|
def backup_password_dialog(self):
|
||||||
@@ -254,10 +254,15 @@ class DigitalBitbox_Client():
|
|||||||
if not dbb_user_dir:
|
if not dbb_user_dir:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Python 3.5+
|
||||||
|
jsonDecodeError = json.JSONDecodeError
|
||||||
|
except AttributeError:
|
||||||
|
jsonDecodeError = ValueError
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(dbb_user_dir, "config.dat")) as f:
|
with open(os.path.join(dbb_user_dir, "config.dat")) as f:
|
||||||
dbb_config = json.load(f)
|
dbb_config = json.load(f)
|
||||||
except (FileNotFoundError, json.JSONDecodeError):
|
except (FileNotFoundError, jsonDecodeError):
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'encryptionprivkey' not in dbb_config or 'comserverchannelid' not in dbb_config:
|
if 'encryptionprivkey' not in dbb_config or 'comserverchannelid' not in dbb_config:
|
||||||
@@ -284,8 +289,8 @@ class DigitalBitbox_Client():
|
|||||||
|
|
||||||
def dbb_generate_wallet(self):
|
def dbb_generate_wallet(self):
|
||||||
key = self.stretch_key(self.password)
|
key = self.stretch_key(self.password)
|
||||||
filename = ("Electrum-" + time.strftime("%Y-%m-%d-%H-%M-%S") + ".pdf").encode('utf8')
|
filename = ("Electrum-" + time.strftime("%Y-%m-%d-%H-%M-%S") + ".pdf")
|
||||||
msg = b'{"seed":{"source": "create", "key": "%s", "filename": "%s", "entropy": "%s"}}' % (key, filename, b'Digital Bitbox Electrum Plugin')
|
msg = ('{"seed":{"source": "create", "key": "%s", "filename": "%s", "entropy": "%s"}}' % (key, filename, 'Digital Bitbox Electrum Plugin')).encode('utf8')
|
||||||
reply = self.hid_send_encrypt(msg)
|
reply = self.hid_send_encrypt(msg)
|
||||||
if 'error' in reply:
|
if 'error' in reply:
|
||||||
raise Exception(reply['error']['message'])
|
raise Exception(reply['error']['message'])
|
||||||
@@ -320,7 +325,7 @@ class DigitalBitbox_Client():
|
|||||||
self.handler.show_message(_("Loading backup...") + "\n\n" +
|
self.handler.show_message(_("Loading backup...") + "\n\n" +
|
||||||
_("To continue, touch the Digital Bitbox's light for 3 seconds.") + "\n\n" +
|
_("To continue, touch the Digital Bitbox's light for 3 seconds.") + "\n\n" +
|
||||||
_("To cancel, briefly touch the light or wait for the timeout."))
|
_("To cancel, briefly touch the light or wait for the timeout."))
|
||||||
msg = b'{"seed":{"source": "backup", "key": "%s", "filename": "%s"}}' % (key, backups['backup'][f].encode('utf8'))
|
msg = ('{"seed":{"source": "backup", "key": "%s", "filename": "%s"}}' % (key, backups['backup'][f])).encode('utf8')
|
||||||
hid_reply = self.hid_send_encrypt(msg)
|
hid_reply = self.hid_send_encrypt(msg)
|
||||||
self.handler.finished()
|
self.handler.finished()
|
||||||
if 'error' in hid_reply:
|
if 'error' in hid_reply:
|
||||||
@@ -448,7 +453,7 @@ class DigitalBitbox_KeyStore(Hardware_KeyStore):
|
|||||||
hasharray.append({'hash': inputHash, 'keypath': inputPath})
|
hasharray.append({'hash': inputHash, 'keypath': inputPath})
|
||||||
hasharray = json.dumps(hasharray)
|
hasharray = json.dumps(hasharray)
|
||||||
|
|
||||||
msg = b'{"sign":{"meta":"sign message", "data":%s}}' % hasharray.encode('utf8')
|
msg = ('{"sign":{"meta":"sign message", "data":%s}}' % hasharray).encode('utf8')
|
||||||
|
|
||||||
dbb_client = self.plugin.get_client(self)
|
dbb_client = self.plugin.get_client(self)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user