module Shard where import Types import Serialization import Cost import qualified Crypto.SecretSharing as SS import qualified Data.ByteString.Lazy as BL import Raaz.Core.Encode (toByteString, fromByteString) import Data.Binary genShards :: EncryptedSecretKey -> ShardParams -> IO [StorableObject] genShards esk ps = map (StorableObject . encode) <$> SS.encode (neededObjects ps) (totalObjects ps) (BL.fromStrict (toByteString esk)) -- Throws AssertionFailed if the number of shares is too small. combineShards :: [StorableObject] -> Maybe EncryptedSecretKey combineShards = fromByteString . BL.toStrict . SS.decode . map conv where conv = decode . fromStorableObject