@@ -3,7 +3,7 @@ use std::{str::FromStr, time::Duration};
3
3
use alloy:: { primitives:: Address as StrataAddress , providers:: WalletProvider } ;
4
4
use argh:: FromArgs ;
5
5
use bdk_wallet:: {
6
- bitcoin:: { taproot:: LeafVersion , Address , TapNodeHash , XOnlyPublicKey } ,
6
+ bitcoin:: { taproot:: LeafVersion , Address , ScriptBuf , TapNodeHash , XOnlyPublicKey } ,
7
7
chain:: ChainOracle ,
8
8
descriptor:: IntoWalletDescriptor ,
9
9
miniscript:: { miniscript:: Tap , Miniscript } ,
@@ -71,7 +71,7 @@ pub async fn deposit(
71
71
recovery_address. to_string( ) . yellow( )
72
72
) ;
73
73
74
- let ( bridge_in_desc, _recovery_script_hash) =
74
+ let ( bridge_in_desc, _recovery_script , _recovery_script_hash) =
75
75
bridge_in_descriptor ( settings. bridge_musig2_pubkey , recovery_address)
76
76
. expect ( "valid bridge in descriptor" ) ;
77
77
@@ -171,7 +171,7 @@ pub async fn deposit(
171
171
fn bridge_in_descriptor (
172
172
bridge_pubkey : XOnlyPublicKey ,
173
173
recovery_address : Address ,
174
- ) -> Result < ( DescriptorTemplateOut , TapNodeHash ) , NotTaprootAddress > {
174
+ ) -> Result < ( DescriptorTemplateOut , ScriptBuf , TapNodeHash ) , NotTaprootAddress > {
175
175
let recovery_xonly_pubkey = recovery_address. extract_p2tr_pubkey ( ) ?;
176
176
177
177
let desc = bdk_wallet:: descriptor!(
@@ -193,5 +193,33 @@ fn bridge_in_descriptor(
193
193
194
194
let recovery_script_hash = TapNodeHash :: from_script ( & recovery_script, LeafVersion :: TapScript ) ;
195
195
196
- Ok ( ( desc, recovery_script_hash) )
196
+ Ok ( ( desc, recovery_script, recovery_script_hash) )
197
+ }
198
+
199
+ #[ cfg( test) ]
200
+ mod tests {
201
+ use bdk_wallet:: bitcoin:: { consensus, secp256k1:: SECP256K1 , Network , Sequence } ;
202
+
203
+ use super :: * ;
204
+ use crate :: constants:: BRIDGE_MUSIG2_PUBKEY ;
205
+
206
+ #[ test]
207
+ fn bridge_in_descriptor_script ( ) {
208
+ let bridge_musig2_pubkey = BRIDGE_MUSIG2_PUBKEY . parse :: < XOnlyPublicKey > ( ) . unwrap ( ) ;
209
+ let internal_recovery_pubkey = XOnlyPublicKey :: from_slice ( & [ 2u8 ; 32 ] ) . unwrap ( ) ;
210
+ let recovery_address =
211
+ Address :: p2tr ( SECP256K1 , internal_recovery_pubkey, None , Network :: Bitcoin ) ;
212
+ let external_recovery_pubkey = recovery_address. extract_p2tr_pubkey ( ) . unwrap ( ) ;
213
+ let sequence = Sequence :: from_consensus ( RECOVER_DELAY ) ;
214
+ let sequence_hex = consensus:: encode:: serialize_hex ( & sequence) ;
215
+
216
+ let ( _bridge_in_descriptor, recovery_script, _recovery_script_hash) =
217
+ bridge_in_descriptor ( bridge_musig2_pubkey, recovery_address) . unwrap ( ) ;
218
+
219
+ let expected = format ! (
220
+ "OP_PUSHBYTES_32 {external_recovery_pubkey} OP_CHECKSIGVERIFY OP_PUSHBYTES_2 {sequence_hex:.4} OP_CSV"
221
+ ) ;
222
+ let got = recovery_script. to_asm_string ( ) ;
223
+ assert_eq ! ( got, expected) ;
224
+ }
197
225
}
0 commit comments