I am trying to generate a Starknet public key from the private key that i get from the provider after logging in — but I get an error that suggests that the private key too large
SDK/Platform: Web3Auth Plug n Play (likely Web SDK, but please confirm if it’s React Native, Web, or another platform).
What’s Happening?
Starknet uses a specific elliptic curve (Stark curve), which has a much smaller valid private key range than secp256k1 (used by EVM chains). The private key you receive from Web3Auth might be a random 32-byte value, which can sometimes be out of Starknet’s valid range.
Next Steps & Suggestions
Check How You’re Deriving the Starknet Key:
You should use the private key from Web3Auth as entropy to derive a valid Starknet private key, not use it directly.
Use a hash function (e.g., SHA-256) to hash the Web3Auth private key, then mod it by the Starknet curve order to ensure it falls within the valid range.
Example (pseudo-code):
import { ec as starkEc } from "starknet";
import { keccak256 } from "js-sha3";
const rawPrivKey = await web3authProvider.request({ method: "private_key" });
// Hash the private key
const hashedPrivKey = keccak256(rawPrivKey);
// Modulo with Stark curve order to ensure it's in range
const starkCurveOrder = "3618502788666131213697322783095070105526743751716087489154079457884512865583";
const validPrivKey = BigInt("0x" + hashedPrivKey) % BigInt(starkCurveOrder);
// Use validPrivKey to generate Starknet keypair
const keyPair = starkEc.getKeyPair(validPrivKey.toString(16));
This ensures your key is always valid for Starknet.
If possible, share your key derivation code snippet so we can provide more targeted help.
Confirm the SDK/platform you’re using (Web, React Native, etc.) for more precise guidance.
Let us know if this helps or if you need further clarification!
Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.
Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours