mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-11 16:41:29 +01:00
feat: add from_elements to NodeIndex
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::RpoDigest;
|
||||
use super::{Felt, MerkleError, RpoDigest, StarkField};
|
||||
|
||||
// NODE INDEX
|
||||
// ================================================================================================
|
||||
@@ -19,6 +19,18 @@ impl NodeIndex {
|
||||
Self { depth, value }
|
||||
}
|
||||
|
||||
/// Creates a node index from a pair of field elements representing the depth and value.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Will error if the `u64` representation of the depth doesn't fit a `u8`.
|
||||
pub fn from_elements(depth: &Felt, value: &Felt) -> Result<Self, MerkleError> {
|
||||
let depth = depth.as_int();
|
||||
let depth = u8::try_from(depth).map_err(|_| MerkleError::DepthTooBig(depth))?;
|
||||
let value = value.as_int();
|
||||
Ok(Self::new(depth, value))
|
||||
}
|
||||
|
||||
/// Creates a new node index pointing to the root of the tree.
|
||||
pub const fn root() -> Self {
|
||||
Self { depth: 0, value: 0 }
|
||||
|
||||
Reference in New Issue
Block a user