Skip to content

Commit

Permalink
Add Verifier datatype;move SigCapability to separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
giantimi committed Apr 11, 2024
1 parent b7eb7ff commit eb50a6b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
2 changes: 2 additions & 0 deletions chainweb-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ library
Chainweb.Api.Payload
Chainweb.Api.RespItems
Chainweb.Api.Sig
Chainweb.Api.SigCapability
Chainweb.Api.Signer
Chainweb.Api.StringEncoded
Chainweb.Api.Transaction
Chainweb.Api.Verifier
ChainwebData.Api
ChainwebData.EventDetail
ChainwebData.TransferDetail
Expand Down
28 changes: 28 additions & 0 deletions lib/Chainweb/Api/SigCapability.hs
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"
21 changes: 1 addition & 20 deletions lib/Chainweb/Api/Signer.hs
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Chainweb.Api.Signer where

------------------------------------------------------------------------------
import Chainweb.Api.SigCapability
import Data.Aeson
import Data.Maybe (fromMaybe, catMaybes)
import Data.Ord

Check warning on line 9 in lib/Chainweb/Api/Signer.hs

View workflow job for this annotation

GitHub Actions / Build master with 8.6.5 / 3.0 on ubuntu-20.04

The import of ‘Data.Ord’ is redundant

Check warning on line 9 in lib/Chainweb/Api/Signer.hs

View workflow job for this annotation

GitHub Actions / Build master with 8.6.5 / 3.0 on ubuntu-22.04

The import of ‘Data.Ord’ is redundant

Check warning on line 9 in lib/Chainweb/Api/Signer.hs

View workflow job for this annotation

GitHub Actions / Build master with 8.6.5 / 3.0 on macOS-latest

The import of ‘Data.Ord’ is redundant

Check warning on line 9 in lib/Chainweb/Api/Signer.hs

View workflow job for this annotation

GitHub Actions / Build master with 8.8.2 / 3.0 on ubuntu-20.04

The import of ‘Data.Ord’ is redundant

Check warning on line 9 in lib/Chainweb/Api/Signer.hs

View workflow job for this annotation

GitHub Actions / Build master with 8.8.2 / 3.0 on ubuntu-22.04

The import of ‘Data.Ord’ is redundant

Check warning on line 9 in lib/Chainweb/Api/Signer.hs

View workflow job for this annotation

GitHub Actions / Build master with 8.8.2 / 3.0 on macOS-latest

The import of ‘Data.Ord’ is redundant
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"

data Signer = Signer
{ _signer_addr :: Maybe Text
, _signer_scheme :: Maybe Text
Expand Down
33 changes: 33 additions & 0 deletions lib/Chainweb/Api/Verifier.hs
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"

0 comments on commit eb50a6b

Please sign in to comment.