Skip to content

SNIP-12 enum type encoding fails to include referenced types except when used alone #1287

@xJonathanLEI

Description

@xJonathanLEI

Describe the bug

When encoding an enum type that uses another user-defined type as an array, the referenced type fails to be included in the encoded signature.

Edit: After looking into the problematic code I realized this is the case not just for when using as array. It happens as long as contains is not exactly (DEPENDENCY_TYPE). So the reproducer below would still trigger the issue even if (Child*) is changed to something like (u128,Child).

To Reproduce

Run this code:

import { typedData, TypedDataRevision } from "starknet";

console.log(
  typedData.encodeType(
    {
      Parent: [{ name: "variant", type: "(Child*)" }],
      Child: [{ name: "test", type: "u128" }],
    },
    "Parent",
    TypedDataRevision.ACTIVE,
  ),
);

and it prints:

"Parent"("variant":("Child*"))

Expected behavior

The correct encoding would instead be:

"Parent"("variant":("Child*"))"Child"("test":"u128")

since Child is indeed used by Parent.

Screenshots

N/A

Desktop (please complete the following information):

  • Node version: v20.17.0
  • Starknet.js version: v6.20.3

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions