majin-blob-core 0.1.3

A minimalistic Rust library for working with Starknet blobs.
Documentation
use num_bigint::BigUint;
use num_traits::Num;

use crate::math::ifft;
use majin_blob_eip_4844::{BLOB_LEN, BLS_MODULUS, GENERATOR};

/// Recovers the original data from a given blob.
///
/// This function takes a vector of `BigUint` representing the data of a blob and
/// returns the recovered original data as a vector of `BigUint`.
///
/// # Arguments
///
/// * `data` - A vector of `BigUint` representing the blob data.
///
/// # Returns
///
/// A vector of `BigUint` representing the recovered original data.
pub fn recover(data: Vec<BigUint>) -> Vec<BigUint> {
    let xs: Vec<BigUint> = (0..BLOB_LEN)
        .map(|i| {
            let bin = format!("{:012b}", i);
            let bin_rev = bin.chars().rev().collect::<String>();
            GENERATOR.modpow(&BigUint::from_str_radix(&bin_rev, 2).unwrap(), &BLS_MODULUS)
        })
        .collect();

    ifft(data, xs, &BLS_MODULUS)
}