handy online tools for AT Protocol boat.kelinci.net
atproto bluesky atcute typescript solidjs
20
fork

Configure Feed

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

fix: verify did:plc identifiers

Mary d1de16cb d817dbca

+10 -4
+7 -3
src/api/queries/did-doc.ts
··· 1 1 import { At } from '@atcute/client/lexicons'; 2 2 3 3 import { didDocument, DidDocument } from '../types/did-doc'; 4 - import { DID_WEB_RE } from '../utils/strings'; 4 + import { DID_PLC_RE, DID_WEB_RE } from '../utils/strings'; 5 5 6 6 export const getDidDocument = async ({ 7 7 did, ··· 18 18 let rawDoc: any; 19 19 20 20 if (type === 'plc') { 21 + if (!DID_PLC_RE.test(did)) { 22 + throw new Error(`invalid did:plc identifier`); 23 + } 24 + 21 25 const origin = import.meta.env.VITE_PLC_DIRECTORY_URL; 22 26 const response = await fetch(`${origin}/${did}`, { signal }); 23 27 ··· 31 35 32 36 rawDoc = json; 33 37 } else if (type === 'web') { 34 - if (!DID_WEB_RE.test(ident)) { 35 - throw new Error(`invalid identifier`); 38 + if (!DID_WEB_RE.test(did)) { 39 + throw new Error(`invalid did:web identifier`); 36 40 } 37 41 38 42 const response = await fetch(`https://${ident}/.well-known/did.json`, { signal });
+3 -1
src/api/utils/strings.ts
··· 7 7 8 8 export const DID_RE = /^did:([a-z]+):([a-zA-Z0-9._:%\-]*[a-zA-Z0-9._\-])$/; 9 9 10 - export const DID_WEB_RE = /^([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,}))$/; 10 + export const DID_WEB_RE = /^did:web:([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,}))$/; 11 + 12 + export const DID_PLC_RE = /^did:plc:([a-z2-7]{24})$/; 11 13 12 14 export const DID_KEY_RE = /^did:key:z[a-km-zA-HJ-NP-Z1-9]+$/; 13 15