Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

How to read G1Affine/G2Affine from compressed bytes #17

Open
@webmaster128

Description

@webmaster128

Heyho! Thanks for building this library. I successfully built a drand verifier on top of it.

However, I wonder what the proper way to create G1Affine/G2Affine from the compressed point serialization is? The following works for me

use paired::bls12_381::{G1Affine, G1Compressed, G2Affine, G2Compressed};
use paired::EncodedPoint;

pub fn g1_from_variable(data: &[u8]) -> G1Affine {
    if data.len() != G1Compressed::size() {
        panic!("Invalid length");
    }

    let mut buf = [0u8; 48];
    for i in 0..48 {
        buf[i] = data[i];
    }
    g1_from_fixed(buf)
}

pub fn g1_from_fixed(data: [u8; 48]) -> G1Affine {
    G1Compressed(data).into_affine().unwrap()
}

pub fn g2_from_variable(data: &[u8]) -> G2Affine {
    if data.len() != G2Compressed::size() {
        panic!("Invalid length");
    }

    let mut buf = [0u8; 96];
    for i in 0..96 {
        buf[i] = data[i];
    }
    g2_from_fixed(buf)
}

pub fn g2_from_fixed(data: [u8; 96]) -> G2Affine {
    G2Compressed(data).into_affine().unwrap()
}

but it requires to make the field in G1Compressed/G2Compressed. So far I avoided looking into serde_impl since this appears to be too simple to require serde. Am I missing something? Is there a better way to do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions