Created
December 20, 2018 21:08
-
-
Save sirlensalot/5bc2435761d3c65d6e974450008e7d7f to your computer and use it in GitHub Desktop.
Scheme type families
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data HashAlgo | |
data SignatureAlgo | |
data PPKScheme' a where | |
ED25519' :: PPKScheme' ED25519Scheme | |
ETH' :: PPKScheme' ETHScheme | |
deriving instance Show a => Show (PPKScheme' a) | |
class Scheme a where | |
type SchemePubKey a :: * | |
type SchemePrivKey a :: * | |
readPubKey :: a -> ByteString -> SchemePubKey a | |
reify :: a | |
data ED25519Scheme = ED25519Scheme deriving (Eq,Show) | |
data ETHScheme = ETHScheme | |
instance Scheme a => Scheme (PPKScheme' a) where | |
type SchemePubKey (PPKScheme' a) = SchemePubKey a | |
type SchemePrivKey (PPKScheme' a) = SchemePrivKey a | |
reify = reify | |
readPubKey p bs = readPubKey reify bs | |
instance Scheme ED25519Scheme where | |
type SchemePubKey ED25519Scheme = Ed25519.PublicKey | |
type SchemePrivKey ED25519Scheme = Ed25519.PrivateKey | |
readPubKey _ = maybe undefined id . importPublic | |
reify = ED25519Scheme |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment