multichain-address-validator
Version:
Multichain address validator for Bitcoin and other blockchains.
20 lines (19 loc) • 660 B
JavaScript
import cryptoUtils from '../crypto/utils.js';
import { getAddress } from '../helpers.js';
function verifyChecksum(address) {
const checksumBytes = address.slice(0, 32 * 2);
const check = address.slice(32 * 2, 38 * 2);
const blakeHash = cryptoUtils.blake2b(checksumBytes, 32).slice(0, 6 * 2);
return blakeHash === check;
}
export default {
isValidAddress: function (address) {
const addr = getAddress(address);
if (addr.length !== 76) {
// Check if it has the basic requirements of an address
return false;
}
// Otherwise check each case
return verifyChecksum(addr);
},
};