Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit de11ded

Browse files
committed
Introduce '.getChecksumAddressString()'
1 parent 3c09bc2 commit de11ded

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ Wallet.prototype.getAddressString = function () {
4141
return '0x' + this.getAddress().toString('hex')
4242
}
4343

44+
Wallet.prototype.getChecksumAddressString = function () {
45+
var address = this.getAddress().toString('hex')
46+
var hash = ethUtil.sha3(address).toString('hex')
47+
var ret = '0x'
48+
49+
for (var i = 0; i < address.length; i++) {
50+
if (parseInt(hash[i], 16) >= 8) {
51+
ret += address[i].toUpperCase()
52+
} else {
53+
ret += address[i]
54+
}
55+
}
56+
57+
return ret
58+
}
59+
4460
// https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition
4561
Wallet.prototype.toV3 = function (password, opts) {
4662
opts = opts || {}

0 commit comments

Comments
 (0)