cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cometa.Script.Native

Description

Native signature, threshold, time and Dijkstra guard scripts. Values own their exact CBOR encoding. Equality and ordering compare that encoding, so semantically equivalent nonminimal encodings can differ. Slot numbers count slots, with an inclusive lower bound and exclusive upper bound.

import qualified Cometa.Script.Native as Native

window :: Native.NativeScript
window = Native.allOf [Native.invalidBefore 100, Native.invalidAfter 200]
Synopsis

Script values

data NativeScript Source #

An immutable script with validated hash lengths and unsigned thresholds. Imported script encodings are retained exactly, including child encodings. Show is diagnostic, not an interchange format.

data NativeScriptView Source #

Read-only alternatives. Construct scripts with the functions below; inspecting this value cannot bypass credential validation.

Constructors

RequireSignature !(KeyHash Payment)

Requires a payment verification-key signature.

RequireAll ![NativeScript]

All children must succeed; an empty list succeeds.

RequireAny ![NativeScript]

One or more children must succeed; an empty list fails.

RequireAtLeast !Word64 ![NativeScript]

Required count followed by ordered children; zero always succeeds.

InvalidBefore !Word64

Inclusive lower slot bound.

InvalidAfter !Word64

Exclusive upper slot bound.

RequireGuard !(Credential Guard)

Credential must be present in transaction guards (Dijkstra onwards).

Conditions

signature :: KeyHash Payment -> NativeScript Source #

Require a signature from this payment key hash.

allOf :: [NativeScript] -> NativeScript Source #

Require every child in order. Empty input is an always-succeeding script.

anyOf :: [NativeScript] -> NativeScript Source #

Require at least one child. Empty input is an always-failing script.

atLeast :: Word64 -> [NativeScript] -> NativeScript Source #

Require this many successful children. Counts above the child count are valid and deliberately unsatisfiable. Duplicate children retain their positions and count separately; zero with no children is valid and always succeeds.

invalidBefore :: Word64 -> NativeScript Source #

Require the validity interval to start at or after the supplied slot.

invalidAfter :: Word64 -> NativeScript Source #

Require the validity interval to end at or before the supplied exclusive upper bound. Slot zero is valid and yields an unsatisfiable time restriction.

requireGuard :: Credential Guard -> NativeScript Source #

Require a key or script guard credential. This alternative requires Dijkstra ledger support; construction does not assert era availability.

Inspection and encoding

view :: NativeScript -> NativeScriptView Source #

Inspect the semantic alternative and its ordered children.

encodeCbor :: NativeScript -> ByteString Source #

Exact imported bytes, or a definite-length encoding for assembled values. Assembling a parent preserves each child's exact encoding.

decodeCbor :: ByteString -> Either Error NativeScript Source #

Decode exactly one complete script, checking all alternatives and credential hash lengths. Malformed, trailing or schema-invalid bytes return InvalidScriptCbor. Nonminimal and indefinite encodings are retained.

toJson :: NativeScript -> Value Source #

Export the native script JSON construction schema, shared with cardano-api for signatures, allanyatLeast and before/after. Dijkstra guards use {"type":"guard","keyHash":"..."} or "scriptHash" as accepted by cardano-c. Numbers are unsigned JSON integers and hashes are lowercase hex. This describes semantic conditions, so importing it creates fresh CBOR and does not retain an imported script's original encoding or hash identity. This construction schema is distinct from CIP-116 inspection JSON.

fromJson :: Value -> Either Error NativeScript Source #

Import native script construction JSON. Required fields and hash lengths are validated, thresholds and slots must be unsigned 64-bit integers, and children preserve order and duplicates. A guard requires exactly one of keyHash or scriptHash. Other object fields are ignored. Invalid input returns InvalidScriptJson. Valid but unsatisfiable thresholds are retained. Fresh definite CBOR is assembled; original JSON/CBOR encoding is not retained.

Script hash

hash :: NativeScript -> IO (Either Error ScriptHash) Source #

Compute BLAKE2b-224 over byte zero followed by the exact script encoding. Native hashing failures return NativeError.