use core::ops::Deref;
use bitcoin::secp256k1::{PublicKey, SecretKey};
-use bitcoin::secp256k1::constants::{PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, COMPACT_SIGNATURE_SIZE};
-use bitcoin::secp256k1::ecdsa::Signature;
+use bitcoin::secp256k1::constants::{PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, COMPACT_SIGNATURE_SIZE, SCHNORR_SIGNATURE_SIZE};
+use bitcoin::secp256k1::ecdsa;
+use bitcoin::secp256k1::schnorr;
use bitcoin::blockdata::constants::ChainHash;
use bitcoin::blockdata::script::Script;
use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
impl_array!(16); // for IPv6
impl_array!(32); // for channel id & hmac
impl_array!(PUBLIC_KEY_SIZE); // for PublicKey
-impl_array!(COMPACT_SIGNATURE_SIZE); // for Signature
+impl_array!(64); // for ecdsa::Signature and schnorr::Signature
impl_array!(1300); // for OnionPacket.hop_data
impl Writeable for [u16; 8] {
Ok(ret)
}
}
-impl Writeable for Vec<Signature> {
+impl Writeable for Vec<ecdsa::Signature> {
#[inline]
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
(self.len() as u16).write(w)?;
}
}
-impl Readable for Vec<Signature> {
+impl Readable for Vec<ecdsa::Signature> {
#[inline]
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let len: u16 = Readable::read(r)?;
}
}
-impl Writeable for Signature {
+impl Writeable for ecdsa::Signature {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
self.serialize_compact().write(w)
}
- #[inline]
- fn serialized_length(&self) -> usize {
- COMPACT_SIGNATURE_SIZE
- }
}
-impl Readable for Signature {
+impl Readable for ecdsa::Signature {
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let buf: [u8; COMPACT_SIGNATURE_SIZE] = Readable::read(r)?;
- match Signature::from_compact(&buf) {
+ match ecdsa::Signature::from_compact(&buf) {
+ Ok(sig) => Ok(sig),
+ Err(_) => return Err(DecodeError::InvalidValue),
+ }
+ }
+}
+
+impl Writeable for schnorr::Signature {
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ self.as_ref().write(w)
+ }
+}
+
+impl Readable for schnorr::Signature {
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ let buf: [u8; SCHNORR_SIGNATURE_SIZE] = Readable::read(r)?;
+ match schnorr::Signature::from_slice(&buf) {
Ok(sig) => Ok(sig),
Err(_) => return Err(DecodeError::InvalidValue),
}