1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use js_export_macro::js_export;
use miden_client::note::{Note as NativeNote, NoteInclusionProof as NativeNoteInclusionProof};
use miden_client::transaction::InputNote as NativeInputNote;
use super::note::Note;
use super::note_id::NoteId;
use super::note_inclusion_proof::NoteInclusionProof;
use super::note_location::NoteLocation;
use super::word::Word;
/// Note supplied as an input to a transaction, optionally with authentication data.
#[derive(Clone)]
#[js_export]
pub struct InputNote(pub(crate) NativeInputNote);
#[js_export]
impl InputNote {
/// Creates an authenticated input note from a note and its inclusion proof.
///
/// An authenticated note has a proof of inclusion in the block's note tree,
/// which is required for consuming the note in a transaction.
pub fn authenticated(note: &Note, inclusion_proof: &NoteInclusionProof) -> InputNote {
let native_note: NativeNote = note.into();
let native_proof: NativeNoteInclusionProof = inclusion_proof.clone().into();
InputNote(NativeInputNote::authenticated(native_note, native_proof))
}
/// Creates an unauthenticated input note from note details.
///
/// An unauthenticated note can be consumed in a transaction as long as the note exists in the
/// network as of the transaction batch in which the consume transaction is included.
pub fn unauthenticated(note: &Note) -> InputNote {
InputNote(NativeInputNote::unauthenticated(note.clone().into()))
}
/// Returns the identifier of the input note.
pub fn id(&self) -> NoteId {
self.0.id().into()
}
/// Returns the underlying note contents.
pub fn note(&self) -> Note {
self.0.note().into()
}
/// Returns the commitment to the note (its ID).
///
/// Migration note (miden-client PR #2214): `Note::commitment()` was
/// removed on the 0.15 surface — the note ID *is* the commitment (it
/// hashes details + metadata). Return the underlying `NoteId` as a
/// `Word` so the JS API contract is unchanged.
pub fn commitment(&self) -> Word {
self.0.note().id().as_word().into()
}
/// Returns the inclusion proof if the note is authenticated.
pub fn proof(&self) -> Option<NoteInclusionProof> {
self.0.proof().map(Into::into)
}
/// Returns the note's location within the commitment tree when available.
pub fn location(&self) -> Option<NoteLocation> {
self.0.location().map(Into::into)
}
}
// CONVERSIONS
// ================================================================================================
impl From<NativeInputNote> for InputNote {
fn from(native_note: NativeInputNote) -> Self {
InputNote(native_note)
}
}
impl From<&NativeInputNote> for InputNote {
fn from(native_note: &NativeInputNote) -> Self {
InputNote(native_note.clone())
}
}