Skip to content
Snippets Groups Projects
Commit 53d7c91b authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Stuff some values into the Succeeded value

parent 28338506
No related branches found
No related tags found
1 merge request!8HTTP API for Voucher redemption
......@@ -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 =
......
......@@ -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"]
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment