Skip to content

Conversation

Copy link

Copilot AI commented Sep 12, 2025

Typed data signing was failing with StarknetTypedDataError.decodingError when string fields contained hex addresses. This issue occurred specifically with typed data like:

{
  "types": {
    "AccountCreation": [
      {"name": "wallet", "type": "string"}
    ]
  },
  "message": {
    "wallet": "0x2a7877881132f27cbfff1021f0ca82ffbcadd14e7599f55e03e891c01edc534"
  }
}

Root Cause:
During JSON decoding, hex strings like "0x2a7877..." were being parsed as Felt elements instead of remaining as String elements due to aggressive number parsing in Element.init(from decoder:). Later, when processing string types in revision v1, the unwrapLongString method expected a .string(String) element but received a .felt(Felt) element, causing the decoding error shown in the stack trace.

Solution:
Modified unwrapLongString(from element:) to handle both .string(String) and .felt(Felt) elements:

  • .string(String) elements: processed directly (preserves existing behavior)
  • .felt(Felt) elements: converted back to hex string using felt.toHex() method

This approach maintains backward compatibility while fixing the specific case where hex strings were incorrectly parsed during JSON decoding.

Testing:

  • Added comprehensive test cases covering the exact issue scenario
  • Tested edge cases (short hex, long hex, empty strings, regular text)
  • Verified compatibility with both v0 and v1 revisions
  • Confirmed existing tests continue to pass (they use regular text strings)

Fixes #251.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Author

Copilot AI commented Sep 12, 2025

@franciszekjob 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits September 12, 2025 08:21
Co-authored-by: franciszekjob <54181625+franciszekjob@users.noreply.github.com>
Co-authored-by: franciszekjob <54181625+franciszekjob@users.noreply.github.com>
Copilot AI changed the title [WIP] Typed data signing doesn't work for 'string' addresses Fix typed data signing for string fields containing hex addresses Sep 12, 2025
Copilot AI requested a review from franciszekjob September 12, 2025 08:26
Copilot finished work on behalf of franciszekjob September 12, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed data signing doesn't work for 'string' addresses

2 participants