morley-1.20.0: Developer tools for the Michelson Language
Safe HaskellSafe-Inferred
LanguageHaskell2010

Morley.Tezos.Crypto

Description

Cryptographic primitives used in Tezos.

WARNING: some functions may be vulnerable to timing attacks. Also, this code was not reviewed by cryptography/security experts. Do not use it with secret keys that have some value. We provide SecretKey type and (limited) signing functionality only for testing. If you need to sign something in production, use something else (e. g. octez-client).

Tezos supports multiple cryptographic curves that are denoted by the number after tz in the public key hash: • tz1 — ed25519 • tz2 — secp256k1 • tz3 — P256 • tz4 — BLS12381 We have Morley.Tezos.Crypto.Curve module for each of these curves. They expose very similar functionality and their main purpose is to hide implementation details for each curve as well as some other specifics (e. g. prefixes that are used for human-readable representation).

Additionally, Tezos uses b2b hashes to represent addresses of contracts (using KT1 prefix) and transaction rollups (using txr1 prefix) -- these hashes are also implemented here.

We do not support txr1 addresses as those are disabled on the mainnet.

This module serves two purposes: 1. It is an umbrella module that re-exports some stuff from other modules. 2. Michelson types such as key and signature may store primitive of any curve, so we need "union" types in Haskell as well.

During conversion to human-readable representation usually some magical prefix is used. They have been found in source code in some repos (e. g. https://gitlab.com/tezos/tezos/blob/c52ee69231c5ae4d9cec1f3c8aba0c3573922e2a/src/lib_crypto/base58.ml) and checked manually. Existing tests confirm they are correct.

Synopsis

Cryptographic primitive types

data PublicKey Source #

Public cryptographic key used by Tezos. There are three cryptographic curves each represented by its own constructor.

Constructors

PublicKeyEd25519 PublicKey

Public key that uses the ed25519 cryptographic curve.

PublicKeySecp256k1 PublicKey

Public key that uses the secp256k1 cryptographic curve.

PublicKeyP256 PublicKey

Public key that uses the NIST P-256 cryptographic curve.

PublicKeyBLS PublicKey

Public key that uses the BLS12-381 cryptographic curve.

Instances

Instances details
FromJSON PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

ToJSON PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Generic PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Associated Types

type Rep PublicKey :: Type -> Type #

Show PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

NFData PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

rnf :: PublicKey -> () #

Eq PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Ord PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

HasRPCRepr PublicKey Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC PublicKey Source #

TypeHasDoc PublicKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

IsoValue PublicKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT PublicKey :: T Source #

Buildable PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

build :: PublicKey -> Doc

buildList :: [PublicKey] -> Doc

type Rep PublicKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

type AsRPC PublicKey Source # 
Instance details

Defined in Morley.AsRPC

type TypeDocFieldDescriptions PublicKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

type ToT PublicKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

data SecretKey Source #

Secret cryptographic key used by Tezos. Constructors correspond to PublicKey constructors.

Constructors

SecretKeyEd25519 SecretKey

Secret key that uses the ed25519 cryptographic curve.

SecretKeySecp256k1 SecretKey

Secret key that uses the secp256k1 cryptographic curve.

SecretKeyP256 SecretKey

Secret key that uses the NIST P-256 cryptographic curve.

SecretKeyBLS SecretKey

Secret key that uses BLS12-381 curve.

Instances

Instances details
Generic SecretKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Associated Types

type Rep SecretKey :: Type -> Type #

Show SecretKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

NFData SecretKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

rnf :: SecretKey -> () #

Eq SecretKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

HasCLReader SecretKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Buildable SecretKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

build :: SecretKey -> Doc

buildList :: [SecretKey] -> Doc

type Rep SecretKey Source # 
Instance details

Defined in Morley.Tezos.Crypto

data Signature Source #

Cryptographic signatures used by Tezos. Constructors correspond to PublicKey constructors.

Tezos distinguishes signatures for different curves. For instance, ed25519 signatures and secp256k1 signatures are printed differently (have different prefix). However, signatures are packed without information about the curve. For this purpose there is a generic signature which only stores bytes and doesn't carry information about the curve. Apparently unpacking from bytes always produces such signature. Unpacking from string produces a signature with curve information.

Constructors

SignatureEd25519 Signature

Signature that uses the ed25519 cryptographic curve.

SignatureSecp256k1 Signature

Siganture that uses the secp256k1 cryptographic curve.

SignatureP256 Signature

Signature that uses the NIST P-256 cryptographic curve.

SignatureBLS Signature

Signature that uses the BLS12-381 cryptographic curve.

SignatureGeneric ByteString

Generic signature for which curve is unknown.

Instances

Instances details
FromJSON Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

ToJSON Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

Generic Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

Associated Types

type Rep Signature :: Type -> Type #

Show Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

NFData Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

rnf :: Signature -> () #

Eq Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

Ord Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

HasRPCRepr Signature Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC Signature Source #

TypeHasDoc Signature Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

IsoValue Signature Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT Signature :: T Source #

Buildable Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

build :: Signature -> Doc

buildList :: [Signature] -> Doc

type Rep Signature Source # 
Instance details

Defined in Morley.Tezos.Crypto

type AsRPC Signature Source # 
Instance details

Defined in Morley.AsRPC

type TypeDocFieldDescriptions Signature Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

type ToT Signature Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

data HashTag (kind :: HashKind) where Source #

What specific type of hash is used for the Hash.

Instances

Instances details
Lift (HashTag kind :: Type) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

lift :: Quote m => HashTag kind -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => HashTag kind -> Code m (HashTag kind) #

Show (HashTag kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

showsPrec :: Int -> HashTag kind -> ShowS #

show :: HashTag kind -> String #

showList :: [HashTag kind] -> ShowS #

NFData (HashTag kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

rnf :: HashTag kind -> () #

Eq (HashTag kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

(==) :: HashTag kind -> HashTag kind -> Bool #

(/=) :: HashTag kind -> HashTag kind -> Bool #

Ord (HashTag kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

compare :: HashTag kind -> HashTag kind -> Ordering #

(<) :: HashTag kind -> HashTag kind -> Bool #

(<=) :: HashTag kind -> HashTag kind -> Bool #

(>) :: HashTag kind -> HashTag kind -> Bool #

(>=) :: HashTag kind -> HashTag kind -> Bool #

max :: HashTag kind -> HashTag kind -> HashTag kind #

min :: HashTag kind -> HashTag kind -> HashTag kind #

type KeyHashTag = HashTag 'HashKindPublicKey Source #

A compatibility synonym for a public key hash tag.

data Hash (kind :: HashKind) Source #

Blake2b_160 hash of something.

Constructors

Hash 

Fields

Instances

Instances details
HasRPCRepr KeyHash Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC KeyHash Source #

TypeHasDoc KeyHash Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

IsoValue KeyHash Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT KeyHash :: T Source #

Lift (Hash kind :: Type) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

lift :: Quote m => Hash kind -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Hash kind -> Code m (Hash kind) #

AllHashTags kind => FromJSON (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

parseJSON :: Value -> Parser (Hash kind) #

parseJSONList :: Value -> Parser [Hash kind] #

AllHashTags kind => FromJSONKey (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

ToJSON (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

toJSON :: Hash kind -> Value #

toEncoding :: Hash kind -> Encoding #

toJSONList :: [Hash kind] -> Value #

toEncodingList :: [Hash kind] -> Encoding #

ToJSONKey (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Generic (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Associated Types

type Rep (Hash kind) :: Type -> Type #

Methods

from :: Hash kind -> Rep (Hash kind) x #

to :: Rep (Hash kind) x -> Hash kind #

Show (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

showsPrec :: Int -> Hash kind -> ShowS #

show :: Hash kind -> String #

showList :: [Hash kind] -> ShowS #

NFData (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

rnf :: Hash kind -> () #

Eq (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

(==) :: Hash kind -> Hash kind -> Bool #

(/=) :: Hash kind -> Hash kind -> Bool #

Ord (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

compare :: Hash kind -> Hash kind -> Ordering #

(<) :: Hash kind -> Hash kind -> Bool #

(<=) :: Hash kind -> Hash kind -> Bool #

(>) :: Hash kind -> Hash kind -> Bool #

(>=) :: Hash kind -> Hash kind -> Bool #

max :: Hash kind -> Hash kind -> Hash kind #

min :: Hash kind -> Hash kind -> Hash kind #

AllHashTags kind => HasCLReader (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Buildable (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

build :: Hash kind -> Doc

buildList :: [Hash kind] -> Doc

type AsRPC KeyHash Source # 
Instance details

Defined in Morley.AsRPC

type TypeDocFieldDescriptions KeyHash Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

type ToT KeyHash Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

type Rep (Hash kind) Source # 
Instance details

Defined in Morley.Tezos.Crypto

type Rep (Hash kind) = D1 ('MetaData "Hash" "Morley.Tezos.Crypto" "morley-1.20.0-inplace" 'False) (C1 ('MetaCons "Hash" 'PrefixI 'True) (S1 ('MetaSel ('Just "hTag") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HashTag kind)) :*: S1 ('MetaSel ('Just "hBytes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ByteString)))

data HashKind Source #

A kind of a hash.

Constructors

HashKindPublicKey

Public key hash for tz1, tz2, tz3 addresses.

HashKindContract

Contract hash for KT1 smart contract addresses.

HashKindSmartRollup

Smart rollup hash for sr1 addresses.

type KeyHash = Hash 'HashKindPublicKey Source #

Convenience synonym for an on-chain public key hash.

type ContractHash = Hash 'HashKindContract Source #

Convenience synonym for a contract hash.

type SmartRollupHash = Hash 'HashKindSmartRollup Source #

Convenience synonym for a smart rollup hash.

data Bls12381Fr Source #

An element of an algebraic number field (scalar), used for multiplying Bls12381G1 and Bls12381G2.

Instances

Instances details
Bounded Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Enum Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Num Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Fractional Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Integral Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Real Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Show Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

NFData Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Methods

rnf :: Bls12381Fr -> () #

Eq Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Ord Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

HasRPCRepr Bls12381Fr Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC Bls12381Fr Source #

IsoValue Bls12381Fr Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT Bls12381Fr :: T Source #

CurveObject Bls12381Fr Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

MultiplyPoint Bls12381Fr Bls12381G1 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

MultiplyPoint Bls12381Fr Bls12381G2 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

type AsRPC Bls12381Fr Source # 
Instance details

Defined in Morley.AsRPC

type ToT Bls12381Fr Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

data Bls12381G1 Source #

G1 point on the curve.

Instances

Instances details
Show Bls12381G1 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

NFData Bls12381G1 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Methods

rnf :: Bls12381G1 -> () #

Eq Bls12381G1 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

HasRPCRepr Bls12381G1 Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC Bls12381G1 Source #

IsoValue Bls12381G1 Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT Bls12381G1 :: T Source #

CurveObject Bls12381G1 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

MultiplyPoint Bls12381Fr Bls12381G1 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

MultiplyPoint Integer Bls12381G1 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

type AsRPC Bls12381G1 Source # 
Instance details

Defined in Morley.AsRPC

type ToT Bls12381G1 Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

data Bls12381G2 Source #

G2 point on the curve.

Instances

Instances details
Show Bls12381G2 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

NFData Bls12381G2 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

Methods

rnf :: Bls12381G2 -> () #

Eq Bls12381G2 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

HasRPCRepr Bls12381G2 Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC Bls12381G2 Source #

IsoValue Bls12381G2 Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT Bls12381G2 :: T Source #

CurveObject Bls12381G2 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

MultiplyPoint Bls12381Fr Bls12381G2 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

MultiplyPoint Integer Bls12381G2 Source # 
Instance details

Defined in Morley.Tezos.Crypto.BLS12381

type AsRPC Bls12381G2 Source # 
Instance details

Defined in Morley.AsRPC

type ToT Bls12381G2 Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Public/secret key functions

detSecretKey :: ByteString -> SecretKey Source #

Deterministically generate a secret key from seed. Type of the key depends on seed value.

detSecretKey' :: KeyType -> ByteString -> SecretKey Source #

Deterministically generate a secret key from seed. Key type is specified explicitly.

data KeyType Source #

Type of public/secret key as enum.

Instances

Instances details
Bounded KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Enum KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Generic KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Associated Types

type Rep KeyType :: Type -> Type #

Methods

from :: KeyType -> Rep KeyType x #

to :: Rep KeyType x -> KeyType #

Show KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

NFData KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

rnf :: KeyType -> () #

Eq KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

(==) :: KeyType -> KeyType -> Bool #

(/=) :: KeyType -> KeyType -> Bool #

Ord KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Buildable KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

build :: KeyType -> Doc

buildList :: [KeyType] -> Doc

Lift KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

Methods

lift :: Quote m => KeyType -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => KeyType -> Code m KeyType #

type Rep KeyType Source # 
Instance details

Defined in Morley.Tezos.Crypto

type Rep KeyType = D1 ('MetaData "KeyType" "Morley.Tezos.Crypto" "morley-1.20.0-inplace" 'False) ((C1 ('MetaCons "KeyTypeEd25519" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "KeyTypeSecp256k1" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "KeyTypeP256" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "KeyTypeBLS" 'PrefixI 'False) (U1 :: Type -> Type)))

toPublic :: SecretKey -> PublicKey Source #

Create a public key from a secret key.

Signature

signatureToBytes :: ByteArray ba => Signature -> ba Source #

Convert a Signature to raw bytes.

mkSignature :: ByteArray ba => ba -> Maybe Signature Source #

Make a Signature from raw bytes. Can return only SignatureGeneric or SignatureBLS

parseSignatureRaw :: ByteString -> Either ParseSignatureRawError Signature Source #

checkSignature :: PublicKey -> Signature -> ByteString -> Bool Source #

Check that a sequence of bytes has been signed with a given key.

Formatting

hashLengthBytes :: Integral n => n Source #

Length of a hash in bytes (only the hash itself, no tags, checksums or anything).

parseSecretKey :: Text -> Either CryptoParseError SecretKey Source #

Parse unencrypted secret key. It accepts formats containing either with or without the unecrypted prefix.

Hashing

hashKey :: PublicKey -> KeyHash Source #

Compute the b58check of a public key hash.

blake2b :: ByteString -> ByteString Source #

Compute a cryptographic hash of a bytestring using the Blake2b_256 cryptographic hash function. It's used by the BLAKE2B instruction in Michelson.

blake2b160 :: ByteString -> ByteString Source #

Compute a cryptographic hash of a bytestring using the Blake2b_160 cryptographic hash function.

keccak :: ByteString -> ByteString Source #

Compute a cryptographic hash of a bytestring using the Keccak_256 cryptographic hash function. It is used by the KECCAK Michelson instruction.

sha256 :: ByteString -> ByteString Source #

Compute a cryptographic hash of a bytestring using the Sha256 cryptographic hash function.

sha3 :: ByteString -> ByteString Source #

Compute a cryptographic hash of a bytestring using the Sha3_256 cryptographic hash function. It is used by the SHA3 Michelson instruction.

sha512 :: ByteString -> ByteString Source #

Compute a cryptographic hash of a bytestring using the Sha512 cryptographic hash function.

Timelock puzzle

data Chest Source #

A locked chest

Instances

Instances details
Generic Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Associated Types

type Rep Chest :: Type -> Type #

Methods

from :: Chest -> Rep Chest x #

to :: Rep Chest x -> Chest #

Show Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

showsPrec :: Int -> Chest -> ShowS #

show :: Chest -> String #

showList :: [Chest] -> ShowS #

Binary Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

put :: Chest -> Put #

get :: Get Chest #

putList :: [Chest] -> Put #

NFData Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

rnf :: Chest -> () #

Eq Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

(==) :: Chest -> Chest -> Bool #

(/=) :: Chest -> Chest -> Bool #

HasRPCRepr Chest Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC Chest Source #

TypeHasDoc Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

IsoValue Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT Chest :: T Source #

type Rep Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

type Rep Chest
type AsRPC Chest Source # 
Instance details

Defined in Morley.AsRPC

type TypeDocFieldDescriptions Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

type ToT Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

type ToT Chest = 'TChest

data ChestKey Source #

A chest "key" with proof that it was indeed opened fairly.

Instances

Instances details
Generic ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Associated Types

type Rep ChestKey :: Type -> Type #

Methods

from :: ChestKey -> Rep ChestKey x #

to :: Rep ChestKey x -> ChestKey #

Show ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Binary ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

put :: ChestKey -> Put #

get :: Get ChestKey #

putList :: [ChestKey] -> Put #

NFData ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

rnf :: ChestKey -> () #

Eq ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

HasRPCRepr ChestKey Source # 
Instance details

Defined in Morley.AsRPC

Associated Types

type AsRPC ChestKey Source #

TypeHasDoc ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

IsoValue ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT ChestKey :: T Source #

type Rep ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

type AsRPC ChestKey Source # 
Instance details

Defined in Morley.AsRPC

type TypeDocFieldDescriptions ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

type ToT ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

data OpeningResult Source #

The result of opening the chest.

Constructors

Correct ByteString

The chest was opened correctly.

BogusCipher

The chest was opened correctly, but the contents do not decode with the given symmetric key.

BogusOpening

The chest was not opened correctly, i.e. proof verification failed.

newtype TLTime Source #

Number of steps a timelock needs to be opened without knowing a "secret", i.e. modulo factorization.

The reference implementation uses OCaml int, and it can only be positive, so on 64-bit architecture it's actually a 62-bit natural. We use Word62 to represent it.

The constructor is marked Unsafe since GHC does not warn on overflowing literals (exceeding custom Word62 type bounds), thus the resultant TLTime value may get truncated silently.

>>> UnsafeTLTime 4611686018427387906
UnsafeTLTime {unTLTime = 2}

Constructors

UnsafeTLTime 

Fields

Bundled Patterns

pattern TLTime :: Word62 -> TLTime 

Instances

Instances details
Bounded TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Show TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Eq TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

(==) :: TLTime -> TLTime -> Bool #

(/=) :: TLTime -> TLTime -> Bool #

HasCLReader TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Buildable TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

build :: TLTime -> Doc

buildList :: [TLTime] -> Doc

openChest :: Chest -> ChestKey -> TLTime -> OpeningResult Source #

Try to (quickly) open a chest with the given key, verifying the proof.

mkTLTime :: Integral i => i -> Either Text TLTime Source #

Safely creates TLTime checking for overflow and underflow. Accepts a number of any type.

toTLTime :: (Integral a, CheckIntSubType a Word62) => a -> TLTime Source #

Safely creates TLTime.

This is the recommended way to create TLTime values.

When constructing literals, you'll need to specify the type of the literal. Bear in mind that GHC will check for literal overflow on builtin types like Word16 and Word32, but not on Word62, so be aware that toTLTime from Word62 will overflow silently. Prefer using builtin types when possible.

>>> unTLTime $ toTLTime (4611686018427387903 :: Word62)
4611686018427387903
>>> unTLTime $ toTLTime (4611686018427387904 :: Word62)
0

Utilities

encodeBase58Check :: ByteString -> Text Source #

Encode a bytestring in Base58Check format.

decodeBase58Check :: Text -> Maybe ByteString Source #

Decode a bytestring from Base58Check format.

decodeBase58CheckWithPrefix :: ByteString -> Text -> Either B58CheckWithPrefixError ByteString Source #

Parse a base58check encoded value expecting some prefix. If the actual prefix matches the expected one, it's stripped of and the resulting payload is returned.

parseSomeHashBase58 :: Text -> Either CryptoParseError (Some Hash) Source #

Parse a Hash of any known kind from its its human-readable textual representation.