neo3/neo_crypto/
mod.rs

1//! # Neo Crypto (v0.1.8)
2//!
3//! Cryptographic utilities for the Neo N3 blockchain.
4//!
5//! ## Overview
6//!
7//! The neo_crypto module provides cryptographic primitives and utilities for working with
8//! the Neo N3 blockchain. It includes:
9//!
10//! - Key pair generation and management
11//! - Cryptographic signing and verification
12//! - Hashing functions (SHA256, RIPEMD160, etc.)
13//! - Base58 encoding and decoding
14//! - WIF (Wallet Import Format) utilities
15//! - Secure random number generation
16//! - Encryption and decryption utilities
17//!
18//! This module forms the cryptographic foundation for wallet management, transaction signing,
19//! and secure communication within the Neo N3 ecosystem.
20//!
21//! ## Examples
22//!
23//! ### Creating a key pair
24//!
25//! ```rust,no_run
26//! use neo3::neo_crypto::KeyPair;
27//!
28//! // Generate a new random key pair
29//! let key_pair = KeyPair::new_random();
30//! println!("Public key: {:?}", key_pair.public_key());
31//! println!("Private key: {:?}", key_pair.private_key());
32//!
33//! // Create a key pair from a private key (32 bytes)
34//! let private_key_bytes = [1u8; 32]; // Replace with actual private key bytes
35//! let key_pair = KeyPair::from_private_key(&private_key_bytes).unwrap();
36//! ```
37//!
38//! ### Signing and verifying data
39//!
40//! ```ignore
41//! use neo3::neo_crypto::KeyPair;
42//!
43//! // Generate a key pair
44//! let key_pair = KeyPair::new_random();
45//!
46//! // Data to sign
47//! let data = b"Hello, Neo!";
48//!
49//! // Sign the data
50//! let signature = key_pair.sign(data).unwrap();
51//!
52//! // Verify the signature
53//! let is_valid = key_pair.verify_signature(data, &signature).unwrap();
54//! assert!(is_valid);
55//! ```
56//!
57//! ### Working with WIF format
58//!
59//! ```rust,no_run
60//! use neo3::neo_crypto::KeyPair;
61//!
62//! // Import a private key from WIF format
63//! let wif = "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn";
64//! let key_pair = KeyPair::from_wif(wif).unwrap();
65//!
66//! // Export a private key to WIF format
67//! let exported_wif = key_pair.export_as_wif();
68//! assert_eq!(wif, exported_wif);
69//! ```
70
71pub use base58_helper::*;
72pub use error::*;
73pub use key_pair::*;
74pub use keys::*;
75pub use utils::*;
76pub use wif::*;
77
78mod base58_helper;
79mod error;
80pub mod hash;
81mod key_pair;
82mod keys;
83pub mod utils;
84mod wif;
85
86// Re-export important types
87pub use error::CryptoError;
88pub use hash::HashableForVec;
89pub use key_pair::KeyPair;
90pub use keys::{Secp256r1PublicKey, Secp256r1Signature};
91
92pub(crate) fn add(left: usize, right: usize) -> usize {
93	left + right
94}
95
96#[cfg(test)]
97mod tests {
98	use super::*;
99
100	#[test]
101	fn it_works() {
102		let result = add(2, 2);
103		assert_eq!(result, 4);
104	}
105}