@@ -586,20 +586,44 @@ impl Witness {
586586 }
587587
588588 /// Turn a public key related to a pkh into (part of) a satisfaction
589- fn pkh_public_key < Pk : ToPublicKey , S : Satisfier < Pk > > ( sat : S , pkh : & hash160:: Hash ) -> Self {
590- match sat. lookup_raw_pkh_pk ( pkh) {
591- Some ( pk) => Witness :: Stack ( vec ! [ pk. to_public_key( ) . to_bytes( ) ] ) ,
592- // public key hashes are assumed to be unavailable
593- // instead of impossible since it is the same as pub-key hashes
594- None => Witness :: Unavailable ,
589+ fn pkh_public_key < Pk : ToPublicKey , S : Satisfier < Pk > , Ctx : ScriptContext > (
590+ sat : S ,
591+ pkh : & hash160:: Hash ,
592+ ) -> Self {
593+ // public key hashes are assumed to be unavailable
594+ // instead of impossible since it is the same as pub-key hashes
595+ match Ctx :: sig_type ( ) {
596+ SigType :: Ecdsa => match sat. lookup_raw_pkh_pk ( pkh) {
597+ Some ( pk) => Witness :: Stack ( vec ! [ pk. to_bytes( ) ] ) ,
598+ None => Witness :: Unavailable ,
599+ } ,
600+ SigType :: Schnorr => match sat. lookup_raw_pkh_x_only_pk ( pkh) {
601+ Some ( pk) => Witness :: Stack ( vec ! [ pk. serialize( ) . to_vec( ) ] ) ,
602+ None => Witness :: Unavailable ,
603+ } ,
595604 }
596605 }
597606
598607 /// Turn a key/signature pair related to a pkh into (part of) a satisfaction
599- fn pkh_signature < Pk : ToPublicKey , S : Satisfier < Pk > > ( sat : S , pkh : & hash160:: Hash ) -> Self {
600- match sat. lookup_raw_pkh_ecdsa_sig ( pkh) {
601- Some ( ( pk, sig) ) => Witness :: Stack ( vec ! [ sig. to_vec( ) , pk. to_public_key( ) . to_bytes( ) ] ) ,
602- None => Witness :: Impossible ,
608+ fn pkh_signature < Pk : ToPublicKey , S : Satisfier < Pk > , Ctx : ScriptContext > (
609+ sat : S ,
610+ pkh : & hash160:: Hash ,
611+ leaf_hash : & TapLeafHash ,
612+ ) -> Self {
613+ match Ctx :: sig_type ( ) {
614+ SigType :: Ecdsa => match sat. lookup_raw_pkh_ecdsa_sig ( pkh) {
615+ Some ( ( pk, sig) ) => {
616+ Witness :: Stack ( vec ! [ sig. to_vec( ) , pk. to_public_key( ) . to_bytes( ) ] )
617+ }
618+ None => Witness :: Impossible ,
619+ } ,
620+ SigType :: Schnorr => match sat. lookup_raw_pkh_tap_leaf_script_sig ( & ( * pkh, * leaf_hash) ) {
621+ Some ( ( pk, sig) ) => Witness :: Stack ( vec ! [
622+ sig. to_vec( ) ,
623+ pk. to_x_only_pubkey( ) . serialize( ) . to_vec( ) ,
624+ ] ) ,
625+ None => Witness :: Impossible ,
626+ } ,
603627 }
604628 }
605629
@@ -959,12 +983,19 @@ impl Satisfaction {
959983 stack : Witness :: signature :: < _ , _ , Ctx > ( stfr, pk, leaf_hash) ,
960984 has_sig : true ,
961985 } ,
962- Terminal :: PkH ( ref pk) => Satisfaction {
963- stack : Witness :: pkh_signature ( stfr, & pk. to_pubkeyhash ( Ctx :: sig_type ( ) ) ) ,
964- has_sig : true ,
965- } ,
986+ Terminal :: PkH ( ref pk) => {
987+ let wit = Witness :: signature :: < _ , _ , Ctx > ( stfr, pk, leaf_hash) ;
988+ let pk_bytes = match Ctx :: sig_type ( ) {
989+ SigType :: Ecdsa => pk. to_public_key ( ) . to_bytes ( ) ,
990+ SigType :: Schnorr => pk. to_x_only_pubkey ( ) . serialize ( ) . to_vec ( ) ,
991+ } ;
992+ Satisfaction {
993+ stack : Witness :: combine ( wit, Witness :: Stack ( vec ! [ pk_bytes] ) ) ,
994+ has_sig : true ,
995+ }
996+ }
966997 Terminal :: RawPkH ( ref pkh) => Satisfaction {
967- stack : Witness :: pkh_signature ( stfr, pkh) ,
998+ stack : Witness :: pkh_signature :: < _ , _ , Ctx > ( stfr, pkh, leaf_hash ) ,
968999 has_sig : true ,
9691000 } ,
9701001 Terminal :: After ( t) => Satisfaction {
@@ -1271,17 +1302,23 @@ impl Satisfaction {
12711302 stack : Witness :: push_0 ( ) ,
12721303 has_sig : false ,
12731304 } ,
1274- Terminal :: PkH ( ref pk) => Satisfaction {
1305+ Terminal :: PkH ( ref pk) => {
1306+ let pk_bytes = match Ctx :: sig_type ( ) {
1307+ SigType :: Ecdsa => pk. to_public_key ( ) . to_bytes ( ) ,
1308+ SigType :: Schnorr => pk. to_x_only_pubkey ( ) . serialize ( ) . to_vec ( ) ,
1309+ } ;
1310+ Satisfaction {
1311+ stack : Witness :: combine ( Witness :: push_0 ( ) , Witness :: Stack ( vec ! [ pk_bytes] ) ) ,
1312+ has_sig : false ,
1313+ }
1314+ }
1315+ Terminal :: RawPkH ( ref pkh) => Satisfaction {
12751316 stack : Witness :: combine (
12761317 Witness :: push_0 ( ) ,
1277- Witness :: pkh_public_key ( stfr , & pk . to_pubkeyhash ( Ctx :: sig_type ( ) ) ) ,
1318+ Witness :: pkh_public_key :: < _ , _ , Ctx > ( stfr , pkh ) ,
12781319 ) ,
12791320 has_sig : false ,
12801321 } ,
1281- Terminal :: RawPkH ( ref pkh) => Satisfaction {
1282- stack : Witness :: combine ( Witness :: push_0 ( ) , Witness :: pkh_public_key ( stfr, pkh) ) ,
1283- has_sig : false ,
1284- } ,
12851322 Terminal :: False => Satisfaction {
12861323 stack : Witness :: empty ( ) ,
12871324 has_sig : false ,
0 commit comments