-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8c47382
Showing
28 changed files
with
3,669 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Build & Test Package | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
linux-node10: | ||
runs-on: ubuntu-16.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '10.x' | ||
registry-url: 'https://npm.pkg.github.com' | ||
- run: sudo apt install libboost-dev | ||
- run: npm install | ||
- run: npm test | ||
|
||
linux-node12: | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '12.x' | ||
registry-url: 'https://npm.pkg.github.com' | ||
- run: sudo apt install libboost-dev | ||
- run: npm install | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Publish Package | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '10.x' | ||
registry-url: 'https://npm.pkg.github.com' | ||
- run: sudo apt install libboost-all-dev | ||
- run: npm install | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.vscode/ | ||
.idea/ | ||
*.iml | ||
node_modules/ | ||
build/ | ||
cmake-build-debug/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
cmake_minimum_required(VERSION 3.5.1) | ||
project(hasherbeamhash) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
file(GLOB hasher_beamhash_SRC | ||
"src/*/*.c" | ||
"src/*.c" | ||
"src/*.cpp" | ||
"src/*/*.cpp" | ||
) | ||
|
||
#ff building Node JS Addon | ||
if (CMAKE_JS_VERSION) | ||
|
||
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static") | ||
|
||
# add node include directories, fix potential backslashes | ||
foreach(CMAKE_JS_INC_ITEM ${CMAKE_JS_INC}) | ||
string(REPLACE "\\" "/" CMAKE_JS_INC_ITEM ${CMAKE_JS_INC_ITEM}) | ||
message(STATUS "include_directories ${CMAKE_JS_INC_ITEM}") | ||
include_directories(${CMAKE_JS_INC_ITEM}) | ||
endforeach(CMAKE_JS_INC_ITEM) | ||
|
||
string(REPLACE "\\" "/" PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}) | ||
message(STATUS "include_directories ${PROJECT_SOURCE_DIR}") | ||
include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) | ||
include_directories(${PROJECT_NAME} PUBLIC "./src") | ||
|
||
# include static libraries | ||
|
||
add_library(${PROJECT_NAME} SHARED ${hasher_beamhash_SRC} "hasherbeamhash.cc") | ||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") | ||
|
||
endif() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 JCThePants, contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
hasher-beamhash | ||
=============== | ||
|
||
This is a Node module for simple hashing and verifying [Beam coin](https://beam.mw) proof-of-work solutions. | ||
Most of the native code comes from or is adapted from [Beam source code](https://github.com/BeamMW/beam/tree/master/3rdparty/crypto). | ||
|
||
This module has been developed and tested on [Node v10.17](https://nodejs.org/) and | ||
[Ubuntu 16.04](http://releases.ubuntu.com/16.04/) for the [Beam mining pool](https://mintpond.com/#!/beam) at [MintPond](https://mintpond.com). | ||
|
||
## Install ## | ||
__Install as Dependency in NodeJS Project__ | ||
```bash | ||
# Install from Github NPM repository | ||
|
||
sudo apt-get install build-essential | ||
sudo apt-get install libboost-dev | ||
npm config set @mintpond:registry https://npm.pkg.github.com/mintpond | ||
npm config set //npm.pkg.github.com/:_authToken <MY_GITHUB_AUTH_TOKEN> | ||
|
||
npm install @mintpond/[email protected] --save | ||
``` | ||
[Creating a personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) | ||
|
||
__Install & Test__ | ||
```bash | ||
# Install nodejs v10 | ||
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - | ||
sudo apt-get install nodejs -y | ||
|
||
# Download hasher-beamhash | ||
git clone https://github.com/MintPond/hasher-beamhash | ||
|
||
# build | ||
cd hasher-beamhash | ||
npm install | ||
|
||
# test | ||
npm test | ||
``` | ||
|
||
## Usage ## | ||
__Verify BeamHashII__ | ||
```javascript | ||
const beamhash = require('@mintpond/hasher-beamhash'); | ||
|
||
/** | ||
* Verify a BeamHashII solution. | ||
* | ||
* @param inputBuf {Buffer} | ||
* @param nonceBuf {Buffer} | ||
* @param solutionBuf {Buffer} | ||
* @returns {boolean} True if valid, otherwise false. | ||
*/ | ||
const isValid = beamhash.verify2(inputBuf, nonceBuf, solutionBuf); | ||
|
||
if (isValid) { | ||
console.log('Valid solution'); | ||
} | ||
else { | ||
console.log('Invalid solution'); | ||
} | ||
``` | ||
|
||
__Verify BeamHashIII__ | ||
```javascript | ||
const beamhash = require('@mintpond/hasher-beamhash'); | ||
|
||
/** | ||
* Verify a BeamHashIII solution. | ||
* | ||
* @param inputBuf {Buffer} | ||
* @param nonceBuf {Buffer} | ||
* @param solutionBuf {Buffer} | ||
* @returns {boolean} True if valid, otherwise false. | ||
*/ | ||
const isValid = beamhash.verify3(inputBuf, nonceBuf, solutionBuf); | ||
|
||
if (isValid) { | ||
console.log('Valid solution'); | ||
} | ||
else { | ||
console.log('Invalid solution'); | ||
} | ||
``` | ||
|
||
## Dependencies ## | ||
In Ubuntu: | ||
``` | ||
sudo apt-get install build-essential | ||
sudo apt-get install libboost-dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "hasherbeamhash", | ||
"sources": [ | ||
"src/blake/blake2b.cpp", | ||
"src/beamHashIII_imp.cpp", | ||
"src/equihashR_imp.cpp", | ||
"hasherbeamhash.cc" | ||
], | ||
"include_dirs": [ | ||
".", | ||
"src", | ||
"<!(node -e \"require('nan')\")" | ||
], | ||
"cflags": [ | ||
"-fexceptions", | ||
"-std=c++17" | ||
], | ||
"cflags_cc": [ | ||
"-fexceptions", | ||
"-std=c++17" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include <node.h> | ||
#include <node_buffer.h> | ||
#include <v8.h> | ||
#include <stdint.h> | ||
#include <iostream> | ||
#include "nan.h" | ||
#include "src/equihashR.h" | ||
#include "src/beamHashIII.h" | ||
|
||
using namespace node; | ||
using namespace v8; | ||
|
||
#define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x) | ||
|
||
static BeamHash_III BeamHashIII; | ||
|
||
|
||
bool verifyPoWScheme(PoWScheme &scheme, const char *input_ptr, const char *nonce64_ptr, Local <Object> solution) { | ||
|
||
const char *solution_ptr = (char *) Buffer::Data(solution); | ||
|
||
blake2b_state state; | ||
scheme.InitialiseState(state); | ||
blake2b_update(&state, (const unsigned char *) input_ptr, 32); | ||
blake2b_update(&state, (const unsigned char *) nonce64_ptr, 8); | ||
|
||
std::vector<unsigned char> solution_vec(solution_ptr, solution_ptr + node::Buffer::Length(solution)); | ||
|
||
return scheme.IsValidSolution(state, solution_vec); | ||
} | ||
|
||
|
||
NAN_METHOD(verify1) { | ||
|
||
if (info.Length() < 3) { | ||
return THROW_ERROR_EXCEPTION("hasher-beamhash.verify1 - 3 arguments expected."); | ||
} | ||
|
||
const char* input_ptr = (char*)Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked()); | ||
const char* nonce64_ptr = (char*)Buffer::Data(Nan::To<v8::Object>(info[1]).ToLocalChecked()); | ||
Local<Object> solution = Nan::To<v8::Object>(info[2]).ToLocalChecked(); | ||
|
||
bool isValid = verifyPoWScheme(BeamHashI, input_ptr, nonce64_ptr, solution); | ||
|
||
if (isValid) { | ||
info.GetReturnValue().Set(Nan::True()); | ||
} | ||
else { | ||
info.GetReturnValue().Set(Nan::False()); | ||
} | ||
} | ||
|
||
|
||
NAN_METHOD(verify2) { | ||
|
||
if (info.Length() < 3) { | ||
return THROW_ERROR_EXCEPTION("hasher-beamhash.verify2 - 3 arguments expected."); | ||
} | ||
|
||
const char* input_ptr = (char*)Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked()); | ||
const char* nonce64_ptr = (char*)Buffer::Data(Nan::To<v8::Object>(info[1]).ToLocalChecked()); | ||
Local<Object> solution = Nan::To<v8::Object>(info[2]).ToLocalChecked(); | ||
|
||
bool isValid = verifyPoWScheme(BeamHashII, input_ptr, nonce64_ptr, solution); | ||
|
||
if (isValid) { | ||
info.GetReturnValue().Set(Nan::True()); | ||
} | ||
else { | ||
info.GetReturnValue().Set(Nan::False()); | ||
} | ||
} | ||
|
||
|
||
NAN_METHOD(verify3) { | ||
|
||
if (info.Length() < 3) { | ||
return THROW_ERROR_EXCEPTION("hasher-beamhash.verify3 - 3 arguments expected."); | ||
} | ||
|
||
const char* input_ptr = (char*)Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked()); | ||
const char* nonce64_ptr = (char*)Buffer::Data(Nan::To<v8::Object>(info[1]).ToLocalChecked()); | ||
Local<Object> solution = Nan::To<v8::Object>(info[2]).ToLocalChecked(); | ||
|
||
bool isValid = verifyPoWScheme(BeamHashIII, input_ptr, nonce64_ptr, solution); | ||
|
||
if (isValid) { | ||
info.GetReturnValue().Set(Nan::True()); | ||
} | ||
else { | ||
info.GetReturnValue().Set(Nan::False()); | ||
} | ||
} | ||
|
||
|
||
NAN_MODULE_INIT(init) { | ||
|
||
Nan::Set(target, Nan::New("verify1").ToLocalChecked(), | ||
Nan::GetFunction(Nan::New<FunctionTemplate>(verify1)).ToLocalChecked()); | ||
|
||
Nan::Set(target, Nan::New("verify2").ToLocalChecked(), | ||
Nan::GetFunction(Nan::New<FunctionTemplate>(verify2)).ToLocalChecked()); | ||
|
||
Nan::Set(target, Nan::New("verify3").ToLocalChecked(), | ||
Nan::GetFunction(Nan::New<FunctionTemplate>(verify3)).ToLocalChecked()); | ||
} | ||
|
||
|
||
NODE_MODULE(hasherbeamhash, init) |
Oops, something went wrong.