@@ -586,20 +586,44 @@ impl Witness {
586
586
}
587
587
588
588
/// 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
+ } ,
595
604
}
596
605
}
597
606
598
607
/// 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
+ } ,
603
627
}
604
628
}
605
629
@@ -959,12 +983,19 @@ impl Satisfaction {
959
983
stack : Witness :: signature :: < _ , _ , Ctx > ( stfr, pk, leaf_hash) ,
960
984
has_sig : true ,
961
985
} ,
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
+ }
966
997
Terminal :: RawPkH ( ref pkh) => Satisfaction {
967
- stack : Witness :: pkh_signature ( stfr, pkh) ,
998
+ stack : Witness :: pkh_signature :: < _ , _ , Ctx > ( stfr, pkh, leaf_hash ) ,
968
999
has_sig : true ,
969
1000
} ,
970
1001
Terminal :: After ( t) => Satisfaction {
@@ -1271,17 +1302,23 @@ impl Satisfaction {
1271
1302
stack : Witness :: push_0 ( ) ,
1272
1303
has_sig : false ,
1273
1304
} ,
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 {
1275
1316
stack : Witness :: combine (
1276
1317
Witness :: push_0 ( ) ,
1277
- Witness :: pkh_public_key ( stfr , & pk . to_pubkeyhash ( Ctx :: sig_type ( ) ) ) ,
1318
+ Witness :: pkh_public_key :: < _ , _ , Ctx > ( stfr , pkh ) ,
1278
1319
) ,
1279
1320
has_sig : false ,
1280
1321
} ,
1281
- Terminal :: RawPkH ( ref pkh) => Satisfaction {
1282
- stack : Witness :: combine ( Witness :: push_0 ( ) , Witness :: pkh_public_key ( stfr, pkh) ) ,
1283
- has_sig : false ,
1284
- } ,
1285
1322
Terminal :: False => Satisfaction {
1286
1323
stack : Witness :: empty ( ) ,
1287
1324
has_sig : false ,
0 commit comments