Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
53d7c91b
Commit
53d7c91b
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Stuff some values into the Succeeded value
parent
28338506
No related branches found
Branches containing commit
No related tags found
1 merge request
!8
HTTP API for Voucher redemption
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/PaymentServer/Redemption.hs
+26
-4
26 additions, 4 deletions
src/PaymentServer/Redemption.hs
test/SpecRedemption.hs
+3
-1
3 additions, 1 deletion
test/SpecRedemption.hs
with
29 additions
and
5 deletions
src/PaymentServer/Redemption.hs
+
26
−
4
View file @
53d7c91b
...
...
@@ -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
=
...
...
This diff is collapsed.
Click to expand it.
test/SpecRedemption.hs
+
3
−
1
View file @
53d7c91b
...
...
@@ -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"
]
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment