Skip to content

Commit 5817d32

Browse files
committed
Merge #607: Add serialize function for schnorr::Signature
8af2cf1 add .serialize() function to schnorr signature (isaac-asdf) Pull request description: convert from Signature to a byte_array ACKs for top commit: Kixunil: ACK 8af2cf1 tcharding: ACK 8af2cf1 apoelstra: ACK 8af2cf1 Tree-SHA512: b69d58646cdba4d83a79189f18628590970f471771feef0e11e089d73bd934777e3554a448b88a3643203522fde98084fd7570a5cec400516166583a3433c000
2 parents ecdec75 + 8af2cf1 commit 5817d32

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/schnorr.rs

+17
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ impl Signature {
8888
}
8989
}
9090

91+
/// Returns a signature as a byte array.
92+
#[inline]
93+
pub fn serialize(&self) -> [u8; constants::SCHNORR_SIGNATURE_SIZE] { self.0 }
94+
9195
/// Verifies a schnorr signature for `msg` using `pk` and the global [`SECP256K1`] context.
9296
#[inline]
9397
#[cfg(feature = "global-context")]
@@ -291,6 +295,19 @@ mod tests {
291295
assert!(secp.verify_schnorr(&sig, &msg, &pubkey).is_ok());
292296
}
293297

298+
#[test]
299+
fn test_serialize() {
300+
let sig = Signature::from_str("6470FD1303DDA4FDA717B9837153C24A6EAB377183FC438F939E0ED2B620E9EE5077C4A8B8DCA28963D772A94F5F0DDF598E1C47C137F91933274C7C3EDADCE8").unwrap();
301+
let sig_bytes = sig.serialize();
302+
let bytes = [
303+
100, 112, 253, 19, 3, 221, 164, 253, 167, 23, 185, 131, 113, 83, 194, 74, 110, 171, 55,
304+
113, 131, 252, 67, 143, 147, 158, 14, 210, 182, 32, 233, 238, 80, 119, 196, 168, 184,
305+
220, 162, 137, 99, 215, 114, 169, 79, 95, 13, 223, 89, 142, 28, 71, 193, 55, 249, 25,
306+
51, 39, 76, 124, 62, 218, 220, 232,
307+
];
308+
assert_eq!(sig_bytes, bytes);
309+
}
310+
294311
#[test]
295312
fn test_pubkey_from_slice() {
296313
assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey));

0 commit comments

Comments
 (0)