majin_blob_core/blob.rs
1use num_bigint::BigUint;
2use num_traits::Num;
3
4use crate::math::ifft;
5use majin_blob_eip_4844::{BLOB_LEN, BLS_MODULUS, GENERATOR};
6
7/// Recovers the original data from a given blob.
8///
9/// This function takes a vector of `BigUint` representing the data of a blob and
10/// returns the recovered original data as a vector of `BigUint`.
11///
12/// # Arguments
13///
14/// * `data` - A vector of `BigUint` representing the blob data.
15///
16/// # Returns
17///
18/// A vector of `BigUint` representing the recovered original data.
19pub fn recover(data: Vec<BigUint>) -> Vec<BigUint> {
20 let xs: Vec<BigUint> = (0..BLOB_LEN)
21 .map(|i| {
22 let bin = format!("{:012b}", i);
23 let bin_rev = bin.chars().rev().collect::<String>();
24 GENERATOR.modpow(&BigUint::from_str_radix(&bin_rev, 2).unwrap(), &BLS_MODULUS)
25 })
26 .collect();
27
28 ifft(data, xs, &BLS_MODULUS)
29}