Skip to content

Commit d5f9b1a

Browse files
committed
Proper address checking for all CryptoNote currencies
1 parent 71f1a6d commit d5f9b1a

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

src/main.cc

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <cmath>
12
#include <node.h>
23
#include <node_buffer.h>
34
#include <v8.h>
@@ -10,6 +11,7 @@
1011
#include "crypto/crypto.h"
1112
#include "crypto/hash.h"
1213
#include "common/base58.h"
14+
#include "serialization/binary_utils.h"
1315

1416
using namespace node;
1517
using namespace v8;
@@ -82,35 +84,45 @@ Handle<Value> convert_blob_bb(const Arguments& args) {
8284
return scope.Close(buff->handle_);
8385
}
8486

85-
Handle<Value> address_decode(const Arguments& args) {
87+
Handle<Value> check_address(const Arguments& args) {
8688
HandleScope scope;
8789

88-
if (args.Length() < 1)
89-
return except("You must provide one argument.");
90+
if (args.Length() < 2)
91+
return except("You must provide two arguments.");
9092

9193
Local<Object> target = args[0]->ToObject();
9294

9395
if (!Buffer::HasInstance(target))
94-
return except("Argument should be a buffer object.");
96+
return except("First argument should be a buffer object.");
97+
98+
if (!args[1]->IsNumber())
99+
return except("Second argument should be an unsigned integer number.");
95100

96101
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
97-
blobdata output = "";
102+
Local<Number> expected_prefix = Number::New(args[1]->NumberValue());
98103

104+
blobdata data;
99105
uint64_t prefix;
106+
if (!tools::base58::decode_addr(input, prefix, data))
107+
return scope.Close(Boolean::New(false));
100108

101-
tools::base58::decode_addr(input, prefix, output);
102-
103-
if(output.length())
104-
output = uint64be_to_blob(prefix) + output;
109+
if (static_cast<uint64_t>(llround(expected_prefix->NumberValue())) != prefix)
110+
return scope.Close(Boolean::New(false));
105111

106-
Buffer* buff = Buffer::New(output.data(), output.size());
107-
return scope.Close(buff->handle_);
112+
account_public_address adr;
113+
if (!::serialization::parse_binary(data, adr))
114+
return scope.Close(Boolean::New(false));
115+
116+
//if (!crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
117+
// return scope.Close(Boolean::New(false));
118+
119+
return scope.Close(Boolean::New(true));
108120
}
109121

110122
void init(Handle<Object> exports) {
111123
exports->Set(String::NewSymbol("convert_blob"), FunctionTemplate::New(convert_blob)->GetFunction());
112124
exports->Set(String::NewSymbol("convert_blob_bb"), FunctionTemplate::New(convert_blob_bb)->GetFunction());
113-
exports->Set(String::NewSymbol("address_decode"), FunctionTemplate::New(address_decode)->GetFunction());
125+
exports->Set(String::NewSymbol("check_address"), FunctionTemplate::New(check_address)->GetFunction());
114126
}
115127

116128
NODE_MODULE(cryptonote, init)

0 commit comments

Comments
 (0)