silent_payments_psbt/output.rs
1//! Result type from PSBT Silent Payment output extraction.
2//!
3//! [`ExtractedSpOutput`] contains the computed P2TR script, x-only public key,
4//! output index, and scan public key for wallet mapping after the
5//! [`SpPsbtExtractor`](crate::roles::SpPsbtExtractor) computes SP outputs.
6
7use bitcoin::secp256k1::{PublicKey, XOnlyPublicKey};
8use bitcoin::ScriptBuf;
9
10/// A Silent Payment output extracted from a PSBT after ECDH share aggregation.
11///
12/// Contains everything a wallet needs to assemble the final transaction:
13/// - The computed P2TR script for the output
14/// - The x-only public key embedded in the script
15/// - The PSBT output index this corresponds to
16/// - The recipient's scan public key for wallet-side mapping
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct ExtractedSpOutput {
19 script_pubkey: ScriptBuf,
20 x_only_pubkey: XOnlyPublicKey,
21 output_index: usize,
22 scan_pubkey: PublicKey,
23}
24
25impl ExtractedSpOutput {
26 /// Create a new extracted output with all required fields.
27 pub fn new(
28 script_pubkey: ScriptBuf,
29 x_only_pubkey: XOnlyPublicKey,
30 output_index: usize,
31 scan_pubkey: PublicKey,
32 ) -> Self {
33 Self {
34 script_pubkey,
35 x_only_pubkey,
36 output_index,
37 scan_pubkey,
38 }
39 }
40
41 /// The computed P2TR script for this output.
42 pub fn script_pubkey(&self) -> &ScriptBuf {
43 &self.script_pubkey
44 }
45
46 /// The x-only public key embedded in the P2TR output.
47 pub fn x_only_pubkey(&self) -> XOnlyPublicKey {
48 self.x_only_pubkey
49 }
50
51 /// The PSBT output index this extracted output corresponds to.
52 pub fn output_index(&self) -> usize {
53 self.output_index
54 }
55
56 /// The recipient's scan public key, for wallet-side recipient mapping.
57 pub fn scan_pubkey(&self) -> &PublicKey {
58 &self.scan_pubkey
59 }
60}