Browse Source

Update equihashverify.cc

master
LiteCoinZ 6 years ago
committed by GitHub
parent
commit
161261e67a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      equihashverify.cc

26
equihashverify.cc

@ -9,17 +9,29 @@
#include <vector>
using namespace v8;
int verifyEH(const char *hdr, const std::vector<unsigned char> &soln){
unsigned int n = 200;
unsigned int k = 9;
int verifyEH(const char *hdr, const std::vector<unsigned char> &soln, unsigned int n, unsigned int k){
// Hash state
crypto_generichash_blake2b_state state;
EhInitialiseState(n, k, state);
crypto_generichash_blake2b_update(&state, (const unsigned char*)hdr, 140);
bool isValid = Eh200_9.IsValidSolution(state, soln);
bool isValid;
if (n == 96 && k == 3) {
isValid = Eh96_3.IsValidSolution(state, soln);
} else if (n == 200 && k == 9) {
isValid = Eh200_9.IsValidSolution(state, soln);
} else if (n == 144 && k == 5) {
isValid = Eh144_5.IsValidSolution(state, soln);
} else if (n == 192 && k == 7) {
isValid = Eh192_7.IsValidSolution(state, soln);
} else if (n == 96 && k == 5) {
isValid = Eh96_5.IsValidSolution(state, soln);
} else if (n == 48 && k == 5) {
isValid = Eh48_5.IsValidSolution(state, soln);
} else {
throw std::invalid_argument("Unsupported Equihash parameters");
}
return isValid;
}
@ -36,6 +48,8 @@ void Verify(const v8::FunctionCallbackInfo<Value>& args) {
Local<Object> header = args[0]->ToObject();
Local<Object> solution = args[1]->ToObject();
unsigned int n = args[2]->Uint32Value();
unsigned int k = args[3]->Uint32Value();
if(!node::Buffer::HasInstance(header) || !node::Buffer::HasInstance(solution)) {
isolate->ThrowException(Exception::TypeError(
@ -53,7 +67,7 @@ void Verify(const v8::FunctionCallbackInfo<Value>& args) {
std::vector<unsigned char> vecSolution(soln, soln + node::Buffer::Length(solution));
bool result = verifyEH(hdr, vecSolution);
bool result = verifyEH(hdr, vecSolution, n, k);
args.GetReturnValue().Set(result);
}

Loading…
Cancel
Save