Rename bitcoin-secp256k1-rs to secp256k1

This commit is contained in:
Andrew Poelstra 2015-03-26 10:08:36 -05:00
parent c3377032f8
commit 2101e4a56d
16 changed files with 56 additions and 49 deletions

View File

@ -11,6 +11,6 @@ path = "src/lib.rs"
[dependencies.rust-crypto]
git = "https://github.com/DaGenix/rust-crypto.git"
[dependencies.bitcoin-secp256k1-rs]
[dependencies.secp256k1]
git = "https://github.com/apoelstra/bitcoin-secp256k1-rs.git"

View File

@ -22,7 +22,8 @@
use std::num::{Zero, from_u64};
use util::error::{BitcoinResult, SpvBadTarget, SpvBadProofOfWork};
use util::error::{BitcoinResult};
use util::error::BitcoinError::{SpvBadTarget, SpvBadProofOfWork};
use util::hash::Sha256dHash;
use util::uint::Uint256;
use network::encodable::{ConsensusEncodable, VarInt};

View File

@ -29,11 +29,12 @@ use blockdata::block::{Block, BlockHeader};
use blockdata::transaction::Transaction;
use blockdata::constants::{DIFFCHANGE_INTERVAL, DIFFCHANGE_TIMESPAN,
TARGET_BLOCK_SPACING, max_target, genesis_block};
use network::constants::{Network, BitcoinTestnet};
use network::constants::Network::{self, BitcoinTestnet};
use network::encodable::{ConsensusDecodable, ConsensusEncodable};
use network::serialize::{BitcoinHash, SimpleDecoder, SimpleEncoder};
use util::BitArray;
use util::error::{BitcoinResult, BlockNotFound, DuplicateHash, PrevHashNotFound};
use util::error::BitcoinResult;
use util::error::BitcoinError::{BlockNotFound, DuplicateHash, PrevHashNotFound};
use util::uint::Uint256;
use util::hash::Sha256dHash;
use util::patricia_tree::PatriciaTree;
@ -613,7 +614,7 @@ mod tests {
use blockdata::blockchain::Blockchain;
use blockdata::constants::genesis_block;
use network::constants::Bitcoin;
use network::constants::Network::Bitcoin;
use network::serialize::{BitcoinHash, deserialize, serialize};
#[test]

View File

@ -26,7 +26,7 @@ use blockdata::opcodes;
use blockdata::script::Script;
use blockdata::transaction::{Transaction, TxOut, TxIn};
use blockdata::block::{Block, BlockHeader};
use network::constants::{Network, Bitcoin, BitcoinTestnet};
use network::constants::Network::{Bitcoin, BitcoinTestnet};
use util::misc::hex_bytes;
use util::hash::MerkleRoot;
use util::uint::Uint256;
@ -123,7 +123,7 @@ mod test {
use std::default::Default;
use serialize::hex::FromHex;
use network::constants::{Bitcoin, BitcoinTestnet};
use network::constants::Network::{Bitcoin, BitcoinTestnet};
use network::serialize::{BitcoinHash, serialize};
use blockdata::constants::{genesis_block, bitcoin_genesis_tx};
use blockdata::constants::{MAX_SEQUENCE, COIN_VALUE};

View File

@ -2453,7 +2453,7 @@ mod test {
use super::{Script, build_scriptint, read_scriptint, read_scriptbool};
use super::{EqualVerifyFailed, NoTransaction, PopEmptyStack};
use super::Owned;
use super::MaybeOwned::Owned;
use network::serialize::{deserialize, serialize};
use blockdata::opcodes;

View File

@ -27,7 +27,7 @@ use std::os::num_cpus;
use std::sync::Future;
use blockdata::transaction::{Transaction, TxOut};
use blockdata::transaction::{TransactionError, InputNotFound};
use blockdata::transaction::TransactionError::{self, InputNotFound};
use blockdata::constants::genesis_block;
use blockdata::block::Block;
use network::constants::Network;
@ -437,7 +437,7 @@ mod tests {
use super::{UtxoSet, TxoValidation};
use blockdata::block::Block;
use network::constants::Bitcoin;
use network::constants::Network::Bitcoin;
use network::serialize::{BitcoinHash, deserialize, serialize};
#[test]

View File

@ -51,7 +51,7 @@ extern crate serialize;
extern crate test;
extern crate time;
extern crate "bitcoin-secp256k1-rs" as secp256k1;
extern crate secp256k1;
extern crate crypto;
#[macro_use]

View File

@ -67,7 +67,7 @@ impl<D:SimpleDecoder<E>, E> ConsensusDecodable<D, E> for Network {
#[cfg(test)]
mod tests {
use super::{Network, Bitcoin, BitcoinTestnet};
use super::Network::{self, Bitcoin, BitcoinTestnet};
use network::serialize::{deserialize, serialize};

View File

@ -21,7 +21,9 @@
use std::io::{IoResult, standard_error, ConnectionFailed};
use network::constants::Network;
use network::message::{self, SocketResponse, MessageReceived, Verack};
use network::message;
use network::message::SocketResponse::{self, MessageReceived};
use network::message::NetworkMessage::Verack;
use network::socket::Socket;
/// A message which can be sent on the Bitcoin network

View File

@ -28,7 +28,8 @@ use std::sync::{Arc, Mutex};
use network::constants;
use network::address::Address;
use network::encodable::{ConsensusEncodable, ConsensusDecodable};
use network::message::{RawNetworkMessage, NetworkMessage, Version};
use network::message::{RawNetworkMessage, NetworkMessage};
use network::message::NetworkMessage::Version;
use network::message_network::VersionMessage;
use network::serialize::{RawEncoder, RawDecoder};
use util::misc::prepend_err;

View File

@ -529,8 +529,8 @@ mod tests {
use network::serialize::{deserialize, serialize};
use util::hash::Sha256dHash;
use util::usize::Uint128;
use util::usize::Uint256;
use util::uint::Uint128;
use util::uint::Uint256;
use util::patricia_tree::PatriciaTree;
#[test]

View File

@ -21,7 +21,7 @@
use alloc::heap::{allocate, reallocate, deallocate};
use std::raw;
use std::slice::{Items, MutItems};
use std::slice::{Iter, MutIter};
use std::{fmt, mem, ptr};
use std::u32;
@ -63,13 +63,13 @@ impl<T> ThinVec<T> {
/// Iterator over elements of the vector
#[inline]
pub fn iter<'a>(&'a self) -> Items<'a, T> {
pub fn iter<'a>(&'a self) -> Iter<'a, T> {
self.as_slice().iter()
}
/// Mutable iterator over elements of the vector
#[inline]
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> {
pub fn iter_mut<'a>(&'a mut self) -> MutIter<'a, T> {
self.as_mut_slice().iter_mut()
}

View File

@ -22,11 +22,10 @@ use crypto::sha2::Sha256;
use blockdata::script::Script;
use blockdata::opcodes::all;
use network::constants::{Network, Bitcoin, BitcoinTestnet};
use network::constants::Network::{self, Bitcoin, BitcoinTestnet};
use util::hash::Ripemd160Hash;
use util::base58::{Base58Error,
InvalidLength, InvalidVersion,
FromBase58, ToBase58};
use util::base58::Base58Error::{self, InvalidLength, InvalidVersion};
use util::base58::{FromBase58, ToBase58};
#[deriving(Clone, PartialEq, Eq)]
/// A Bitcoin address
@ -130,7 +129,7 @@ mod tests {
use secp256k1::Secp256k1;
use network::constants::Bitcoin;
use network::constants::Network::Bitcoin;
use util::hash::Ripemd160Hash;
use util::base58::{FromBase58, ToBase58};
use super::Address;

View File

@ -23,7 +23,8 @@ use collections::hash::sip::hash_with_keys;
use secp256k1::key::SecretKey;
use blockdata::transaction::{TxOut, PayToPubkeyHash};
use blockdata::transaction::TxOut;
use blockdata::transaction::ScriptPubkeyTemplate::PayToPubkeyHash;
use blockdata::utxoset::UtxoSet;
use blockdata::script::Script;
use network::constants::Network;

View File

@ -29,10 +29,10 @@ use crypto::sha2::Sha512;
use secp256k1::key::{PublicKey, SecretKey};
use secp256k1;
use network::constants::{Network, Bitcoin, BitcoinTestnet};
use util::base58::{Base58Error,
InvalidLength, InvalidVersion, OtherBase58Error,
FromBase58, ToBase58};
use network::constants::Network::{self, Bitcoin, BitcoinTestnet};
use util::base58::Base58Error::{self, InvalidLength, InvalidVersion,
OtherBase58Error};
use util::base58::{FromBase58, ToBase58};
/// A chain code
pub struct ChainCode([u8; 32]);
@ -96,8 +96,8 @@ pub enum ChildNumber {
impl<S: Encoder<E>, E> Encodable<S, E> for ChildNumber {
fn encode(&self, s: &mut S) -> Result<(), E> {
match *self {
Hardened(n) => (n + (1 << 31)).encode(s),
Normal(n) => n.encode(s)
ChildNumber::Hardened(n) => (n + (1 << 31)).encode(s),
ChildNumber::Normal(n) => n.encode(s)
}
}
}
@ -106,9 +106,9 @@ impl<D: Decoder<E>, E> Decodable<D, E> for ChildNumber {
fn decode(d: &mut D) -> Result<ChildNumber, E> {
let n: u32 = try!(Decodable::decode(d));
if n < (1 << 31) {
Ok(Normal(n))
Ok(ChildNumber::Normal(n))
} else {
Ok(Hardened(n - (1 << 31)))
Ok(ChildNumber::Hardened(n - (1 << 31)))
}
}
}
@ -138,7 +138,7 @@ impl ExtendedPrivKey {
network: network,
depth: 0,
parent_fingerprint: Default::default(),
child_number: Normal(0),
child_number: ChildNumber::Normal(0),
secret_key: try!(SecretKey::from_slice(result.slice_to(32)).map_err(EcdsaError)),
chain_code: ChainCode::from_slice(result.slice_from(32))
})
@ -159,7 +159,7 @@ impl ExtendedPrivKey {
let mut result = [0; 64];
let mut hmac = Hmac::new(Sha512::new(), self.chain_code.as_slice());
match i {
Normal(n) => {
ChildNumber::Normal(n) => {
if n >= (1 << 31) { return Err(InvalidChildNumber(i)) }
// Non-hardened key: compute public data and use that
secp256k1::init();
@ -167,7 +167,7 @@ impl ExtendedPrivKey {
hmac.input(PublicKey::from_secret_key(&self.secret_key, true).as_slice());
u64_to_be_bytes(n as u64, 4, |raw| hmac.input(raw));
}
Hardened(n) => {
ChildNumber::Hardened(n) => {
if n >= (1 << 31) { return Err(InvalidChildNumber(i)) }
// Hardened key: use only secret data to prevent public derivation
hmac.input([0]);
@ -230,14 +230,14 @@ impl ExtendedPubKey {
/// Public->Public child key derivation
pub fn ckd_pub(&self, i: ChildNumber) -> Result<ExtendedPubKey, Error> {
match i {
Hardened(n) => {
ChildNumber::Hardened(n) => {
if n >= (1 << 31) {
Err(InvalidChildNumber(i))
} else {
Err(CannotDeriveFromHardenedKey)
}
}
Normal(n) => {
ChildNumber::Normal(n) => {
let mut hmac = Hmac::new(Sha512::new(), self.chain_code.as_slice());
hmac.input(self.public_key.as_slice());
u64_to_be_bytes(n as u64, 4, |raw| hmac.input(raw));
@ -293,10 +293,10 @@ impl ToBase58 for ExtendedPrivKey {
ret.push(self.depth as u8);
ret.push_all(self.parent_fingerprint.as_slice());
match self.child_number {
Hardened(n) => {
ChildNumber::Hardened(n) => {
u64_to_be_bytes(n as u64 + (1 << 31), 4, |raw| ret.push_all(raw));
}
Normal(n) => {
ChildNumber::Normal(n) => {
u64_to_be_bytes(n as u64, 4, |raw| ret.push_all(raw));
}
}
@ -314,8 +314,8 @@ impl FromBase58 for ExtendedPrivKey {
}
let cn_int = u64_from_be_bytes(data.as_slice(), 9, 4) as u32;
let child_number = if cn_int < (1 << 31) { Normal(cn_int) }
else { Hardened(cn_int - (1 << 31)) };
let child_number = if cn_int < (1 << 31) { ChildNumber::Normal(cn_int) }
else { ChildNumber::Hardened(cn_int - (1 << 31)) };
Ok(ExtendedPrivKey {
network: match data.slice_to(4) {
@ -345,10 +345,10 @@ impl ToBase58 for ExtendedPubKey {
ret.push(self.depth as u8);
ret.push_all(self.parent_fingerprint.as_slice());
match self.child_number {
Hardened(n) => {
ChildNumber::Hardened(n) => {
u64_to_be_bytes(n as u64 + (1 << 31), 4, |raw| ret.push_all(raw));
}
Normal(n) => {
ChildNumber::Normal(n) => {
u64_to_be_bytes(n as u64, 4, |raw| ret.push_all(raw));
}
}
@ -365,8 +365,8 @@ impl FromBase58 for ExtendedPubKey {
}
let cn_int = u64_from_be_bytes(data.as_slice(), 9, 4) as u32;
let child_number = if cn_int < (1 << 31) { Normal(cn_int) }
else { Hardened(cn_int - (1 << 31)) };
let child_number = if cn_int < (1 << 31) { ChildNumber::Normal(cn_int) }
else { ChildNumber::Hardened(cn_int - (1 << 31)) };
Ok(ExtendedPubKey {
network: match data.slice_to(4) {
@ -390,10 +390,11 @@ mod tests {
use serialize::hex::FromHex;
use test::{Bencher, black_box};
use network::constants::{Network, Bitcoin};
use network::constants::Network::{self, Bitcoin};
use util::base58::{FromBase58, ToBase58};
use super::{ChildNumber, ExtendedPrivKey, ExtendedPubKey, Hardened, Normal};
use super::{ChildNumber, ExtendedPrivKey, ExtendedPubKey};
use super::ChildNumber::{Hardened, Normal};
fn test_path(network: Network,
seed: &[u8],

View File

@ -25,7 +25,8 @@ use secp256k1::key::PublicKey;
use blockdata::utxoset::UtxoSet;
use network::constants::Network;
use wallet::bip32::{self, ChildNumber, ExtendedPrivKey, ExtendedPubKey, Normal, Hardened};
use wallet::bip32::{self, ChildNumber, ExtendedPrivKey, ExtendedPubKey};
use wallet::bip32::ChildNumber::{Normal, Hardened};
use wallet::address::Address;
use wallet::address_index::AddressIndex;