From 1fca7d2223ab8fb1735408f4fcd42eb1891b16d4 Mon Sep 17 00:00:00 2001 From: ngutech21 Date: Fri, 16 Feb 2024 10:45:54 +0100 Subject: [PATCH] fix: deserialize tokens with missing padding --- moksha-core/src/fixtures/token_no_pad60.cashu | 1 + moksha-core/src/token.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 moksha-core/src/fixtures/token_no_pad60.cashu diff --git a/moksha-core/src/fixtures/token_no_pad60.cashu b/moksha-core/src/fixtures/token_no_pad60.cashu new file mode 100644 index 00000000..c6c876a5 --- /dev/null +++ b/moksha-core/src/fixtures/token_no_pad60.cashu @@ -0,0 +1 @@ +cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHA6Ly8xMjcuMC4wLjE6MzMzOCIsInByb29mcyI6W3siYW1vdW50Ijo0LCJzZWNyZXQiOiJzR3Z3OVZwalpqNGQ0YnFFU3FvQzdwTWEiLCJDIjoiMDM3YmQ2MGY2YWE1ZTE5ZjZhOWVjMzU5MjlkOGViN2E2Yzk1Y2YyOTM5NTlmMzMzNTQzYWQ5MWIxNTkyNWU2OTE1IiwiaWQiOiJtUjlQSjNNempMMXkifSx7ImFtb3VudCI6OCwic2VjcmV0IjoiQjJqNmw4Z1VUYjIxR0hqMFRnbUNRUjZHIiwiQyI6IjAyOTQzYmI0MWY4MmY3MGE2MWIwMzM0ZGU1YjJjZjNmYzc0YmI2ZTlhZTY5OWVlMzc4YjYyMzc3ZTVhMWJiZmM5ZCIsImlkIjoibVI5UEozTXpqTDF5In0seyJhbW91bnQiOjE2LCJzZWNyZXQiOiJ2SFRHbGJoRXFBQUdEUVBteFBkczc1MFkiLCJDIjoiMDI4NDU0OGJkN2FiNjhmNTIyNzdkOTQxYTgwN2JmZjJlZWI4ZjNmY2EzYmVlODY2ODgxN2RjYTg3MGJhOGQxYWJkIiwiaWQiOiJtUjlQSjNNempMMXkifSx7ImFtb3VudCI6MzIsInNlY3JldCI6IldSajZCTXVQNTQyTFpmWXdiTldlbTJLaCIsIkMiOiIwMzc5NWE0NGUwNGY1YWU5MGYyZGIwZTkzYzc3MzJkMDJkYTQ0ZGIxZmRkMWYzNDlkN2EwMzJmN2U5OGZkYzZjYzQiLCJpZCI6Im1SOVBKM016akwxeSJ9XX1dfQ \ No newline at end of file diff --git a/moksha-core/src/token.rs b/moksha-core/src/token.rs index 76c0fb84..7d4eb4ff 100644 --- a/moksha-core/src/token.rs +++ b/moksha-core/src/token.rs @@ -107,7 +107,7 @@ impl TokenV3 { } pub fn deserialize(data: impl Into) -> Result { - let json = general_purpose::URL_SAFE.decode( + let json = general_purpose::URL_SAFE_NO_PAD.decode( data.into() .strip_prefix(TOKEN_PREFIX_V3) .ok_or(MokshaCoreError::InvalidTokenPrefix)? @@ -285,4 +285,13 @@ mod tests { assert_eq!(tokens.tokens.len(), 1); Ok(()) } + + #[test] + fn test_tokens_deserialize_no_pad() -> anyhow::Result<()> { + let input = read_fixture("token_no_pad60.cashu")?; + let tokens = TokenV3::deserialize(input)?; + assert_eq!(tokens.memo, None); + assert_eq!(tokens.tokens.len(), 1); + Ok(()) + } }