Get address with public key Ethereum in Rust

Viewed 404

I'm trying to get an address with the public key in Rust. I'm using sha3 and ethereum-types to archive it but I faced some error. Here is my code:

use sha3::{Digest, Keccak256};
use ethereum_types::{H160, H256};

let address = H160::from_slice(Keccak256::digest(&pubkey).as_slice());

I got this error

panicked at 'assertion failed: `(left == right)`
  left: `32`,
 right: `20`

I need first convert to H256 then H160 to make it work because the length of Keccak256::digest(&pubkey).as_slice() is 32 not 20.

How can I convert the Keccak256::digest(&pubkey).as_slice() len to 20?

0 Answers
Related