core: fix encoding for name proof (#7672)

Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
Evgeny
2026-10-09 07:48:04 +01:00
committed by GitHub
co-authored by Evgeny @ SimpleX Chat
parent f2b3fe385c
commit f924d233e4
2 changed files with 23 additions and 1 deletions
+7 -1
View File
@@ -295,7 +295,13 @@ data ProofPresHeader
| PHFileDescr {chatBinding :: ByteString, fileSize :: Int64, descrHash :: ByteString, fileExpires :: Maybe UTCTime}
| PHUnknown Char ByteString
deriving (Eq, Show)
deriving (ToJSON, FromJSON) via (StrJSON "ProofPresHeader" ProofPresHeader)
instance ToJSON ProofPresHeader where
toJSON = toJSON . BBSPresHeader . strEncode
toEncoding = toEncoding . BBSPresHeader . strEncode
instance FromJSON ProofPresHeader where
parseJSON v = parseJSON v >>= \(BBSPresHeader ph) -> either fail pure $ strDecode ph
instance StrEncoding ProofPresHeader where
strEncode = \case
+16
View File
@@ -51,6 +51,7 @@ badgeTests = do
it "should accept unknown badge types" testUnknownBadgeType
it "credential serializes to a paste-able token and back" testCredentialSerialization
it "presentation headers encode and decode" testPresHeaderEncoding
it "presentation headers with binary bytes round-trip through JSON" testPresHeaderJSON
it "should reject a proof presented under another chat binding" testOtherChatBinding
describe "redemption codes" $ do
it "a generated code reads back" testCodeRoundTrip
@@ -209,6 +210,21 @@ testPresHeaderEncoding =
PHUnknown 'Z' "payload"
]
testPresHeaderJSON :: IO ()
testPresHeaderJSON =
mapM_
( \ph -> do
J.eitherDecode (J.encode ph) `shouldBe` Right ph
J.toJSON ph `shouldBe` J.toJSON (BBSPresHeader $ strEncode ph)
)
[ PHChat binaryBytes,
PHFileInv {chatBinding = binaryBytes, fileSize = 139737},
PHFileDescr {chatBinding = binaryBytes, fileSize = 139737, descrHash = binaryBytes, fileExpires = Just futureTime},
PHUnknown 'Z' binaryBytes
]
where
binaryBytes = "\0\1\31\34\92\127\128\195\255"
testOtherChatBinding :: IO ()
testOtherChatBinding = do
let ph = PHFileInv {chatBinding = aliceBinding, fileSize = 139737}