From a0209d67d643353b6295f6813c020489955e68b9 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Sat, 21 Apr 2018 02:56:34 +0300 Subject: [PATCH] Add with0x argument to toAddress() and toChecksumAddress(). --- eth_keys.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/eth_keys.nim b/eth_keys.nim index caab311..506a252 100644 --- a/eth_keys.nim +++ b/eth_keys.nim @@ -84,14 +84,15 @@ proc recoverKeyFromSignature*(signature: Signature, if recoverSignatureKey(signature, hash.data, result) != EthKeysStatus.Success: raise newException(EthKeysException, ekErrorMsg()) -proc toAddress*(pubkey: PublicKey): string = +proc toAddress*(pubkey: PublicKey, with0x = true): string = ## Convert public key to hexadecimal string address. var hash = keccak256.digest(pubkey.getRaw()) - result = "0x" & toHex(toOpenArray(hash.data, 12, len(hash.data) - 1), true) + result = if with0x: "0x" else: "" + result.add(toHex(toOpenArray(hash.data, 12, len(hash.data) - 1), true)) -proc toChecksumAddress*(pubkey: PublicKey): string = +proc toChecksumAddress*(pubkey: PublicKey, with0x = true): string = ## Convert public key to checksumable mixed-case address (EIP-55). - result = "0x" + result = if with0x: "0x" else: "" var hash1 = keccak256.digest(pubkey.getRaw()) var hhash1 = toHex(toOpenArray(hash1.data, 12, len(hash1.data) - 1), true) var hash2 = keccak256.digest(hhash1)