-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmultihashing.cc
50 lines (33 loc) · 1.2 KB
/
multihashing.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
#include <stdint.h>
#include <nan.h>
extern "C" {
#include "PoW.h"
}
#define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x)
using namespace node;
using namespace v8;
NAN_METHOD(cryptohello) {
if (info.Length() < 1)
return THROW_ERROR_EXCEPTION("You must provide one argument.");
if (info.Length() >= 2) {
if(!info[1]->IsBoolean())
return THROW_ERROR_EXCEPTION("Argument 2 should be a boolean");
}
Local<Object> target = info[0]->ToObject();
if(!Buffer::HasInstance(target))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
uint8_t * input = (uint8_t *)Buffer::Data(target);
uint8_t output[OUTPUT_LEN];
uint32_t input_len = Buffer::Length(target);
//input_len=input_len;
helloHash(input, input_len, output);
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char *)output, OUTPUT_LEN).ToLocalChecked();
info.GetReturnValue().Set(returnValue);
}
NAN_MODULE_INIT(init) {
Nan::Set(target, Nan::New("cryptohello").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(cryptohello)).ToLocalChecked());
}
NODE_MODULE(multihashing, init)