@getdelta/wallet-address-validator
Version:
Wallet address validator for Bitcoin and other Altcoins.
34 lines (29 loc) • 1.01 kB
JavaScript
const cryptoUtils = require("./crypto/utils");
const bitcoinValidator = require("./bitcoin_validator");
const NEO_PROTOCOL_VERSION = 53;
module.exports = {
isValidAddress: function (address, currency, networkType) {
try {
const decoded = cryptoUtils.base58(address);
/**
* If prefix doesn't match the current protocol version
* we can try to validate the address as a legacy address
*/
if (decoded[0] !== NEO_PROTOCOL_VERSION) {
return bitcoinValidator.isValidAddress(
address,
currency,
networkType
);
}
return true;
} catch (err) {
// Something went wrong while decoding the address so try the legacy validation
return bitcoinValidator.isValidAddress(
address,
currency,
networkType
);
}
},
};