from enum import Enum
from typing import Annotated, Any
from pydantic import Field, RootModel
from erc7730.model.base import Model
from erc7730.model.types import Id
# ruff: noqa: N815 - camel case field names are tolerated to match schema
[docs]
class TokenAmountParameters(Model):
"""
Token Amount Formatting Parameters.
"""
tokenPath: str | None = Field(
title="Token Path",
description="Path reference to the address of the token contract. Used to associate correct ticker. If ticker"
"is not found or tokenPath is not set, the wallet SHOULD display the raw value instead with an"
'"Unknown token" warning.',
)
nativeCurrencyAddress: str | list[str] | None = Field(
default=None,
title="Native Currency Address",
description="An address or array of addresses, any of which are interpreted as an amount in native currency"
"rather than a token.",
)
threshold: str | None = Field(
default=None,
title="Unlimited Threshold",
description="The threshold above which the amount should be displayed using the message parameter rather than"
"the real amount.",
)
message: str | None = Field(
default=None,
title="Unlimited Message",
description="The message to display when the amount is above the threshold.",
)
[docs]
class DateEncoding(str, Enum):
"""
The encoding for a date.
"""
BLOCKHEIGHT = "blockheight"
"""The date is encoded as a block height."""
TIMESTAMP = "timestamp"
"""The date is encoded as a timestamp."""
[docs]
class DateParameters(Model):
"""
Date Formatting Parameters
"""
encoding: DateEncoding = Field(title="Date Encoding", description="The encoding of the date.")
[docs]
class AddressNameType(str, Enum):
"""
The type of address to display. Restrict allowable sources of names and MAY lead to additional checks from wallets.
"""
WALLET = "wallet"
"""Address is an account controlled by the wallet."""
EOA = "eoa"
"""Address is an Externally Owned Account."""
CONTRACT = "contract"
"""Address is a well known smartcontract."""
TOKEN = "token" # nosec B105 - bandit false positive
"""Address is a well known ERC-20 token."""
COLLECTION = "collection"
"""Address is a well known NFT collection."""
[docs]
class AddressNameSources(str, Enum):
"""
Trusted Source for names.
"""
LOCAL = "local"
"""Address MAY be replaced with a local name trusted by user. Wallets MAY consider that local setting for sources
is always valid."""
ENS = "ens"
"""Address MAY be replaced with an associated ENS domain."""
[docs]
class AddressNameParameters(Model):
"""
Address Names Formatting Parameters.
"""
type: AddressNameType | None = Field(
default=None,
title="Address Type",
description="The type of address to display. Restrict allowable sources of names and MAY lead to additional"
"checks from wallets.",
)
sources: list[AddressNameSources] | None = Field(
default=None,
title="Trusted Sources",
description="Trusted Sources for names, in order of preferences. See specification for more details on sources"
"values.",
)
[docs]
class CallDataParameters(Model):
"""
Embedded Calldata Formatting Parameters.
"""
selector: str | None = Field(
default=None,
title="Called Selector",
description="The selector being called, if not contained in the calldata. Hex string representation.",
)
calleePath: str | None = Field(
default=None,
title="Callee Path",
description="The path to the address of the contract being called by this embedded calldata.",
)
[docs]
class NftNameParameters(Model):
"""
NFT Names Formatting Parameters.
"""
collectionPath: str = Field(
title="Collection Path", description="The path to the collection in the structured data."
)
[docs]
class UnitParameters(Model):
"""
Unit Formatting Parameters.
"""
base: str = Field(
title="Unit base symbol",
description="The base symbol of the unit, displayed after the converted value. It can be an SI unit symbol or"
"acceptable dimensionless symbols like % or bps.",
)
decimals: int | None = Field(
default=None, title="Decimals", description="The number of decimals of the value, used to convert to a float."
)
prefix: bool | None = Field(
default=None,
title="Prefix",
description="Whether the value should be converted to a prefixed unit, like k, M, G, etc.",
)
[docs]
class Screen(RootModel[dict[str, Any]]):
"""
Screens section is used to group multiple fields to display into screens. Each key is a wallet type name. The
format of the screens is wallet type dependent, as well as what can be done (reordering fields, max number of
screens, etc...). See each wallet manufacturer documentation for more information.
"""
[docs]
class FieldsBase(Model):
"""
A field formatter, containing formatting information of a single field in a message.
"""
path: str = Field(
title="Path",
description="A path to the field in the structured data. The path is a JSON path expression that can be used to"
"extract the field value from the structured data.",
)
SimpleIntent = Annotated[
str,
Field(
title="Simple Intent",
description="A description of the intent of the structured data signing, that will be displayed to the user.",
),
]
ComplexIntent = Annotated[
dict[str, str],
Field(
title="Complex Intent",
description="A description of the intent of the structured data signing, that will be displayed to the user.",
),
]