Rename BitcoinKey object to Key

This commit is contained in:
Jeff Garzik 2013-07-09 10:51:26 -04:00
parent 5c0db96180
commit 7da3c3b969
3 changed files with 51 additions and 51 deletions

View File

@ -1,5 +1,5 @@
#ifndef BITCOINJS_SERVER_INCLUDE_COMMON_H_ #ifndef LIBCOIN_SERVER_INCLUDE_COMMON_H_
#define BITCOINJS_SERVER_INCLUDE_COMMON_H_ #define LIBCOIN_SERVER_INCLUDE_COMMON_H_
#include <v8.h> #include <v8.h>

View File

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

View File

@ -1,5 +1,5 @@
#ifndef BITCOINJS_SERVER_INCLUDE_ECKEY_H_ #ifndef LIBCOIN_SERVER_INCLUDE_ECKEY_H_
#define BITCOINJS_SERVER_INCLUDE_ECKEY_H_ #define LIBCOIN_SERVER_INCLUDE_ECKEY_H_
#include <v8.h> #include <v8.h>
#include <node.h> #include <node.h>
@ -7,7 +7,7 @@
using namespace v8; using namespace v8;
using namespace node; using namespace node;
class BitcoinKey : ObjectWrap class Key : ObjectWrap
{ {
private: private:
@ -21,7 +21,7 @@ private:
struct verify_sig_baton_t { struct verify_sig_baton_t {
// Parameters // Parameters
BitcoinKey *key; Key *key;
const unsigned char *digest; const unsigned char *digest;
const unsigned char *sig; const unsigned char *sig;
int digestLen; int digestLen;
@ -48,10 +48,10 @@ public:
static void Init(Handle<Object> target); static void Init(Handle<Object> target);
BitcoinKey(); Key();
~BitcoinKey(); ~Key();
static BitcoinKey* New(); static Key* New();
static Handle<Value> New(const Arguments& args); static Handle<Value> New(const Arguments& args);
static Handle<Value> GenerateSync(const Arguments& args); static Handle<Value> GenerateSync(const Arguments& args);