import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
import * as CurrencyInfo from '@keetanetwork/currency-info';
export function toEVMAsset(input) {
    return (`evm:${input}`);
}
function isHexString(input) {
    if (typeof input === 'string' && input.startsWith('0x')) {
        return (true);
    }
    return (false);
}
export function parseEVMAsset(input) {
    const parts = input.split(':');
    if (parts.length !== 2 || parts[0] !== 'evm') {
        throw (new Error('Invalid EVMAsset string'));
    }
    const value = parts[1];
    if (!isHexString(value)) {
        throw (new Error('Invalid hex string in EVMAsset'));
    }
    return (value);
}
export function isEVMAsset(input) {
    return (typeof input === 'string' && input.startsWith('evm:0x'));
}
export function toTronAsset(input) {
    return (`tron:${input}`);
}
export function parseTronAsset(input) {
    const parts = input.split(':');
    if (parts.length !== 2 || parts[0] !== 'tron') {
        throw (new Error('Invalid TronAsset string'));
    }
    const value = parts[1];
    if (!value || typeof value !== 'string' || value.length === 0) {
        throw (new Error('Invalid hex string in TronAsset'));
    }
    return (value);
}
export function isTronAsset(input) {
    return (typeof input === 'string' && input.startsWith('tron:'));
}
export function toSolanaAsset(input) {
    return (`solana:${input}`);
}
export function parseSolanaAsset(input) {
    const parts = input.split(':');
    if (parts.length !== 2 || parts[0] !== 'solana') {
        throw (new Error('Invalid SolanaAsset string'));
    }
    const value = parts[1];
    if (!value || typeof value !== 'string' || value.length === 0) {
        throw (new Error('Invalid string in SolanaAsset'));
    }
    return (value);
}
export function isSolanaAsset(input) {
    return (typeof input === 'string' && input.startsWith('solana:'));
}
export function isBitcoinAsset(input) {
    return (typeof input === 'string' && input.startsWith('bitcoin:'));
}
// XXX:TODO We should eventually refactor these to be shared between location and asset, so we can have one source of truth per location
export function isExternalChainAsset(input, type) {
    const checks = {
        evm: isEVMAsset,
        solana: isSolanaAsset,
        tron: isTronAsset,
        bitcoin: isBitcoinAsset
    };
    if (type) {
        return (checks[type](input));
    }
    else {
        return (Object.values(checks).some(check => check(input)));
    }
}
export function convertAssetSearchInputToCanonical(input) {
    if (input instanceof CurrencyInfo.Currency || CurrencyInfo.Currency.isCurrencyCode(input) || CurrencyInfo.Currency.isISOCurrencyNumber(input)) {
        if (CurrencyInfo.Currency.isCurrencyCode(input)) {
            return (input);
        }
        else if (CurrencyInfo.Currency.isISOCurrencyNumber(input)) {
            input = new CurrencyInfo.Currency(input);
        }
        return (input.code);
    }
    else {
        if (typeof input === 'string') {
            return (input);
        }
        input.assertKeyType(KeetaNetLib.Account.AccountKeyAlgorithm.TOKEN);
        return (input.publicKeyString.get());
    }
}
//# sourceMappingURL=asset.js.map