keys lib
This commit is contained in:
parent
e1a9f70429
commit
0edcc08ab1
|
@ -2,14 +2,11 @@
|
||||||
name = "pbtc"
|
name = "pbtc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"bitcrypto 0.1.0",
|
"bitcrypto 0.1.0",
|
||||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chain 0.1.0",
|
"chain 0.1.0",
|
||||||
"eth-secp256k1 0.5.6 (git+https://github.com/ethcore/rust-secp256k1)",
|
"keys 0.1.0",
|
||||||
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"primitives 0.1.0",
|
"primitives 0.1.0",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serialization 0.1.0",
|
"serialization 0.1.0",
|
||||||
]
|
]
|
||||||
|
@ -77,6 +74,19 @@ dependencies = [
|
||||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "keys"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"bitcrypto 0.1.0",
|
||||||
|
"eth-secp256k1 0.5.6 (git+https://github.com/ethcore/rust-secp256k1)",
|
||||||
|
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"primitives 0.1.0",
|
||||||
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|
|
@ -4,14 +4,11 @@ version = "0.1.0"
|
||||||
authors = ["debris <marek.kotewicz@gmail.com>"]
|
authors = ["debris <marek.kotewicz@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.3.14"
|
|
||||||
byteorder = "0.5"
|
byteorder = "0.5"
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
lazy_static = "0.2"
|
|
||||||
eth-secp256k1 = { git = "https://github.com/ethcore/rust-secp256k1" }
|
|
||||||
base58 = "0.1"
|
|
||||||
|
|
||||||
bitcrypto = { path = "crypto" }
|
bitcrypto = { path = "crypto" }
|
||||||
chain = { path = "chain" }
|
chain = { path = "chain" }
|
||||||
|
keys = { path = "keys" }
|
||||||
primitives = { path = "primitives" }
|
primitives = { path = "primitives" }
|
||||||
serialization = { path = "serialization" }
|
serialization = { path = "serialization" }
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "keys"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["debris <marek.kotewicz@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rand = "0.3.14"
|
||||||
|
rustc-serialize = "0.3"
|
||||||
|
lazy_static = "0.2"
|
||||||
|
base58 = "0.1"
|
||||||
|
eth-secp256k1 = { git = "https://github.com/ethcore/rust-secp256k1" }
|
||||||
|
bitcrypto = { path = "../crypto" }
|
||||||
|
primitives = { path = "../primitives" }
|
|
@ -8,7 +8,7 @@ use std::str::FromStr;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use base58::{ToBase58, FromBase58};
|
use base58::{ToBase58, FromBase58};
|
||||||
use network::Network;
|
use network::Network;
|
||||||
use keys::{DisplayLayout, checksum, Error, AddressHash};
|
use {DisplayLayout, checksum, Error, AddressHash};
|
||||||
|
|
||||||
/// There are two address formats currently in use.
|
/// There are two address formats currently in use.
|
||||||
/// https://bitcoin.org/en/developer-reference#address-conversion
|
/// https://bitcoin.org/en/developer-reference#address-conversion
|
|
@ -1,5 +1,5 @@
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use keys::Error;
|
use Error;
|
||||||
|
|
||||||
pub trait DisplayLayout {
|
pub trait DisplayLayout {
|
||||||
type Target: Deref<Target = [u8]>;
|
type Target: Deref<Target = [u8]>;
|
|
@ -1,6 +1,6 @@
|
||||||
use rand::os::OsRng;
|
use rand::os::OsRng;
|
||||||
use network::Network;
|
use network::Network;
|
||||||
use keys::{KeyPair, SECP256K1, Error};
|
use {KeyPair, SECP256K1, Error};
|
||||||
|
|
||||||
pub trait Generator {
|
pub trait Generator {
|
||||||
fn generate(&self) -> Result<KeyPair, Error>;
|
fn generate(&self) -> Result<KeyPair, Error>;
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use secp256k1::key;
|
use secp256k1::key;
|
||||||
use network::Network;
|
|
||||||
use keys::{Public, Error, SECP256K1, Address, Type, Private, Secret};
|
|
||||||
use hash::{H264, H520};
|
use hash::{H264, H520};
|
||||||
|
use network::Network;
|
||||||
|
use {Public, Error, SECP256K1, Address, Type, Private, Secret};
|
||||||
|
|
||||||
pub struct KeyPair {
|
pub struct KeyPair {
|
||||||
private: Private,
|
private: Private,
|
||||||
|
@ -88,7 +88,7 @@ impl KeyPair {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crypto::dhash256;
|
use crypto::dhash256;
|
||||||
use keys::Public;
|
use Public;
|
||||||
use super::KeyPair;
|
use super::KeyPair;
|
||||||
|
|
||||||
/// Tests from:
|
/// Tests from:
|
|
@ -6,16 +6,29 @@
|
||||||
//! `AddressHash` - 20 bytes derived from public
|
//! `AddressHash` - 20 bytes derived from public
|
||||||
//! `Address` - address_hash with network identifier and format type
|
//! `Address` - address_hash with network identifier and format type
|
||||||
|
|
||||||
|
extern crate rand;
|
||||||
|
extern crate rustc_serialize;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
extern crate base58;
|
||||||
|
extern crate secp256k1;
|
||||||
|
extern crate bitcrypto as crypto;
|
||||||
|
extern crate primitives;
|
||||||
|
|
||||||
mod address;
|
mod address;
|
||||||
mod checksum;
|
mod checksum;
|
||||||
pub mod display;
|
pub mod display;
|
||||||
pub mod generator;
|
pub mod generator;
|
||||||
pub mod keypair;
|
pub mod keypair;
|
||||||
mod error;
|
mod error;
|
||||||
|
mod network;
|
||||||
mod private;
|
mod private;
|
||||||
mod public;
|
mod public;
|
||||||
mod signature;
|
mod signature;
|
||||||
|
|
||||||
|
pub use rustc_serialize::hex;
|
||||||
|
pub use primitives::{hash, bytes};
|
||||||
|
|
||||||
pub use self::address::{Type, Address};
|
pub use self::address::{Type, Address};
|
||||||
pub use self::checksum::checksum;
|
pub use self::checksum::checksum;
|
||||||
pub use self::display::DisplayLayout;
|
pub use self::display::DisplayLayout;
|
||||||
|
@ -26,11 +39,11 @@ pub use self::public::Public;
|
||||||
pub use self::signature::{Signature, CompactSignature};
|
pub use self::signature::{Signature, CompactSignature};
|
||||||
|
|
||||||
use hash::{H160, H256};
|
use hash::{H160, H256};
|
||||||
|
|
||||||
pub type AddressHash = H160;
|
pub type AddressHash = H160;
|
||||||
pub type Secret = H256;
|
pub type Secret = H256;
|
||||||
pub type Message = H256;
|
pub type Message = H256;
|
||||||
|
|
||||||
use secp256k1;
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref SECP256K1: secp256k1::Secp256k1 = secp256k1::Secp256k1::new();
|
pub static ref SECP256K1: secp256k1::Secp256k1 = secp256k1::Secp256k1::new();
|
||||||
}
|
}
|
|
@ -4,9 +4,9 @@ use secp256k1::key;
|
||||||
use secp256k1::Message as SecpMessage;
|
use secp256k1::Message as SecpMessage;
|
||||||
use hex::ToHex;
|
use hex::ToHex;
|
||||||
use base58::{ToBase58, FromBase58};
|
use base58::{ToBase58, FromBase58};
|
||||||
use network::Network;
|
|
||||||
use keys::{Secret, DisplayLayout, checksum, Error, Message, Signature, CompactSignature, SECP256K1};
|
|
||||||
use hash::H520;
|
use hash::H520;
|
||||||
|
use network::Network;
|
||||||
|
use {Secret, DisplayLayout, checksum, Error, Message, Signature, CompactSignature, SECP256K1};
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct Private {
|
pub struct Private {
|
|
@ -5,7 +5,7 @@ use secp256k1::{Message as SecpMessage, RecoveryId, RecoverableSignature, Error
|
||||||
use hex::ToHex;
|
use hex::ToHex;
|
||||||
use crypto::dhash160;
|
use crypto::dhash160;
|
||||||
use hash::{H264, H520};
|
use hash::{H264, H520};
|
||||||
use keys::{AddressHash, Error, CompactSignature, Signature, Message, SECP256K1};
|
use {AddressHash, Error, CompactSignature, Signature, Message, SECP256K1};
|
||||||
|
|
||||||
pub enum Public {
|
pub enum Public {
|
||||||
Normal(H520),
|
Normal(H520),
|
|
@ -5,7 +5,7 @@
|
||||||
use std::{fmt, ops, str};
|
use std::{fmt, ops, str};
|
||||||
use hex::{ToHex, FromHex};
|
use hex::{ToHex, FromHex};
|
||||||
use hash::H520;
|
use hash::H520;
|
||||||
use keys::Error;
|
use Error;
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct Signature(Vec<u8>);
|
pub struct Signature(Vec<u8>);
|
|
@ -10,24 +10,17 @@
|
||||||
//! serialization(primitives)
|
//! serialization(primitives)
|
||||||
//! primitives
|
//! primitives
|
||||||
|
|
||||||
extern crate rand;
|
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
extern crate secp256k1;
|
|
||||||
extern crate base58;
|
|
||||||
|
|
||||||
extern crate bitcrypto as crypto;
|
extern crate bitcrypto as crypto;
|
||||||
extern crate chain;
|
extern crate chain;
|
||||||
|
extern crate keys;
|
||||||
extern crate primitives;
|
extern crate primitives;
|
||||||
extern crate serialization as ser;
|
extern crate serialization as ser;
|
||||||
|
|
||||||
pub mod keys;
|
|
||||||
pub mod net;
|
pub mod net;
|
||||||
pub mod script;
|
pub mod script;
|
||||||
|
|
||||||
pub mod network;
|
|
||||||
|
|
||||||
pub use rustc_serialize::hex;
|
pub use rustc_serialize::hex;
|
||||||
pub use primitives::{hash, bytes};
|
pub use primitives::{hash, bytes};
|
||||||
|
|
Loading…
Reference in New Issue