UNPKG

@xswap-link/sdk

Version:
27 lines (23 loc) 708 B
import { PublicKey } from "@solana/web3.js"; export const shortAddress = (address: string): string => { return `${address?.substring(0, 5)}...${address?.substring( address.length - 5, address.length, )}`; }; export const isETHAddressValid = (address: string): boolean => { return /^0x[a-fA-F0-9]{40}$/.test(address); }; /** * Checks if a Solana address is on the Ed25519 curve (has a private key) * If true: standard wallet address * If false: program-derived address (PDA) */ export const isSolanaAddressValid = (address: string): boolean => { try { const publicKey = new PublicKey(address); return PublicKey.isOnCurve(publicKey); } catch (error) { return false; } };