@@ -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 } ;
@@ -527,7 +528,7 @@ impl_array!(12); // for OnionV2
527
528
impl_array ! ( 16 ) ; // for IPv6
528
529
impl_array ! ( 32 ) ; // for channel id & hmac
529
530
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
530
- impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
531
+ impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr:: Signature
531
532
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
532
533
533
534
/// For variable-length values within TLV record where the length is encoded as part of the record.
@@ -659,7 +660,7 @@ impl Readable for Vec<u8> {
659
660
Ok ( ret)
660
661
}
661
662
}
662
- impl Writeable for Vec < Signature > {
663
+ impl Writeable for Vec < ecdsa :: Signature > {
663
664
#[ inline]
664
665
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
665
666
( self . len ( ) as u16 ) . write ( w) ?;
@@ -670,7 +671,7 @@ impl Writeable for Vec<Signature> {
670
671
}
671
672
}
672
673
673
- impl Readable for Vec < Signature > {
674
+ impl Readable for Vec < ecdsa :: Signature > {
674
675
#[ inline]
675
676
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
676
677
let len: u16 = Readable :: read ( r) ?;
@@ -759,7 +760,7 @@ impl Readable for Sha256dHash {
759
760
}
760
761
}
761
762
762
- impl Writeable for Signature {
763
+ impl Writeable for ecdsa :: Signature {
763
764
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
764
765
self . serialize_compact ( ) . write ( w)
765
766
}
@@ -769,10 +770,30 @@ impl Writeable for Signature {
769
770
}
770
771
}
771
772
772
- impl Readable for Signature {
773
+ impl Readable for ecdsa :: Signature {
773
774
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
774
775
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
775
- match Signature :: from_compact ( & buf) {
776
+ match ecdsa:: Signature :: from_compact ( & buf) {
777
+ Ok ( sig) => Ok ( sig) ,
778
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
779
+ }
780
+ }
781
+ }
782
+
783
+ impl Writeable for schnorr:: Signature {
784
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
785
+ self . as_ref ( ) . write ( w)
786
+ }
787
+ #[ inline]
788
+ fn serialized_length ( & self ) -> usize {
789
+ SCHNORR_SIGNATURE_SIZE
790
+ }
791
+ }
792
+
793
+ impl Readable for schnorr:: Signature {
794
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
795
+ let buf: [ u8 ; SCHNORR_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
796
+ match schnorr:: Signature :: from_slice ( & buf) {
776
797
Ok ( sig) => Ok ( sig) ,
777
798
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
778
799
}
0 commit comments