From de11ded5df238ff7fdb2fc506238239d39e2174f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 8 Mar 2016 19:47:55 +0000 Subject: [PATCH] Introduce '.getChecksumAddressString()' --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index bdb209a..f189768 100644 --- a/index.js +++ b/index.js @@ -41,6 +41,22 @@ Wallet.prototype.getAddressString = function () { return '0x' + this.getAddress().toString('hex') } +Wallet.prototype.getChecksumAddressString = function () { + var address = this.getAddress().toString('hex') + var hash = ethUtil.sha3(address).toString('hex') + var ret = '0x' + + for (var i = 0; i < address.length; i++) { + if (parseInt(hash[i], 16) >= 8) { + ret += address[i].toUpperCase() + } else { + ret += address[i] + } + } + + return ret +} + // https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition Wallet.prototype.toV3 = function (password, opts) { opts = opts || {}