Created
July 8, 2018 15:05
-
-
Save KamilLelonek/46a96d3de7d65579c4d3cea1c2722c5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def derive_key(%Private{chain_code: chain_code} = private_key, index) | |
when normal?(index) do | |
chain_code | |
|> compressed_hmac_sha512(private_key, index) | |
|> private_derivation(private_key) | |
end | |
def derive_key(%Private{key: key, chain_code: chain_code} = private_key, index) | |
when hardened?(index) do | |
chain_code | |
|> Crypto.hmac_sha512(<<0::8, key::binary, index::32>>) | |
|> private_derivation(private_key) | |
end | |
def derive_key(%Public{chain_code: chain_code} = public_key, index) | |
when normal?(index) do | |
chain_code | |
|> compressed_hmac_sha512(public_key, index) | |
|> elliptic_curve_point_addition(public_key) | |
end | |
def derive_key(%Public{}, index) | |
when hardened?(index), | |
do: raise("Cannot derive Public Hardened Child!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment