@@ -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 } ;
@@ -531,7 +532,7 @@ impl_array!(12); // for OnionV2
531
532
impl_array ! ( 16 ) ; // for IPv6
532
533
impl_array ! ( 32 ) ; // for channel id & hmac
533
534
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
534
- impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
535
+ impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr:: Signature
535
536
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
536
537
537
538
/// For variable-length values within TLV record where the length is encoded as part of the record.
@@ -676,7 +677,7 @@ impl Readable for Vec<u8> {
676
677
Ok ( ret)
677
678
}
678
679
}
679
- impl Writeable for Vec < Signature > {
680
+ impl Writeable for Vec < ecdsa :: Signature > {
680
681
#[ inline]
681
682
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
682
683
( self . len ( ) as u16 ) . write ( w) ?;
@@ -687,7 +688,7 @@ impl Writeable for Vec<Signature> {
687
688
}
688
689
}
689
690
690
- impl Readable for Vec < Signature > {
691
+ impl Readable for Vec < ecdsa :: Signature > {
691
692
#[ inline]
692
693
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
693
694
let len: u16 = Readable :: read ( r) ?;
@@ -776,7 +777,7 @@ impl Readable for Sha256dHash {
776
777
}
777
778
}
778
779
779
- impl Writeable for Signature {
780
+ impl Writeable for ecdsa :: Signature {
780
781
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
781
782
self . serialize_compact ( ) . write ( w)
782
783
}
@@ -786,10 +787,30 @@ impl Writeable for Signature {
786
787
}
787
788
}
788
789
789
- impl Readable for Signature {
790
+ impl Readable for ecdsa :: Signature {
790
791
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
791
792
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
792
- match Signature :: from_compact ( & buf) {
793
+ match ecdsa:: Signature :: from_compact ( & buf) {
794
+ Ok ( sig) => Ok ( sig) ,
795
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
796
+ }
797
+ }
798
+ }
799
+
800
+ impl Writeable for schnorr:: Signature {
801
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
802
+ self . as_ref ( ) . write ( w)
803
+ }
804
+ #[ inline]
805
+ fn serialized_length ( & self ) -> usize {
806
+ SCHNORR_SIGNATURE_SIZE
807
+ }
808
+ }
809
+
810
+ impl Readable for schnorr:: Signature {
811
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
812
+ let buf: [ u8 ; SCHNORR_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
813
+ match schnorr:: Signature :: from_slice ( & buf) {
793
814
Ok ( sig) => Ok ( sig) ,
794
815
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
795
816
}
0 commit comments