fn try_from()

in akd_client/src/ecvrf.rs [62:97]


    fn try_from(bytes: &[u8]) -> Result<VRFPublicKey, Self::Error> {
        if bytes.len() != ed25519_dalek::PUBLIC_KEY_LENGTH {
            return Err(VerificationError::build(
                Some(VerificationErrorType::Vrf),
                Some("Wrong length".to_string()),
            ));
        }

        let mut bits: [u8; 32] = [0u8; 32];
        bits.copy_from_slice(&bytes[..32]);

        let compressed = curve25519_dalek::edwards::CompressedEdwardsY(bits);
        let point = compressed.decompress().ok_or_else(|| {
            VerificationError::build(
                Some(VerificationErrorType::Vrf),
                Some("Deserialization failed".to_string()),
            )
        })?;

        // Check if the point lies on a small subgroup. This is required
        // when using curves with a small cofactor (in ed25519, cofactor = 8).
        if point.is_small_order() {
            return Err(crate::VerificationError::build(
                Some(VerificationErrorType::Vrf),
                Some("Small subgroup".to_string()),
            ));
        }

        match ed25519_PublicKey::from_bytes(bytes) {
            Ok(result) => Ok(VRFPublicKey(result)),
            Err(sig_err) => Err(VerificationError::build(
                Some(VerificationErrorType::Vrf),
                Some(format!("Signature error {}", sig_err)),
            )),
        }
    }