|
| 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; |
@@ -177,36 +179,46 @@ Handle<Value> convert_blob_bb(const Arguments& args) { |
177 | 179 | return scope.Close(buff->handle_); |
178 | 180 | } |
179 | 181 |
|
180 | | -Handle<Value> address_decode(const Arguments& args) { |
| 182 | +Handle<Value> check_address(const Arguments& args) { |
181 | 183 | HandleScope scope; |
182 | 184 |
|
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."); |
185 | 187 |
|
186 | 188 | Local<Object> target = args[0]->ToObject(); |
187 | 189 |
|
188 | 190 | 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."); |
190 | 195 |
|
191 | 196 | blobdata input = std::string(Buffer::Data(target), Buffer::Length(target)); |
192 | | - blobdata output = ""; |
| 197 | + Local<Number> expected_prefix = Number::New(args[1]->NumberValue()); |
193 | 198 |
|
| 199 | + blobdata data; |
194 | 200 | uint64_t prefix; |
| 201 | + if (!tools::base58::decode_addr(input, prefix, data)) |
| 202 | + return scope.Close(Boolean::New(false)); |
195 | 203 |
|
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)); |
200 | 206 |
|
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)); |
203 | 215 | } |
204 | 216 |
|
205 | 217 | void init(Handle<Object> exports) { |
206 | 218 | exports->Set(String::NewSymbol("construct_block_blob"), FunctionTemplate::New(construct_block_blob)->GetFunction()); |
207 | 219 | exports->Set(String::NewSymbol("convert_blob"), FunctionTemplate::New(convert_blob)->GetFunction()); |
208 | 220 | 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()); |
210 | 222 | } |
211 | 223 |
|
212 | 224 | NODE_MODULE(cryptonote, init) |
0 commit comments