From de54d86c1e88fe49a6dc2557339cd67fcc51a8a3 Mon Sep 17 00:00:00 2001 From: qima Date: Tue, 4 Jun 2024 18:31:38 +0800 Subject: [PATCH] chore(transfer): make discord_name decryption backward compatible --- sn_transfers/src/cashnotes/spend_reason.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sn_transfers/src/cashnotes/spend_reason.rs b/sn_transfers/src/cashnotes/spend_reason.rs index ee87f04e7d..ded813c7a2 100644 --- a/sn_transfers/src/cashnotes/spend_reason.rs +++ b/sn_transfers/src/cashnotes/spend_reason.rs @@ -114,9 +114,14 @@ impl DiscordName { let nonce = DerivationIndex(nonce_bytes.to_owned()); let mut checksum = [0; CHECK_SUM_SIZE]; - checksum.copy_from_slice(&bytes[CONTENT_SIZE..LIMIT_SIZE]); - if checksum != CHECK_SUM { - return Err(TransferError::InvalidDecryptionKey); + if bytes.len() < LIMIT_SIZE { + // Backward compatible, which will allow invalid key generate a random hash result + checksum = CHECK_SUM; + } else { + checksum.copy_from_slice(&bytes[CONTENT_SIZE..LIMIT_SIZE]); + if checksum != CHECK_SUM { + return Err(TransferError::InvalidDecryptionKey); + } } Ok(Self {