Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transaction sign with Ledger hw #57

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions electrum_dash/plugins/ledger/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,24 @@ def getTrustedInput(self, transaction, index):
self.dongle.exchange(bytearray(apdu))
offset += dataLength

#Sending the lockTime and the extraPayload
blockLength = 255
buffer = []
writeVarint(len(transaction.extra_data), buffer)
offset = blockLength - len(transaction.lockTime) - len(buffer)
apdu = [self.BTCHIP_CLA, self.BTCHIP_INS_GET_TRUSTED_INPUT, 0x80, 0x00, blockLength]
params = []
if transaction.extra_data:
if len(transaction.extra_data) > 255 - len(transaction.lockTime):
# for now the size should be sufficient
raise Exception('The size of the DIP2 extra data block has exceeded the limit.')

writeVarint(len(transaction.extra_data), params)
params.extend(transaction.extra_data)

apdu = [self.BTCHIP_CLA, self.BTCHIP_INS_GET_TRUSTED_INPUT, 0x80, 0x00, len(transaction.lockTime) + len(params)]
# Locktime
apdu.extend(transaction.lockTime)
apdu.extend(buffer)
if offset > len(transaction.extra_data):
offset = len(transaction.extra_data)
apdu.extend(transaction.extra_data[0: offset])
apdu.extend(params)
response = self.dongle.exchange(bytearray(apdu))
while (offset < len(transaction.extra_data)):
blockLength = 255
if ((offset + blockLength) < len(transaction.extra_data)):
dataLength = blockLength
else:
dataLength = len(transaction.extra_data) - offset
apdu = [self.BTCHIP_CLA, self.BTCHIP_INS_GET_TRUSTED_INPUT, 0x80, 0x00, dataLength]
apdu.extend(transaction.extra_data[offset: offset + dataLength])
response = self.dongle.exchange(bytearray(apdu))
offset += dataLength

result['trustedInput'] = True
result['value'] = response
return result


class Ledger_Client(HardwareClientBase):
def __init__(self, hidDevice, *, product_key: Tuple[int, int],
plugin: HW_PluginBase):
Expand Down Expand Up @@ -297,6 +287,7 @@ def perform_hw1_preflight(self):
self.dongleObject.verifyPin(pin)
if self.canAlternateCoinVersions:
self.dongleObject.setAlternateCoinVersions(constants.net.ADDRTYPE_P2PKH,
constants.net.ADDRTYPE_EXP2PKH,
constants.net.ADDRTYPE_P2SH)
except BTChipException as e:
if (e.sw == 0x6faa):
Expand Down Expand Up @@ -531,7 +522,7 @@ def sign_transaction(self, tx, password):
output = txout.address
if not self.get_client_electrum().canAlternateCoinVersions:
v, h = b58_address_to_hash160(output)
if v == constants.net.ADDRTYPE_P2PKH:
if v == constants.net.ADDRTYPE_P2PKH or v == constants.net.ADDRTYPE_EXP2PKH:
output = hash160_to_b58_address(h, 0)

self.handler.show_message(_("Confirm Transaction on your Ledger device..."))
Expand Down
Loading