我正在尝试使用 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,现在它可以工作了。我对任何关于为什么现在被打破的想法感兴趣。
最佳答案
documentation for secp256k1 version 0.8.1在 docs.rs 上没有列出任何方法 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)
generate_keypair
函数仅在启用可选的 rand
依赖项时可用。这是在 commit 29892960 中介绍的.不幸的是,这个 crate 的维护者没有将版本标签发布到 git 存储库,因此很难判断这个更改发生在哪个版本中。
关于rust - 在当前范围内找不到类型 `generate_keypair` 的名为 `secp256k1::Secp256k1` 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48512351/