@@ -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
/// For variable-length values within TLV record where the length is encoded as part of the record.
@@ -632,7 +633,7 @@ impl Readable for Vec<u8> {
632
633
Ok ( ret)
633
634
}
634
635
}
635
- impl Writeable for Vec < Signature > {
636
+ impl Writeable for Vec < ecdsa :: Signature > {
636
637
#[ inline]
637
638
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
638
639
( self . len ( ) as u16 ) . write ( w) ?;
@@ -643,7 +644,7 @@ impl Writeable for Vec<Signature> {
643
644
}
644
645
}
645
646
646
- impl Readable for Vec < Signature > {
647
+ impl Readable for Vec < ecdsa :: Signature > {
647
648
#[ inline]
648
649
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
649
650
let len: u16 = Readable :: read ( r) ?;
@@ -732,7 +733,7 @@ impl Readable for Sha256dHash {
732
733
}
733
734
}
734
735
735
- impl Writeable for Signature {
736
+ impl Writeable for ecdsa :: Signature {
736
737
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
737
738
self . serialize_compact ( ) . write ( w)
738
739
}
@@ -742,10 +743,30 @@ impl Writeable for Signature {
742
743
}
743
744
}
744
745
745
- impl Readable for Signature {
746
+ impl Readable for ecdsa :: Signature {
746
747
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
747
748
let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
748
- match Signature :: from_compact ( & buf) {
749
+ match ecdsa:: Signature :: from_compact ( & buf) {
750
+ Ok ( sig) => Ok ( sig) ,
751
+ Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
752
+ }
753
+ }
754
+ }
755
+
756
+ impl Writeable for schnorr:: Signature {
757
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
758
+ self . as_ref ( ) . write ( w)
759
+ }
760
+ #[ inline]
761
+ fn serialized_length ( & self ) -> usize {
762
+ SCHNORR_SIGNATURE_SIZE
763
+ }
764
+ }
765
+
766
+ impl Readable for schnorr:: Signature {
767
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
768
+ let buf: [ u8 ; SCHNORR_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
769
+ match schnorr:: Signature :: from_slice ( & buf) {
749
770
Ok ( sig) => Ok ( sig) ,
750
771
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
751
772
}
0 commit comments