miden_objects/decoded/
note_file.rs1use miden_protobuf::unwrap_infallible;
4use miden_protocol::note::NoteId;
5pub use proto::note_file::DecodedNoteSyncHint as NoteSyncHint;
6
7use crate::decoded::VerificationError;
8use crate::{Verify, proto};
9
10#[cfg(test)]
11pub(crate) mod test_utils;
12#[cfg(test)]
13mod tests;
14
15impl Verify for NoteSyncHint {
16 type Verified = crate::note_file::NoteSyncHint;
17 type Error = core::convert::Infallible;
18 fn verify(self) -> Result<Self::Verified, Self::Error> {
19 Ok(Self::Verified::new(
20 unwrap_infallible(self.after_block_num.verify()),
21 miden_protocol::note::NoteTag::new(self.tag),
22 ))
23 }
24}
25
26pub use proto::note_file::DecodedExpectedNote as ExpectedNote;
27
28impl Verify for ExpectedNote {
29 type Verified = crate::note_file::NoteFile;
30 type Error = VerificationError;
31 fn verify(self) -> Result<Self::Verified, Self::Error> {
32 Ok(Self::Verified::ExpectedNote {
33 details: self.details.verify()?,
34 sync_hint: unwrap_infallible(self.sync_hint.verify()),
35 })
36 }
37}
38
39pub use proto::note_file::DecodedCommittedNote as CommittedNote;
40
41impl Verify for CommittedNote {
42 type Verified = crate::note_file::NoteFile;
43 type Error = VerificationError;
44 fn verify(self) -> Result<Self::Verified, Self::Error> {
45 let note = self.note.verify()?;
46 let (proof_note_id, proof) = self.proof.verify()?;
47 if proof_note_id != note.id() {
48 return Err(CommittedNoteError::InclusionProofNoteIdMismatch {
49 note_id: note.id(),
50 proof_note_id,
51 }
52 .into());
53 }
54 Ok(Self::Verified::Committed { note, proof })
55 }
56}
57
58#[derive(Debug, thiserror::Error)]
59pub enum CommittedNoteError {
60 #[error("inclusion proof commits to note ID {proof_note_id} but the note's ID is {note_id}")]
61 InclusionProofNoteIdMismatch { note_id: NoteId, proof_note_id: NoteId },
62}
63
64pub use proto::note_file::DecodedNoteFile as NoteFile;
65
66impl Verify for NoteFile {
67 type Verified = crate::note_file::NoteFile;
68 type Error = VerificationError;
69 fn verify(self) -> Result<Self::Verified, Self::Error> {
70 match self.version {
71 proto::note_file::note_file::DecodedVersion::V1(file) => file.verify(),
72 }
73 }
74}
75
76pub use proto::note_file::DecodedNoteFileV1 as NoteFileV1;
77
78impl Verify for NoteFileV1 {
79 type Verified = crate::note_file::NoteFile;
80 type Error = VerificationError;
81 fn verify(self) -> Result<Self::Verified, Self::Error> {
82 use proto::note_file::note_file_v1::DecodedVariant;
83
84 match self.variant {
85 DecodedVariant::NoteId(note_id) => {
86 Ok(Self::Verified::NoteId(unwrap_infallible(note_id.verify())))
87 },
88 DecodedVariant::ExpectedNote(note) => note.verify(),
89 DecodedVariant::CommittedNote(note) => note.verify(),
90 }
91 }
92}