this repo has no description
0
fork

Configure Feed

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

detect DIDs via HTTPS/JSON

authored by

alice and committed by
Jesse J. Anderson
c0b299ce d90863bd

+26 -5
+26 -5
content.js
··· 11 11 } 12 12 13 13 // Function to check for a DID in the domain's TXT records 14 - async function checkForDID(domain) { 14 + async function checkForDIDDNS(domain) { 15 15 // We use Google's DNS over HTTPS API to resolve the TXT record 16 16 const response = await fetch( 17 17 `https://dns.google/resolve?name=_atproto.${domain}&type=TXT` ··· 30 30 return didRecord ? didRecord.data.replace("did=", "") : null 31 31 } 32 32 33 + // Function to check for a DID in the well-known (not .well-known) location 34 + async function checkForDIDHTTPS(domain) { 35 + const response = await fetch( 36 + `https://${domain}/xrpc/com.atproto.identity.resolveHandle` 37 + ) 38 + 39 + if (response.status === 200) { 40 + try { 41 + const data = await response.json() 42 + return data.did 43 + } catch (error) { 44 + return null 45 + } 46 + } 47 + 48 + return null 49 + } 50 + 33 51 // Main function to perform actions, but only if the privacy consent has been accepted 34 52 function performAction(privacyConsentAccepted) { 35 53 // If the user has accepted the privacy consent ··· 37 55 // We check for a DID on the current domain 38 56 ;(async function () { 39 57 const domain = getDomainName() 40 - const did = await checkForDID(domain) 58 + const domainDID = await checkForDIDDNS(domain) 59 + const httpsDID = await checkForDIDHTTPS(domain) 41 60 42 - if (did) { 43 - runtime.sendMessage({ type: "DID_FOUND", did }) 61 + if (domainDID) { 62 + runtime.sendMessage({ type: "DID_FOUND", did: domainDID }) 63 + } else if (httpsDID) { 64 + runtime.sendMessage({ type: "DID_FOUND", did: httpsDID }) 44 65 } else { 45 66 runtime.sendMessage({ type: "DID_NOT_FOUND" }) 46 67 } ··· 49 70 // We listen for messages from the background script 50 71 runtime.onMessage.addListener((message, sender, sendResponse) => { 51 72 if (message.type === "GET_DID") { 52 - checkForDID(getDomainName()) 73 + checkForDIDDNS(getDomainName()) 53 74 .then((did) => sendResponse({ did })) 54 75 .catch(() => sendResponse({ did: null })) 55 76 return true // Indicate that the response will be sent asynchronously.