Fix panic in create_transaction when payload is not exactly 32 bytes

- Add length check before copy_from_slice to prevent panic
- Generate random commitment if payload length is invalid
- Fixes issue where empty commitment string caused crash
This commit is contained in:
4NK Dev 2025-09-20 01:10:16 +00:00
parent e205229e92
commit a8e4cd324a

View File

@ -198,7 +198,12 @@ pub fn create_transaction(
) -> Result<SilentPaymentUnsignedTransaction> {
let mut commitment = [0u8; 32];
if let Some(ref p) = payload {
commitment.copy_from_slice(&p);
if p.len() == 32 {
commitment.copy_from_slice(&p);
} else {
// If payload is not exactly 32 bytes, generate random commitment
thread_rng().fill(&mut commitment);
}
} else {
thread_rng().fill(&mut commitment);
}