diff options
Diffstat (limited to 'src/lib/strings/url-helpers.ts')
-rw-r--r-- | src/lib/strings/url-helpers.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts index 0407df757..95c6bcead 100644 --- a/src/lib/strings/url-helpers.ts +++ b/src/lib/strings/url-helpers.ts @@ -339,3 +339,21 @@ export function shortLinkToHref(url: string): string { return url } } + +export function getHostnameFromUrl(url: string): string | null { + let urlp + try { + urlp = new URL(url) + } catch (e) { + return null + } + return urlp.hostname +} + +export function getServiceAuthAudFromUrl(url: string): string | null { + const hostname = getHostnameFromUrl(url) + if (!hostname) { + return null + } + return `did:web:${hostname}` +} |