@@ -208,31 +208,7 @@ impl<Pk: MiniscriptKey> Pegin<Pk> {
208208 . explicit_script ( )
209209 . expect ( "Tr pegins unknown yet" )
210210 . into_bytes ( ) ;
211- let tweak = hashes:: sha256:: Hash :: hash ( & tweak_vec) ;
212-
213- struct TranslateTweak < ' a , C : secp256k1_zkp:: Verification > (
214- hashes:: sha256:: Hash ,
215- & ' a secp256k1_zkp:: Secp256k1 < C > ,
216- ) ;
217-
218- impl < ' a , Pk , C > bitcoin_miniscript:: Translator < Pk , bitcoin:: PublicKey , ( ) > for TranslateTweak < ' a , C >
219- where
220- Pk : MiniscriptKey + ToPublicKey ,
221- C : secp256k1_zkp:: Verification ,
222- {
223- fn pk ( & mut self , pk : & Pk ) -> Result < bitcoin:: PublicKey , ( ) > {
224- Ok ( tweak_key ( & pk. to_public_key ( ) , self . 1 , & self . 0 [ ..] ) )
225- }
226-
227- // We don't need to implement these methods as we are not using them in the policy.
228- // Fail if we encounter any hash fragments. See also translate_hash_clone! macro.
229- translate_hash_fail ! ( Pk , bitcoin:: PublicKey , ( ) ) ;
230- }
231- let mut t = TranslateTweak ( tweak, secp) ;
232-
233- let tweaked_desc = bitcoin_miniscript:: TranslatePk :: translate_pk ( & self . fed_desc , & mut t)
234- . expect ( "Tweaking must succeed" ) ;
235- Ok ( tweaked_desc. explicit_script ( ) ?)
211+ bitcoin_witness_script ( & self . fed_desc , & tweak_vec[ ..] , secp)
236212 }
237213
238214 /// Returns satisfying witness and scriptSig to spend an
@@ -298,3 +274,35 @@ impl<Pk: MiniscriptKey> Pegin<Pk> {
298274 self . elem_desc
299275 }
300276}
277+
278+ fn bitcoin_witness_script < C : secp256k1_zkp:: Verification , Pk : ToPublicKey > (
279+ fed_desc : & BtcDescriptor < Pk > ,
280+ claim_script : & [ u8 ] ,
281+ secp : & secp256k1_zkp:: Secp256k1 < C > ,
282+ ) -> Result < BtcScript , Error > {
283+ let tweak = hashes:: sha256:: Hash :: hash ( & claim_script) ;
284+
285+ struct TranslateTweak < ' a , C : secp256k1_zkp:: Verification > (
286+ hashes:: sha256:: Hash ,
287+ & ' a secp256k1_zkp:: Secp256k1 < C > ,
288+ ) ;
289+
290+ impl < ' a , Pk , C > bitcoin_miniscript:: Translator < Pk , bitcoin:: PublicKey , ( ) > for TranslateTweak < ' a , C >
291+ where
292+ Pk : MiniscriptKey + ToPublicKey ,
293+ C : secp256k1_zkp:: Verification ,
294+ {
295+ fn pk ( & mut self , pk : & Pk ) -> Result < bitcoin:: PublicKey , ( ) > {
296+ Ok ( tweak_key ( & pk. to_public_key ( ) , self . 1 , & self . 0 [ ..] ) )
297+ }
298+
299+ // We don't need to implement these methods as we are not using them in the policy.
300+ // Fail if we encounter any hash fragments. See also translate_hash_clone! macro.
301+ translate_hash_fail ! ( Pk , bitcoin:: PublicKey , ( ) ) ;
302+ }
303+ let mut t = TranslateTweak ( tweak, secp) ;
304+
305+ let tweaked_desc = bitcoin_miniscript:: TranslatePk :: translate_pk ( fed_desc, & mut t)
306+ . expect ( "Tweaking must succeed" ) ;
307+ Ok ( tweaked_desc. explicit_script ( ) ?)
308+ }
0 commit comments