Skip to content

Commit 8af2cf1

Browse files
committed
add .serialize() function to schnorr signature
1 parent 74e6ced commit 8af2cf1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/schnorr.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ impl Signature {
8686
}
8787
}
8888

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

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

0 commit comments

Comments
 (0)