singular-registry
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Singular.Registry.Blueprint

Description

Minimal CIP-57 Plutus blueprint parser and validator. Loads a plutus.json blueprint file produced by the Aiken compiler, extracts type schemas and script hashes, and validates Data values against the declared schemas.

The blueprint also carries optional compiledCode fields (hex-encoded double-CBOR PlutusV3 scripts). extractCompiledCode decodes these into ShortByteString suitable for PlutusBinary. The state script is parameterized by previousPolicies (a predecessor-policy allowlist) via applyPreviousPolicies; the request script is parameterized by (statePolicyId, cageToken) via applyRequestParams.

This module is the public compatibility facade: it holds no implementations of its own and re-exports the focused owners Singular.Registry.Blueprint.Schema (schema and validation), Singular.Registry.Blueprint.Params (parameter application) and Singular.Registry.Blueprint.Load (loading and code selection).

Synopsis

Schema types

data Blueprint Source #

A parsed CIP-57 blueprint.

Constructors

Blueprint 

Fields

Instances

Instances details
FromJSON Blueprint Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

parseJSON :: Value -> Parser Blueprint

parseJSONList :: Value -> Parser [Blueprint]

omittedField :: Maybe Blueprint

Show Blueprint Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

showsPrec :: Int -> Blueprint -> ShowS Source #

show :: Blueprint -> String Source #

showList :: [Blueprint] -> ShowS Source #

Eq Blueprint Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

(==) :: Blueprint -> Blueprint -> Bool Source #

(/=) :: Blueprint -> Blueprint -> Bool Source #

data Validator Source #

A validator entry in the blueprint.

Constructors

Validator 

Fields

  • vTitle :: Text

    Human-readable validator name

  • vDatum :: Maybe Schema

    Datum schema, absent for minting validators

  • vRedeemer :: Schema

    Redeemer schema

  • vHash :: Text

    Hex-encoded script hash (28 bytes)

  • vCompiledCode :: Maybe Text

    Hex-encoded double-CBOR PlutusV3 script

  • vParameters :: Int

    How many parameters this validator applies. A blueprint omits the array entirely for a parameterless validator, so an absent parameters key reads as zero. This is what makes a parameterless policy's compiled hash its policy id, with no applied hash to derive, so a consumer that wants to state it should READ it here rather than write the number down.

Instances

Instances details
FromJSON Validator Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

parseJSON :: Value -> Parser Validator

parseJSONList :: Value -> Parser [Validator]

omittedField :: Maybe Validator

Show Validator Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

showsPrec :: Int -> Validator -> ShowS Source #

show :: Validator -> String Source #

showList :: [Validator] -> ShowS Source #

Eq Validator Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

(==) :: Validator -> Validator -> Bool Source #

(/=) :: Validator -> Validator -> Bool Source #

data Schema Source #

CIP-57 schema for a Plutus data type.

Constructors

SBytes
{"dataType": "bytes"}
SInteger
{"dataType": "integer"}
SList Schema

{"dataType": "list", "items": schema} — a homogeneous list of any length.

STuple [Schema]

{"dataType": "list", "items": [schema, ...]} — Aiken's FIXED TUPLE (#157 request-destination-binding): an ARRAY of positional item schemas. On the wire it is a Plutus List of exactly that arity, each element of its own declared type, which is what distinguishes it from SList and why it cannot share that case: a homogeneous rule would accept a three-element pair.

SConstructors [Constructor]
{"anyOf": [...constructors...]}
SRef Text
{"$ref": "#definitions..."}

Instances

Instances details
FromJSON Schema Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

parseJSON :: Value -> Parser Schema

parseJSONList :: Value -> Parser [Schema]

omittedField :: Maybe Schema

Show Schema Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

showsPrec :: Int -> Schema -> ShowS Source #

show :: Schema -> String Source #

showList :: [Schema] -> ShowS Source #

Eq Schema Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

(==) :: Schema -> Schema -> Bool Source #

(/=) :: Schema -> Schema -> Bool Source #

data Constructor Source #

A single constructor alternative in a schema.

Constructors

Constructor 

Fields

  • conIndex :: Integer

    Constructor tag (matches Aiken's Constr index)

  • conFields :: [Schema]

    Schemas for each positional field

Instances

Instances details
FromJSON Constructor Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

parseJSON :: Value -> Parser Constructor

parseJSONList :: Value -> Parser [Constructor]

omittedField :: Maybe Constructor

Show Constructor Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

showsPrec :: Int -> Constructor -> ShowS Source #

show :: Constructor -> String Source #

showList :: [Constructor] -> ShowS Source #

Eq Constructor Source # 
Instance details

Defined in Singular.Registry.Blueprint.Schema

Methods

(==) :: Constructor -> Constructor -> Bool Source #

(/=) :: Constructor -> Constructor -> Bool Source #

Loading

loadBlueprint Source #

Arguments

:: FilePath

Path to the plutus.json file

-> IO (Either String Blueprint) 

Load and parse a CIP-57 blueprint from a file path.

Supplied application and token-policy code

data ApplicationCodes Source #

Supplied application and active-token-policy code for the shared identity adapters. The caller chooses the application; no application is built into the registry library.

Constructors

ApplicationCodes 

Fields

Validation

validateData Source #

Arguments

:: Map Text Schema

Named definitions for $ref resolution

-> Schema

Schema to validate against

-> Data

Value to validate

-> Bool 

Validate a Data value against a Schema, resolving $ref through the definitions map.

Script hash extraction

extractScriptHash Source #

Arguments

:: Text

Title prefix to match

-> Blueprint

Blueprint to search

-> Maybe Text 

Find the first validator whose title starts with the given prefix and return its hash.

Compiled code extraction

extractCompiledCode Source #

Arguments

:: Text

Title prefix to match

-> Blueprint

Blueprint to search

-> Maybe ShortByteString 

Find the first validator whose title starts with the given prefix and return its compiled script bytes as a ShortByteString. The hex-encoded compiledCode is decoded to raw bytes suitable for PlutusBinary.

Parameter application

applyDataParam Source #

Arguments

:: Data

Encoded parameter value

-> ShortByteString

Flat-encoded UPLC program

-> ShortByteString 

Apply a Data parameter to a UPLC script. The blueprint's compiledCode is a flat-encoded UPLC program that expects one parameter. This function applies the supplied Data value to that parameter slot, producing the final script bytes.

applyIntParam Source #

Arguments

:: Integer

Encoded integer parameter

-> ShortByteString

Flat-encoded UPLC program

-> ShortByteString 

Apply an integer parameter to a UPLC script.

`witness(kind, registry)` (#157 mint-matches-edge-deltas) takes its kind as a plain integer, and the deployment applies it three times. Wrapping the Data encoding here keeps the Data vocabulary inside this module, where the rest of the blueprint's encoding already lives.

applyBytesParam Source #

Arguments

:: ByteString

Encoded bytes parameter

-> ShortByteString

Flat-encoded UPLC program

-> ShortByteString 

Apply a raw bytes parameter to a UPLC script.

applyOutputRef Source #

Arguments

:: OnChainTxOutRef

Output reference to apply as the seed parameter

-> ShortByteString

Flat-encoded UPLC program

-> ShortByteString 

Apply an OnChainTxOutRef parameter to a UPLC script. Wraps applyDataParam with the canonical Constr 0 [bytes, integer] encoding produced by the 'ToData OnChainTxOutRef' instance — matching what the on-chain validator's parameter slot expects when the Aiken validator is parameterized by an OutputReference.

applyPreviousPolicies Source #

Arguments

:: [ByteString]

Predecessor policy-id bytes (28 bytes each); [] for genesis

-> ShortByteString

Flat-encoded raw state UPLC program

-> ShortByteString 

Apply the state validator's previousPolicies allowlist parameter. The on-chain parameter type is List<PolicyId>, encoded as List [B pid0, B pid1, …] (an empty List [] for a genesis cage, which makes migration into it impossible).

applyRequestParams Source #

Arguments

:: ByteString

State policy id bytes

-> OnChainTokenId

Cage token asset name

-> ShortByteString

Flat-encoded request UPLC program

-> ShortByteString 

Apply request-validator parameters in source order: statePolicyId first, then cageTokenName.