我正在尝试使用Rust中的secp256k1库。我有一个简单的测试程序,它无法编译,因为它找不到generate_keypair
extern crate secp256k1;
extern crate rand;
use secp256k1::{Secp256k1, ContextFlag};
use rand::{thread_rng};
fn main() {
let full = Secp256k1::with_caps(ContextFlag::Full);
let (sk, pk) = full.generate_keypair(&mut thread_rng()).unwrap();
}编译失败,并显示以下错误:
error[E0599]: no method named `generate_keypair` found for type `secp256k1::Secp256k1` in the current scope
--> src/main.rs:9:25
|
9 | let (sk, pk) = full.generate_keypair(&mut thread_rng()).unwrap();
| ^^^^^^^^^^^^^^^^据我所知,我使用的库与how its used in the library's tests类似。
我已经将rand回滚到0.3,并将secp256k1回滚到0.6,现在它可以工作了。我很感兴趣的任何想法,为什么这是现在被打破。
发布于 2018-01-30 10:54:08
docs.rs上的documentation for secp256k1 version 0.8.1没有列出任何方法generate_keypair。
如果你使用look at the source,你会看到:
/// Generates a random keypair. Convenience function for `key::SecretKey::new`
/// and `key::PublicKey::from_secret_key`; call those functions directly for
/// batch key generation. Requires a signing-capable context.
#[inline]
#[cfg(any(test, feature = "rand"))]
pub fn generate_keypair<R: Rng>(&self, rng: &mut R)仅当启用可选的rand依赖项时,generate_keypair函数才可用。这是在commit 29892960中引入的。不幸的是,这个板条箱的维护者不会将版本标签发布到git存储库,所以很难判断这个更改发生在哪个版本上。
https://stackoverflow.com/questions/48512351
复制相似问题