@@ -25,7 +25,7 @@ use core::cmp::Reverse;
25
25
use std:: error;
26
26
27
27
use hashes:: { sha256, sha256t, Hash , HashEngine } ;
28
- use schnorr;
28
+ use schnorr:: { TweakedPublicKey , UntweakedPublicKey } ;
29
29
use Script ;
30
30
31
31
use consensus:: Encodable ;
@@ -101,7 +101,7 @@ impl TapTweakHash {
101
101
/// Create a new BIP341 [`TapTweakHash`] from key and tweak
102
102
/// Produces H_taptweak(P||R) where P is internal key and R is the merkle root
103
103
pub fn from_key_and_tweak (
104
- internal_key : schnorr :: PublicKey ,
104
+ internal_key : UntweakedPublicKey ,
105
105
merkle_root : Option < TapBranchHash > ,
106
106
) -> TapTweakHash {
107
107
let mut eng = TapTweakHash :: engine ( ) ;
@@ -171,13 +171,13 @@ type ScriptMerkleProofMap = BTreeMap<(Script, LeafVersion), BTreeSet<TaprootMerk
171
171
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
172
172
pub struct TaprootSpendInfo {
173
173
/// The BIP341 internal key.
174
- internal_key : schnorr :: PublicKey ,
174
+ internal_key : UntweakedPublicKey ,
175
175
/// The Merkle root of the script tree (None if there are no scripts)
176
176
merkle_root : Option < TapBranchHash > ,
177
177
/// The sign final output pubkey as per BIP 341
178
178
output_key_parity : bool ,
179
179
/// The tweaked output key
180
- output_key : schnorr :: PublicKey ,
180
+ output_key : TweakedPublicKey ,
181
181
/// Map from (script, leaf_version) to (sets of) [`TaprootMerkleBranch`].
182
182
/// More than one control block for a given script is only possible if it
183
183
/// appears in multiple branches of the tree. In all cases, keeping one should
@@ -204,7 +204,7 @@ impl TaprootSpendInfo {
204
204
/// dealing with numbers close to 2^64.
205
205
pub fn with_huffman_tree < C , I > (
206
206
secp : & Secp256k1 < C > ,
207
- internal_key : schnorr :: PublicKey ,
207
+ internal_key : UntweakedPublicKey ,
208
208
script_weights : I ,
209
209
) -> Result < Self , TaprootBuilderError >
210
210
where
@@ -250,7 +250,7 @@ impl TaprootSpendInfo {
250
250
///
251
251
pub fn new_key_spend < C : secp256k1:: Verification > (
252
252
secp : & Secp256k1 < C > ,
253
- internal_key : schnorr :: PublicKey ,
253
+ internal_key : UntweakedPublicKey ,
254
254
merkle_root : Option < TapBranchHash > ,
255
255
) -> Self {
256
256
let tweak = TapTweakHash :: from_key_and_tweak ( internal_key, merkle_root) ;
@@ -268,7 +268,7 @@ impl TaprootSpendInfo {
268
268
internal_key : internal_key,
269
269
merkle_root : merkle_root,
270
270
output_key_parity : parity,
271
- output_key : output_key,
271
+ output_key : TweakedPublicKey :: new ( output_key) ,
272
272
script_map : BTreeMap :: new ( ) ,
273
273
}
274
274
}
@@ -279,7 +279,7 @@ impl TaprootSpendInfo {
279
279
}
280
280
281
281
/// Obtain the internal key
282
- pub fn internal_key ( & self ) -> schnorr :: PublicKey {
282
+ pub fn internal_key ( & self ) -> UntweakedPublicKey {
283
283
self . internal_key
284
284
}
285
285
@@ -290,7 +290,7 @@ impl TaprootSpendInfo {
290
290
291
291
/// Output key(the key used in script pubkey) from Spend data. See also
292
292
/// [`TaprootSpendInfo::output_key_parity`]
293
- pub fn output_key ( & self ) -> schnorr :: PublicKey {
293
+ pub fn output_key ( & self ) -> TweakedPublicKey {
294
294
self . output_key
295
295
}
296
296
@@ -302,7 +302,7 @@ impl TaprootSpendInfo {
302
302
// Internal function to compute [`TaprootSpendInfo`] from NodeInfo
303
303
fn from_node_info < C : secp256k1:: Verification > (
304
304
secp : & Secp256k1 < C > ,
305
- internal_key : schnorr :: PublicKey ,
305
+ internal_key : UntweakedPublicKey ,
306
306
node : NodeInfo ,
307
307
) -> TaprootSpendInfo {
308
308
// Create as if it is a key spend path with the given merkle root
@@ -430,7 +430,7 @@ impl TaprootBuilder {
430
430
pub fn finalize < C : secp256k1:: Verification > (
431
431
mut self ,
432
432
secp : & Secp256k1 < C > ,
433
- internal_key : schnorr :: PublicKey ,
433
+ internal_key : UntweakedPublicKey ,
434
434
) -> Result < TaprootSpendInfo , TaprootBuilderError > {
435
435
if self . branch . len ( ) > 1 {
436
436
return Err ( TaprootBuilderError :: IncompleteTree ) ;
@@ -652,7 +652,7 @@ pub struct ControlBlock {
652
652
/// The parity of the output key (NOT THE INTERNAL KEY WHICH IS ALWAYS XONLY)
653
653
pub output_key_parity : bool ,
654
654
/// The internal key
655
- pub internal_key : schnorr :: PublicKey ,
655
+ pub internal_key : UntweakedPublicKey ,
656
656
/// The merkle proof of a script associated with this leaf
657
657
pub merkle_branch : TaprootMerkleBranch ,
658
658
}
@@ -674,7 +674,7 @@ impl ControlBlock {
674
674
}
675
675
let output_key_parity = ( sl[ 0 ] & 1 ) == 1 ;
676
676
let leaf_version = LeafVersion :: from_u8 ( sl[ 0 ] & TAPROOT_LEAF_MASK ) ?;
677
- let internal_key = schnorr :: PublicKey :: from_slice ( & sl[ 1 ..TAPROOT_CONTROL_BASE_SIZE ] )
677
+ let internal_key = UntweakedPublicKey :: from_slice ( & sl[ 1 ..TAPROOT_CONTROL_BASE_SIZE ] )
678
678
. map_err ( TaprootError :: InvalidInternalKey ) ?;
679
679
let merkle_branch = TaprootMerkleBranch :: from_slice ( & sl[ TAPROOT_CONTROL_BASE_SIZE ..] ) ?;
680
680
Ok ( ControlBlock {
@@ -719,7 +719,7 @@ impl ControlBlock {
719
719
pub fn verify_taproot_commitment < C : secp256k1:: Verification > (
720
720
& self ,
721
721
secp : & Secp256k1 < C > ,
722
- output_key : & schnorr :: PublicKey ,
722
+ output_key : & TweakedPublicKey ,
723
723
script : & Script ,
724
724
) -> bool {
725
725
// compute the script hash
@@ -743,7 +743,7 @@ impl ControlBlock {
743
743
let tweak = TapTweakHash :: from_key_and_tweak ( self . internal_key , Some ( curr_hash) ) ;
744
744
self . internal_key . tweak_add_check (
745
745
secp,
746
- output_key,
746
+ output_key. as_inner ( ) ,
747
747
self . output_key_parity ,
748
748
tweak. into_inner ( ) ,
749
749
)
@@ -900,6 +900,7 @@ mod test {
900
900
use hashes:: { sha256, Hash , HashEngine } ;
901
901
use secp256k1:: VerifyOnly ;
902
902
use core:: str:: FromStr ;
903
+ use schnorr;
903
904
904
905
fn tag_engine ( tag_name : & str ) -> sha256:: HashEngine {
905
906
let mut engine = sha256:: Hash :: engine ( ) ;
@@ -984,6 +985,7 @@ mod test {
984
985
985
986
fn _verify_tap_commitments ( secp : & Secp256k1 < VerifyOnly > , out_spk_hex : & str , script_hex : & str , control_block_hex : & str ) {
986
987
let out_pk = schnorr:: PublicKey :: from_str ( & out_spk_hex[ 4 ..] ) . unwrap ( ) ;
988
+ let out_pk = TweakedPublicKey :: new ( out_pk) ;
987
989
let script = Script :: from_hex ( script_hex) . unwrap ( ) ;
988
990
let control_block = ControlBlock :: from_slice ( & Vec :: < u8 > :: from_hex ( control_block_hex) . unwrap ( ) ) . unwrap ( ) ;
989
991
assert_eq ! ( control_block_hex, control_block. serialize( ) . to_hex( ) ) ;
@@ -1025,7 +1027,7 @@ mod test {
1025
1027
#[ test]
1026
1028
fn build_huffman_tree ( ) {
1027
1029
let secp = Secp256k1 :: verification_only ( ) ;
1028
- let internal_key = schnorr :: PublicKey :: from_str ( "93c7378d96518a75448821c4f7c8f4bae7ce60f804d03d1f0628dd5dd0f5de51" ) . unwrap ( ) ;
1030
+ let internal_key = UntweakedPublicKey :: from_str ( "93c7378d96518a75448821c4f7c8f4bae7ce60f804d03d1f0628dd5dd0f5de51" ) . unwrap ( ) ;
1029
1031
1030
1032
let script_weights = vec ! [
1031
1033
( 10 , Script :: from_hex( "51" ) . unwrap( ) ) , // semantics of script don't matter for this test
@@ -1075,7 +1077,7 @@ mod test {
1075
1077
#[ test]
1076
1078
fn taptree_builder ( ) {
1077
1079
let secp = Secp256k1 :: verification_only ( ) ;
1078
- let internal_key = schnorr :: PublicKey :: from_str ( "93c7378d96518a75448821c4f7c8f4bae7ce60f804d03d1f0628dd5dd0f5de51" ) . unwrap ( ) ;
1080
+ let internal_key = UntweakedPublicKey :: from_str ( "93c7378d96518a75448821c4f7c8f4bae7ce60f804d03d1f0628dd5dd0f5de51" ) . unwrap ( ) ;
1079
1081
1080
1082
let builder = TaprootBuilder :: new ( ) ;
1081
1083
// Create a tree as shown below
0 commit comments