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

Add ledger wallet support #398

Merged
merged 2 commits into from Jan 4, 2018
Merged

Add ledger wallet support #398

merged 2 commits into from Jan 4, 2018

Conversation

marceloneil
Copy link
Collaborator

Fixes #153

This was tested using the Nano S - I can't verify it would work for the Blue or HW1.

I tested both standard and multisig wallets, along with multiple outputs on the Bitcoin Cash testnet and mainnet.

Most of the code needed for ledger wallet BIP143 transactions was sourced directly from the segwit update of spesmilo/electrum, so credit is due there.

Copy link

@DarkLordGMS DarkLordGMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this out @fyookball @kyuupichan

This is needed since the native Ledger app is kinda broken:
https://www.reddit.com/r/btc/comments/7n2t6o/ledger_cto_requests_suggestions_to_fix_their/

def perform_hw1_preflight(self):
try:
firmwareInfo = self.dongleObject.getFirmwareVersion()
firmware = firmwareInfo['version'].split(".")
self.multiOutputSupported = int(firmware[0]) >= 1 and int(firmware[1]) >= 1 and int(firmware[2]) >= 4
bitcoinCashSupport = int(firmware[0]) >= 1 and int(firmware[1]) >= 1 and int(firmware[2]) >= 8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the change from 4 to 8 signify? might be worth pulling this number out into a named variable for readability 👍

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, that's the version for the Bitcoin Cash app in the Nano S.

The current version is 1.1.8 @bderose

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, however the current version checking is a bit odd (ie. 1.1.9 would work but not 1.2.0), so a few things could be tweaked to provide backwards compatibility. Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One solution would be to use something like the semver package to do this comparison. I realize we may not want to introduce new dependencies, though. In that case, this SO question has some good suggestions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added the version comparison from distutils.version so no new dependencies are required, and it seems to work well.

def perform_hw1_preflight(self):
try:
firmwareInfo = self.dongleObject.getFirmwareVersion()
firmware = firmwareInfo['version'].split(".")
self.multiOutputSupported = int(firmware[0]) >= 1 and int(firmware[1]) >= 1 and int(firmware[2]) >= 4
bitcoinCashSupport = int(firmware[0]) >= 1 and int(firmware[1]) >= 1 and int(firmware[2]) >= 8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, that's the version for the Bitcoin Cash app in the Nano S.

The current version is 1.1.8 @bderose

inputIndex = inputIndex + 1
if pin != 'paired':
firstTransaction = False
self.get_client().startUntrustedTransaction(True, inputIndex,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice clean up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only BIP143 signing is needed

tmp += bfh(int_to_hex(utxo[1], 4))
chipInputs.append({'value' : tmp, 'sequence' : sequence})
redeemScripts.append(bfh(utxo[2]))
txtmp = bitcoinTransaction(bfh(utxo[0]))
Copy link

@bderose bderose Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this support both P2SH and non-P2SH transactions using the Nano S?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only tested 2 cosigner multisig, but it should (since all transactions are BIP143, unlike core where its only segwit)

@fyookball fyookball merged commit fd5a080 into Electron-Cash:master Jan 4, 2018
@marceloneil marceloneil deleted the fix-ledger branch January 4, 2018 17:37
@mooncryption
Copy link

Awesome! You have no idea how useful this will be. Glad to see work being done on this issue, especially while Ledger's native software is having huge problems with low-fee transactions (see here).

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants