Skip to content

Commit 1cb6493

Browse files
committed
Merge branch 'address_checking'
2 parents a3a3cb6 + d5f9b1a commit 1cb6493

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;
@@ -177,36 +179,46 @@ Handle<Value> convert_blob_bb(const Arguments& args) {
177179
return scope.Close(buff->handle_);
178180
}
179181

180-
Handle<Value> address_decode(const Arguments& args) {
182+
Handle<Value> check_address(const Arguments& args) {
181183
HandleScope scope;
182184

183-
if (args.Length() < 1)
184-
return except("You must provide one argument.");
185+
if (args.Length() < 2)
186+
return except("You must provide two arguments.");
185187

186188
Local<Object> target = args[0]->ToObject();
187189

188190
if (!Buffer::HasInstance(target))
189-
return except("Argument should be a buffer object.");
191+
return except("First argument should be a buffer object.");
192+
193+
if (!args[1]->IsNumber())
194+
return except("Second argument should be an unsigned integer number.");
190195

191196
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
192-
blobdata output = "";
197+
Local<Number> expected_prefix = Number::New(args[1]->NumberValue());
193198

199+
blobdata data;
194200
uint64_t prefix;
201+
if (!tools::base58::decode_addr(input, prefix, data))
202+
return scope.Close(Boolean::New(false));
195203

196-
tools::base58::decode_addr(input, prefix, output);
197-
198-
if(output.length())
199-
output = uint64be_to_blob(prefix) + output;
204+
if (static_cast<uint64_t>(llround(expected_prefix->NumberValue())) != prefix)
205+
return scope.Close(Boolean::New(false));
200206

201-
Buffer* buff = Buffer::New(output.data(), output.size());
202-
return scope.Close(buff->handle_);
207+
account_public_address adr;
208+
if (!::serialization::parse_binary(data, adr))
209+
return scope.Close(Boolean::New(false));
210+
211+
//if (!crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
212+
// return scope.Close(Boolean::New(false));
213+
214+
return scope.Close(Boolean::New(true));
203215
}
204216

205217
void init(Handle<Object> exports) {
206218
exports->Set(String::NewSymbol("construct_block_blob"), FunctionTemplate::New(construct_block_blob)->GetFunction());
207219
exports->Set(String::NewSymbol("convert_blob"), FunctionTemplate::New(convert_blob)->GetFunction());
208220
exports->Set(String::NewSymbol("convert_blob_bb"), FunctionTemplate::New(convert_blob_bb)->GetFunction());
209-
exports->Set(String::NewSymbol("address_decode"), FunctionTemplate::New(address_decode)->GetFunction());
221+
exports->Set(String::NewSymbol("check_address"), FunctionTemplate::New(check_address)->GetFunction());
210222
}
211223

212224
NODE_MODULE(cryptonote, init)

0 commit comments

Comments
 (0)