forked from ceozero/equihashverify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
equihashverify.cc
46 lines (33 loc) · 1.04 KB
/
equihashverify.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
#include <nan.h>
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
#include <stdint.h>
extern "C" {
#include "src/equi/equi.h"
}
using namespace v8;
void Verify(const v8::FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.Length() < 2) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
Local<Object> header = args[0]->ToObject();
Local<Object> solution = args[1]->ToObject();
if(!node::Buffer::HasInstance(header) || !node::Buffer::HasInstance(solution)) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Arguments should be buffer objects.")));
return;
}
const char *hdr = node::Buffer::Data(header);
const char *soln = node::Buffer::Data(solution);
bool result = verifyEH(hdr, soln);
args.GetReturnValue().Set(result);
}
void Init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "verify", Verify);
}
NODE_MODULE(equihashverify, Init)