From 9b580395d879dcfb35424dbe07cc3c292291bd50 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 9 Mar 2021 16:50:28 +0100 Subject: [PATCH] Conversion from public key to ethereum address --- nitro/keys.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nitro/keys.nim b/nitro/keys.nim index 5768669..0dc0640 100644 --- a/nitro/keys.nim +++ b/nitro/keys.nim @@ -22,3 +22,10 @@ proc `$`*(key: PrivateKey): string = proc parse*(_: type PrivateKey, s: string): ?PrivateKey = SkSecretKey.fromHex(s).toOption() + +proc toAddress*(key: PublicKey): EthAddress = + let hash = keccak256.digest(key.toRaw()) + var bytes: array[20, byte] + for i in 0..<20: + bytes[i] = hash.data[12 + i] + EthAddress(bytes)