···372372 }
373373 return `did:web:${hostname}`
374374}
375375+376376+// passes URL.parse, and has a TLD etc
377377+export function definitelyUrl(maybeUrl: string) {
378378+ try {
379379+ if (maybeUrl.endsWith('.')) return null
380380+381381+ // Prepend 'https://' if the input doesn't start with a protocol
382382+ if (!maybeUrl.startsWith('https://') && !maybeUrl.startsWith('http://')) {
383383+ maybeUrl = 'https://' + maybeUrl
384384+ }
385385+386386+ const url = new URL(maybeUrl)
387387+388388+ // Extract the hostname and split it into labels
389389+ const hostname = url.hostname
390390+ const labels = hostname.split('.')
391391+392392+ // Ensure there are at least two labels (e.g., 'example' and 'com')
393393+ if (labels.length < 2) return null
394394+395395+ const tld = labels[labels.length - 1]
396396+397397+ // Check that the TLD is at least two characters long and contains only letters
398398+ if (!/^[a-z]{2,}$/i.test(tld)) return null
399399+400400+ return url.toString()
401401+ } catch {
402402+ return null
403403+ }
404404+}