@@ -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:: script:: Script ;
26
27
use bitcoin:: blockdata:: transaction:: { OutPoint , Transaction , TxOut } ;
27
28
use bitcoin:: consensus;
@@ -530,7 +531,7 @@ impl_array!(12); // for OnionV2
530
531
impl_array ! ( 16 ) ; // for IPv6
531
532
impl_array ! ( 32 ) ; // for channel id & hmac
532
533
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
533
- impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
534
+ impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr:: Signature
534
535
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
535
536
536
537
/// For variable-length values within TLV subtypes where the length cannot be inferred from the
@@ -704,7 +705,7 @@ impl Readable for Vec<u8> {
704
705
Ok ( ret)
705
706
}
706
707
}
707
- impl Writeable for Vec < Signature > {
708
+ impl Writeable for Vec < ecdsa :: Signature > {
708
709
#[ inline]
709
710
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
710
711
( self . len ( ) as u16 ) . write ( w) ?;
@@ -715,7 +716,7 @@ impl Writeable for Vec<Signature> {
715
716
}
716
717
}
717
718
718
- impl Readable for Vec < Signature > {
719
+ impl Readable for Vec < ecdsa :: Signature > {
719
720
#[ inline]
720
721
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
721
722
let len: u16 = Readable :: read ( r) ?;
@@ -804,7 +805,7 @@ impl Readable for Sha256dHash {
804
805
}
805
806
}
806
807
807
- impl Writeable for Signature {
808
+ impl Writeable for ecdsa :: Signature {
808
809
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
809
810
self . serialize_compact ( ) . write ( w)
810
811
}
@@ -814,10 +815,30 @@ impl Writeable for Signature {
814
815
}
815
816
}
816
817
817
- impl Readable for Signature {
818
+ impl Readable for ecdsa :: Signature {
818
819
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
819
820
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
820
- match Signature :: from_compact ( & buf) {
821
+ match ecdsa:: Signature :: from_compact ( & buf) {
822
+ Ok ( sig) => Ok ( sig) ,
823
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
824
+ }
825
+ }
826
+ }
827
+
828
+ impl Writeable for schnorr:: Signature {
829
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
830
+ self . as_ref ( ) . write ( w)
831
+ }
832
+ #[ inline]
833
+ fn serialized_length ( & self ) -> usize {
834
+ SCHNORR_SIGNATURE_SIZE
835
+ }
836
+ }
837
+
838
+ impl Readable for schnorr:: Signature {
839
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
840
+ let buf: [ u8 ; SCHNORR_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
841
+ match schnorr:: Signature :: from_slice ( & buf) {
821
842
Ok ( sig) => Ok ( sig) ,
822
843
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
823
844
}
0 commit comments