mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
added separate function for checksum
This commit is contained in:
parent
9f47fa5535
commit
cd1974b883
@ -405,20 +405,35 @@ var isAddress = function (address) {
|
||||
return true;
|
||||
} else {
|
||||
// Otherwise check each case
|
||||
address = address.replace('0x','');
|
||||
var addressHash = web3.sha3(address.toLowerCase());
|
||||
|
||||
for (var i = 0; i < 40; i++ ) {
|
||||
// the nth letter should be uppercase if the nth digit of casemap is 1
|
||||
if ((parseInt(addressHash[i], 16) > 8 && address[i].toUpperCase() != address[i]) || (parseInt(addressHash[i], 16) <= 8 && address[i].toLowerCase() != address[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return isChecksumAddress(address);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given string is a checksummed address
|
||||
*
|
||||
* @method isChecksumAddress
|
||||
* @param {String} address the given HEX adress
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isChecksumAddress = function (address) {
|
||||
// Check each case
|
||||
address = address.replace('0x','');
|
||||
var addressHash = web3.sha3(address.toLowerCase());
|
||||
|
||||
for (var i = 0; i < 40; i++ ) {
|
||||
// the nth letter should be uppercase if the nth digit of casemap is 1
|
||||
if ((parseInt(addressHash[i], 16) > 8 && address[i].toUpperCase() != address[i]) || (parseInt(addressHash[i], 16) <= 8 && address[i].toLowerCase() != address[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Makes a checksum address
|
||||
*
|
||||
@ -565,6 +580,7 @@ module.exports = {
|
||||
isBigNumber: isBigNumber,
|
||||
isStrictAddress: isStrictAddress,
|
||||
isAddress: isAddress,
|
||||
isChecksumAddress: isChecksumAddress,
|
||||
toChecksumAddress: toChecksumAddress,
|
||||
isFunction: isFunction,
|
||||
isString: isString,
|
||||
|
@ -91,6 +91,7 @@ Web3.prototype.toBigNumber = utils.toBigNumber;
|
||||
Web3.prototype.toWei = utils.toWei;
|
||||
Web3.prototype.fromWei = utils.fromWei;
|
||||
Web3.prototype.isAddress = utils.isAddress;
|
||||
Web3.prototype.isChecksumAddress = utils.isChecksumAddress;
|
||||
Web3.prototype.toChecksumAddress = utils.toChecksumAddress;
|
||||
Web3.prototype.isIBAN = utils.isIBAN;
|
||||
Web3.prototype.sha3 = sha3;
|
||||
|
Loading…
x
Reference in New Issue
Block a user