feat(bls): aiken level g1 and g2 literals

This commit is contained in:
rvcas
2023-11-06 22:58:21 -05:00
committed by Lucas
parent 90aea6476a
commit 3675762c3e
10 changed files with 397 additions and 47 deletions

View File

@@ -1,4 +1,5 @@
use chumsky::prelude::*;
use uplc::machine::runtime::Compressable;
use crate::{
ast,
@@ -45,14 +46,37 @@ pub fn value() -> impl Parser<Token, ast::Constant, Error = ParseError> {
base,
});
let constant_bytearray_parser =
literal::bytearray(
|bytes, preferred_format, location| ast::Constant::ByteArray {
let constant_bytearray_parser = literal::bytearray(
|bytes, preferred_format, curve, location, emit| match curve {
Some(curve @ ast::CurveType::Bls12_381(point)) => {
let point = match point {
ast::Bls12_381PointType::G1 => {
blst::blst_p1::uncompress(&bytes).map(ast::Bls12_381Point::G1)
}
ast::Bls12_381PointType::G2 => {
blst::blst_p2::uncompress(&bytes).map(ast::Bls12_381Point::G2)
}
};
let point = point.unwrap_or_else(|_err| {
emit(ParseError::point_not_on_curve(curve, location));
ast::Bls12_381Point::default()
});
ast::Constant::CurvePoint {
location,
point: ast::Curve::Bls12_381(point),
preferred_format,
}
}
None => ast::Constant::ByteArray {
location,
bytes,
preferred_format,
},
);
},
);
choice((
constant_string_parser,