Skip to content

Commit

Permalink
chore: update model and linter to support excluded (#63)
Browse files Browse the repository at this point in the history
* chore: update model and linter to support `excluded`

align with LedgerHQ/clear-signing-erc7730-registry#31

* Update src/erc7730/model/display.py

Co-authored-by: ckorchane-ledger <[email protected]>

---------

Co-authored-by: ckorchane-ledger <[email protected]>
  • Loading branch information
jnicoulaud-ledger and ckorchane-ledger authored Oct 9, 2024
1 parent 44d23e8 commit b0ec7a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/erc7730/lint/lint_validate_display_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _validate_eip712_paths(cls, descriptor: ResolvedERC7730Descriptor, out: Outp
if schema.primaryType not in schema.types:
out.error(
title="Invalid EIP712 Schema",
message=f"Primary type `{schema.primaryType}` is not present in schema types. Please make"
message=f"Primary type `{schema.primaryType}` is not present in schema types. Please make "
f"sure the EIP-712 includes a definition for the primary type.",
)
continue
Expand All @@ -44,27 +44,32 @@ def _validate_eip712_paths(cls, descriptor: ResolvedERC7730Descriptor, out: Outp
)
continue
eip712_paths = compute_eip712_paths(schema)
format_paths = compute_format_paths(descriptor.display.formats[schema.primaryType]).data_paths
primary_type_format = descriptor.display.formats[schema.primaryType]
format_paths = compute_format_paths(primary_type_format).data_paths
excluded = primary_type_format.excluded or []

for path in eip712_paths - format_paths:
if path in excluded:
continue

if any(re.fullmatch(regex, path) for regex in AUTHORIZED_MISSING_DISPLAY_FIELDS_REGEX):
out.debug(
title="Optional Display field missing",
message=f"Display field for path `{path}` is missing for message {schema.primaryType}."
f"If intentionally excluded, please add it to `exclude` list to avoid this"
message=f"Display field for path `{path}` is missing for message {schema.primaryType}. "
f"If intentionally excluded, please add it to `exclude` list to avoid this "
f"warning.",
)
else:
out.warning(
title="Missing Display field",
message=f"Display field for path `{path}` is missing for message {schema.primaryType}."
f"If intentionally excluded, please add it to `exclude` list to avoid this"
message=f"Display field for path `{path}` is missing for message {schema.primaryType}. "
f"If intentionally excluded, please add it to `exclude` list to avoid this "
f"warning.",
)
for path in format_paths - eip712_paths:
out.error(
title="Extra Display field",
message=f"Display field for path `{path}` is not in message {schema.primaryType}. Please"
message=f"Display field for path `{path}` is not in message {schema.primaryType}. Please "
f"check the field path is valid according to the EIP-712 schema.",
)

Expand All @@ -78,8 +83,8 @@ def _validate_eip712_paths(cls, descriptor: ResolvedERC7730Descriptor, out: Outp
if fmt not in primary_types:
out.error(
title="Invalid Display field",
message=f"Format message `{fmt}` is not in EIP712 schemas. Please check the field path is valid"
f"according to the EIP-712 schema.",
message=f"Format message `{fmt}` is not in EIP712 schemas. Please check the field path is "
f"valid according to the EIP-712 schema.",
)

@classmethod
Expand Down Expand Up @@ -113,18 +118,24 @@ def _validate_abi_paths(cls, descriptor: ResolvedERC7730Descriptor, out: OutputA
continue
format_paths = compute_format_paths(fmt).data_paths
abi_paths = abi_paths_by_selector[keccak]
excluded = fmt.excluded or []
function = cls._display(selector, keccak)

for path in abi_paths - format_paths:
function = cls._display(selector, keccak)
if path in excluded:
continue

if not any(re.fullmatch(regex, path) for regex in AUTHORIZED_MISSING_DISPLAY_FIELDS_REGEX):
out.debug(
title="Optional Display field missing",
message=f"Display field for path `{path}` is missing for selector {function}.",
message=f"Display field for path `{path}` is missing for selector {function}. If "
f"intentionally excluded, please add it to `exclude` list to avoid this warning.",
)
else:
out.warning(
title="Missing Display field",
message=f"Display field for path `{path}` is missing for selector {function}.",
message=f"Display field for path `{path}` is missing for selector {function}. If "
f"intentionally excluded, please add it to `exclude` list to avoid this warning.",
)
for path in format_paths - abi_paths:
out.error(
Expand Down
8 changes: 8 additions & 0 deletions src/erc7730/model/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ class FormatBase(Model):
"shown.",
)

excluded: list[str] | None = Field(
default=None,
title="Excluded fields",
description="Intentionally excluded fields, as an array of *paths* referring to specific fields. A field that "
"has no formatter and is not declared in this list MAY be considered as an error by the wallet when"
"interpreting the descriptor.",
)

screens: dict[str, list[Screen]] | None = Field(
default=None,
title="Screens grouping information",
Expand Down

0 comments on commit b0ec7a8

Please sign in to comment.