2018-03-31 04:55:00 -06:00
|
|
|
const WebFinger = require('webfinger.js');
|
|
|
|
|
2018-04-01 08:33:48 -06:00
|
|
|
const webFinger = new WebFinger({ });
|
2018-03-31 04:55:00 -06:00
|
|
|
|
|
|
|
type ILink = {
|
|
|
|
href: string;
|
|
|
|
rel: string;
|
2018-04-01 06:24:25 -06:00
|
|
|
};
|
2018-03-31 04:55:00 -06:00
|
|
|
|
|
|
|
type IWebFinger = {
|
2018-04-01 06:24:25 -06:00
|
|
|
links: ILink[];
|
2018-03-31 04:55:00 -06:00
|
|
|
subject: string;
|
2018-04-01 06:24:25 -06:00
|
|
|
};
|
2018-03-31 04:55:00 -06:00
|
|
|
|
|
|
|
export default (query, verifier): Promise<IWebFinger> => new Promise((res, rej) => webFinger.lookup(query, (error, result) => {
|
|
|
|
if (error) {
|
|
|
|
return rej(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.object.subject.toLowerCase().replace(/^acct:/, '') !== verifier) {
|
|
|
|
return rej('WebFinger verfification failed');
|
|
|
|
}
|
|
|
|
|
|
|
|
res(result.object);
|
|
|
|
}));
|