fromSecretKey static method
Create a keypair from a raw secret key byte array.
Throw error if the provided secret key is invalid and validation is not skipped.
Implementation
static Secp256k1Keypair fromSecretKey(
Uint8List secretKey,
{ bool? skipValidation }
) {
Uint8List publicKey = secp256k1.getPublicKeyFromPrivateKeyBytes(secretKey, false);
if (skipValidation == null || !skipValidation) {
final signData = utf8.encode('sui validation');
final msgHash = sha256(signData);
final signature = secp256k1.sign(msgHash, secretKey);
if (!secp256k1.verifySignature(msgHash, signature, publicKey)) {
throw ArgumentError('Invalid private key.');
}
}
return Secp256k1Keypair(Secp256KeypairData(publicKey, secretKey));
}