Add with0x argument to toAddress() and toChecksumAddress().
This commit is contained in:
parent
ddc80f8bff
commit
a0209d67d6
|
@ -84,14 +84,15 @@ proc recoverKeyFromSignature*(signature: Signature,
|
||||||
if recoverSignatureKey(signature, hash.data, result) != EthKeysStatus.Success:
|
if recoverSignatureKey(signature, hash.data, result) != EthKeysStatus.Success:
|
||||||
raise newException(EthKeysException, ekErrorMsg())
|
raise newException(EthKeysException, ekErrorMsg())
|
||||||
|
|
||||||
proc toAddress*(pubkey: PublicKey): string =
|
proc toAddress*(pubkey: PublicKey, with0x = true): string =
|
||||||
## Convert public key to hexadecimal string address.
|
## Convert public key to hexadecimal string address.
|
||||||
var hash = keccak256.digest(pubkey.getRaw())
|
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).
|
## Convert public key to checksumable mixed-case address (EIP-55).
|
||||||
result = "0x"
|
result = if with0x: "0x" else: ""
|
||||||
var hash1 = keccak256.digest(pubkey.getRaw())
|
var hash1 = keccak256.digest(pubkey.getRaw())
|
||||||
var hhash1 = toHex(toOpenArray(hash1.data, 12, len(hash1.data) - 1), true)
|
var hhash1 = toHex(toOpenArray(hash1.data, 12, len(hash1.data) - 1), true)
|
||||||
var hash2 = keccak256.digest(hhash1)
|
var hash2 = keccak256.digest(hhash1)
|
||||||
|
|
Loading…
Reference in New Issue