summaryrefslogtreecommitdiffhomepage
path: root/Crypto.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Crypto.hs')
-rw-r--r--Crypto.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/Crypto.hs b/Crypto.hs
new file mode 100644
index 0000000..3d0529d
--- /dev/null
+++ b/Crypto.hs
@@ -0,0 +1,24 @@
+module Crypto where
+
+import Val
+import Hash
+import Types
+
+import qualified Crypto.PubKey.Ed25519 as Ed25519
+import Data.ByteArray (convert)
+import Crypto.Error
+
+dummySignature :: Signature
+dummySignature = Unsigned
+
+-- | Sign any Hashable value.
+sign :: Hashable v => Ed25519.SecretKey -> Ed25519.PublicKey -> v -> Signature
+sign sk pk v = Ed25519 $ Val $ convert $
+ Ed25519.sign sk pk $ val $ hashValue $ hash v
+
+-- | Verifiy a signature of any Hashable value.
+verify :: Hashable v => Ed25519.PublicKey -> v -> Signature -> Bool
+verify pk v (Ed25519 (Val s)) = case Ed25519.signature s of
+ CryptoPassed sig -> Ed25519.verify pk (val $ hashValue $ hash v) sig
+ CryptoFailed _ -> False
+verify _ _ Unsigned = False