NethermindEth/starknet.go

Improve SNIP-12 with validation function

Aperta

#770 aperta il 10 lug 2025

 (5 commenti) (0 reazioni) (1 assegnatario)Go (140 fork)auto 404
help wanted

Metriche repository

Star
 (177 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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" }
    ]
  }
}

Guida contributor