decentralised sync engine
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: copy over atproto schemas from shard

serenity 4362aac3 6e2b55c3

+82 -1
+82 -1
src/lib/types/atproto.ts
··· 1 1 import { z } from "zod"; 2 2 3 3 export const didPlcSchema = z.templateLiteral(["did:plc:", z.string()]); 4 + export type DidPlc = z.infer<typeof didPlcSchema>; 4 5 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>; 8 + 9 + export const didSchema = z.templateLiteral([ 10 + "did:", 11 + z.string(), 12 + ":", 13 + z.string(), 14 + ]); 15 + export type Did = z.infer<typeof didSchema>; 16 + 17 + export const nsidSchema = z.custom<`${string}.${string}.${string}`>( 18 + (val): val is `${string}.${string}.${string}` => { 19 + return ( 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( 22 + val, 23 + ) 24 + ); 25 + }, 26 + { message: "Invalid atproto nsid format." }, 27 + ); 28 + export type Nsid = z.infer<typeof nsidSchema>; 29 + 30 + export const atprotoHandleSchema = z.custom<`${string}.${string}`>( 31 + (val): val is `${string}.${string}` => { 32 + return ( 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( 35 + val, 36 + ) 37 + ); 38 + }, 39 + { message: "Invalid atproto handle format." }, 40 + ); 41 + export type AtprotoHandle = z.infer<typeof atprotoHandleSchema>; 42 + 43 + export const atUriAuthoritySchema = z.union([ 44 + didPlcSchema, 45 + didWebSchema, 46 + atprotoHandleSchema, 47 + ]); 48 + export type AtUriAuthority = z.infer<typeof atUriAuthoritySchema>; 49 + 50 + export const atUriSchema = z.object({ 51 + authority: atUriAuthoritySchema, 52 + collection: z.optional(nsidSchema), 53 + rKey: z.optional(z.string()), 54 + }); 55 + export type AtUri = z.infer<typeof atUriSchema>; 56 + 57 + export const verificationMethodSchema = z.object({ 58 + id: z.string(), 59 + type: z.string(), 60 + controller: z.string(), 61 + publicKeyMultibase: z.optional(z.string()), 62 + }); 63 + export type VerificationMethod = z.infer<typeof verificationMethodSchema>; 64 + 65 + export const didDocumentSchema = z.object({ 66 + "@context": z.array(z.string()), 67 + id: z.string(), 68 + alsoKnownAs: z.optional(z.array(z.string())), 69 + verificationMethod: z.optional(z.array(verificationMethodSchema)), 70 + service: z.optional( 71 + z.array( 72 + z.object({ 73 + id: z.string(), 74 + type: z.union([z.string(), z.array(z.string())]), 75 + serviceEndpoint: z.union([ 76 + z.string(), 77 + z.record(z.string(), z.string()), 78 + z.array( 79 + z.union([z.string(), z.record(z.string(), z.string())]), 80 + ), 81 + ]), 82 + }), 83 + ), 84 + ), 85 + }); 86 + export type DidDocument = z.infer<typeof didDocumentSchema>;