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

Key derivation in ethstore & rpc #4515

Merged
merged 20 commits into from
Feb 15, 2017
Merged

Key derivation in ethstore & rpc #4515

merged 20 commits into from
Feb 15, 2017

Conversation

NikVolf
Copy link
Contributor

@NikVolf NikVolf commented Feb 10, 2017

Now client can create derived address for any of his accounts and optionally save it as a new account (or just get raw address and it's up to him how to use it)

Two types of derivation:

  • hierarchical deterministic wallet (kind of bitcoin-compatible standard of bip0032), where you provide a series of indices for one or more sequental derivations (for example, Soft(0)/Soft(1)/Hard(0))

  • hash derivation where you provide just H256 (for example, invoice or other content hash) and derivation type (soft/hard)

Right now it's up to client how to use derived keys - as a full account or just save it in address book after derivation (to use it later - client must then derive this address again from the same account with the same parameters and save: true).

Another option is to sign transaction with the derived key directly - coming in following pr to keep things small here

@NikVolf NikVolf added A0-pleasereview 🤓 Pull request needs code review. F1-security 🛡 The client fails to follow expected, security-sensitive, behaviour. M4-core ⛓ Core client code / Rust. and removed F1-security 🛡 The client fails to follow expected, security-sensitive, behaviour. labels Feb 10, 2017
if !account.check_password(password) {
continue;
}
let extended = self.generate(account.crypto.secret(password)?, derivation)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a bottleneck? can we cache extended key-pairs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not in release build at all

continue;
}
let extended = self.generate(account.crypto.secret(password)?, derivation)?;
let secret = extended.secret().secret();
Copy link
Contributor

@rphmeier rphmeier Feb 10, 2017

Choose a reason for hiding this comment

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

would a Deref or Into implementation make this less weird?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well it's not that weird
first secret() is ExtendedSecret of the extended key pair and second secret() is a raw H256 secret of this extended secret, i don't see logical reason to Deref them in something they are not in any way equal to

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a strange API design for sure. Doesn't help readability that you have to dig into the internals to know what's happening.

let secret = extended.secret(); // I have the secret!
let secret = secret.secret(); // I have the...secret secret?

Would definitely make more sense (to read) as x.secret().as_raw() or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i didn't like it either, but when it comes to individual function names, their names are legit, it's just when they are used one after another weirdness shows :)

as_raw looks nice, yeah, will rename

@rphmeier
Copy link
Contributor

rphmeier commented Feb 10, 2017

It seems like we could unify the _derived and regular interfaces under the same function names with a Derivation::None/Derivation::Identity enum. Fewer functions to look up, fewer branches in consumers of this API.

@arkpar
Copy link
Collaborator

arkpar commented Feb 10, 2017

Would be nice to adopt BIP-44 string format. Maybe in another PR.
These RPCs should also be implemented for hardware wallets eventually.

@@ -25,7 +25,7 @@ use ethcore::account_provider::AccountProvider;
use jsonrpc_core::Error;
use v1::helpers::errors;
use v1::traits::ParityAccounts;
use v1::types::{H160 as RpcH160, H256 as RpcH256, DappId};
use v1::types::{H160 as RpcH160, H256 as RpcH256, DappId, Derivate, DerivateHierarchical, DerivateHash};
Copy link
Contributor

Choose a reason for hiding this comment

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

Derivate not a word, should be Derive

@NikVolf
Copy link
Contributor Author

NikVolf commented Feb 10, 2017

@rphmeier Not sure if i want to break existing api just to introduce key derivation which is rather small and humble part of it

@NikVolf
Copy link
Contributor Author

NikVolf commented Feb 10, 2017

@arkpar
Looks like it can be adopted by the wallet app using this rpc api
it will just derive address with specified node indices and that's it

@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 13, 2017
@gavofyork gavofyork added A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Feb 14, 2017
@NikVolf NikVolf added A8-looksgood 🦄 Pull request is reviewed well. and removed A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts. labels Feb 15, 2017
@gavofyork gavofyork merged commit 494a0de into master Feb 15, 2017
@gavofyork gavofyork deleted the hd-wallet-rpc branch February 15, 2017 15:56
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

4 participants