Key Derivation
StarkWare recommends two methods for starkPrivateKey derivation:
  • BIP32 compatible wallets should implement EIP-2645. In this context, wallets are expected to be stateful of their own Ethereum address.
  • Non BIP32 wallets should implement the methodology presented at the bottom of the current page
The starkKey value derives from a path called starkPath that consists of four passed parameters and two internal parameters as described below, and has the following structure: m/purpose'/layer'/application'/ethAddress1'/ethAddress2'/index

Passed parameters

  • purpose - 2645
  • layer - Differentiate between technologies, defined as sha256(layer) & ((1 << 31) - 1))
  • application - Differentiate applications, defined as sha256(application) & ((1 << 31) - 1))
  • index - Allow multiple keys per Ethereum address

Internal parameters

  • ethAddress1 - 31 LSB of the user ethereum address (i.e. ethAddress & ((1 << 31) - 1))
  • ethAddress2 - 31 following LSB of the user ethereum address (i.e. (ethAddress >> 31) & ((1 << 31) - 1))

Derivation methodology for BIP32 wallets

The implementation details are available in EIP-2645 description.

Derivation methodology for non-BIP32 wallets

1
pk = Ethereum Private Key
2
sign = ECDSA on secp256k1
3
ethAddress1 = ethAddress & ((1 << 31) - 1)
4
ethAddress2 = (ethAddress >> 31 ) & ((1 << 31) - 1)
5
N = secp256k1 curve order
6
n = Layer2 curve order (available in the cryptography section)
7
path = "m/purpose'/layer'/application'/ethAddress1'/ethAddress2'/index"
8
i = 0
9
10
root_key = bip39
11
.fromSecret(pk).derivePath(path)
12
.getWallet()
13
.getPrivateKeyString()
14
while True:
15
key = _hash(root_key.to_bytes(32,byteorder='big') + i.to_bytes(1,byteorder='big'))
16
if (key < (N - (N % n))):
17
return key % n
18
i++
Copied!
Last modified 4mo ago