@snapshot-labs/snapshot.js 0.12.21 → 0.12.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -147,9 +147,7 @@ declare const _default: {
147
147
  maxItems: number;
148
148
  items: {
149
149
  type: string;
150
- pattern: string;
151
- minLength: number;
152
- maxLength: number;
150
+ format: string;
153
151
  };
154
152
  title: string;
155
153
  uniqueItems: boolean;
@@ -159,9 +157,7 @@ declare const _default: {
159
157
  maxItems: number;
160
158
  items: {
161
159
  type: string;
162
- pattern: string;
163
- minLength: number;
164
- maxLength: number;
160
+ format: string;
165
161
  };
166
162
  title: string;
167
163
  uniqueItems: boolean;
@@ -171,9 +167,7 @@ declare const _default: {
171
167
  maxItems: number;
172
168
  items: {
173
169
  type: string;
174
- pattern: string;
175
- minLength: number;
176
- maxLength: number;
170
+ format: string;
177
171
  };
178
172
  title: string;
179
173
  uniqueItems: boolean;
@@ -264,18 +258,24 @@ declare const _default: {
264
258
  };
265
259
  delegationContract: {
266
260
  type: string;
267
- format: string;
268
261
  title: string;
269
262
  description: string;
270
263
  examples: string[];
264
+ anyOf: {
265
+ format: string;
266
+ }[];
271
267
  };
272
268
  delegationNetwork: {
273
269
  type: string;
274
- snapshotNetwork: boolean;
275
270
  title: string;
276
- minLength: number;
277
- maxLength: number;
278
271
  description: string;
272
+ anyOf: ({
273
+ snapshotNetwork: boolean;
274
+ starknetNetwork?: undefined;
275
+ } | {
276
+ starknetNetwork: boolean;
277
+ snapshotNetwork?: undefined;
278
+ })[];
279
279
  };
280
280
  delegationApi: {
281
281
  type: string;
@@ -373,9 +373,14 @@ declare const _default: {
373
373
  };
374
374
  network: {
375
375
  type: string;
376
- snapshotNetwork: boolean;
377
376
  title: string;
378
- maxLength: number;
377
+ anyOf: ({
378
+ snapshotNetwork: boolean;
379
+ starknetNetwork?: undefined;
380
+ } | {
381
+ starknetNetwork: boolean;
382
+ snapshotNetwork?: undefined;
383
+ })[];
379
384
  };
380
385
  };
381
386
  required: string[];
@@ -143,9 +143,7 @@ declare const _default: {
143
143
  maxItems: number;
144
144
  items: {
145
145
  type: string;
146
- pattern: string;
147
- minLength: number;
148
- maxLength: number;
146
+ format: string;
149
147
  };
150
148
  title: string;
151
149
  uniqueItems: boolean;
@@ -155,9 +153,7 @@ declare const _default: {
155
153
  maxItems: number;
156
154
  items: {
157
155
  type: string;
158
- pattern: string;
159
- minLength: number;
160
- maxLength: number;
156
+ format: string;
161
157
  };
162
158
  title: string;
163
159
  uniqueItems: boolean;
@@ -167,9 +163,7 @@ declare const _default: {
167
163
  maxItems: number;
168
164
  items: {
169
165
  type: string;
170
- pattern: string;
171
- minLength: number;
172
- maxLength: number;
166
+ format: string;
173
167
  };
174
168
  title: string;
175
169
  uniqueItems: boolean;
@@ -260,18 +254,24 @@ declare const _default: {
260
254
  };
261
255
  delegationContract: {
262
256
  type: string;
263
- format: string;
264
257
  title: string;
265
258
  description: string;
266
259
  examples: string[];
260
+ anyOf: {
261
+ format: string;
262
+ }[];
267
263
  };
268
264
  delegationNetwork: {
269
265
  type: string;
270
- snapshotNetwork: boolean;
271
266
  title: string;
272
- minLength: number;
273
- maxLength: number;
274
267
  description: string;
268
+ anyOf: ({
269
+ snapshotNetwork: boolean;
270
+ starknetNetwork?: undefined;
271
+ } | {
272
+ starknetNetwork: boolean;
273
+ snapshotNetwork?: undefined;
274
+ })[];
275
275
  };
276
276
  delegationApi: {
277
277
  type: string;
@@ -369,9 +369,14 @@ declare const _default: {
369
369
  };
370
370
  network: {
371
371
  type: string;
372
- snapshotNetwork: boolean;
373
372
  title: string;
374
- maxLength: number;
373
+ anyOf: ({
374
+ snapshotNetwork: boolean;
375
+ starknetNetwork?: undefined;
376
+ } | {
377
+ starknetNetwork: boolean;
378
+ snapshotNetwork?: undefined;
379
+ })[];
375
380
  };
376
381
  };
377
382
  required: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.12.21",
3
+ "version": "0.12.23",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
@@ -147,9 +147,7 @@
147
147
  "maxItems": 100,
148
148
  "items": {
149
149
  "type": "string",
150
- "pattern": "^0x[a-fA-F0-9]{40}$",
151
- "minLength": 42,
152
- "maxLength": 42
150
+ "format": "evmAddress"
153
151
  },
154
152
  "title": "members",
155
153
  "uniqueItems": true
@@ -159,9 +157,7 @@
159
157
  "maxItems": 100,
160
158
  "items": {
161
159
  "type": "string",
162
- "pattern": "^0x[a-fA-F0-9]{40}$",
163
- "minLength": 42,
164
- "maxLength": 42
160
+ "format": "evmAddress"
165
161
  },
166
162
  "title": "admins",
167
163
  "uniqueItems": true
@@ -171,9 +167,7 @@
171
167
  "maxItems": 100,
172
168
  "items": {
173
169
  "type": "string",
174
- "pattern": "^0x[a-fA-F0-9]{40}$",
175
- "minLength": 42,
176
- "maxLength": 42
170
+ "format": "evmAddress"
177
171
  },
178
172
  "title": "moderators",
179
173
  "uniqueItems": true
@@ -264,18 +258,22 @@
264
258
  },
265
259
  "delegationContract": {
266
260
  "type": "string",
267
- "format": "address",
268
261
  "title": "Contract address",
269
262
  "description": "The address of your delegation contract",
270
- "examples": ["0x3901D0fDe202aF1427216b79f5243f8A022d68cf"]
263
+ "examples": ["0x3901D0fDe202aF1427216b79f5243f8A022d68cf"],
264
+ "anyOf": [
265
+ { "format": "evmAddress" },
266
+ { "format": "starknetAddress" }
267
+ ]
271
268
  },
272
269
  "delegationNetwork": {
273
270
  "type": "string",
274
- "snapshotNetwork": true,
275
271
  "title": "Delegation network",
276
- "minLength": 1,
277
- "maxLength": 32,
278
- "description": "The network of your delegation contract"
272
+ "description": "The network of your delegation contract",
273
+ "anyOf": [
274
+ { "snapshotNetwork": true },
275
+ { "starknetNetwork": true }
276
+ ]
279
277
  },
280
278
  "delegationApi": {
281
279
  "type": "string",
@@ -287,7 +285,7 @@
287
285
  ]
288
286
  }
289
287
  },
290
- "required": ["delegationType", "delegationApi", "delegationContract"],
288
+ "required": ["delegationType", "delegationNetwork", "delegationApi", "delegationContract"],
291
289
  "additionalProperties": false
292
290
  },
293
291
  "allowAlias": {
@@ -379,15 +377,17 @@
379
377
  "title": "Contract address",
380
378
  "examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"],
381
379
  "anyOf": [
382
- { "format": "address" },
380
+ { "format": "evmAddress" },
383
381
  { "format": "starknetAddress" }
384
382
  ]
385
383
  },
386
384
  "network": {
387
385
  "type": "string",
388
- "snapshotNetwork": true,
389
386
  "title": "Network",
390
- "maxLength": 12
387
+ "anyOf": [
388
+ { "snapshotNetwork": true },
389
+ { "starknetNetwork": true }
390
+ ]
391
391
  }
392
392
  },
393
393
  "required": ["name", "address", "network"],
package/src/utils.ts CHANGED
@@ -36,6 +36,7 @@ const ENS_ABI = [
36
36
  'function resolver(bytes32 node) view returns (address)' // ENS registry ABI
37
37
  ];
38
38
  const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000';
39
+ const STARKNET_NETWORKS = ['0x534e5f4d41494e', '0x534e5f5345504f4c4941'];
39
40
 
40
41
  const scoreApiHeaders = {
41
42
  Accept: 'application/json',
@@ -99,6 +100,17 @@ ajv.addFormat('address', {
99
100
  }
100
101
  });
101
102
 
103
+ ajv.addFormat('evmAddress', {
104
+ validate: (value: string) => {
105
+ try {
106
+ getAddress(value);
107
+ return true;
108
+ } catch (e: any) {
109
+ return false;
110
+ }
111
+ }
112
+ });
113
+
102
114
  ajv.addFormat('starknetAddress', {
103
115
  validate: (value: string) => {
104
116
  try {
@@ -155,6 +167,16 @@ ajv.addKeyword({
155
167
  }
156
168
  });
157
169
 
170
+ ajv.addKeyword({
171
+ keyword: 'starknetNetwork',
172
+ validate: function (schema, data) {
173
+ return STARKNET_NETWORKS.includes(data);
174
+ },
175
+ error: {
176
+ message: 'network not allowed'
177
+ }
178
+ });
179
+
158
180
  ajv.addKeyword({
159
181
  keyword: 'maxLengthWithSpaceType',
160
182
  validate: function validate(schema, data) {