this repo has no description
0
fork

Configure Feed

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

DID Input Validation

+13 -3
+13 -3
content.js
··· 4 4 const storage = 5 5 typeof browser !== "undefined" ? browser.storage.local : chrome.storage.local 6 6 7 + // Regular expression to validate the DID format 8 + const didRegex = /^did:plc:[a-zA-Z0-9._-]+(:[a-zA-Z0-9._-]+)*$/ 9 + 10 + // Function to validate the DID string 11 + function isValidDID(didString) { 12 + return didRegex.test(didString) 13 + } 14 + 7 15 // Function to get the domain name from the current hostname 8 16 function getDomainName() { 9 17 const hostname = window.location.hostname ··· 26 34 record.data.includes("did=did:plc:") 27 35 ) 28 36 29 - // We return the DID if we found one 30 - return didRecord ? didRecord.data.replace("did=", "") : null 37 + // We return the DID if we found one and it's valid 38 + return didRecord && isValidDID(didRecord.data.replace("did=", "")) 39 + ? didRecord.data.replace("did=", "") 40 + : null 31 41 } 32 42 33 43 // Function to check for a DID in the well-known (not .well-known) location ··· 37 47 `https://${domain}/xrpc/com.atproto.identity.resolveHandle` 38 48 ) 39 49 const data = await response.json() 40 - return data.did 50 + return data.did && isValidDID(data.did) ? data.did : null 41 51 } catch (error) { 42 52 return null 43 53 }