0

我正在尝试从十六进制私钥获取以太坊公共地址。我为此写了一个 rust 脚本 -

extern crate hex;
extern crate secp256k1;
extern crate sha3;

use secp256k1::{PublicKey, SecretKey};
use sha3::Keccak256;

fn main() {
    let context = secp256k1::Secp256k1::new();
    let private_key: &[u8] =
        "616E6769652E6A6A706572657A616775696E6167612E6574682E6C696E6B0D0A".as_bytes();
    let secret_key = SecretKey::from_slice(&hex::decode(private_key).unwrap());
    let public_key = PublicKey::from_secret_key(&context, &secret_key.unwrap());
    println!("Public Key -> {:?}", public_key);
    let mut hasher = Keccak256::new();
    // making it an ethereum address
}

但是let mut hasher = Keccak256::new();给我一个错误-

error[E0599]: no function or associated item named `new` found for struct `CoreWrapper` in the current scope
  --> src/main.rs:14:33
   |
14 |     let mut hasher = Keccak256::new();
   |                                 ^^^ function or associated item not found in `CoreWrapper<Keccak256Core>`
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
5  | use crate::sha3::Digest;
   |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `ecdsa-test` due to previous error
4

0 回答 0