mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-17 10:15:47 +00:00
core: change badge code prefix to "SB" (#7478)
This commit is contained in:
@@ -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.
|
||||
|
||||
+6
-6
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user