pub struct Stark;
Expand description
HD derivation for stark curve
§Algorithm
The algorithm is a modification of BIP32:
def derive_child_key(parent_public_key[, parent_secret_key], parent_chain_code, child_index):
if is_hardened(child_index):
i = HMAC_SHA512(key = parent_chain_code, 0x00 || 0x00 || parent_secret_key || child_index)
|| HMAC_SHA512(key = parent_chain_code, 0x01 || 0x00 || parent_secret_key || child_index)
else:
i = HMAC_SHA512(key = parent_chain_code, 0x00 || parent_public_key || child_index)
|| HMAC_SHA512(key = parent_chain_code, 0x01 || parent_public_key || child_index)
shift = i[..96] mod order
child_secret_key = parent_secret_key + shift and/or child_public_key = parent_public_key + shift G
child_chain_code = i[N..]
return child_public_key[, child_secret_key], child_chain_code
§Other known methods for stark HD derivation
There’s another known method for HD derivation on stark curve implemented in argent-x, which basically derives secp256k1 child key from a seed, and then uses grinding function to deterministically convert it into stark key.
We decided not to implement it due to its cons:
- No support for non-hardened derivation
- Grinding is a probabilistic algorithm which does a lot of hashing (32 hashes on average, but in worst case can be 1000+).
- In general, it’s strange to derive secp256k1 key and then convert it to stark key
Our derivation algorithm addresses these flaws: it yields a stark key right away (without any intermediate secp256k1 keys), supports non-hardened derivation, does only 2 hashes per derivation.
Auto Trait Implementations§
impl Freeze for Stark
impl RefUnwindSafe for Stark
impl Send for Stark
impl Sync for Stark
impl Unpin for Stark
impl UnwindSafe for Stark
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<E, S> HdWallet<E> for Swhere
E: Curve,
S: DeriveShift<E>,
impl<E, S> HdWallet<E> for Swhere
E: Curve,
S: DeriveShift<E>,
Source§fn derive_child_public_key(
parent_public_key: &ExtendedPublicKey<E>,
child_index: NonHardenedIndex,
) -> ExtendedPublicKey<E>
fn derive_child_public_key( parent_public_key: &ExtendedPublicKey<E>, child_index: NonHardenedIndex, ) -> ExtendedPublicKey<E>
Derives child extended public key from parent extended public key Read more
Source§fn derive_child_key_pair(
parent_key: &ExtendedKeyPair<E>,
child_index: impl Into<ChildIndex>,
) -> ExtendedKeyPair<E>
fn derive_child_key_pair( parent_key: &ExtendedKeyPair<E>, child_index: impl Into<ChildIndex>, ) -> ExtendedKeyPair<E>
Derives child key pair (extended secret key + public key) from parent key pair Read more
Source§fn try_derive_child_key_pair_with_path<Err>(
parent_key: &ExtendedKeyPair<E>,
path: impl IntoIterator<Item = Result<impl Into<ChildIndex>, Err>>,
) -> Result<ExtendedKeyPair<E>, Err>
fn try_derive_child_key_pair_with_path<Err>( parent_key: &ExtendedKeyPair<E>, path: impl IntoIterator<Item = Result<impl Into<ChildIndex>, Err>>, ) -> Result<ExtendedKeyPair<E>, Err>
Derives a child key pair with specified derivation path from parent key pair Read more
Source§fn derive_child_key_pair_with_path(
parent_key: &ExtendedKeyPair<E>,
path: impl IntoIterator<Item = impl Into<ChildIndex>>,
) -> ExtendedKeyPair<E>
fn derive_child_key_pair_with_path( parent_key: &ExtendedKeyPair<E>, path: impl IntoIterator<Item = impl Into<ChildIndex>>, ) -> ExtendedKeyPair<E>
Derives a child key pair with specified derivation path from parent key pair Read more
Source§fn try_derive_child_public_key_with_path<Err>(
parent_public_key: &ExtendedPublicKey<E>,
path: impl IntoIterator<Item = Result<NonHardenedIndex, Err>>,
) -> Result<ExtendedPublicKey<E>, Err>
fn try_derive_child_public_key_with_path<Err>( parent_public_key: &ExtendedPublicKey<E>, path: impl IntoIterator<Item = Result<NonHardenedIndex, Err>>, ) -> Result<ExtendedPublicKey<E>, Err>
Derives a child public key with specified derivation path Read more
Source§fn derive_child_public_key_with_path(
parent_public_key: &ExtendedPublicKey<E>,
path: impl IntoIterator<Item = NonHardenedIndex>,
) -> ExtendedPublicKey<E>
fn derive_child_public_key_with_path( parent_public_key: &ExtendedPublicKey<E>, path: impl IntoIterator<Item = NonHardenedIndex>, ) -> ExtendedPublicKey<E>
Derives a child public key with specified derivation path Read more