From 53d7c91b33e9fa4cd5b8631e76c51e8c5cee9a4d Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Wed, 4 Sep 2019 14:44:16 -0400 Subject: [PATCH] Stuff some values into the Succeeded value --- src/PaymentServer/Redemption.hs | 30 ++++++++++++++++++++++++++---- test/SpecRedemption.hs | 4 +++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/PaymentServer/Redemption.hs b/src/PaymentServer/Redemption.hs index 35963cb..87e3ed0 100644 --- a/src/PaymentServer/Redemption.hs +++ b/src/PaymentServer/Redemption.hs @@ -61,9 +61,20 @@ import PaymentServer.Persistence , Voucher ) +-- | A cryptographic signature of a blinded token created using our private +-- key. +type Signature = Text + +-- | A public key corresponding to our private key. +type PublicKey = Text + +-- | A zero-knowledge proof that signatures were created of the corresponding +-- blinded tokens using the corresponding public key's private key. +type Proof = Text + data Result = Failed - | Succeeded + | Succeeded PublicKey [Signature] Proof deriving (Show, Eq) -- | A blinded token is presented along with a voucher to be signed and the @@ -81,12 +92,23 @@ instance ToJSON Redeem where instance ToJSON Result where toJSON Failed = object [ "success" .= False ] - toJSON Succeeded = object [ "success" .= True ] + toJSON (Succeeded key signatures proof) = object + [ "success" .= True + , "public-key" .= key + , "signatures" .= signatures + , "proof" .= proof + ] instance FromJSON Result where parseJSON = withObject "Result" $ \v -> v .: "success" >>= \success -> - return $ if success then Succeeded else Failed + if success then + Succeeded + <$> v .: "public-key" + <*> v .: "signatures" + <*> v .: "proof" + else + return Failed type RedemptionAPI = ReqBody '[JSON] Redeem :> Post '[JSON] Result @@ -104,7 +126,7 @@ redeem database (Redeem voucher tokens) = do result <- liftIO $ PaymentServer.Persistence.redeemVoucher database voucher fingerprint case result of Left err -> throwError jsonErr400 - Right () -> return Succeeded + Right () -> return $ Succeeded "" [] "" fingerprintFromTokens :: [BlindedToken] -> Fingerprint fingerprintFromTokens = diff --git a/test/SpecRedemption.hs b/test/SpecRedemption.hs index 00b9f33..ba4bf06 100644 --- a/test/SpecRedemption.hs +++ b/test/SpecRedemption.hs @@ -156,7 +156,9 @@ spec_redemption = parallel $ do it "receive a success response when redemption succeeds" $ property $ \(voucher :: Voucher) (tokens :: [BlindedToken]) -> propertyRedeem path voucher tokens 200 - { matchBody = matchJSONBody Succeeded + -- TODO: Get some real crypto involved to be able to replace these + -- dummy values. + { matchBody = matchJSONBody $ Succeeded "" [] "" , matchHeaders = ["Content-Type" <:> "application/json;charset=utf-8"] } -- GitLab