Conversion from public key to ethereum address

This commit is contained in:
Mark Spanbroek 2021-03-09 16:50:28 +01:00
parent 11a2329bf2
commit 9b580395d8

View File

@ -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)