1 import * as WebFinger from 'webfinger.js'
3 import { isTestInstance } from './core-utils'
4 import { isActivityPubUrlValid } from './custom-validators'
5 import { WebFingerData } from '../../shared'
6 import { fetchRemoteAccountAndCreatePod } from './activitypub'
8 const webfinger = new WebFinger({
9 webfist_fallback: false,
10 tls_only: isTestInstance(),
15 async function getAccountFromWebfinger (url: string) {
16 const webfingerData: WebFingerData = await webfingerLookup(url)
18 if (Array.isArray(webfingerData.links) === false) return undefined
20 const selfLink = webfingerData.links.find(l => l.rel === 'self')
21 if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) return undefined
23 const { account } = await fetchRemoteAccountAndCreatePod(selfLink.href)
28 // ---------------------------------------------------------------------------
31 getAccountFromWebfinger
34 // ---------------------------------------------------------------------------
36 function webfingerLookup (url: string) {
37 return new Promise<WebFingerData>((res, rej) => {
38 webfinger.lookup(url, (err, p) => {
39 if (err) return rej(err)