Skip to main content

miden_node_proto/domain/
nullifier.rs

1use miden_protocol::Word;
2use miden_protocol::crypto::merkle::smt::SmtProof;
3use miden_protocol::note::Nullifier;
4
5use crate::decode::GrpcDecodeExt;
6use crate::errors::ConversionError;
7use crate::{decode, generated as proto};
8
9// FROM NULLIFIER
10// ================================================================================================
11
12impl From<&Nullifier> for proto::primitives::Digest {
13    fn from(value: &Nullifier) -> Self {
14        value.as_word().into()
15    }
16}
17
18impl From<Nullifier> for proto::primitives::Digest {
19    fn from(value: Nullifier) -> Self {
20        value.as_word().into()
21    }
22}
23
24// INTO NULLIFIER
25// ================================================================================================
26
27impl TryFrom<proto::primitives::Digest> for Nullifier {
28    type Error = ConversionError;
29
30    fn try_from(value: proto::primitives::Digest) -> Result<Self, Self::Error> {
31        let digest: Word = value.try_into()?;
32        Ok(Nullifier::from_raw(digest))
33    }
34}
35
36// NULLIFIER WITNESS RECORD
37// ================================================================================================
38
39#[derive(Clone, Debug)]
40pub struct NullifierWitnessRecord {
41    pub nullifier: Nullifier,
42    pub proof: SmtProof,
43}
44
45impl TryFrom<proto::store::block_inputs::NullifierWitness> for NullifierWitnessRecord {
46    type Error = ConversionError;
47
48    fn try_from(
49        nullifier_witness_record: proto::store::block_inputs::NullifierWitness,
50    ) -> Result<Self, Self::Error> {
51        let decoder = nullifier_witness_record.decoder();
52        Ok(Self {
53            nullifier: decode!(decoder, nullifier_witness_record.nullifier)?,
54            proof: decode!(decoder, nullifier_witness_record.opening)?,
55        })
56    }
57}
58
59impl From<NullifierWitnessRecord> for proto::store::block_inputs::NullifierWitness {
60    fn from(value: NullifierWitnessRecord) -> Self {
61        Self {
62            nullifier: Some(value.nullifier.into()),
63            opening: Some(value.proof.into()),
64        }
65    }
66}