Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JCThePants committed Apr 13, 2020
0 parents commit 66ca111
Show file tree
Hide file tree
Showing 54 changed files with 72,356 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build & Test Package
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
linux-node10:
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: npm install
- run: npm test

linux-node12:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm test

windows-node10:
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm test

windows-node12:
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm test
17 changes: 17 additions & 0 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode/
.idea/
*.iml
node_modules/
build/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Traysi Hylian

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.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
hasher-x16rv2
=============

This repo is adapted for use with MintPond from the original repo which is located at https://github.com/traysi/x16rv2_hash/

This module has been developed and tested on [Node v10.16.3](https://nodejs.org/) and [Ubuntu 16.04](http://releases.ubuntu.com/16.04/)

## Install ##
__Install as Dependency in NodeJS Project__
```bash
# Install from Github git package

sudo apt-get install build-essential
npm install mintpond/hasher-x16rv2 --save
```
-or-
```bash
# Install from Github NPM repository

sudo apt-get install build-essential
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/hasher-x16rv2@1.0.0 --save
```

__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-x16rv2
git clone https://github.com/MintPond/hasher-x16rv2

# build
cd hasher-x16rv2
sudo apt-get install build-essential
npm install
npm test
```

## Usage ##
__Hash__
```js
const hasher = require('hasher-x16rv2');

/**
* Hash 80-byte input.
*
* @param inputBuf {Buffer} 80-byte input to hash.
* @param [outputBuf] {Buffer} Optional 32-byte buffer to copy result into.
* @returns {Buffer} The outputBuf or a new Buffer containing the hash result.
*/
const result = hasher.x16rv2(input);

console.log(result.toString('hex'));
```

__Hash into Output Buffer__
```js
const hasher = require('hasher-x16rv2');

const resultOut = Buffer.alloc(32); // Output buffer must be 32-bytes.

hasher.x16rv2(input, resultOut);

console.log(resultOut.toString('hex'));
```
38 changes: 38 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"targets": [
{
"target_name": "hasherx16rv2",
"sources": [
"hasherx16rv2.cc",
"x16rv2.c",
"sha3/blake.c",
"sha3/bmw.c",
"sha3/groestl.c",
"sha3/jh.c",
"sha3/keccak.c",
"sha3/skein.c",
"sha3/cubehash.c",
"sha3/echo.c",
"sha3/luffa.c",
"sha3/simd.c",
"sha3/hamsi.c",
"sha3/hamsi_helper.c",
"sha3/fugue.c",
"sha3/shavite.c",
"sha3/shabal.c",
"sha3/whirlpool.c",
"sha3/sha2big.c",
"sha3/tiger.c"
],
"include_dirs": [
"<!(node -e \"require('nan')\")"
],
"cflags_cc": [
"-std=c++11"
]
}
]
}



42 changes: 42 additions & 0 deletions hasherx16rv2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
#include <stdint.h>
#include "nan.h"

extern "C" {
#include "x16rv2.h"

}

#define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x)
#define THROW_ERROR_EXCEPTION_WITH_STATUS_CODE(x, y) NanThrowError(x, y)

using namespace node;
using namespace v8;

NAN_METHOD(x16rv2) {

if (info.Length() < 2)
return THROW_ERROR_EXCEPTION("You must provide two arguments.");

Local<Object> argInput = Nan::To<Object>(info[0]).ToLocalChecked();
Local<Object> argOutput = Nan::To<Object>(info[1]).ToLocalChecked();

if(!Buffer::HasInstance(argInput))
return THROW_ERROR_EXCEPTION("input should be a buffer object.");

if(!Buffer::HasInstance(argOutput))
return THROW_ERROR_EXCEPTION("output should be a buffer object.");

char * input = Buffer::Data(argInput);
char * output = Buffer::Data(argOutput);

x16rv2_hash(input, output);
}

NAN_MODULE_INIT(init) {
Nan::Set(target, Nan::New("x16rv2").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(x16rv2)).ToLocalChecked());
}

NODE_MODULE(nodex16rv2, init)
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const hasher = require('bindings')('hasherx16rv2.node');

const OUTPUT_BUFFER = Buffer.alloc(32);

module.exports = {

/**
* Hash 80-byte input.
*
* @param inputBuf {Buffer} 80-byte input to hash.
* @param [outputBuf] {Buffer} Optional 32-byte buffer to copy result into.
* @returns {Buffer} The outputBuf or a new Buffer containing the hash result.
*/
x16rv2: x16rv2
};

function x16rv2(inputBuf, outputBuf) {

_expectBuffer(inputBuf, 'inputBuf', 80);
outputBuf && _expectBuffer(outputBuf, 'outputBuf', 32);

hasher.x16rv2(inputBuf, OUTPUT_BUFFER);

const resultBuf = outputBuf || Buffer.alloc(32);
OUTPUT_BUFFER.copy(resultBuf, 0, 0);

return resultBuf;
}


function _expectBuffer(buffer, name, size) {
if (!Buffer.isBuffer(buffer))
throw new Error(`"${name}" is expected to be a Buffer. Got ${(typeof buffer)} instead.`);

if (size && buffer.length !== size)
throw new Error(`"${name}" is expected to be exactly ${size} bytes. Got ${buffer.length} instead.`);
}
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@mintpond/hasher-x16rv2",
"version": "1.0.0",
"description": "x16rv2 algorithm hashing function for NodeJS.",
"main": "index.js",
"authors": [
"Traysi Hylian",
"JCThePants"
],
"dependencies": {
"bindings": "^1.3.0",
"nan": "^2.6.2"
},
"scripts": {
"test": "node test"
},
"homepage": "https://github.com/MintPond/hasher-x16rv2",
"bugs": {
"url": "https://github.com/MintPond/hasher-x16rv2/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MintPond/hasher-x16rv2.git"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
"engines": {
"node": ">=10.17.0"
}
}
Loading

0 comments on commit 66ca111

Please sign in to comment.