Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect SNIP-12 enum type signature encoding #1286

Closed
xJonathanLEI opened this issue Jan 1, 2025 · 1 comment · Fixed by #1288
Closed

Incorrect SNIP-12 enum type signature encoding #1286

xJonathanLEI opened this issue Jan 1, 2025 · 1 comment · Fixed by #1288
Labels
released on @next Type: bug Something isn't working

Comments

@xJonathanLEI
Copy link
Contributor

Describe the bug

SNIP-12 specifies the enum type to be encoded as:

escape(enum_name) || "(" || escape(variant_1_name) || "(" || escape(param1_type) || "," || ... || escape(paramN_type) || ")," || ... || escape(variant_n_name) || "(" || ... || ")" || ")"

with an example given:

type_hash(MyEnum) = starknet_keccak('"My Enum"("Variant 1"(),"Variant 2"("u128","u128*"),...,"Variant N"("u128"))')

However, starknet.js inserts an extra : between variant names and their type lists:

https://github.com/starknet-io/starknet.js/blob/2b69310840fb57b89d76949a3ea6cc188c42e8aa/src/utils/typedData.ts#L269_L271

The code above does not distinguish between structs and enums and always inserts :.

To Reproduce

Run this code:

import { typedData, TypedDataRevision } from "starknet";

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

and it prints:

"Enum"("variant":("u128"))

Expected behavior

According to SNIP-12 there should be no : between "variant" and ("u128").

Screenshots

N/A

Desktop (please complete the following information):

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

Additional context

N/A

Copy link

github-actions bot commented Jan 8, 2025

🎉 This issue has been resolved in version 6.21.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @next Type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant