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 Secp256r1Keypair fromSecretKey(
Uint8List secretKey,
{ bool? skipValidation }
) {
Uint8List publicKey = secp256r1.getPublicKeyFromPrivateKeyBytes(secretKey, false);
if (skipValidation == null || !skipValidation) {
final signData = utf8.encode('sui validation');
final msgHash = sha256(signData);
final signature = secp256r1.sign(msgHash, secretKey);
if (!secp256r1.verifySignature(msgHash, signature, publicKey)) {
throw ArgumentError('Invalid private key.');
}
}
return Secp256r1Keypair(Secp256KeypairData(publicKey, secretKey));
}