Skip to content

Commit fc479a0

Browse files
authored
fix: loosen some address validation to accept lowercase (#1067)
1 parent de0e11d commit fc479a0

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/schemas/space.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@
147147
"maxItems": 100,
148148
"items": {
149149
"type": "string",
150-
"pattern": "^0x[a-fA-F0-9]{40}$",
151-
"minLength": 42,
152-
"maxLength": 42
150+
"format": "evmAddress"
153151
},
154152
"title": "members",
155153
"uniqueItems": true
@@ -159,9 +157,7 @@
159157
"maxItems": 100,
160158
"items": {
161159
"type": "string",
162-
"pattern": "^0x[a-fA-F0-9]{40}$",
163-
"minLength": 42,
164-
"maxLength": 42
160+
"format": "evmAddress"
165161
},
166162
"title": "admins",
167163
"uniqueItems": true
@@ -171,9 +167,7 @@
171167
"maxItems": 100,
172168
"items": {
173169
"type": "string",
174-
"pattern": "^0x[a-fA-F0-9]{40}$",
175-
"minLength": 42,
176-
"maxLength": 42
170+
"format": "evmAddress"
177171
},
178172
"title": "moderators",
179173
"uniqueItems": true
@@ -264,7 +258,7 @@
264258
},
265259
"delegationContract": {
266260
"type": "string",
267-
"format": "address",
261+
"format": "evmAddress",
268262
"title": "Contract address",
269263
"description": "The address of your delegation contract",
270264
"examples": ["0x3901D0fDe202aF1427216b79f5243f8A022d68cf"]
@@ -379,7 +373,7 @@
379373
"title": "Contract address",
380374
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
381375
"anyOf": [
382-
{ "format": "address" },
376+
{ "format": "evmAddress" },
383377
{ "format": "starknetAddress" }
384378
]
385379
},

src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ ajv.addFormat('address', {
9999
}
100100
});
101101

102+
ajv.addFormat('evmAddress', {
103+
validate: (value: string) => {
104+
try {
105+
getAddress(value);
106+
return true;
107+
} catch (e: any) {
108+
return false;
109+
}
110+
}
111+
});
112+
102113
ajv.addFormat('starknetAddress', {
103114
validate: (value: string) => {
104115
try {

test/examples/space.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@
3535
"period": 15552000,
3636
"quorum": 100
3737
},
38+
"treasuries": [
39+
{
40+
"name": "EVM treasury with checksummed address",
41+
"address": "0xF296178d553C8Ec21A2fBD2c5dDa8CA9ac905A00",
42+
"network": "1"
43+
},
44+
{
45+
"name": "EVM treasury with lowercase address",
46+
"address": "0xf296178d553c8ec21a2fbd2c5dda8ca9ac905a00",
47+
"network": "1"
48+
},
49+
{
50+
"name": "Starknet treasury",
51+
"address": "0x05702362b68a350c1cae8f2a529d74fdbb502369ddcebfadac7e91da37636947",
52+
"network": "1"
53+
}
54+
],
3855
"labels": [
3956
{
4057
"id": "4b6a8c88",

0 commit comments

Comments
 (0)