pub use proto::transaction::DecodedInputNoteCommitment as InputNoteCommitment;
use crate::decoded::VerificationError;
use crate::{BuildUnchecked, Verify, proto};
#[cfg(test)]
mod tests;
impl BuildUnchecked for InputNoteCommitment {
type Output = miden_protocol::transaction::InputNoteCommitment;
type Error = VerificationError;
fn build_unchecked(self) -> Result<Self::Output, Self::Error> {
Ok(Self::Output::from_parts_unchecked(
miden_protocol::note::Nullifier::from_raw(self.nullifier),
self.header.verify()?,
))
}
}
pub use proto::transaction::DecodedPrivateOutputNote as PrivateOutputNote;
impl Verify for PrivateOutputNote {
type Verified = miden_protocol::transaction::PrivateOutputNote;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
Ok(Self::Verified::new(self.header.verify()?, self.attachments.verify()?)?)
}
}
pub use proto::transaction::DecodedPublicOutputNote as PublicOutputNote;
impl Verify for PublicOutputNote {
type Verified = miden_protocol::transaction::PublicOutputNote;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
Ok(Self::Verified::new(self.note.verify()?)?)
}
}
pub use proto::transaction::DecodedOutputNote as OutputNote;
impl Verify for OutputNote {
type Verified = miden_protocol::transaction::OutputNote;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
use proto::transaction::output_note::DecodedNote;
match self.note {
DecodedNote::Public(note) => Ok(Self::Verified::Public(note.verify()?)),
DecodedNote::Private(note) => Ok(Self::Verified::Private(note.verify()?)),
}
}
}
pub use proto::transaction::DecodedAuthenticatedInputNote as AuthenticatedInputNote;
impl Verify for AuthenticatedInputNote {
type Verified = miden_protocol::transaction::InputNote;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
let note = self.note.verify()?;
let (proof_id, proof) = self.proof.verify()?;
if proof_id != note.id() {
return Err(InputNoteError::IdMismatch {
transmitted: proof_id,
decoded: note.id(),
}
.into());
}
Ok(Self::Verified::authenticated(note, proof))
}
}
#[derive(Debug, thiserror::Error)]
pub enum InputNoteError {
#[error("note ID mismatch: transmitted {transmitted}, decoded {decoded}")]
IdMismatch {
transmitted: miden_protocol::note::NoteId,
decoded: miden_protocol::note::NoteId,
},
}
pub use proto::transaction::DecodedInputNote as InputNote;
impl Verify for InputNote {
type Verified = miden_protocol::transaction::InputNote;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
use proto::transaction::input_note::DecodedNote;
match self.note {
DecodedNote::Authenticated(note) => note.verify(),
DecodedNote::Unauthenticated(note) => {
Ok(Self::Verified::unauthenticated(note.verify()?))
},
}
}
}
pub use proto::transaction::DecodedInputNotes as InputNotes;
impl Verify for InputNotes {
type Verified = miden_protocol::transaction::InputNotes<miden_protocol::transaction::InputNote>;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
let notes = self.notes.verify()?;
Ok(Self::Verified::new(notes)?)
}
}
pub use proto::transaction::DecodedRawOutputNote as RawOutputNote;
impl Verify for RawOutputNote {
type Verified = miden_protocol::transaction::RawOutputNote;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
use proto::transaction::raw_output_note::DecodedNote;
match self.note {
DecodedNote::Full(note) => Ok(Self::Verified::Full(note.verify()?)),
DecodedNote::Partial(note) => Ok(Self::Verified::Partial(note.verify()?)),
}
}
}
pub use proto::transaction::DecodedRawOutputNotes as RawOutputNotes;
impl Verify for RawOutputNotes {
type Verified = miden_protocol::transaction::RawOutputNotes;
type Error = VerificationError;
fn verify(self) -> Result<Self::Verified, Self::Error> {
Ok(Self::Verified::new(self.notes.verify()?)?)
}
}