Onchain.ERC7730.Descriptor (onchain v0.7.0)

Copy Markdown View Source

Parsed, validated representation of an ERC-7730 clear-signing descriptor.

An ERC-7730 descriptor is a JSON document with three top-level sections:

  • context — the binding constraints: either a contract (deployments + ABI) or an eip712 (domain + typed-data schemas) context.
  • metadata — owner, constants, enums, and optional token info.
  • displayformats keyed by function signature (contract) or primary type (EIP-712), each carrying an ordered list of display fields.

parse/1 turns the decoded JSON map into a t/0 struct, validating the structural rules. The original decoded JSON is retained in :raw so that $.-rooted paths (e.g. $.metadata.constants.tokenAddress) resolve against the document.

Scope

This first pass keeps the structure faithful to the spec but does not resolve includes / $ref-to-external-document references — descriptors are expected to be self-contained (the registry-side resolution of shared ercs/* includes is out of scope, per Task 74).

API Functions

FunctionArityDescriptionParam Kinds
parse1Parse and structurally validate a decoded ERC-7730 JSON map.raw: value

Summary

Functions

Parse and structurally validate a decoded ERC-7730 JSON map.

Types

context()

@type context() ::
  {:contract,
   %{
     deployments: [deployment()],
     abi: term() | nil,
     address_matcher: String.t() | nil
   }}
  | {:eip712,
     %{
       deployments: [deployment()],
       domain: map() | nil,
       domain_separator: String.t() | nil,
       schemas: term() | nil
     }}

deployment()

@type deployment() :: %{chain_id: non_neg_integer(), address: <<_::160>>}

field()

@type field() :: %{
  path: String.t() | nil,
  value: term(),
  label: String.t() | nil,
  format: atom(),
  params: map(),
  visible: boolean()
}

format()

@type format() :: %{intent: String.t() | map() | nil, fields: [field()]}

t()

@type t() :: %Onchain.ERC7730.Descriptor{
  context: context(),
  display: %{formats: %{optional(String.t()) => format()}},
  metadata: map(),
  raw: map()
}

Functions

parse(raw)

@spec parse(map()) :: {:ok, t()} | {:error, {atom(), term()}}

Parse and structurally validate a decoded ERC-7730 JSON map.

Parameters

  • raw - Decoded JSON map (string keys) of an ERC-7730 descriptor (value)

Returns

Validated descriptor struct, or an error: :missing_context, :invalid_context, :no_deployments, :invalid_address, :missing_display, :invalid_field ({:ok, t()} | {:error, {tag, reason}})

# descripex:contract
%{
  params: %{
    raw: %{
      description: "Decoded JSON map (string keys) of an ERC-7730 descriptor",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, t()} | {:error, {tag, reason}}",
    description: "Validated descriptor struct, or an error: :missing_context, :invalid_context, :no_deployments, :invalid_address, :missing_display, :invalid_field"
  }
}