Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static async resolve(
value: string,
opts: FederationServer.Options = {},
): Promise {
// Check if `value` is in account ID format
if (value.indexOf("*") < 0) {
if (!StrKey.isValidEd25519PublicKey(value)) {
return Promise.reject(new Error("Invalid Account ID"));
}
return Promise.resolve({ account_id: value });
}
const addressParts = value.split("*");
const [, domain] = addressParts;
if (addressParts.length !== 2 || !domain) {
return Promise.reject(new Error("Invalid Stellar address"));
}
const federationServer = await FederationServer.createForDomain(
domain,
opts,
);
return federationServer.resolveAddress(value);
function isValidAsset(asset) {
if (asset.asset_type === 0 && !asset.asset_code && !asset.asset_issuer) return true
if (!StrKey.isValidEd25519PublicKey(asset.asset_issuer)) return false
if (!asset.asset_code) return false
if (!/^[a-zA-Z0-9]{1,12}$/.test(asset.asset_code)) return false
if (normalizeAssetType(asset.asset_code) !== asset.asset_type) return false
return true
}