-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ledger wallet support #4486
Ledger wallet support #4486
Conversation
hw/src/ledger.rs
Outdated
/// Ethereum wallet protocol error. | ||
ProtocolError(&'static str), | ||
/// Hidapi error. | ||
UsbError(hidapi::HidError), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: no Error suffix
parity/account.rs
Outdated
@@ -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}; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some grumbles.
ethcore/src/account_provider/mod.rs
Outdated
@@ -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()? |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
rpc/src/v1/impls/parity.rs
Outdated
@@ -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> { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: Ledget
|
@arkpar need |
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 { |
There was a problem hiding this comment.
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]
.
There was a problem hiding this comment.
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]
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@General-Beck
libudev-dev
is now required to build on linux@tomusdrw please review RPC/signer changes