Skip to main content
Version: 11.x

Function: randomStarkPrivateKey()

randomStarkPrivateKey(): string

Defined in: src/utils/stark/index.ts:163

Random private key of the Stark curve.

A private key is an integer in the range [1, n), n being the order of the Stark curve : 3618502788666131213697322783095070105526743751716087489154079457884512865583. This range is slightly narrower than the range of a felt, so a random felt is not always a usable private key : always create a key with this function.

Returns

string

an hex string of a random private key, always 32 bytes long

Example

const privateKey = stark.randomStarkPrivateKey();
// privateKey = "0x0051fc8126a13cd5ddb29a71ca399cb1e814f086f5af1b502d7151c14929554f"
const publicKey = ec.starkCurve.getStarkKey(privateKey);