@@ -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 } ;
@@ -491,7 +492,7 @@ impl_array!(12); // for OnionV2
491
492
impl_array ! ( 16 ) ; // for IPv6
492
493
impl_array ! ( 32 ) ; // for channel id & hmac
493
494
impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
494
- impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
495
+ impl_array ! ( 64 ) ; // for ecdsa::Signature and schnorr:: Signature
495
496
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
496
497
497
498
impl Writeable for [ u16 ; 8 ] {
@@ -656,7 +657,7 @@ impl Readable for Vec<u8> {
656
657
Ok ( ret)
657
658
}
658
659
}
659
- impl Writeable for Vec < Signature > {
660
+ impl Writeable for Vec < ecdsa :: Signature > {
660
661
#[ inline]
661
662
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
662
663
( self . len ( ) as u16 ) . write ( w) ?;
@@ -667,7 +668,7 @@ impl Writeable for Vec<Signature> {
667
668
}
668
669
}
669
670
670
- impl Readable for Vec < Signature > {
671
+ impl Readable for Vec < ecdsa :: Signature > {
671
672
#[ inline]
672
673
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
673
674
let len: u16 = Readable :: read ( r) ?;
@@ -756,7 +757,7 @@ impl Readable for Sha256dHash {
756
757
}
757
758
}
758
759
759
- impl Writeable for Signature {
760
+ impl Writeable for ecdsa :: Signature {
760
761
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
761
762
self . serialize_compact ( ) . write ( w)
762
763
}
@@ -766,10 +767,30 @@ impl Writeable for Signature {
766
767
}
767
768
}
768
769
769
- impl Readable for Signature {
770
+ impl Readable for ecdsa :: Signature {
770
771
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
771
772
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
772
- match Signature :: from_compact ( & buf) {
773
+ match ecdsa:: Signature :: from_compact ( & buf) {
774
+ Ok ( sig) => Ok ( sig) ,
775
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
776
+ }
777
+ }
778
+ }
779
+
780
+ impl Writeable for schnorr:: Signature {
781
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
782
+ self . as_ref ( ) . write ( w)
783
+ }
784
+ #[ inline]
785
+ fn serialized_length ( & self ) -> usize {
786
+ SCHNORR_SIGNATURE_SIZE
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) {
773
794
Ok ( sig) => Ok ( sig) ,
774
795
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
775
796
}
0 commit comments