getKeypair function

KeyPair getKeypair(
  1. Uint8List pvKey,
  2. String curve
)

Implementation

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