Secp256k1 private key
To retrieve the secp256k1 private key of the user, use getPrivateKey method. The method returns an EVM compatible private key which can be used to sign transactions on EVM compatible chains.
note
Web3Auth supports two widely used cryptographic curves, Secp256k1 and Ed25519, making it chain-agnostic and compatible with multiple blockchain networks. Learn more about how to connect different blockchains.
Session behavior
- After
initialize()orconnectTo()completes successfully,getPrivateKey()returns the private key. - If no session has been restored or created on this
Web3Authinstance,getPrivateKey()returns an empty string (""). - After
logout(), or if the session has no key of the requested type,getPrivateKey()throwsIllegalStateException(No valid private key found). - If
useSFAKey = trueinWeb3AuthOptions, this method returns the SFA core kit key (coreKitKey) instead of the standard secp256k1 key.
Track whether the user is signed in from the results of initialize(), connectTo(), and logout(), rather than by probing the key.
Usage
val initializeCF = web3Auth.initialize()
initializeCF.whenComplete { _, error ->
if (error == null) {
// Active session restored
val privateKey = web3Auth.getPrivateKey()
} else {
// No active session, prompt the user to sign in
}
}