miden_objects/decoded/transaction/
notes.rs1pub use proto::transaction::DecodedInputNoteCommitment as InputNoteCommitment;
2
3use crate::decoded::VerificationError;
4use crate::{BuildUnchecked, Verify, proto};
5
6#[cfg(test)]
7mod tests;
8
9impl BuildUnchecked for InputNoteCommitment {
13 type Output = miden_protocol::transaction::InputNoteCommitment;
14 type Error = VerificationError;
15 fn build_unchecked(self) -> Result<Self::Output, Self::Error> {
16 Ok(Self::Output::from_parts_unchecked(
17 miden_protocol::note::Nullifier::from_raw(self.nullifier),
18 self.header.map(Verify::verify).transpose()?,
19 ))
20 }
21}
22
23pub use proto::transaction::DecodedPrivateOutputNote as PrivateOutputNote;
24
25impl Verify for PrivateOutputNote {
26 type Verified = miden_protocol::transaction::PrivateOutputNote;
27 type Error = VerificationError;
28 fn verify(self) -> Result<Self::Verified, Self::Error> {
29 Ok(Self::Verified::new(self.header.verify()?, self.attachments.verify()?)?)
30 }
31}
32
33pub use proto::transaction::DecodedPublicOutputNote as PublicOutputNote;
34
35impl Verify for PublicOutputNote {
36 type Verified = miden_protocol::transaction::PublicOutputNote;
37 type Error = VerificationError;
38 fn verify(self) -> Result<Self::Verified, Self::Error> {
39 Ok(Self::Verified::new(self.note.verify()?)?)
40 }
41}
42
43pub use proto::transaction::DecodedOutputNote as OutputNote;
44
45impl Verify for OutputNote {
46 type Verified = miden_protocol::transaction::OutputNote;
47 type Error = VerificationError;
48 fn verify(self) -> Result<Self::Verified, Self::Error> {
49 use proto::transaction::output_note::DecodedNote;
50 match self.note {
51 DecodedNote::Public(note) => Ok(Self::Verified::Public(note.verify()?)),
52 DecodedNote::Private(note) => Ok(Self::Verified::Private(note.verify()?)),
53 }
54 }
55}
56
57pub use proto::transaction::DecodedAuthenticatedInputNote as AuthenticatedInputNote;
58
59impl Verify for AuthenticatedInputNote {
61 type Verified = miden_protocol::transaction::InputNote;
62 type Error = VerificationError;
63 fn verify(self) -> Result<Self::Verified, Self::Error> {
64 let note = self.note.verify()?;
65 let (proof_id, proof) = self.proof.verify()?;
66 if proof_id != note.id() {
67 return Err(InputNoteError::IdMismatch {
68 transmitted: proof_id,
69 decoded: note.id(),
70 }
71 .into());
72 }
73 Ok(Self::Verified::authenticated(note, proof))
74 }
75}
76
77#[derive(Debug, thiserror::Error)]
78pub enum InputNoteError {
79 #[error("note ID mismatch: transmitted {transmitted}, decoded {decoded}")]
80 IdMismatch {
81 transmitted: miden_protocol::note::NoteId,
82 decoded: miden_protocol::note::NoteId,
83 },
84}
85
86pub use proto::transaction::DecodedInputNote as InputNote;
87
88impl Verify for InputNote {
89 type Verified = miden_protocol::transaction::InputNote;
90 type Error = VerificationError;
91 fn verify(self) -> Result<Self::Verified, Self::Error> {
92 use proto::transaction::input_note::DecodedNote;
93 match self.note {
94 DecodedNote::Authenticated(note) => note.verify(),
95 DecodedNote::Unauthenticated(note) => {
96 Ok(Self::Verified::unauthenticated(note.verify()?))
97 },
98 }
99 }
100}
101
102pub use proto::transaction::DecodedInputNotes as InputNotes;
103
104impl Verify for InputNotes {
105 type Verified = miden_protocol::transaction::InputNotes<miden_protocol::transaction::InputNote>;
106 type Error = VerificationError;
107 fn verify(self) -> Result<Self::Verified, Self::Error> {
108 let notes = self.notes.into_iter().map(Verify::verify).collect::<Result<_, _>>()?;
109 Ok(Self::Verified::new(notes)?)
110 }
111}