Keypair.fromSeckeySync constructor
Creates a Keypair from a seckey
byte array.
This method should only be used to recreate a keypair from a previously generated seckey
.
Generating keypairs from a random seed should be done with the Keypair.fromSeedSync method.
Throws a KeypairException for invalid seckey
s that do not pass validation.
Implementation
factory Keypair.fromSeckeySync(
final Uint8List seckey, {
final bool skipValidation = false,
}) {
final Ed25519Keypair keypair = nacl.sign.keypair.fromSeckeySync(seckey);
if (!skipValidation) {
const String message = 'solana/web3.dart';
final Uint8List signData = Uint8List.fromList(utf8.encode(message));
final Uint8List signature =
nacl.sign.detached.sync(signData, keypair.seckey);
if (!nacl.sign.detached.verifySync(signData, signature, keypair.pubkey)) {
throw const KeypairException('Invalid secret key.');
}
}
return Keypair(keypair);
}