@@ -38,6 +38,8 @@ use bitcoin::hash_types::{Txid, BlockHash};
38
38
use core:: marker:: Sized ;
39
39
use core:: time:: Duration ;
40
40
use crate :: ln:: msgs:: DecodeError ;
41
+ #[ cfg( taproot) ]
42
+ use crate :: ln:: msgs:: PartialSignatureWithNonce ;
41
43
use crate :: ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
42
44
43
45
use crate :: util:: byte_utils:: { be48_to_array, slice_to_be48} ;
@@ -574,6 +576,7 @@ impl_array!(16); // for IPv6
574
576
impl_array ! ( 32 ) ; // for channel id & hmac
575
577
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
576
578
impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr::Signature
579
+ impl_array ! ( 66 ) ; // for MuSig2 nonces
577
580
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
578
581
579
582
impl Writeable for [ u16 ; 8 ] {
@@ -861,6 +864,48 @@ impl Readable for SecretKey {
861
864
}
862
865
}
863
866
867
+ #[ cfg( taproot) ]
868
+ impl Writeable for musig2:: types:: PublicNonce {
869
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
870
+ self . serialize ( ) . to_vec ( ) . write ( w)
871
+ }
872
+
873
+ fn serialized_length ( & self ) -> usize {
874
+ PUBLIC_KEY_SIZE * 2
875
+ }
876
+ }
877
+
878
+ #[ cfg( taproot) ]
879
+ impl Readable for musig2:: types:: PublicNonce {
880
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
881
+ let buf: [ u8 ; PUBLIC_KEY_SIZE * 2 ] = Readable :: read ( r) ?;
882
+ let nonce = musig2:: types:: PublicNonce :: from_slice ( & buf) . unwrap ( ) ;
883
+ Ok ( nonce)
884
+ }
885
+ }
886
+
887
+ #[ cfg( taproot) ]
888
+ impl Writeable for PartialSignatureWithNonce {
889
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
890
+ self . 0 . serialize ( ) . write ( w) ?;
891
+ self . 1 . write ( w)
892
+ }
893
+
894
+ fn serialized_length ( & self ) -> usize {
895
+ SECRET_KEY_SIZE + self . 1 . serialized_length ( )
896
+ }
897
+ }
898
+
899
+ #[ cfg( taproot) ]
900
+ impl Readable for PartialSignatureWithNonce {
901
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
902
+ let partial_signature_buf: [ u8 ; SECRET_KEY_SIZE ] = Readable :: read ( r) ?;
903
+ let partial_signature: musig2:: types:: PartialSignature = musig2:: types:: PartialSignature :: from_slice ( & partial_signature_buf) . unwrap ( ) ;
904
+ let public_nonce: musig2:: types:: PublicNonce = Readable :: read ( r) ?;
905
+ Ok ( PartialSignatureWithNonce ( partial_signature, public_nonce) )
906
+ }
907
+ }
908
+
864
909
impl Writeable for Sha256dHash {
865
910
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
866
911
w. write_all ( & self [ ..] )
@@ -1277,7 +1322,7 @@ mod tests {
1277
1322
fn bigsize_encoding_decoding ( ) {
1278
1323
let values = vec ! [ 0 , 252 , 253 , 65535 , 65536 , 4294967295 , 4294967296 , 18446744073709551615 ] ;
1279
1324
let bytes = vec ! [
1280
- "00" ,
1325
+ "00" ,
1281
1326
"fc" ,
1282
1327
"fd00fd" ,
1283
1328
"fdffff" ,
@@ -1286,7 +1331,7 @@ mod tests {
1286
1331
"ff0000000100000000" ,
1287
1332
"ffffffffffffffffff"
1288
1333
] ;
1289
- for i in 0 ..=7 {
1334
+ for i in 0 ..=7 {
1290
1335
let mut stream = crate :: io:: Cursor :: new ( :: hex:: decode ( bytes[ i] ) . unwrap ( ) ) ;
1291
1336
assert_eq ! ( super :: BigSize :: read( & mut stream) . unwrap( ) . 0 , values[ i] ) ;
1292
1337
let mut stream = super :: VecWriter ( Vec :: new ( ) ) ;
0 commit comments