INNER CODE UNIT · Rust

biguint_to_hex_addr

renegade-fi/renegade · crates/circuits/circuit-types/src/lib.rs:198

pub fn biguint_to_hex_addr<S>(val: &BigUint, s: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
{
    let mut bytes = [0_u8; ADDRESS_BYTE_LENGTH];
    let val_bytes = val.to_bytes_be();

    let len = val_bytes.len();
    debug_assert!(len <= ADDRESS_BYTE_LENGTH, "BigUint too large for an address");

    bytes[ADDRESS_BYTE_LENGTH - val_bytes.len()..].copy_from_slice(&val_bytes);
    let hex_str = hex::encode(bytes);

    s.serialize_str(&format!("0x{hex_str}"))
}

/// A helper to deserialize a BigUint from a hex string
pub fn biguint_from_hex_string<'de, D>(d: D) -> Result<BigUint, D::Error>

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…