Permalink
Browse files

Add verifySignature support

  • Loading branch information...
vmchale committed Feb 9, 2019
1 parent 0ac2e05 commit fe835919f1266e59e682da756af1d1920501d89e
@@ -39,3 +39,8 @@ source-repository-package
type: git
location: https://github.com/shmish111/servant-purescript.git
tag: 315ccf5d720937c091c8cf3aca8adc8110766a23

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-crypto.git
tag: f5cecb6e424cc84f85b6a3e1f803517bb7b4cfb1
@@ -151,7 +151,9 @@ library
hedgehog -any,
filepath -any,
tasty -any,
tasty-golden -any
tasty-golden -any,
cryptonite,
cardano-crypto

if (flag(development) && impl(ghc <8.4))
ghc-options: -Werror
@@ -13,6 +13,7 @@ module PlutusPrelude ( -- * Reëxports from base
, second
, on
, isJust
, fromMaybe
, guard
, foldl'
, fold
@@ -110,7 +111,7 @@ import Data.Functor (void, ($>))
import Data.Functor.Foldable (Base, Corecursive, Recursive, embed, project)
import Data.List (foldl')
import Data.List.NonEmpty (NonEmpty (..))
import Data.Maybe (isJust)
import Data.Maybe (fromMaybe, isJust)
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import Data.Text.Prettyprint.Doc
@@ -27,6 +27,8 @@ import Language.PlutusCore.Type
import PlutusPrelude

import Control.Monad.Trans.Class (lift)
import Crypto.ECC.Ed25519Donna
import Crypto.Error (maybeCryptoError)
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.Hash as Hash
import Data.IntMap.Strict (IntMap)
@@ -218,6 +220,13 @@ applyTypedBuiltinName
=> TypedBuiltinName a r -> a -> [Value TyName Name ()] -> QuoteT (Evaluate m) ConstAppResult
applyTypedBuiltinName (TypedBuiltinName _ schema) = applyTypeSchemed schema

-- we default to 'False' in accordance with the spec
verifySignature :: BSL.ByteString -- ^ Public Key
-> BSL.ByteString -- ^ Message
-> BSL.ByteString -- ^ Signature
-> Bool
verifySignature pubKey msg sig = fromMaybe False $ maybeCryptoError (verify <$> publicKey (BSL.toStrict pubKey) <*> pure (BSL.toStrict msg) <*> signature (BSL.toStrict sig))

-- | Apply a 'TypedBuiltinName' to a list of 'Constant's (unwrapped from 'Value's)
-- Checks that the constants are of expected types and there are no size mismatches.
applyBuiltinName
@@ -243,6 +252,6 @@ applyBuiltinName DropByteString = applyTypedBuiltinName typedDropByteStrin
applyBuiltinName ResizeByteString = applyTypedBuiltinName typedResizeByteString (const id)
applyBuiltinName SHA2 = applyTypedBuiltinName typedSHA2 Hash.sha2
applyBuiltinName SHA3 = applyTypedBuiltinName typedSHA3 Hash.sha3
applyBuiltinName VerifySignature = applyTypedBuiltinName typedVerifySignature undefined
applyBuiltinName VerifySignature = applyTypedBuiltinName typedVerifySignature verifySignature
applyBuiltinName EqByteString = applyTypedBuiltinName typedEqByteString (==)
applyBuiltinName SizeOfInteger = applyTypedBuiltinName typedSizeOfInteger (const ())

0 comments on commit fe83591

Please sign in to comment.