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

Ethkey - extended keys #4377

Merged
merged 16 commits into from
Feb 5, 2017
Merged

Ethkey - extended keys #4377

merged 16 commits into from
Feb 5, 2017

Conversation

NikVolf
Copy link
Contributor

@NikVolf NikVolf commented Feb 1, 2017

Deterministic derivation of private & public keys using secp256k1 elliptic curve

based on bitcoin hd wallet spec (BIP0032): https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

@NikVolf NikVolf added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Feb 1, 2017
let mut data = [0u8; 37];

let sec_private = SecretKey::from_slice(&SECP256K1, &*private_key)
.expect("Caller should provide valid private key");
Copy link
Contributor

Choose a reason for hiding this comment

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

not a valid expectation -> either prove or provide an error return path

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 internal function, the upper code never passes random hashes in it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comment that it can panic just in case

// curve point (compressed public key) -- index
// 0.33 -- 33..37
data[0..33].copy_from_slice(&public_serialized);
BigEndian::write_u32(&mut data[33..37], index);
Copy link
Contributor

Choose a reason for hiding this comment

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

only u32? we might want to provide an extended version of this which can handle 256-bit indexs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why do you need so much?
using u32 allows to derive 2^31 soft and 2^31 hard keys

Copy link
Contributor

Choose a reason for hiding this comment

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

yup, but that number is theoretically searchable. my understanding is that the maths allows for 2**256 soft keys, which then means that you can have cryptographically secure receive addresses. basically, you want to make a secret payment to address X: you generate address Y = soft(X, H) where H is some cryptographically secure invoice identifier (e.g. the sha3 of the invoice PDF). if you don't have H then you cannot associate X with Y, but once you do have H then you can prove that the owner of X can access the funds at Y.

basically it lets you send funds to someone's public address without the payment itself being made public. but still with the ability for either party to make the payment public at a later date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice explanation, and It's easy to implement, actually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gavofyork
Copy link
Contributor

gavofyork commented Feb 1, 2017

i presume those tests are the official test vectors?

@NikVolf
Copy link
Contributor Author

NikVolf commented Feb 1, 2017

@gavofyork
there is no "official" test vectors for exactly this algorithm
i'll try to adapt bip0032 test vectors, but there can be errors while adapting as well :)

@NikVolf
Copy link
Contributor Author

NikVolf commented Feb 2, 2017

@gavofyork
done, extracted test vectors and added from bitcoin bip0032
it can be later published as our test vectors also once algorithm is somewhat proven good

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

@NikVolf let me know if you can't see an easy way to extend index length to 256 bit.

@gavofyork
Copy link
Contributor

will merge as-is; 256-bit indexes can be added in a second PR.

@gavofyork gavofyork merged commit e257e4e into master Feb 5, 2017
@gavofyork gavofyork deleted the hd-wallet branch February 5, 2017 15:17
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.

2 participants