@@ -28,6 +28,9 @@ use util::psbt::raw;
28
28
use util:: psbt:: serialize:: Deserialize ;
29
29
use util:: psbt:: { Error , error} ;
30
30
31
+ use schnorr;
32
+ use util:: taproot:: { ControlBlock , LeafVersion , TapLeafHash , TapBranchHash } ;
33
+
31
34
/// Type: Non-Witness UTXO PSBT_IN_NON_WITNESS_UTXO = 0x00
32
35
const PSBT_IN_NON_WITNESS_UTXO : u8 = 0x00 ;
33
36
/// Type: Witness UTXO PSBT_IN_WITNESS_UTXO = 0x01
@@ -54,6 +57,18 @@ const PSBT_IN_SHA256: u8 = 0x0b;
54
57
const PSBT_IN_HASH160 : u8 = 0x0c ;
55
58
/// Type: HASH256 preimage PSBT_IN_HASH256 = 0x0d
56
59
const PSBT_IN_HASH256 : u8 = 0x0d ;
60
+ /// Type: Schnorr Signature in Key Spend PSBT_IN_TAP_KEY_SIG = 0x13
61
+ const PSBT_IN_TAP_KEY_SIG : u8 = 0x13 ;
62
+ /// Type: Schnorr Signature in Script Spend PSBT_IN_TAP_SCRIPT_SIG = 0x14
63
+ const PSBT_IN_TAP_SCRIPT_SIG : u8 = 0x14 ;
64
+ /// Type: Taproot Leaf Script PSBT_IN_TAP_LEAF_SCRIPT = 0x14
65
+ const PSBT_IN_TAP_LEAF_SCRIPT : u8 = 0x15 ;
66
+ /// Type: Taproot Key BIP 32 Derivation Path PSBT_IN_TAP_BIP32_DERIVATION = 0x16
67
+ const PSBT_IN_TAP_BIP32_DERIVATION : u8 = 0x16 ;
68
+ /// Type: Taproot Internal Key PSBT_IN_TAP_INTERNAL_KEY = 0x17
69
+ const PSBT_IN_TAP_INTERNAL_KEY : u8 = 0x17 ;
70
+ /// Type: Taproot Merkle Root PSBT_IN_TAP_MERKLE_ROOT = 0x18
71
+ const PSBT_IN_TAP_MERKLE_ROOT : u8 = 0x18 ;
57
72
/// Type: Proprietary Use Type PSBT_IN_PROPRIETARY = 0xFC
58
73
const PSBT_IN_PROPRIETARY : u8 = 0xFC ;
59
74
@@ -104,6 +119,21 @@ pub struct Input {
104
119
/// HAS256 hash to preimage map
105
120
#[ cfg_attr( feature = "serde" , serde( with = "::serde_utils::btreemap_byte_values" ) ) ]
106
121
pub hash256_preimages : BTreeMap < sha256d:: Hash , Vec < u8 > > ,
122
+ /// Serialized schnorr signature with sighash type for key spend
123
+ pub tap_key_sig : Option < schnorr:: SchnorrSig > ,
124
+ /// Map of <xonlypubkey>|<leafhash> with signature
125
+ #[ cfg_attr( feature = "serde" , serde( with = "::serde_utils::btreemap_as_seq" ) ) ]
126
+ pub tap_script_sigs : BTreeMap < ( schnorr:: PublicKey , TapLeafHash ) , schnorr:: SchnorrSig > ,
127
+ /// Map of Control blocks to Script version pair
128
+ #[ cfg_attr( feature = "serde" , serde( with = "::serde_utils::btreemap_as_seq" ) ) ]
129
+ pub tap_scripts : BTreeMap < ControlBlock , ( Script , LeafVersion ) > ,
130
+ /// Map of tap root x only keys to origin info and leaf hashes contained in it
131
+ #[ cfg_attr( feature = "serde" , serde( with = "::serde_utils::btreemap_as_seq" ) ) ]
132
+ pub tap_key_origins : BTreeMap < schnorr:: PublicKey , ( Vec < TapLeafHash > , KeySource ) > ,
133
+ /// Taproot Internal key
134
+ pub tap_internal_key : Option < schnorr:: PublicKey > ,
135
+ /// Taproot Merkle root
136
+ pub tap_merkle_root : Option < TapBranchHash > ,
107
137
/// Proprietary key-value pairs for this input.
108
138
#[ cfg_attr( feature = "serde" , serde( with = "::serde_utils::btreemap_as_seq_byte_values" ) ) ]
109
139
pub proprietary : BTreeMap < raw:: ProprietaryKey , Vec < u8 > > ,
@@ -177,6 +207,36 @@ impl Map for Input {
177
207
PSBT_IN_HASH256 => {
178
208
psbt_insert_hash_pair ( & mut self . hash256_preimages , raw_key, raw_value, error:: PsbtHash :: Hash256 ) ?;
179
209
}
210
+ PSBT_IN_TAP_KEY_SIG => {
211
+ impl_psbt_insert_pair ! {
212
+ self . tap_key_sig <= <raw_key: _>|<raw_value: schnorr:: SchnorrSig >
213
+ }
214
+ }
215
+ PSBT_IN_TAP_SCRIPT_SIG => {
216
+ impl_psbt_insert_pair ! {
217
+ self . tap_script_sigs <= <raw_key: ( schnorr:: PublicKey , TapLeafHash ) >|<raw_value: schnorr:: SchnorrSig >
218
+ }
219
+ }
220
+ PSBT_IN_TAP_LEAF_SCRIPT => {
221
+ impl_psbt_insert_pair ! {
222
+ self . tap_scripts <= <raw_key: ControlBlock >|< raw_value: ( Script , LeafVersion ) >
223
+ }
224
+ }
225
+ PSBT_IN_TAP_BIP32_DERIVATION => {
226
+ impl_psbt_insert_pair ! {
227
+ self . tap_key_origins <= <raw_key: schnorr:: PublicKey >|< raw_value: ( Vec <TapLeafHash >, KeySource ) >
228
+ }
229
+ }
230
+ PSBT_IN_TAP_INTERNAL_KEY => {
231
+ impl_psbt_insert_pair ! {
232
+ self . tap_internal_key <= <raw_key: _>|< raw_value: schnorr:: PublicKey >
233
+ }
234
+ }
235
+ PSBT_IN_TAP_MERKLE_ROOT => {
236
+ impl_psbt_insert_pair ! {
237
+ self . tap_merkle_root <= <raw_key: _>|< raw_value: TapBranchHash >
238
+ }
239
+ }
180
240
PSBT_IN_PROPRIETARY => match self . proprietary . entry ( raw:: ProprietaryKey :: from_key ( raw_key. clone ( ) ) ?) {
181
241
btree_map:: Entry :: Vacant ( empty_key) => { empty_key. insert ( raw_value) ; } ,
182
242
btree_map:: Entry :: Occupied ( _) => return Err ( Error :: DuplicateKey ( raw_key) . into ( ) ) ,
@@ -249,6 +309,30 @@ impl Map for Input {
249
309
rv. push( self . hash256_preimages as <PSBT_IN_HASH256 , sha256d:: Hash >|<Vec <u8 >>)
250
310
}
251
311
312
+ impl_psbt_get_pair ! {
313
+ rv. push( self . tap_key_sig as <PSBT_IN_TAP_KEY_SIG , _>|<Vec <u8 >>)
314
+ }
315
+
316
+ impl_psbt_get_pair ! {
317
+ rv. push( self . tap_script_sigs as <PSBT_IN_TAP_SCRIPT_SIG , ( schnorr:: PublicKey , TapLeafHash ) >|<Vec <u8 >>)
318
+ }
319
+
320
+ impl_psbt_get_pair ! {
321
+ rv. push( self . tap_scripts as <PSBT_IN_TAP_LEAF_SCRIPT , ControlBlock >|<( Script , LeafVersion ) >)
322
+ }
323
+
324
+ impl_psbt_get_pair ! {
325
+ rv. push( self . tap_key_origins as <PSBT_IN_TAP_BIP32_DERIVATION ,
326
+ schnorr:: PublicKey >|<( Vec <TapLeafHash >, KeySource ) >)
327
+ }
328
+
329
+ impl_psbt_get_pair ! {
330
+ rv. push( self . tap_internal_key as <PSBT_IN_TAP_INTERNAL_KEY , _>|<schnorr:: PublicKey >)
331
+ }
332
+
333
+ impl_psbt_get_pair ! {
334
+ rv. push( self . tap_merkle_root as <PSBT_IN_TAP_MERKLE_ROOT , _>|<TapBranchHash >)
335
+ }
252
336
for ( key, value) in self . proprietary . iter ( ) {
253
337
rv. push ( raw:: Pair {
254
338
key : key. to_key ( ) ,
@@ -280,13 +364,19 @@ impl Map for Input {
280
364
self . sha256_preimages . extend ( other. sha256_preimages ) ;
281
365
self . hash160_preimages . extend ( other. hash160_preimages ) ;
282
366
self . hash256_preimages . extend ( other. hash256_preimages ) ;
367
+ self . tap_script_sigs . extend ( other. tap_script_sigs ) ;
368
+ self . tap_scripts . extend ( other. tap_scripts ) ;
369
+ self . tap_key_origins . extend ( other. tap_key_origins ) ;
283
370
self . proprietary . extend ( other. proprietary ) ;
284
371
self . unknown . extend ( other. unknown ) ;
285
372
286
373
merge ! ( redeem_script, self , other) ;
287
374
merge ! ( witness_script, self , other) ;
288
375
merge ! ( final_script_sig, self , other) ;
289
376
merge ! ( final_script_witness, self , other) ;
377
+ merge ! ( tap_key_sig, self , other) ;
378
+ merge ! ( tap_internal_key, self , other) ;
379
+ merge ! ( tap_merkle_root, self , other) ;
290
380
291
381
Ok ( ( ) )
292
382
}
0 commit comments