NethermindEth/starknet.go

Improve SNIP-12 with validation function

Open

#770 opened on Jul 10, 2025

 (5 comments) (0 reactions) (1 assignee)Go (140 forks)auto 404
help wanted

Repository metrics

Stars
 (177 stars)
PR merge metrics
 (PR metrics pending)

Description

We could have a validation for the typedData json file to avoid mistakes.

For example, this typed data has an error, but it's considered valid. The amount field value contains an object instead of a u128. A validation would be good for the UX.

SNIP-12 spec: https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-12.md

{
  "domain": {
    "name": "Permit2",
    "version": "v1",
    "chainId": "0x0",
    "revision": "1"
  },
  "primaryType": "PermitSingle",
  "message": {
    "details": {
      "token": "0x1234",
      "amount": { "low": "0x123", "high": "0x0" },
      "expiration": "1234",
      "nonce": "1"
    },
    "spender": "0x1234",
    "sigDeadline": {
      "low": "1234567890",
      "high": "0x0"
    }
  },
  "types": {
    "StarknetDomain": [
      { "name": "name", "type": "shortstring" },
      { "name": "version", "type": "shortstring" },
      { "name": "chainId", "type": "shortstring" },
      { "name": "revision", "type": "shortstring" } 
    ],
    "PermitDetails": [
      { "name": "token", "type": "felt" },
      { "name": "amount", "type": "u128" },
      { "name": "expiration", "type": "u128" },
      { "name": "nonce", "type": "u128" }
    ],
    "PermitSingle": [
      { "name": "details", "type": "PermitDetails" },
      { "name": "spender", "type": "felt" },
      { "name": "sigDeadline", "type": "u256" }
    ]
  }
}

Contributor guide