From 47b499dcc474b8392b1e7fbbf99a18662ce4f3c5 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Wed, 9 Sep 2026 14:42:52 +0000 Subject: [PATCH] core: change badge code prefix to "SB" (#7478) --- src/Simplex/Chat/Badges/Code.hs | 4 ++-- tests/BadgeTests.hs | 12 ++++++------ tests/Bots/BadgeServiceTests.hs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Simplex/Chat/Badges/Code.hs b/src/Simplex/Chat/Badges/Code.hs index 7e2c380119..5098b24a21 100644 --- a/src/Simplex/Chat/Badges/Code.hs +++ b/src/Simplex/Chat/Badges/Code.hs @@ -3,7 +3,7 @@ -- | Badge redemption codes, shared by the client, the badge service and the checkout site. -- --- A code is "SXB-" and 20 Crockford base32 characters in four groups of five: +-- A code is "SB-" and 20 Crockford base32 characters in four groups of five: -- 19 payload characters and a final check character. -- -- Reading folds the characters the alphabet omits so that a code copied by hand still @@ -56,7 +56,7 @@ groupLength :: Int groupLength = 5 codePrefix :: Text -codePrefix = "SXB" +codePrefix = "SB" -- | The Crockford value of a character, folding the omitted characters onto the digits they -- are mistaken for. diff --git a/tests/BadgeTests.hs b/tests/BadgeTests.hs index e26de4823d..5a826bd948 100644 --- a/tests/BadgeTests.hs +++ b/tests/BadgeTests.hs @@ -189,9 +189,9 @@ testCodeRoundTrip = do drg <- C.newRandom code <- randomBadgeCode drg let formatted = formatBadgeCode code - T.length formatted `shouldBe` 27 -- SXB-XXXXX-XXXXX-XXXXX-XXXXX - T.take 4 formatted `shouldBe` "SXB-" - T.length (badgeCodeText code) `shouldBe` 23 -- the canonical form drops the separators + T.length formatted `shouldBe` 26 -- SB-XXXXX-XXXXX-XXXXX-XXXXX + T.take 3 formatted `shouldBe` "SB-" + T.length (badgeCodeText code) `shouldBe` 22 -- the canonical form drops the separators parseBadgeCode formatted `shouldBe` Just code parseBadgeCode (badgeCodeText code) `shouldBe` Just code @@ -208,7 +208,7 @@ testCodeNormalisation = do parseBadgeCode folded `shouldBe` parseBadgeCode fixedCode parseBadgeCode fixedCode `shouldNotBe` Nothing where - fixedCode = "SXB-0C0QS-XAQW1-N1VSA-R00Y3" + fixedCode = "SB-0C0QS-XAQW1-N1VSA-R00Y3" ambiguous = \case '1' -> 'I' '0' -> 'O' @@ -223,8 +223,8 @@ testCodeCheckCharacter = do wrong = T.init canonical <> T.singleton (if T.last canonical == 'Z' then 'Y' else 'Z') parseBadgeCode wrong `shouldBe` Nothing parseBadgeCode "" `shouldBe` Nothing - parseBadgeCode "SXB-00000-00000-00000-0000" `shouldBe` Nothing - parseBadgeCode (T.drop 3 canonical) `shouldBe` Nothing + parseBadgeCode "SB-00000-00000-00000-0000" `shouldBe` Nothing + parseBadgeCode (T.drop 2 canonical) `shouldBe` Nothing testCodeHash :: IO () testCodeHash = do diff --git a/tests/Bots/BadgeServiceTests.hs b/tests/Bots/BadgeServiceTests.hs index a45e8040b0..bf09bbd06c 100644 --- a/tests/Bots/BadgeServiceTests.hs +++ b/tests/Bots/BadgeServiceTests.hs @@ -258,13 +258,13 @@ testRedeemUnknownCode ps = alice ##> ("/_redeem_badge_code 1 " <> codeArg unknown) alice <## "bad chat command: badge service error: code_invalid" -- a failed check character is refused before anything leaves the device - alice ##> "/_redeem_badge_code 1 SXB-00000-00000-00000-00001" + alice ##> "/_redeem_badge_code 1 SB-00000-00000-00000-00001" alice <## "bad chat command: invalid badge code" -- sent straight to the service, past the client's own check, the two are one answer (_, redeemPriv) <- atomically $ C.generateKeyPair g :: IO (C.KeyPair 'C.Ed25519) redeemDirect alice bsLink redeemPriv (T.unpack $ badgeCodeText unknown) alice <## "service response: {\"code\":\"code_invalid\",\"type\":\"error\"}" - redeemDirect alice bsLink redeemPriv "SXB-00000-00000-00000-00001" + redeemDirect alice bsLink redeemPriv "SB-00000-00000-00000-00001" alice <## "service response: {\"code\":\"code_invalid\",\"type\":\"error\"}" -- a signed redeemBadgeCode sent as a raw service request, bypassing the client's own checks