|
| 1 | +#include <cmath> |
1 | 2 | #include <node.h> |
2 | 3 | #include <node_buffer.h> |
3 | 4 | #include <v8.h> |
|
10 | 11 | #include "crypto/crypto.h" |
11 | 12 | #include "crypto/hash.h" |
12 | 13 | #include "common/base58.h" |
| 14 | +#include "serialization/binary_utils.h" |
13 | 15 |
|
14 | 16 | using namespace node; |
15 | 17 | using namespace v8; |
@@ -82,35 +84,45 @@ Handle<Value> convert_blob_bb(const Arguments& args) { |
82 | 84 | return scope.Close(buff->handle_); |
83 | 85 | } |
84 | 86 |
|
85 | | -Handle<Value> address_decode(const Arguments& args) { |
| 87 | +Handle<Value> check_address(const Arguments& args) { |
86 | 88 | HandleScope scope; |
87 | 89 |
|
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."); |
90 | 92 |
|
91 | 93 | Local<Object> target = args[0]->ToObject(); |
92 | 94 |
|
93 | 95 | 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."); |
95 | 100 |
|
96 | 101 | blobdata input = std::string(Buffer::Data(target), Buffer::Length(target)); |
97 | | - blobdata output = ""; |
| 102 | + Local<Number> expected_prefix = Number::New(args[1]->NumberValue()); |
98 | 103 |
|
| 104 | + blobdata data; |
99 | 105 | uint64_t prefix; |
| 106 | + if (!tools::base58::decode_addr(input, prefix, data)) |
| 107 | + return scope.Close(Boolean::New(false)); |
100 | 108 |
|
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)); |
105 | 111 |
|
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)); |
108 | 120 | } |
109 | 121 |
|
110 | 122 | void init(Handle<Object> exports) { |
111 | 123 | exports->Set(String::NewSymbol("convert_blob"), FunctionTemplate::New(convert_blob)->GetFunction()); |
112 | 124 | 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()); |
114 | 126 | } |
115 | 127 |
|
116 | 128 | NODE_MODULE(cryptonote, init) |
0 commit comments