@@ -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 } ;
@@ -499,7 +500,7 @@ impl_array!(12); // for OnionV2
499
500
impl_array ! ( 16 ) ; // for IPv6
500
501
impl_array ! ( 32 ) ; // for channel id & hmac
501
502
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
502
- impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
503
+ impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr:: Signature
503
504
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
504
505
505
506
impl Writeable for [ u16 ; 8 ] {
@@ -664,7 +665,7 @@ impl Readable for Vec<u8> {
664
665
Ok ( ret)
665
666
}
666
667
}
667
- impl Writeable for Vec < Signature > {
668
+ impl Writeable for Vec < ecdsa :: Signature > {
668
669
#[ inline]
669
670
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
670
671
( self . len ( ) as u16 ) . write ( w) ?;
@@ -675,7 +676,7 @@ impl Writeable for Vec<Signature> {
675
676
}
676
677
}
677
678
678
- impl Readable for Vec < Signature > {
679
+ impl Readable for Vec < ecdsa :: Signature > {
679
680
#[ inline]
680
681
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
681
682
let len: u16 = Readable :: read ( r) ?;
@@ -764,20 +765,32 @@ impl Readable for Sha256dHash {
764
765
}
765
766
}
766
767
767
- impl Writeable for Signature {
768
+ impl Writeable for ecdsa :: Signature {
768
769
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
769
770
self . serialize_compact ( ) . write ( w)
770
771
}
771
- #[ inline]
772
- fn serialized_length ( & self ) -> usize {
773
- COMPACT_SIGNATURE_SIZE
774
- }
775
772
}
776
773
777
- impl Readable for Signature {
774
+ impl Readable for ecdsa :: Signature {
778
775
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
779
776
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
780
- match Signature :: from_compact ( & buf) {
777
+ match ecdsa:: Signature :: from_compact ( & buf) {
778
+ Ok ( sig) => Ok ( sig) ,
779
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
780
+ }
781
+ }
782
+ }
783
+
784
+ impl Writeable for schnorr:: Signature {
785
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
786
+ self . as_ref ( ) . write ( w)
787
+ }
788
+ }
789
+
790
+ impl Readable for schnorr:: Signature {
791
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
792
+ let buf: [ u8 ; SCHNORR_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
793
+ match schnorr:: Signature :: from_slice ( & buf) {
781
794
Ok ( sig) => Ok ( sig) ,
782
795
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
783
796
}
0 commit comments