Skip to content

Commit

Permalink
impl Felt.to_biguint() method
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana committed Dec 18, 2023
1 parent 0491cdc commit 8a86316
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions crates/starknet-types-core/src/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ impl Felt {
pub fn bits(&self) -> usize {
self.0.representative().bits_le()
}

pub fn to_biguint(&self) -> BigUint {
let big_digits = self
.to_le_digits()
.into_iter()
.flat_map(|limb| [limb as u32, (limb >> 32) as u32])
.collect();
BigUint::new(big_digits)
}
}

#[cfg(feature = "arbitrary")]
Expand Down Expand Up @@ -824,17 +833,8 @@ mod arithmetic {
}
}

pub fn felt_to_biguint(felt: Felt) -> BigUint {
let big_digits = felt
.to_le_digits()
.into_iter()
.flat_map(|limb| [limb as u32, (limb >> 32) as u32])
.collect();
BigUint::new(big_digits)
}

pub fn felt_to_bigint(felt: Felt) -> BigInt {
felt_to_biguint(felt).to_bigint().unwrap()
felt.to_biguint().to_bigint().unwrap()
}

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -1697,7 +1697,7 @@ mod test {
);

assert_eq!(
felt_to_biguint(Felt::from_hex(number_str).unwrap()),
Felt::from_hex(number_str).unwrap().to_biguint(),
BigUint::from_str_radix(&number_str[2..], 16).unwrap()
);
}
Expand Down

0 comments on commit 8a86316

Please sign in to comment.