Skip to content

Commit

Permalink
fix: loosen some address validation to accept lowercase (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored Oct 8, 2024
1 parent de0e11d commit fc479a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/schemas/space.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@
"maxItems": 100,
"items": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
"format": "evmAddress"
},
"title": "members",
"uniqueItems": true
Expand All @@ -159,9 +157,7 @@
"maxItems": 100,
"items": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
"format": "evmAddress"
},
"title": "admins",
"uniqueItems": true
Expand All @@ -171,9 +167,7 @@
"maxItems": 100,
"items": {
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
"format": "evmAddress"
},
"title": "moderators",
"uniqueItems": true
Expand Down Expand Up @@ -264,7 +258,7 @@
},
"delegationContract": {
"type": "string",
"format": "address",
"format": "evmAddress",
"title": "Contract address",
"description": "The address of your delegation contract",
"examples": ["0x3901D0fDe202aF1427216b79f5243f8A022d68cf"]
Expand Down Expand Up @@ -379,7 +373,7 @@
"title": "Contract address",
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
"anyOf": [
{ "format": "address" },
{ "format": "evmAddress" },
{ "format": "starknetAddress" }
]
},
Expand Down
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ ajv.addFormat('address', {
}
});

ajv.addFormat('evmAddress', {
validate: (value: string) => {
try {
getAddress(value);
return true;
} catch (e: any) {
return false;
}
}
});

ajv.addFormat('starknetAddress', {
validate: (value: string) => {
try {
Expand Down
17 changes: 17 additions & 0 deletions test/examples/space.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@
"period": 15552000,
"quorum": 100
},
"treasuries": [
{
"name": "EVM treasury with checksummed address",
"address": "0xF296178d553C8Ec21A2fBD2c5dDa8CA9ac905A00",
"network": "1"
},
{
"name": "EVM treasury with lowercase address",
"address": "0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00",
"network": "1"
},
{
"name": "Starknet treasury",
"address": "0x05702362b68a350c1cae8f2a529d74fdbb502369ddcebfadac7e91da37636947",
"network": "1"
}
],
"labels": [
{
"id": "4b6a8c88",
Expand Down

0 comments on commit fc479a0

Please sign in to comment.