pub fn publickey_from_secretkey(secret_key_int: &BigInt, curve: Curve) -> Result<String, ()> {
    if curve == Curve::Secp256k1 {
        let secret_key = match ECScalar::from(secret_key_int) {
            Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
            Err(_) => return Err(()),
        };
        let base: Secp256k1Point = ECPoint::generator();
        let pk = match base * secret_key.deref() {
            Ok(v) => v,
            Err(_) => return Err(()),
        };
        publickey_from_secretkey_r1(&pk)
    } else if curve == Curve::Secp256r1 {
        let secret_key = match ECScalar::from(secret_key_int) {
            Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
            Err(_) => return Err(()),
        };
        let pk = match Secp256r1Point::generator() * secret_key.deref() {
            Ok(v) => v,
            Err(_) => return Err(()),
        };
        let tmp = AffinePoint_p256::from_encoded_point(&EncodedPoint_p256::from(&pk.ge));
        if bool::from(tmp.is_none()) {
            return Err(());
        }
        // add leading zeros if necessary
        Ok(format!(
            "{:0>130}",
            BigInt::from_bytes(&tmp.unwrap().to_encoded_point(false).as_bytes()).to_hex()
        ))
    } else {
        Err(())
    }
}
/// derive public key from secret key, in uncompressed format as expected by ME
derive public key from secret key, in uncompressed format as expected by ME
derive public key from secret key in uncompressed format as expected by ME
pub fn publickey_from_secretkey(secret_key_int: &BigInt, curve: Curve) -> Result<String, ()> {
    if curve == Curve::Secp256k1 {
        let secret_key = match ECScalar::from(secret_key_int) {
            Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
            Err(_) => return Err(()),
        };
        let base: Secp256k1Point = ECPoint::generator();
        let pk = match base * secret_key.deref() {
            Ok(v) => v,
            Err(_) => return Err(()),
        };
        publickey_from_secretkey_r1(&pk)
    } else if curve == Curve::Secp256r1 {
        let secret_key = match ECScalar::from(secret_key_int) {
            Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
            Err(_) => return Err(()),
        };
        let pk = match Secp256r1Point::generator() * secret_key.deref() {
            Ok(v) => v,
            Err(_) => return Err(()),
        };
        let tmp = AffinePoint_p256::from_encoded_point(&EncodedPoint_p256::from(&pk.ge));
        if bool::from(tmp.is_none()) {
            return Err(());
        }
        // add leading zeros if necessary
        Ok(format!(
            "{:0>130}",
            BigInt::from_bytes(&tmp.unwrap().to_encoded_point(false).as_bytes()).to_hex()
        ))
    } else {
        Err(())
    }
}
pub fn publickey_from_secretkey ( secret_key_int : & BigInt , curve : Curve ) -> Result < String , ( ) > { if curve == Curve :: Secp256k1 { let secret_key = match ECScalar :: from ( secret_key_int ) { Ok ( v ) => Zeroizing :: < Secp256k1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; let base : Secp256k1Point = ECPoint :: generator ( ) ; let pk = match base * secret_key . deref ( ) { Ok ( v ) => v , Err ( _ ) => return Err ( ( ) ) , } ; publickey_from_secretkey_r1 ( & pk ) } else if curve == Curve :: Secp256r1 { let secret_key = match ECScalar :: from ( secret_key_int ) { Ok ( v ) => Zeroizing :: < Secp256r1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; let pk = match Secp256r1Point :: generator ( ) * secret_key . deref ( ) { Ok ( v ) => v , Err ( _ ) => return Err ( ( ) ) , } ; let tmp = AffinePoint_p256 :: from_encoded_point ( & EncodedPoint_p256 :: from ( & pk . ge ) ) ; if bool :: from ( tmp . is_none ( ) ) { return Err ( ( ) ) ; } // add leading zeros if necessary Ok ( format ! ( " " BigInt from_bytes ( tmp unwrap ( ) to_encoded_point ( false ) as_bytes ( ) ) to_hex ( ) ) ) } else { Err ( ( ) ) } }
derive public key from secret key, in uncompressed format as expected by ME
derive public key from secret key in uncompressed format as expected by ME
secret_key_int
&BigInt
curve
Curve