lssa/nssa/core/src/account/commitment.rs

20 lines
564 B
Rust
Raw Normal View History

2025-08-18 09:21:07 -03:00
use risc0_zkvm::{
serde::to_vec,
sha::{Impl, Sha256},
};
2025-08-18 07:39:41 -03:00
use serde::{Deserialize, Serialize};
use crate::account::{Account, NullifierPublicKey};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
pub struct Commitment([u8; 32]);
2025-08-18 07:39:41 -03:00
impl Commitment {
pub fn new(Npk: &NullifierPublicKey, account: &Account) -> Self {
2025-08-18 09:21:07 -03:00
let mut bytes = Vec::new();
bytes.extend_from_slice(&Npk.to_bytes());
bytes.extend_from_slice(&account.to_bytes());
Self(Impl::hash_bytes(&bytes).as_bytes().try_into().unwrap())
2025-08-18 07:39:41 -03:00
}
}