-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathens.ts
More file actions
79 lines (69 loc) · 1.96 KB
/
ens.ts
File metadata and controls
79 lines (69 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { z } from "zod";
import {
AddressSchema,
GithubHandleSchema,
TwitterHandleSchema,
WebUrlSchema,
} from "./common";
/**
* Schema for ENS identity data
*/
export const EnsIdentitySchema = z.object({
id: z.string(),
idShort: z.string(),
avatar: z.string().nullable().optional(),
name: z.string().nullable().optional(),
// Strict validation that falls back to null if invalid
url: WebUrlSchema.nullable().optional().catch(null),
twitter: TwitterHandleSchema.nullable().optional().catch(null),
github: GithubHandleSchema.nullable().optional().catch(null),
description: z.string().nullable().optional(),
isLoading: z.boolean().optional(),
});
/**
* Blacklist of addresses that should be rejected
*/
const ENS_BLACKLIST = ["0xcb69ffc06d3c218472c50ee25f5a1d3ca9650c44"].map((a) =>
a.toLowerCase()
);
/**
* Blacklist of ENS names that should be rejected
*/
const ENS_NAME_BLACKLIST = ["salty-minning.eth"];
/**
* Address schema with blacklist validation for ENS endpoints
*/
export const EnsAddressSchema = AddressSchema.refine(
(address) => !ENS_BLACKLIST.includes(address.toLowerCase()),
{
message: "Address is blacklisted",
}
);
/**
* Schema for ENS name validation (with blacklist check)
*/
export const EnsNameSchema = z
.string()
.min(1, "ENS name cannot be empty")
.refine((name) => !ENS_NAME_BLACKLIST.includes(name), {
message: "ENS name is blacklisted",
});
/**
* Schema for array of ENS identities
*/
export const EnsIdentityArraySchema = z.array(EnsIdentitySchema);
export const EnsAvatarResultSchema = z.string().nullable();
/**
* Schema for ENS text record responses from provider
* Validates that text records are strings (or null if not set)
*/
export const EnsTextRecordSchema = z.string().nullable();
/**
* Schema for ENS avatar response from provider
* Validates the avatar object structure returned by getAvatar()
*/
export const EnsAvatarProviderSchema = z
.object({
url: z.string(),
})
.nullable();