Skip to content

Commit

Permalink
Adds first version of Validate feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Nov 22, 2024
1 parent 5d883e4 commit 5141cfc
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 1 deletion.
27 changes: 27 additions & 0 deletions typed/tests/invalidExamples/danglingType.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"types": {
"StarkNetDomain": [
{ "name": "name", "type": "felt" },
{ "name": "version", "type": "felt" },
{ "name": "chainId", "type": "felt" }
],
"Person": [
{ "name": "name", "type": "felt" },
{ "name": "wallet", "type": "felt" }
],
"Mail": [
{ "name": "name", "type": "felt" },
{ "name": "wallet", "type": "felt" }
]
},
"primaryType": "Person",
"domain": {
"name": "StarkNet Mail",
"version": "1",
"chainId": 1
},
"message": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
}
}
23 changes: 23 additions & 0 deletions typed/tests/invalidExamples/invalidTypeName1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"types": {
"StarkNetDomain": [
{ "name": "name", "type": "felt" },
{ "name": "version", "type": "felt" },
{ "name": "chainId", "type": "felt" }
],
"Mail*": [
{ "name": "name", "type": "felt" },
{ "name": "wallet", "type": "felt" }
]
},
"primaryType": "Mail*",
"domain": {
"name": "StarkNet Mail",
"version": "1",
"chainId": 1
},
"message": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
}
}
23 changes: 23 additions & 0 deletions typed/tests/invalidExamples/invalidTypeName2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"types": {
"StarkNetDomain": [
{ "name": "name", "type": "felt" },
{ "name": "version", "type": "felt" },
{ "name": "chainId", "type": "felt" }
],
"(Mail)": [
{ "name": "name", "type": "felt" },
{ "name": "wallet", "type": "felt" }
]
},
"primaryType": "(Mail)",
"domain": {
"name": "StarkNet Mail",
"version": "1",
"chainId": 1
},
"message": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
}
}
23 changes: 23 additions & 0 deletions typed/tests/invalidExamples/invalidTypeName3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"types": {
"StarkNetDomain": [
{ "name": "name", "type": "felt" },
{ "name": "version", "type": "felt" },
{ "name": "chainId", "type": "felt" }
],
"ClassHash": [
{ "name": "name", "type": "felt" },
{ "name": "wallet", "type": "felt" }
]
},
"primaryType": "ClassHash",
"domain": {
"name": "StarkNet Mail",
"version": "1",
"chainId": 1
},
"message": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
}
}
23 changes: 23 additions & 0 deletions typed/tests/invalidExamples/invalidTypeName4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"types": {
"StarkNetDomain": [
{ "name": "name", "type": "felt" },
{ "name": "version", "type": "felt" },
{ "name": "chainId", "type": "felt" }
],
"TokenAmount": [
{ "name": "name", "type": "felt" },
{ "name": "wallet", "type": "felt" }
]
},
"primaryType": "TokenAmount",
"domain": {
"name": "StarkNet Mail",
"version": "1",
"chainId": 1
},
"message": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
}
}
23 changes: 23 additions & 0 deletions typed/tests/invalidExamples/invalidTypeName5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"types": {
"StarkNetDomain": [
{ "name": "name", "type": "felt" },
{ "name": "version", "type": "felt" },
{ "name": "chainId", "type": "felt" }
],
"Token,Amount": [
{ "name": "name", "type": "felt" },
{ "name": "wallet", "type": "felt" }
]
},
"primaryType": "Token,Amount",
"domain": {
"name": "StarkNet Mail",
"version": "1",
"chainId": 1
},
"message": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
}
}
19 changes: 19 additions & 0 deletions typed/tests/invalidExamples/singleType.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"types": {
"StarkNetDomain": [
{ "name": "name", "type": "felt" },
{ "name": "version", "type": "felt" },
{ "name": "chainId", "type": "felt" }
]
},
"primaryType": "StarkNetDomain",
"domain": {
"name": "StarkNet Mail",
"version": "1",
"chainId": 1
},
"message": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
}
}
2 changes: 1 addition & 1 deletion typed/typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func shortGetStructHash(
// Returns:
// - ret: the hash of the given type
// - err: any error if any
func (td TypedData) GetTypeHash(typeName string) (ret *felt.Felt, err error) {
func (td *TypedData) GetTypeHash(typeName string) (ret *felt.Felt, err error) {
//TODO: create/update methods descriptions
return getTypeHash(typeName, td.Types)
}
Expand Down
Loading

0 comments on commit 5141cfc

Please sign in to comment.