@@ -20,8 +20,9 @@ use core::convert::TryFrom;
20
20
use core:: ops:: Deref ;
21
21
22
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 ;
23
+ use bitcoin:: secp256k1:: constants:: { PUBLIC_KEY_SIZE , SECRET_KEY_SIZE , COMPACT_SIGNATURE_SIZE , SCHNORR_SIGNATURE_SIZE } ;
24
+ use bitcoin:: secp256k1:: ecdsa;
25
+ use bitcoin:: secp256k1:: schnorr;
25
26
use bitcoin:: blockdata:: constants:: ChainHash ;
26
27
use bitcoin:: blockdata:: script:: Script ;
27
28
use bitcoin:: blockdata:: transaction:: { OutPoint , Transaction , TxOut } ;
@@ -498,7 +499,7 @@ impl_array!(12); // for OnionV2
498
499
impl_array ! ( 16 ) ; // for IPv6
499
500
impl_array ! ( 32 ) ; // for channel id & hmac
500
501
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
501
- impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
502
+ impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr:: Signature
502
503
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
503
504
504
505
impl Writeable for [ u16 ; 8 ] {
@@ -663,7 +664,7 @@ impl Readable for Vec<u8> {
663
664
Ok ( ret)
664
665
}
665
666
}
666
- impl Writeable for Vec < Signature > {
667
+ impl Writeable for Vec < ecdsa :: Signature > {
667
668
#[ inline]
668
669
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
669
670
( self . len ( ) as u16 ) . write ( w) ?;
@@ -674,7 +675,7 @@ impl Writeable for Vec<Signature> {
674
675
}
675
676
}
676
677
677
- impl Readable for Vec < Signature > {
678
+ impl Readable for Vec < ecdsa :: Signature > {
678
679
#[ inline]
679
680
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
680
681
let len: u16 = Readable :: read ( r) ?;
@@ -763,7 +764,7 @@ impl Readable for Sha256dHash {
763
764
}
764
765
}
765
766
766
- impl Writeable for Signature {
767
+ impl Writeable for ecdsa :: Signature {
767
768
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
768
769
self . serialize_compact ( ) . write ( w)
769
770
}
@@ -773,10 +774,30 @@ impl Writeable for Signature {
773
774
}
774
775
}
775
776
776
- impl Readable for Signature {
777
+ impl Readable for ecdsa :: Signature {
777
778
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
778
779
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
779
- match Signature :: from_compact ( & buf) {
780
+ match ecdsa:: Signature :: from_compact ( & buf) {
781
+ Ok ( sig) => Ok ( sig) ,
782
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
783
+ }
784
+ }
785
+ }
786
+
787
+ impl Writeable for schnorr:: Signature {
788
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
789
+ self . as_ref ( ) . write ( w)
790
+ }
791
+ #[ inline]
792
+ fn serialized_length ( & self ) -> usize {
793
+ SCHNORR_SIGNATURE_SIZE
794
+ }
795
+ }
796
+
797
+ impl Readable for schnorr:: Signature {
798
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
799
+ let buf: [ u8 ; SCHNORR_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
800
+ match schnorr:: Signature :: from_slice ( & buf) {
780
801
Ok ( sig) => Ok ( sig) ,
781
802
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
782
803
}
0 commit comments