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

Expose key derivation #9

Open
jacogr opened this issue Mar 12, 2019 · 6 comments
Open

Expose key derivation #9

jacogr opened this issue Mar 12, 2019 · 6 comments

Comments

@jacogr
Copy link
Contributor

jacogr commented Mar 12, 2019

Specifically derived_key_simple enabling us to do this logic from the JS side -

pub fn derive<Iter: Iterator<Item=DeriveJunction>>(&self, path: Iter) -> Option<Public> {
	let mut acc = PublicKey::from_bytes(self.as_ref()).ok()?;
	for j in path {
		match j {
			DeriveJunction::Soft(cc) => acc = acc.derived_key_simple(ChainCode(cc), &[]).0,
			DeriveJunction::Hard(_cc) => return None,
		}
	}
	Some(Self(acc.to_bytes()))
}
@kianenigma
Copy link
Collaborator

I assume this is not the only function that you will need, right?

@jacogr
Copy link
Contributor Author

jacogr commented Mar 13, 2019

Only one actually - all the Junction etc. stuff is implemented to do the derivation, however in the JS derive function, cannot call anything to adjust the key (as per the Rust sample).

Not sure how that will work, have not looked - so there are possibly additional functions required around it to make thing work.

@kianenigma
Copy link
Collaborator

Ok then it looks fairly minimal to do. Hopefully within the next day should be delivered for you and the js team to test.

@jacogr
Copy link
Contributor Author

jacogr commented Mar 13, 2019

yes, it looks like a single function, just not 100% sure how to jump through all the hoops since it operates on an actual pair - but basically, in the ed25519 the derivation just is a hash function, in the sr25519 need to call into the lib.

@burdges
Copy link

burdges commented Mar 14, 2019

Just fyi, I added a hard derivation path which previously I'd ignored.

@jacogr
Copy link
Contributor Author

jacogr commented Mar 14, 2019

@burdges Gav did this - https://github.com/paritytech/substrate/blob/master/core/primitives/src/sr25519.rs#L368 which is used further on by https://github.com/paritytech/substrate/blob/master/core/primitives/src/sr25519.rs#L450 (i.e. here the soft derivation goes via w3f/schnorrkel and hard derivation via the first linked function)

So for the meantime the polkadot-js keyring stuff will follow suit until that is adjusted in Substrate.

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

No branches or pull requests

3 participants