-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Verifier datatype;move SigCapability to separate module
- Loading branch information
Showing
4 changed files
with
64 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
module Chainweb.Api.SigCapability where | ||
|
||
------------------------------------------------------------------------------ | ||
import Data.Aeson | ||
import Data.Ord (comparing) | ||
import Data.Text (Text) | ||
------------------------------------------------------------------------------ | ||
|
||
data SigCapability = SigCapability | ||
{ _scName :: Text | ||
, _scArgs :: [Value] | ||
} deriving (Eq,Show) | ||
|
||
instance Ord SigCapability where | ||
compare = comparing _scName | ||
|
||
instance ToJSON SigCapability where | ||
toJSON SigCapability{..} = object | ||
[ "name" .= _scName | ||
, "args" .= _scArgs | ||
] | ||
|
||
instance FromJSON SigCapability where | ||
parseJSON = withObject "SigCapability" $ \o -> SigCapability | ||
<$> o .: "name" | ||
<*> o .: "args" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
module Chainweb.Api.Verifier where | ||
|
||
------------------------------------------------------------------------------ | ||
import Chainweb.Api.SigCapability | ||
import Data.Aeson | ||
import Data.Maybe (catMaybes) | ||
import Data.Ord | ||
import Data.Text (Text) | ||
------------------------------------------------------------------------------ | ||
|
||
data Verifier = Verifier | ||
{ _verifier_name :: Maybe Text | ||
, _verifier_proof :: Maybe Text | ||
, _verifier_capList :: [SigCapability] | ||
} deriving (Eq, Show) | ||
|
||
instance Ord Verifier where | ||
compare = comparing _verifier_name | ||
|
||
instance ToJSON Verifier where | ||
toJSON Verifier{..} = object $ catMaybes | ||
[ fmap ("name" .=) _verifier_name | ||
, fmap ("proof" .=) _verifier_proof | ||
, Just $ "clist" .= _verifier_capList | ||
] | ||
|
||
instance FromJSON Verifier where | ||
parseJSON = withObject "Verifier" $ \o -> Verifier | ||
<$> o .:? "name" | ||
<*> o .:? "proof" | ||
<*> o .: "clist" |