1mod brain;
20mod brain_prefix;
21mod error;
22mod extended;
23mod keypair;
24mod password;
25mod prefix;
26mod random;
27mod secret;
28mod signature;
29
30pub mod brain_recover;
31pub mod crypto;
32pub mod math;
33
34use cfx_crypto::{
35 KeyPair as CryptoKeyPair,
36 RandomKeyPairGenerator as CryptoRandomKeyPairGenerator,
37};
38
39use cfx_types::H256;
40use lazy_static::lazy_static;
41use secp256k1::SecretKey;
42
43pub use cfx_types::{Address, Public};
44pub use parity_wordlist::Error as WordlistError;
45pub type Message = H256;
46
47pub use self::{
48 brain::Brain,
49 brain_prefix::BrainPrefix,
50 error::Error,
51 extended::{
52 Derivation, DerivationError, ExtendedKeyPair, ExtendedPublic,
53 ExtendedSecret,
54 },
55 keypair::{is_compatible_public, public_to_address, KeyPair},
56 math::public_is_valid,
57 password::Password,
58 prefix::Prefix,
59 random::Random,
60 secret::Secret,
61 signature::{recover, sign, verify_address, verify_public, Signature},
62 KeyPairGenerator as Generator,
63};
64
65lazy_static! {
66 pub(crate) static ref ONE_KEY: SecretKey = SecretKey::from_slice(&[
68 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0,
70 0, 0, 0, 0, 0, 0, 0, 0,
71 0, 0, 0, 0, 0, 0, 0, 1,
72 ]).expect("1 is a valid secret key");
73
74 pub(crate) static ref MINUS_ONE_KEY: SecretKey = ONE_KEY.negate();
76}
77
78#[derive(Debug)]
80pub enum Void {}
81
82pub trait KeyPairGenerator {
84 type Error;
85
86 fn generate(&mut self) -> Result<KeyPair, Self::Error>;
88}
89
90impl CryptoKeyPair for KeyPair {
96 type Public = Public;
97 type Secret = Secret;
98
99 fn secret(&self) -> &Self::Secret { self.secret() }
100
101 fn public(&self) -> &Self::Public { self.public() }
102}
103
104impl CryptoRandomKeyPairGenerator for Random {
105 type Error = std::io::Error;
106 type KeyPair = KeyPair;
107
108 fn generate(&mut self) -> Result<Self::KeyPair, Self::Error> {
109 KeyPairGenerator::generate(self)
110 }
111}