diff --git a/src/common.h b/src/common.h index 2f588b5..68a163c 100644 --- a/src/common.h +++ b/src/common.h @@ -1,5 +1,5 @@ -#ifndef BITCOINJS_SERVER_INCLUDE_COMMON_H_ -#define BITCOINJS_SERVER_INCLUDE_COMMON_H_ +#ifndef LIBCOIN_SERVER_INCLUDE_COMMON_H_ +#define LIBCOIN_SERVER_INCLUDE_COMMON_H_ #include diff --git a/src/eckey.cc b/src/eckey.cc index 9be3745..9b59276 100644 --- a/src/eckey.cc +++ b/src/eckey.cc @@ -53,7 +53,7 @@ int static inline EC_KEY_regenerate_key(EC_KEY *eckey, const BIGNUM *priv_key) return(ok); } -void BitcoinKey::Generate() +void Key::Generate() { if (!EC_KEY_generate_key(ec)) { lastError = "Error from EC_KEY_generate_key"; @@ -64,13 +64,13 @@ void BitcoinKey::Generate() hasPrivate = true; } -int BitcoinKey::VerifySignature(const unsigned char *digest, int digest_len, +int Key::VerifySignature(const unsigned char *digest, int digest_len, const unsigned char *sig, int sig_len) { return ECDSA_verify(0, digest, digest_len, sig, sig_len, ec); } -void BitcoinKey::EIO_VerifySignature(uv_work_t *req) +void Key::EIO_VerifySignature(uv_work_t *req) { verify_sig_baton_t *b = static_cast(req->data); @@ -80,7 +80,7 @@ void BitcoinKey::EIO_VerifySignature(uv_work_t *req) ); } -ECDSA_SIG *BitcoinKey::Sign(const unsigned char *digest, int digest_len) +ECDSA_SIG *Key::Sign(const unsigned char *digest, int digest_len) { ECDSA_SIG *sig; @@ -92,14 +92,14 @@ ECDSA_SIG *BitcoinKey::Sign(const unsigned char *digest, int digest_len) return sig; } -void BitcoinKey::Init(Handle target) +void Key::Init(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); s_ct = Persistent::New(t); s_ct->InstanceTemplate()->SetInternalFieldCount(1); - s_ct->SetClassName(String::NewSymbol("BitcoinKey")); + s_ct->SetClassName(String::NewSymbol("Key")); // Accessors s_ct->InstanceTemplate()->SetAccessor(String::New("private"), @@ -118,11 +118,11 @@ void BitcoinKey::Init(Handle target) NODE_SET_METHOD(s_ct->GetFunction(), "generateSync", GenerateSync); NODE_SET_METHOD(s_ct->GetFunction(), "fromDER", FromDER); - target->Set(String::NewSymbol("BitcoinKey"), + target->Set(String::NewSymbol("Key"), s_ct->GetFunction()); } -BitcoinKey::BitcoinKey() : +Key::Key() : lastError(NULL), hasPrivate(false), hasPublic(false) @@ -133,24 +133,24 @@ BitcoinKey::BitcoinKey() : } } -BitcoinKey::~BitcoinKey() +Key::~Key() { EC_KEY_free(ec); } -BitcoinKey* -BitcoinKey::New() +Key* +Key::New() { HandleScope scope; Local k = s_ct->GetFunction()->NewInstance(0, NULL); if (k.IsEmpty()) return NULL; - return ObjectWrap::Unwrap(k); + return ObjectWrap::Unwrap(k); } Handle -BitcoinKey::New(const Arguments& args) +Key::New(const Arguments& args) { if (!args.IsConstructCall()) { return FromConstructorTemplate(s_ct, args); @@ -158,7 +158,7 @@ BitcoinKey::New(const Arguments& args) HandleScope scope; - BitcoinKey* key = new BitcoinKey(); + Key* key = new Key(); if (key->lastError != NULL) { return VException(key->lastError); } @@ -169,11 +169,11 @@ BitcoinKey::New(const Arguments& args) } Handle -BitcoinKey::GenerateSync(const Arguments& args) +Key::GenerateSync(const Arguments& args) { HandleScope scope; - BitcoinKey* key = BitcoinKey::New(); + Key* key = Key::New(); key->Generate(); @@ -185,10 +185,10 @@ BitcoinKey::GenerateSync(const Arguments& args) } Handle -BitcoinKey::GetPrivate(Local property, const AccessorInfo& info) +Key::GetPrivate(Local property, const AccessorInfo& info) { HandleScope scope; - BitcoinKey* key = node::ObjectWrap::Unwrap(info.Holder()); + Key* key = node::ObjectWrap::Unwrap(info.Holder()); if (!key->hasPrivate) { return scope.Close(Null()); @@ -225,9 +225,9 @@ BitcoinKey::GetPrivate(Local property, const AccessorInfo& info) } void -BitcoinKey::SetPrivate(Local property, Local value, const AccessorInfo& info) +Key::SetPrivate(Local property, Local value, const AccessorInfo& info) { - BitcoinKey* key = node::ObjectWrap::Unwrap(info.Holder()); + Key* key = node::ObjectWrap::Unwrap(info.Holder()); Handle buffer = value->ToObject(); const unsigned char *data = (const unsigned char*) Buffer::Data(buffer); @@ -239,10 +239,10 @@ BitcoinKey::SetPrivate(Local property, Local value, const Accesso } Handle -BitcoinKey::GetPublic(Local property, const AccessorInfo& info) +Key::GetPublic(Local property, const AccessorInfo& info) { HandleScope scope; - BitcoinKey* key = node::ObjectWrap::Unwrap(info.Holder()); + Key* key = node::ObjectWrap::Unwrap(info.Holder()); if (!key->hasPublic) { return scope.Close(Null()); @@ -270,9 +270,9 @@ BitcoinKey::GetPublic(Local property, const AccessorInfo& info) } void -BitcoinKey::SetPublic(Local property, Local value, const AccessorInfo& info) +Key::SetPublic(Local property, Local value, const AccessorInfo& info) { - BitcoinKey* key = node::ObjectWrap::Unwrap(info.Holder()); + Key* key = node::ObjectWrap::Unwrap(info.Holder()); Handle buffer = value->ToObject(); const unsigned char *data = (const unsigned char*) Buffer::Data(buffer); @@ -285,10 +285,10 @@ BitcoinKey::SetPublic(Local property, Local value, const Accessor } Handle -BitcoinKey::RegenerateSync(const Arguments& args) +Key::RegenerateSync(const Arguments& args) { HandleScope scope; - BitcoinKey* key = node::ObjectWrap::Unwrap(args.This()); + Key* key = node::ObjectWrap::Unwrap(args.This()); if (!key->hasPrivate) { return VException("Regeneration requires a private key."); @@ -307,10 +307,10 @@ BitcoinKey::RegenerateSync(const Arguments& args) } Handle -BitcoinKey::ToDER(const Arguments& args) +Key::ToDER(const Arguments& args) { HandleScope scope; - BitcoinKey* key = node::ObjectWrap::Unwrap(args.This()); + Key* key = node::ObjectWrap::Unwrap(args.This()); if (!key->hasPrivate || !key->hasPublic) { return scope.Close(Null()); @@ -338,7 +338,7 @@ BitcoinKey::ToDER(const Arguments& args) } Handle -BitcoinKey::FromDER(const Arguments& args) +Key::FromDER(const Arguments& args) { HandleScope scope; @@ -349,7 +349,7 @@ BitcoinKey::FromDER(const Arguments& args) return VException("Argument 'der' must be of type Buffer"); } - BitcoinKey* key = new BitcoinKey(); + Key* key = new Key(); if (key->lastError != NULL) { return VException(key->lastError); } @@ -372,10 +372,10 @@ BitcoinKey::FromDER(const Arguments& args) } Handle -BitcoinKey::VerifySignature(const Arguments& args) +Key::VerifySignature(const Arguments& args) { HandleScope scope; - BitcoinKey* key = node::ObjectWrap::Unwrap(args.This()); + Key* key = node::ObjectWrap::Unwrap(args.This()); if (args.Length() != 3) { return VException("Three arguments expected: hash, sig, callback"); @@ -388,7 +388,7 @@ BitcoinKey::VerifySignature(const Arguments& args) } REQ_FUN_ARG(2, cb); if (!key->hasPublic) { - return VException("BitcoinKey does not have a public key set"); + return VException("Key does not have a public key set"); } Handle hash_buf = args[0]->ToObject(); @@ -420,7 +420,7 @@ BitcoinKey::VerifySignature(const Arguments& args) } void -BitcoinKey::VerifySignatureCallback(uv_work_t *req, int status) +Key::VerifySignatureCallback(uv_work_t *req, int status) { HandleScope scope; verify_sig_baton_t *baton = static_cast(req->data); @@ -462,10 +462,10 @@ BitcoinKey::VerifySignatureCallback(uv_work_t *req, int status) } Handle -BitcoinKey::VerifySignatureSync(const Arguments& args) +Key::VerifySignatureSync(const Arguments& args) { HandleScope scope; - BitcoinKey* key = node::ObjectWrap::Unwrap(args.This()); + Key* key = node::ObjectWrap::Unwrap(args.This()); if (args.Length() != 2) { return VException("Two arguments expected: hash, sig"); @@ -477,7 +477,7 @@ BitcoinKey::VerifySignatureSync(const Arguments& args) return VException("Argument 'sig' must be of type Buffer"); } if (!key->hasPublic) { - return VException("BitcoinKey does not have a public key set"); + return VException("Key does not have a public key set"); } Handle hash_buf = args[0]->ToObject(); @@ -510,10 +510,10 @@ BitcoinKey::VerifySignatureSync(const Arguments& args) } Handle -BitcoinKey::SignSync(const Arguments& args) +Key::SignSync(const Arguments& args) { HandleScope scope; - BitcoinKey* key = node::ObjectWrap::Unwrap(args.This()); + Key* key = node::ObjectWrap::Unwrap(args.This()); if (args.Length() != 1) { return VException("One argument expected: hash"); @@ -522,7 +522,7 @@ BitcoinKey::SignSync(const Arguments& args) return VException("Argument 'hash' must be of type Buffer"); } if (!key->hasPrivate) { - return VException("BitcoinKey does not have a private key set"); + return VException("Key does not have a private key set"); } Handle hash_buf = args[0]->ToObject(); @@ -560,12 +560,12 @@ BitcoinKey::SignSync(const Arguments& args) return scope.Close(der_buf->handle_); } -Persistent BitcoinKey::s_ct; +Persistent Key::s_ct; extern "C" void init (Handle target) { - BitcoinKey::Init(target); + Key::Init(target); } NODE_MODULE(native, init) diff --git a/src/eckey.h b/src/eckey.h index 72d9d10..b506051 100644 --- a/src/eckey.h +++ b/src/eckey.h @@ -1,5 +1,5 @@ -#ifndef BITCOINJS_SERVER_INCLUDE_ECKEY_H_ -#define BITCOINJS_SERVER_INCLUDE_ECKEY_H_ +#ifndef LIBCOIN_SERVER_INCLUDE_ECKEY_H_ +#define LIBCOIN_SERVER_INCLUDE_ECKEY_H_ #include #include @@ -7,7 +7,7 @@ using namespace v8; using namespace node; -class BitcoinKey : ObjectWrap +class Key : ObjectWrap { private: @@ -21,7 +21,7 @@ private: struct verify_sig_baton_t { // Parameters - BitcoinKey *key; + Key *key; const unsigned char *digest; const unsigned char *sig; int digestLen; @@ -48,10 +48,10 @@ public: static void Init(Handle target); - BitcoinKey(); - ~BitcoinKey(); + Key(); + ~Key(); - static BitcoinKey* New(); + static Key* New(); static Handle New(const Arguments& args); static Handle GenerateSync(const Arguments& args);