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 exception for invalid seckeys that do not pass validation.
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 exception for invalid seckeys that do not pass validation.
Implementation
// static Future<Keypair> fromSeckey(
// final Uint8List seckey, {
// final bool skipValidation = false,
// }) =>
// compute(
// (_) => Keypair.fromSeckeySync(seckey, skipValidation: skipValidation),
// null);
/// {@template Keypair.fromSeckeySync}
/// 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 exception for invalid [seckey]s that do not pass validation.
/// {@endtemplate}
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 Exception('Invalid secret key.');
}
}
return Keypair(keypair);
}