aladinnetwork-blockstack
Version:
The Aladin Javascript library for authentication, identity, and storage.
41 lines • 1.53 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const profileZoneFiles_1 = require("./profileZoneFiles");
const config_1 = require("../config");
const fetchUtil_1 = require("../fetchUtil");
/**
* Look up a user profile by aladin ID
*
* @param {string} username - The Aladin ID of the profile to look up
* @param {string} [zoneFileLookupURL=null] - The URL
* to use for zonefile lookup. If falsey, lookupProfile will use the
* aladin.js [[getNameInfo]] function.
* @returns {Promise} that resolves to a profile object
*/
function lookupProfile(username, zoneFileLookupURL) {
if (!username) {
return Promise.reject();
}
let lookupPromise;
if (zoneFileLookupURL) {
const url = `${zoneFileLookupURL.replace(/\/$/, '')}/${username}`;
lookupPromise = fetchUtil_1.fetchPrivate(url)
.then(response => response.json());
}
else {
lookupPromise = config_1.config.network.getNameInfo(username);
}
return lookupPromise
.then((responseJSON) => {
if (responseJSON.hasOwnProperty('zonefile')
&& responseJSON.hasOwnProperty('address')) {
return profileZoneFiles_1.resolveZoneFileToProfile(responseJSON.zonefile, responseJSON.address);
}
else {
throw new Error('Invalid zonefile lookup response: did not contain `address`'
+ ' or `zonefile` field');
}
});
}
exports.lookupProfile = lookupProfile;
//# sourceMappingURL=profileLookup.js.map
;