···372 }
373 return `did:web:${hostname}`
374}
375+376+// passes URL.parse, and has a TLD etc
377+export function definitelyUrl(maybeUrl: string) {
378+ try {
379+ if (maybeUrl.endsWith('.')) return null
380+381+ // Prepend 'https://' if the input doesn't start with a protocol
382+ if (!maybeUrl.startsWith('https://') && !maybeUrl.startsWith('http://')) {
383+ maybeUrl = 'https://' + maybeUrl
384+ }
385+386+ const url = new URL(maybeUrl)
387+388+ // Extract the hostname and split it into labels
389+ const hostname = url.hostname
390+ const labels = hostname.split('.')
391+392+ // Ensure there are at least two labels (e.g., 'example' and 'com')
393+ if (labels.length < 2) return null
394+395+ const tld = labels[labels.length - 1]
396+397+ // Check that the TLD is at least two characters long and contains only letters
398+ if (!/^[a-z]{2,}$/i.test(tld)) return null
399+400+ return url.toString()
401+ } catch {
402+ return null
403+ }
404+}