···
export const didPlcSchema = z.templateLiteral(["did:plc:", z.string()]);
4
+
export type DidPlc = z.infer<typeof didPlcSchema>;
5
-
export type DidPlc = z.infer<typeof didPlcSchema>;
6
+
export const didWebSchema = z.templateLiteral(["did:web:", z.string()]);
7
+
export type DidWeb = z.infer<typeof didWebSchema>;
9
+
export const didSchema = z.templateLiteral([
15
+
export type Did = z.infer<typeof didSchema>;
17
+
export const nsidSchema = z.custom<`${string}.${string}.${string}`>(
18
+
(val): val is `${string}.${string}.${string}` => {
20
+
typeof val === "string" &&
21
+
/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/.test(
26
+
{ message: "Invalid atproto nsid format." },
28
+
export type Nsid = z.infer<typeof nsidSchema>;
30
+
export const atprotoHandleSchema = z.custom<`${string}.${string}`>(
31
+
(val): val is `${string}.${string}` => {
33
+
typeof val === "string" &&
34
+
/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/.test(
39
+
{ message: "Invalid atproto handle format." },
41
+
export type AtprotoHandle = z.infer<typeof atprotoHandleSchema>;
43
+
export const atUriAuthoritySchema = z.union([
46
+
atprotoHandleSchema,
48
+
export type AtUriAuthority = z.infer<typeof atUriAuthoritySchema>;
50
+
export const atUriSchema = z.object({
51
+
authority: atUriAuthoritySchema,
52
+
collection: z.optional(nsidSchema),
53
+
rKey: z.optional(z.string()),
55
+
export type AtUri = z.infer<typeof atUriSchema>;
57
+
export const verificationMethodSchema = z.object({
60
+
controller: z.string(),
61
+
publicKeyMultibase: z.optional(z.string()),
63
+
export type VerificationMethod = z.infer<typeof verificationMethodSchema>;
65
+
export const didDocumentSchema = z.object({
66
+
"@context": z.array(z.string()),
68
+
alsoKnownAs: z.optional(z.array(z.string())),
69
+
verificationMethod: z.optional(z.array(verificationMethodSchema)),
70
+
service: z.optional(
74
+
type: z.union([z.string(), z.array(z.string())]),
75
+
serviceEndpoint: z.union([
77
+
z.record(z.string(), z.string()),
79
+
z.union([z.string(), z.record(z.string(), z.string())]),
86
+
export type DidDocument = z.infer<typeof didDocumentSchema>;