Struct Stark

Source
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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<E, S> HdWallet<E> for S
where E: Curve, S: DeriveShift<E>,

Source§

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>

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>

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>

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>

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>

Derives a child public key with specified derivation path Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.