Skip to content

Improve SNIP-12 with validation function #770

@thiagodeev

Description

@thiagodeev

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

Metadata

Metadata

Assignees

Labels

help wantedHelp from collaborators will be appreciated

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions