getKeypair function
Implementation
KeyPair getKeypair(Uint8List pvKey, String curve) {
switch (curve) {
case 'ed25519':
final signingKey = ed25519.SigningKey(seed: pvKey);
final pubBuf = signingKey.publicKey.toUint8List();
return KeyPair(privateKey: pvKey, publicKey: pubBuf);
case 'P256':
final ec = elliptic.getP256();
final privateKey = elliptic.PrivateKey.fromBytes(ec, pvKey);
final publicKey = ec.privateToPublicKey(privateKey);
return KeyPair(
privateKey: pvKey,
publicKey: hexToUint8List(publicKey.toHex()),
);
case 'secp256k1':
final ec = elliptic.getSecp256k1();
final privateKey = elliptic.PrivateKey.fromBytes(ec, pvKey);
final publicKey = ec.privateToPublicKey(privateKey);
return KeyPair(
privateKey: pvKey,
publicKey: hexToUint8List(publicKey.toHex()),
);
default:
throw 'Curve not supported';
}
}