UNPKG

@fordefi-public/crypto-address-validator-ts

Version:

Crypto address validator for Bitcoin and other Altcoins, forked to be used with typescript

33 lines (28 loc) 914 B
import { Currency, Options } from "../types/types"; const base58 = require('../crypto/externals/base58'); // simple base58 validator. Just checks if it can be decoded. export function isValidAddress(address: string, currency: Currency, opts: Options) { try { if (!address || address.length == 0) { return false; } if (currency.minLength && (address.length < currency.minLength)) { return false; } if (currency.maxLength && (address.length > currency.maxLength)) { return false; } try { const decoded = base58.decode(address); if (!decoded || !decoded.length) { return false; } } catch (e) { // if decoding fails, assume invalid address return false; } return true; } catch (e) { return false; } }