| Copyright | 2020 Input Output (Hong Kong) Ltd. 2021-2022 Input Output Global Inc. (IOG) 2023-2025 Intersect |
|---|---|
| License | Apache-2.0 |
| Safe Haskell | None |
| Language | Haskell2010 |
Cardano.Address.Script
Description
Synopsis
- data Script elem
- = RequireSignatureOf !elem
- | RequireAllOf ![Script elem]
- | RequireAnyOf ![Script elem]
- | RequireSomeOf Word8 ![Script elem]
- | ActiveFromSlot Natural
- | ActiveUntilSlot Natural
- serializeScript :: Script KeyHash -> ByteString
- foldScript :: (a -> b -> b) -> b -> Script a -> b
- data ScriptTemplate = ScriptTemplate {}
- newtype Cosigner = Cosigner Word8
- data ValidationLevel
- data ErrValidateScript
- data ErrRecommendedValidateScript
- data ErrValidateScriptTemplate
- validateScript :: ValidationLevel -> Script KeyHash -> Either ErrValidateScript ()
- validateScriptTemplate :: ValidationLevel -> ScriptTemplate -> Either ErrValidateScriptTemplate ()
- validateScriptOfTemplate :: ValidationLevel -> Script Cosigner -> Either ErrValidateScript ()
- prettyErrValidateScript :: ErrValidateScript -> String
- prettyErrValidateScriptTemplate :: ErrValidateScriptTemplate -> String
- newtype ScriptHash = ScriptHash {}
- toScriptHash :: Script KeyHash -> ScriptHash
- scriptHashFromBytes :: ByteString -> Maybe ScriptHash
- scriptHashToText :: ScriptHash -> KeyRole -> Maybe GovernanceType -> Text
- scriptHashFromText :: Text -> Either ErrScriptHashFromText ScriptHash
- prettyErrScriptHashFromText :: ErrScriptHashFromText -> String
Script
A Script type represents multi signature script. The script embodies conditions
that need to be satisfied to make it valid.
Since: 3.0.0
Constructors
| RequireSignatureOf !elem | |
| RequireAllOf ![Script elem] | |
| RequireAnyOf ![Script elem] | |
| RequireSomeOf Word8 ![Script elem] | |
| ActiveFromSlot Natural | |
| ActiveUntilSlot Natural |
Instances
serializeScript :: Script KeyHash -> ByteString #
This function realizes what cardano-node's `Api.serialiseToCBOR script` realizes This is basically doing the symbolically following: toCBOR [0,multisigScript]
Since: 3.0.0
foldScript :: (a -> b -> b) -> b -> Script a -> b #
Script folding
Since: 3.2.0
Script template
data ScriptTemplate #
Represents the script template that show the structure of the script and determines the expected place of verification keys corresponding to given cosigners.
Since: 3.2.0
Instances
| FromJSON ScriptTemplate # | |||||
Defined in Cardano.Address.Script Methods parseJSON :: Value -> Parser ScriptTemplate # parseJSONList :: Value -> Parser [ScriptTemplate] # | |||||
| ToJSON ScriptTemplate # | |||||
Defined in Cardano.Address.Script Methods toJSON :: ScriptTemplate -> Value # toEncoding :: ScriptTemplate -> Encoding # toJSONList :: [ScriptTemplate] -> Value # toEncodingList :: [ScriptTemplate] -> Encoding # omitField :: ScriptTemplate -> Bool # | |||||
| NFData ScriptTemplate # | |||||
Defined in Cardano.Address.Script Methods rnf :: ScriptTemplate -> () # | |||||
| Generic ScriptTemplate # | |||||
Defined in Cardano.Address.Script Associated Types
Methods from :: ScriptTemplate -> Rep ScriptTemplate x # to :: Rep ScriptTemplate x -> ScriptTemplate # | |||||
| Show ScriptTemplate # | |||||
Defined in Cardano.Address.Script Methods showsPrec :: Int -> ScriptTemplate -> ShowS # show :: ScriptTemplate -> String # showList :: [ScriptTemplate] -> ShowS # | |||||
| Eq ScriptTemplate # | |||||
Defined in Cardano.Address.Script Methods (==) :: ScriptTemplate -> ScriptTemplate -> Bool # (/=) :: ScriptTemplate -> ScriptTemplate -> Bool # | |||||
| type Rep ScriptTemplate # | |||||
Defined in Cardano.Address.Script type Rep ScriptTemplate = D1 ('MetaData "ScriptTemplate" "Cardano.Address.Script" "cardano-addresses-4.0.2-inplace" 'False) (C1 ('MetaCons "ScriptTemplate" 'PrefixI 'True) (S1 ('MetaSel ('Just "cosigners") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Cosigner XPub)) :*: S1 ('MetaSel ('Just "template") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Script Cosigner)))) | |||||
Represents the cosigner of the script, ie., party that co-shares the script.
Since: 3.2.0
Instances
| FromJSON Cosigner # | |||||
Defined in Cardano.Address.Script | |||||
| ToJSON Cosigner # | |||||
| NFData Cosigner # | |||||
Defined in Cardano.Address.Script | |||||
| Generic Cosigner # | |||||
Defined in Cardano.Address.Script Associated Types
| |||||
| Show Cosigner # | |||||
| Eq Cosigner # | |||||
| Ord Cosigner # | |||||
Defined in Cardano.Address.Script | |||||
| Hashable Cosigner # | |||||
Defined in Cardano.Address.Script | |||||
| FromJSON (Script Cosigner) # | |||||
| type Rep Cosigner # | |||||
Defined in Cardano.Address.Script | |||||
Validation
data ValidationLevel #
Validation level. Required level does basic check that will make sure the script is accepted in ledger. Recommended level collects a number of checks that will warn about dangerous, unwise and redundant things present in the script.
Since: 3.2.0
Constructors
| RequiredValidation | |
| RecommendedValidation |
Instances
| NFData ValidationLevel # | |||||
Defined in Cardano.Address.Script Methods rnf :: ValidationLevel -> () # | |||||
| Generic ValidationLevel # | |||||
Defined in Cardano.Address.Script Associated Types
Methods from :: ValidationLevel -> Rep ValidationLevel x # to :: Rep ValidationLevel x -> ValidationLevel # | |||||
| Show ValidationLevel # | |||||
Defined in Cardano.Address.Script Methods showsPrec :: Int -> ValidationLevel -> ShowS # show :: ValidationLevel -> String # showList :: [ValidationLevel] -> ShowS # | |||||
| Eq ValidationLevel # | |||||
Defined in Cardano.Address.Script Methods (==) :: ValidationLevel -> ValidationLevel -> Bool # (/=) :: ValidationLevel -> ValidationLevel -> Bool # | |||||
| type Rep ValidationLevel # | |||||
Defined in Cardano.Address.Script | |||||
data ErrValidateScript #
Possible validation errors when validating a script
Since: 3.0.0
Constructors
| LedgerIncompatible | |
| WrongKeyHash | |
| NotUniformKeyType | |
| Malformed | |
| NotRecommended ErrRecommendedValidateScript |
Instances
| Show ErrValidateScript # | |
Defined in Cardano.Address.Script Methods showsPrec :: Int -> ErrValidateScript -> ShowS # show :: ErrValidateScript -> String # showList :: [ErrValidateScript] -> ShowS # | |
| Eq ErrValidateScript # | |
Defined in Cardano.Address.Script Methods (==) :: ErrValidateScript -> ErrValidateScript -> Bool # (/=) :: ErrValidateScript -> ErrValidateScript -> Bool # | |
data ErrRecommendedValidateScript #
Possible recommended validation errors when validating a script
Since: 3.2.0
Instances
| Show ErrRecommendedValidateScript # | |
Defined in Cardano.Address.Script Methods showsPrec :: Int -> ErrRecommendedValidateScript -> ShowS # show :: ErrRecommendedValidateScript -> String # showList :: [ErrRecommendedValidateScript] -> ShowS # | |
| Eq ErrRecommendedValidateScript # | |
Defined in Cardano.Address.Script Methods (==) :: ErrRecommendedValidateScript -> ErrRecommendedValidateScript -> Bool # (/=) :: ErrRecommendedValidateScript -> ErrRecommendedValidateScript -> Bool # | |
data ErrValidateScriptTemplate #
Possible validation errors when validating a script template
Since: 3.2.0
Constructors
| WrongScript ErrValidateScript | |
| DuplicateXPubs | |
| UnknownCosigner | |
| MissingCosignerXPub | |
| NoCosignerInScript | |
| NoCosignerXPub |
Instances
| Show ErrValidateScriptTemplate # | |
Defined in Cardano.Address.Script Methods showsPrec :: Int -> ErrValidateScriptTemplate -> ShowS # show :: ErrValidateScriptTemplate -> String # showList :: [ErrValidateScriptTemplate] -> ShowS # | |
| Eq ErrValidateScriptTemplate # | |
Defined in Cardano.Address.Script Methods (==) :: ErrValidateScriptTemplate -> ErrValidateScriptTemplate -> Bool # (/=) :: ErrValidateScriptTemplate -> ErrValidateScriptTemplate -> Bool # | |
validateScript :: ValidationLevel -> Script KeyHash -> Either ErrValidateScript () #
Validate a Script, semantically
Since: 3.0.0
validateScriptTemplate :: ValidationLevel -> ScriptTemplate -> Either ErrValidateScriptTemplate () #
Validate a ScriptTemplate, semantically
Since: 3.2.0
validateScriptOfTemplate :: ValidationLevel -> Script Cosigner -> Either ErrValidateScript () #
Validate a script in ScriptTemplate
Since: 3.5.0
prettyErrValidateScript :: ErrValidateScript -> String #
Pretty-print a script validation error.
Since: 3.0.0
prettyErrValidateScriptTemplate :: ErrValidateScriptTemplate -> String #
Pretty-print a script template validation error.
Since: 3.2.0
Hashing
newtype ScriptHash #
A ScriptHash type represents script hash. The hash is expected to have size of
28-byte.
Since: 3.0.0
Constructors
| ScriptHash | |
Fields | |
Instances
| NFData ScriptHash # | |||||
Defined in Cardano.Address.Script Methods rnf :: ScriptHash -> () # | |||||
| Generic ScriptHash # | |||||
Defined in Cardano.Address.Script Associated Types
| |||||
| Show ScriptHash # | |||||
Defined in Cardano.Address.Script Methods showsPrec :: Int -> ScriptHash -> ShowS # show :: ScriptHash -> String # showList :: [ScriptHash] -> ShowS # | |||||
| Eq ScriptHash # | |||||
Defined in Cardano.Address.Script | |||||
| Ord ScriptHash # | |||||
Defined in Cardano.Address.Script Methods compare :: ScriptHash -> ScriptHash -> Ordering # (<) :: ScriptHash -> ScriptHash -> Bool # (<=) :: ScriptHash -> ScriptHash -> Bool # (>) :: ScriptHash -> ScriptHash -> Bool # (>=) :: ScriptHash -> ScriptHash -> Bool # max :: ScriptHash -> ScriptHash -> ScriptHash # min :: ScriptHash -> ScriptHash -> ScriptHash # | |||||
| type Rep ScriptHash # | |||||
Defined in Cardano.Address.Script type Rep ScriptHash = D1 ('MetaData "ScriptHash" "Cardano.Address.Script" "cardano-addresses-4.0.2-inplace" 'True) (C1 ('MetaCons "ScriptHash" 'PrefixI 'True) (S1 ('MetaSel ('Just "unScriptHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
toScriptHash :: Script KeyHash -> ScriptHash #
Computes the hash of a given script, by first serializing it to CBOR.
Since: 3.0.0
scriptHashFromBytes :: ByteString -> Maybe ScriptHash #
Construct an ScriptHash from raw ByteString (28 bytes).
Since: 3.0.0
scriptHashToText :: ScriptHash -> KeyRole -> Maybe GovernanceType -> Text #
Encode a ScriptHash to bech32 Text or hex if key role is unknown.
In the case of governance role, if one wants to include additional byte
as specified in CIP-0129
unless the function is called with CIP0105.
One byte is prepended to script hash only in governance context. The rules how to contruct it are summarized below
drep 0010.... hot 0000.... key type cold 0001.... scripthash ....0011 credential type
This is on top of X_script, where X={drep, cc_hot, cc_hot}, which lacks the additional byte.
In scriptHashFromText we additionally
support reading legacy X which also lacks the additional byte, and has the same payload as
as the corresponding X_script.
Since: 4.0.0
scriptHashFromText :: Text -> Either ErrScriptHashFromText ScriptHash #
Construct a ScriptHash from Text. It should be
Bech32 encoded text with one of following hrp:
scriptdrepcc_coldcc_hotdrep_scriptcc_cold_scriptcc_hot_script
If if hex is encountered it is converted in rawly fashion
Since: 4.0.0
prettyErrScriptHashFromText :: ErrScriptHashFromText -> String #
Possible errors when deserializing a script hash from text.
Since: 4.0.0