Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Ledger wallet support #4486

Merged
merged 2 commits into from
Feb 10, 2017
Merged

Ledger wallet support #4486

merged 2 commits into from
Feb 10, 2017

Conversation

arkpar
Copy link
Collaborator

@arkpar arkpar commented Feb 8, 2017

@General-Beck libudev-dev is now required to build on linux
@tomusdrw please review RPC/signer changes

@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Feb 8, 2017
@arkpar arkpar requested a review from tomusdrw February 8, 2017 19:25
hw/src/ledger.rs Outdated
/// Ethereum wallet protocol error.
ProtocolError(&'static str),
/// Hidapi error.
UsbError(hidapi::HidError),
Copy link
Contributor

Choose a reason for hiding this comment

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

style: no Error suffix

hw/src/lib.rs Outdated
/// Ledger device error.
LedgerDeviceError(ledger::Error),
/// USB error.
UsbError(libusb::Error),
Copy link
Contributor

Choose a reason for hiding this comment

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

style: no Error suffix

@@ -18,7 +18,7 @@ use std::path::PathBuf;
use ethcore::ethstore::{EthStore, SecretStore, import_accounts, read_geth_accounts};
use ethcore::ethstore::dir::RootDiskDirectory;
use ethcore::ethstore::SecretVaultRef;
use ethcore::account_provider::AccountProvider;
use ethcore::account_provider::{AccountProvider, AccountProviderSetttings};
Copy link
Contributor

Choose a reason for hiding this comment

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

Setttings -> Settings

parity/params.rs Outdated
@@ -184,6 +185,7 @@ impl Default for AccountsConfig {
testnet: false,
password_files: Vec::new(),
unlocked_accounts: Vec::new(),
enable_hardware_wallets: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be true if it's supposed to be opt-out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is not needed for most use cases of account management such as creating or listing accounts.

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Some grumbles.

@@ -278,14 +328,36 @@ impl AccountProvider {
Ok(r)
}

/// Returns each hardware account along with name and meta.
pub fn hardware_accounts_info(&self) -> Result<HashMap<Address, AccountMeta>, Error> {
let r: HashMap<Address, AccountMeta> = self.hardware_accounts()?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is type annotation necessary here?

hw/src/ledger.rs Outdated
}

let (major, minor, patch) = (ver[1], ver[2], ver[3]);
if major <= 1 && minor == 0 && patch < 3 {
Copy link
Collaborator

@tomusdrw tomusdrw Feb 9, 2017

Choose a reason for hiding this comment

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

Is this condition correct? Should it mean that anything greater than 1.0.3 is supported?
If so then it needs to be:

if major < 1 || (major == 1 && minor == 0 && patch < 3) 

Currently version 0.x.0 (x > 0) will be treated as correct, no?

@@ -138,6 +138,22 @@ impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
)
}

fn hardware_accounts_info(&self) -> Result<BTreeMap<String, BTreeMap<String, String>>, Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be BTreeMap<H160, BTreeMap<String, String>> or even better BTreeMap<H160, HwAccountInfo>

hw/src/ledger.rs Outdated
KeyPath::EthereumClassic => etc_path,
};
let key_and_address = Self::send_apdu(handle, commands::GET_ETH_PUBLIC_ADDRESS, 0, 0, derivation_path)?;
if key_and_address.len() != 107 { // 1 + 65 PK + 1 + 20 Addr
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it correct? 1+65+1+20 = 87, not 107. A bit confusing :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Address actually takes 40 because it comes ascii-hex encoded. Will update the comment.

hw/src/ledger.rs Outdated
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
Error::Protocol(ref s) => write!(f, "Ledget protocol error: {}", s),
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: Ledget

@General-Beck
Copy link
Contributor

libudev-dev added

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 9, 2017
@gavofyork
Copy link
Contributor

gavofyork commented Feb 10, 2017

@arkpar need README altering for linux build instructions, too?

@gavofyork gavofyork merged commit a7e6d87 into master Feb 10, 2017
@gavofyork gavofyork deleted the ledger branch February 10, 2017 00:07
@arkpar
Copy link
Collaborator Author

arkpar commented Feb 10, 2017

already altered

let mut chunk: [u8; HID_PACKET_SIZE] = [0; HID_PACKET_SIZE];
let chunk_size = handle.read(&mut chunk)?;
trace!("read {:?}", &chunk[..]);
if chunk_size < 5 || chunk[1] != 0x01 || chunk[1] != 0x01 || chunk[2] != APDU_TAG {

Choose a reason for hiding this comment

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

If you copy our code, at least copy correctly. First should be chunk[0].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ehm, I'm pretty sure this is correct. Why do you think it should be [0]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is rust code btw

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's checking chunk[1] twice so either one should be chunk[0] or second one is redundant.

Choose a reason for hiding this comment

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

This is rust code btw

You don't say.

The communication channel part of the header is 2 bytes, both 0x01.

Choose a reason for hiding this comment

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

@arkpar Take another look at the code you copied, it's correct there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hidapi sends HID report id in the first byte. I've noticed you are using libusb for communication. This is a poor choice because it does not allow communicating with HID devices on macOS. I'm only using libusb for hotplug notifications - a feature that your code does not have at all. Perhaps you should be more careful with such accusations.

Choose a reason for hiding this comment

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

I didn't say where you copied it from. Seems you're awfully familiar with it though.

Copy link

@karalabe karalabe Feb 14, 2017

Choose a reason for hiding this comment

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

But ok, let's play. I dare you to publicly say you did not write this code segment based on the go-ethereum implementation.

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 sure seen your PR but I did not copy it. I've looked into the reference scala code mostly. In particular https://github.com/LedgerHQ/ledger-wallet-ethereum-chrome/blob/67864c09fc88fd744cd17a28ba9460e20987b898/src/main/scala/co/ledger/wallet/web/ethereum/core/device/LedgerTransportHelper.scala#L39
There's only a few ways you can write a simple function that splits data into 64 byte chunks and appends a simple header.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants