25
25
//! commitments.
26
26
27
27
use amplify:: Slice32 ;
28
- use bitcoin:: util:: taproot:: TaprootMerkleBranch ;
29
28
use bitcoin_scripts:: taproot:: DfsPath ;
30
29
use strict_encoding:: { StrictDecode , StrictEncode } ;
31
30
@@ -93,7 +92,7 @@ impl ProprietaryKeyTapret for ProprietaryKey {}
93
92
94
93
/// Errors processing tapret-related proprietary PSBT keys and their values.
95
94
#[ derive(
96
- Copy , Clone , Ord , PartialOrd , Eq , PartialEq , Hash , Debug , Display , Error
95
+ Copy , Clone , Ord , PartialOrd , Eq , PartialEq , Hash , Debug , Display , Error , From
97
96
) ]
98
97
#[ display( doc_comments) ]
99
98
pub enum TapretKeyError {
@@ -104,6 +103,10 @@ pub enum TapretKeyError {
104
103
/// the output is not marked to host tapret commitments. Please first set
105
104
/// PSBT_OUT_TAPRET_HOST flag.
106
105
TapretProhibited ,
106
+
107
+ /// The key contains invalid value
108
+ #[ from( strict_encoding:: Error ) ]
109
+ InvalidKeyValue ,
107
110
}
108
111
109
112
/// Error decoding [`DfsPath`] inside PSBT data
@@ -189,8 +192,8 @@ impl Output {
189
192
}
190
193
191
194
/// Assigns value of the tapreturn commitment to this PSBT output, by
192
- /// adding [`PSBT_OUT_TAPRET_COMMITMENT`] proprietary key containing the
193
- /// 32-byte commitment as its value .
195
+ /// adding [`PSBT_OUT_TAPRET_COMMITMENT`] and [`PSBT_OUT_TAPRET_PROOF`]
196
+ /// proprietary keys containing the 32-byte commitment as its proof .
194
197
///
195
198
/// # Errors
196
199
///
@@ -201,6 +204,7 @@ impl Output {
201
204
pub fn set_tapret_commitment (
202
205
& mut self ,
203
206
commitment : impl Into < [ u8 ; 32 ] > ,
207
+ proof : & impl StrictEncode ,
204
208
) -> Result < ( ) , TapretKeyError > {
205
209
if !self . is_tapret_host ( ) {
206
210
return Err ( TapretKeyError :: TapretProhibited ) ;
@@ -215,6 +219,9 @@ impl Output {
215
219
commitment. into ( ) . to_vec ( ) ,
216
220
) ;
217
221
222
+ self . proprietary
223
+ . insert ( ProprietaryKey :: tapret_proof ( ) , proof. strict_serialize ( ) ?) ;
224
+
218
225
Ok ( ( ) )
219
226
}
220
227
@@ -238,8 +245,18 @@ impl Output {
238
245
/// commitments (having non-32 bytes) will be filtered at the moment of PSBT
239
246
/// deserialization and this function will return `None` only in situations
240
247
/// when the commitment is absent.
241
- pub fn tapret_proof ( & self ) -> Option < TaprootMerkleBranch > {
242
- let proof = self . proprietary . get ( & ProprietaryKey :: tapret_proof ( ) ) ?;
243
- TaprootMerkleBranch :: from_slice ( proof) . ok ( )
248
+ ///
249
+ /// Function returns generic type since the real type will create dependency
250
+ /// on `bp-dpc` crate, which will result in circular dependency with the
251
+ /// current crate.
252
+ pub fn tapret_proof < T > ( & self ) -> Result < Option < T > , TapretKeyError >
253
+ where
254
+ T : StrictDecode ,
255
+ {
256
+ self . proprietary
257
+ . get ( & ProprietaryKey :: tapret_proof ( ) )
258
+ . map ( T :: strict_deserialize)
259
+ . transpose ( )
260
+ . map_err ( TapretKeyError :: from)
244
261
}
245
262
}
0 commit comments