@@ -19,9 +19,10 @@ use core::cmp;
19
19
use core:: convert:: TryFrom ;
20
20
use core:: ops:: Deref ;
21
21
22
- use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
23
- use bitcoin:: secp256k1:: constants:: { PUBLIC_KEY_SIZE , SECRET_KEY_SIZE , COMPACT_SIGNATURE_SIZE } ;
24
- use bitcoin:: secp256k1:: ecdsa:: Signature ;
22
+ use bitcoin:: secp256k1:: { PublicKey , SecretKey , XOnlyPublicKey } ;
23
+ use bitcoin:: secp256k1:: constants:: { PUBLIC_KEY_SIZE , SECRET_KEY_SIZE , COMPACT_SIGNATURE_SIZE , SCHNORR_PUBLIC_KEY_SIZE , SCHNORR_SIGNATURE_SIZE } ;
24
+ use bitcoin:: secp256k1:: ecdsa;
25
+ use bitcoin:: secp256k1:: schnorr;
25
26
use bitcoin:: blockdata:: script:: Script ;
26
27
use bitcoin:: blockdata:: transaction:: { OutPoint , Transaction , TxOut } ;
27
28
use bitcoin:: consensus;
@@ -510,9 +511,9 @@ impl_array!(3); // for rgb
510
511
impl_array ! ( 4 ) ; // for IPv4
511
512
impl_array ! ( 12 ) ; // for OnionV2
512
513
impl_array ! ( 16 ) ; // for IPv6
513
- impl_array ! ( 32 ) ; // for channel id & hmac
514
+ impl_array ! ( 32 ) ; // for channel id, hmac, and XOnlyPublicKey
514
515
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
515
- impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
516
+ impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr:: Signature
516
517
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
517
518
518
519
// HashMap
@@ -601,7 +602,7 @@ impl Readable for Vec<u8> {
601
602
Ok ( ret)
602
603
}
603
604
}
604
- impl Writeable for Vec < Signature > {
605
+ impl Writeable for Vec < ecdsa :: Signature > {
605
606
#[ inline]
606
607
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
607
608
( self . len ( ) as u16 ) . write ( w) ?;
@@ -612,7 +613,7 @@ impl Writeable for Vec<Signature> {
612
613
}
613
614
}
614
615
615
- impl Readable for Vec < Signature > {
616
+ impl Readable for Vec < ecdsa :: Signature > {
616
617
#[ inline]
617
618
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
618
619
let len: u16 = Readable :: read ( r) ?;
@@ -701,7 +702,7 @@ impl Readable for Sha256dHash {
701
702
}
702
703
}
703
704
704
- impl Writeable for Signature {
705
+ impl Writeable for ecdsa :: Signature {
705
706
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
706
707
self . serialize_compact ( ) . write ( w)
707
708
}
@@ -711,16 +712,56 @@ impl Writeable for Signature {
711
712
}
712
713
}
713
714
714
- impl Readable for Signature {
715
+ impl Readable for ecdsa :: Signature {
715
716
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
716
717
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
717
- match Signature :: from_compact ( & buf) {
718
+ match ecdsa :: Signature :: from_compact ( & buf) {
718
719
Ok ( sig) => Ok ( sig) ,
719
720
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
720
721
}
721
722
}
722
723
}
723
724
725
+ impl Writeable for schnorr:: Signature {
726
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
727
+ self . as_ref ( ) . write ( w)
728
+ }
729
+ #[ inline]
730
+ fn serialized_length ( & self ) -> usize {
731
+ SCHNORR_SIGNATURE_SIZE
732
+ }
733
+ }
734
+
735
+ impl Readable for schnorr:: Signature {
736
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
737
+ let buf: [ u8 ; SCHNORR_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
738
+ match schnorr:: Signature :: from_slice ( & buf) {
739
+ Ok ( sig) => Ok ( sig) ,
740
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
741
+ }
742
+ }
743
+ }
744
+
745
+ impl Writeable for XOnlyPublicKey {
746
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
747
+ self . serialize ( ) . write ( w)
748
+ }
749
+ #[ inline]
750
+ fn serialized_length ( & self ) -> usize {
751
+ SCHNORR_PUBLIC_KEY_SIZE
752
+ }
753
+ }
754
+
755
+ impl Readable for XOnlyPublicKey {
756
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
757
+ let buf: [ u8 ; SCHNORR_PUBLIC_KEY_SIZE ] = Readable :: read ( r) ?;
758
+ match XOnlyPublicKey :: from_slice ( & buf) {
759
+ Ok ( key) => Ok ( key) ,
760
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
761
+ }
762
+ }
763
+ }
764
+
724
765
impl Writeable for PaymentPreimage {
725
766
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
726
767
self . 0 . write ( w)
0 commit comments