packages feed

trust-chain 0.1.1.2 → 0.1.2.0

raw patch · 2 files changed

+11/−22 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.TrustChain: instance (Data.Binary.Class.Binary a, forall a1. Data.Binary.Class.Binary a1 => Data.Binary.Class.Binary (f a1)) => Data.Binary.Class.Binary (Data.TrustChain.TrustChain f a)
- Data.TrustChain: instance (GHC.Read.Read a, forall a1. GHC.Read.Read a1 => GHC.Read.Read (f a1)) => GHC.Read.Read (Data.TrustChain.TrustChain f a)
- Data.TrustChain: instance (GHC.Show.Show a, forall a1. GHC.Show.Show a1 => GHC.Show.Show (f a1)) => GHC.Show.Show (Data.TrustChain.TrustChain f a)
+ Data.TrustChain: instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary (f (Data.TrustChain.TrustChain f a))) => Data.Binary.Class.Binary (Data.TrustChain.TrustChain f a)
+ Data.TrustChain: instance (GHC.Read.Read a, GHC.Read.Read (f (Data.TrustChain.TrustChain f a))) => GHC.Read.Read (Data.TrustChain.TrustChain f a)
+ Data.TrustChain: instance (GHC.Show.Show a, GHC.Show.Show (f (Data.TrustChain.TrustChain f a))) => GHC.Show.Show (Data.TrustChain.TrustChain f a)
- Data.TrustChain: assignments :: (Ord k, Eq a, Ord a) => (a -> k) -> Merge e a a -> [Claim a] -> Either (Inconsistency e a) (Map k a)
+ Data.TrustChain: assignments :: Ord k => (a -> k) -> Merge e a a -> [Claim a] -> Either (Inconsistency e a) (Map k a)
- Data.TrustChain: claims :: (Eq a, Ord a, Foldable f) => TrustChain f a -> [Claim a]
+ Data.TrustChain: claims :: Foldable f => TrustChain f a -> [Claim a]
- Data.TrustChain: mkTrustProxy :: (Traversable f, Binary a, Binary (f a), Binary (f (TrustChain f a)), forall a. Monoid (f a)) => PrivateKey -> f (TrustChain f a) -> IO (TrustChain f a)
+ Data.TrustChain: mkTrustProxy :: (Traversable f, Binary (f (TrustChain f a))) => PrivateKey -> f (TrustChain f a) -> IO (TrustChain f a)
- Data.TrustChain: validTrustChain :: (Binary a, forall x. Binary x => Binary (f x), Foldable f) => TrustChain f a -> Bool
+ Data.TrustChain: validTrustChain :: (Binary a, Binary (f (TrustChain f a)), Foldable f) => TrustChain f a -> Bool

Files

src/Data/TrustChain.hs view
@@ -3,7 +3,6 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE StandaloneDeriving #-}-{-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-}@@ -32,26 +31,18 @@   , Merge   ) where -import Data.Text (Text) import Data.Set (Set) import Data.Typeable (Typeable) import qualified Data.Set as Set import Data.Map (Map) import Data.Foldable (toList) import qualified Data.Map.Strict as Map-import Data.ByteString (ByteString)-import qualified Data.ByteString.Lazy as LBS-import Data.Functor.Identity (Identity (..)) import Data.Binary (Binary (..))-import qualified Data.Binary as Binary import GHC.Generics (Generic) import Data.Semigroup (All(All, getAll)) import Cropty import Data.Merge -encode :: Binary a => a -> ByteString-encode a = LBS.toStrict $ Binary.encode a- -- | A tree of trust of the given shape, where each internal node of the -- tree is signed by potentially different keys. @TrustChain Identity a@ -- is a linear signature chain, whereas @TrustChain NonEmpty a@ is a tree@@ -65,9 +56,9 @@   | TrustProxy (Signed (f (TrustChain f a)))   deriving (Generic, Typeable) -deriving instance (Show a, forall a. Show a => Show (f a)) => Show (TrustChain f a)-deriving instance (Read a, forall a. Read a => Read (f a)) => Read (TrustChain f a)-deriving instance (Binary a, forall a. Binary a => Binary (f a)) => Binary (TrustChain f a)+deriving instance (Show a, Show (f (TrustChain f a))) => Show (TrustChain f a)+deriving instance (Read a, Read (f (TrustChain f a))) => Read (TrustChain f a)+deriving instance (Binary a, Binary (f (TrustChain f a))) => Binary (TrustChain f a)  instance Eq a => Eq (TrustChain f a) where   Trustless a == Trustless a' = a == a'@@ -77,8 +68,8 @@  instance Ord a => Ord (TrustChain f a) where   compare (Trustless a) (Trustless a') = compare a a'-  compare (Trustless a) _ = GT-  compare (TrustProxy a) (Trustless _) = LT+  compare (Trustless _) _ = GT+  compare (TrustProxy _) (Trustless _) = LT   compare (TrustProxy s) (TrustProxy s') =        compare (signature s) (signature s')     <> compare (signedBy s) (signedBy s')@@ -91,23 +82,20 @@ -- | Strips out all elements of the chain which aren't rooted by someone in -- our whitelist, creating a forest of 'TrustChain's instead of a single one. filterByWhitelist :: Foldable f => Whitelist -> TrustChain f a -> [TrustChain f a]-filterByWhitelist w@(Whitelist ws) (Trustless a) = []+filterByWhitelist _ (Trustless _) = [] filterByWhitelist w@(Whitelist ws) (TrustProxy s) = if signedBy s `Set.member` ws then [TrustProxy s] else toList (signed s) >>= filterByWhitelist w  -- | Check that the trust chain has been legitimately signed. Once you receive -- 'True' from this function, you can be certain that all of the 'Signed' -- types within are truly correct.-validTrustChain :: (Binary a, forall x. Binary x => Binary (f x), Foldable f) => TrustChain f a -> Bool+validTrustChain :: (Binary a, Binary (f (TrustChain f a)), Foldable f) => TrustChain f a -> Bool validTrustChain (Trustless _) = True validTrustChain (TrustProxy s) = verifySigned s && getAll (foldMap (All . validTrustChain) (signed s))  -- | Extend the trust chain with new subchains and new items. mkTrustProxy ::   ( Traversable f-  , Binary a-  , Binary (f a)   , Binary (f (TrustChain f a))-  , forall a. Monoid (f a)   )   => PrivateKey   -> f (TrustChain f a)@@ -131,7 +119,7 @@  -- | -- Extract all of the claims from the trust chain.-claims :: (Eq a, Ord a, Foldable f) => TrustChain f a -> [Claim a]+claims :: Foldable f => TrustChain f a -> [Claim a] claims = \case   Trustless a -> [Claim [] a]   TrustProxy s -> (\(Claim ps a) -> Claim (signedBy s : ps) a) <$> foldMap claims (signed s)@@ -139,7 +127,7 @@ -- |  -- Extract all of the assignments from the trust chain, unifying information contained -- within them. This is where we might find potential inconsistencies.-assignments :: (Ord k, Eq a, Ord a) => (a -> k) -> Merge e a a -> [Claim a] -> Either (Inconsistency e a) (Map k a)+assignments :: Ord k => (a -> k) -> Merge e a a -> [Claim a] -> Either (Inconsistency e a) (Map k a) assignments getKey f cs = go Map.empty cs where   go as [] = Right (Map.map fst as)   go as (Claim ps a : xxs) =
trust-chain.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               trust-chain-version:            0.1.1.2+version:            0.1.2.0 category:           Cryptography, Crypto synopsis:           An implementation of a trust chain license:            MIT@@ -24,6 +24,7 @@       , containers >=0.6 && <1       , cropty >=0.3       , merge >=0.3+    ghc-options: -Wall     hs-source-dirs:   src     default-language: Haskell2010