Proper address checking for all CryptoNote currencies

address_checking
CliffordST 2014-07-03 14:33:55 +04:00
parent 71f1a6d8c2
commit d5f9b1a80a
1 changed files with 24 additions and 12 deletions

View File

@ -1,3 +1,4 @@
#include <cmath>
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
@ -10,6 +11,7 @@
#include "crypto/crypto.h"
#include "crypto/hash.h"
#include "common/base58.h"
#include "serialization/binary_utils.h"
using namespace node;
using namespace v8;
@ -82,35 +84,45 @@ Handle<Value> convert_blob_bb(const Arguments& args) {
return scope.Close(buff->handle_);
}
Handle<Value> address_decode(const Arguments& args) {
Handle<Value> check_address(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1)
return except("You must provide one argument.");
if (args.Length() < 2)
return except("You must provide two arguments.");
Local<Object> target = args[0]->ToObject();
if (!Buffer::HasInstance(target))
return except("Argument should be a buffer object.");
return except("First argument should be a buffer object.");
if (!args[1]->IsNumber())
return except("Second argument should be an unsigned integer number.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata output = "";
Local<Number> expected_prefix = Number::New(args[1]->NumberValue());
blobdata data;
uint64_t prefix;
if (!tools::base58::decode_addr(input, prefix, data))
return scope.Close(Boolean::New(false));
tools::base58::decode_addr(input, prefix, output);
if(output.length())
output = uint64be_to_blob(prefix) + output;
if (static_cast<uint64_t>(llround(expected_prefix->NumberValue())) != prefix)
return scope.Close(Boolean::New(false));
Buffer* buff = Buffer::New(output.data(), output.size());
return scope.Close(buff->handle_);
account_public_address adr;
if (!::serialization::parse_binary(data, adr))
return scope.Close(Boolean::New(false));
//if (!crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
// return scope.Close(Boolean::New(false));
return scope.Close(Boolean::New(true));
}
void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("convert_blob"), FunctionTemplate::New(convert_blob)->GetFunction());
exports->Set(String::NewSymbol("convert_blob_bb"), FunctionTemplate::New(convert_blob_bb)->GetFunction());
exports->Set(String::NewSymbol("address_decode"), FunctionTemplate::New(address_decode)->GetFunction());
exports->Set(String::NewSymbol("check_address"), FunctionTemplate::New(check_address)->GetFunction());
}
NODE_MODULE(cryptonote, init)