Giter Site home page Giter Site logo

x11-hash-js's Introduction

x11-hash-js

Performs the x11 hashing algorithm used in the Dash cryptocurrency in JavaScript.

Usage

Install the library as a Node module.

$ npm install --save @dashevo/x11-hash-js

Reference the library within a Node module.

var x11 = require('x11-hash-js');

console.log(x11.digest('The great experiment continues.'));
// -> '4da3b7c5ff698c6546564ebc72204f31885cd87b75b2b3ca5a93b5d75db85b8c'

Download the browserified library from the dist folder and include it in your HTML.

<html>
<head>
  <script src='./dist/x11-hash.min.js'></script>
  <script>
  let x11 = require('x11hash');
  console.log(x11.digest('The great experiment continues.'));
  // -> '4da3b7c5ff698c6546564ebc72204f31885cd87b75b2b3ca5a93b5d75db85b8c'
  </script>
</head>
<body></body>
</html>

Call individual hash functions within the x11 digest.

console.log(x11.blake('The great experiment continues.'));
// -> '8f257723af0741fb7d3d8c264a5ea86a57d4ae833557de04f5f78fad1ac17d6dfa1ae4a78a7564c08fc21d5d8cdd2793ca17d5500ecc2b43eb8aaf9c220d7b49'

console.log(x11.bmw('The great experiment continues.'));
// -> '7b30b4f1ccd83692bc6a01b1f7e374b59b81da6b21421679ae59d84c4f73afec5a0857565b6ebc1b9ddf9da5e75bf1ecd0ba6f5a75b7926ba9278385fb83533c'

console.log(x11.cubehash('The great experiment continues.'));
// -> '64394bcb9d7844070c8516480ea5f03f68386f33c3829e08bf38bea11f09eba5806aa7831cfbe8e515678b0cad7d4ac888ea2b9ea8f63f0cc918d5a6a76b7ae9'

console.log(x11.echo('The great experiment continues.'));
// -> 'b1db282b1672f3423c1e1bdf4496a8ddda0b6f483e92e9a8be2efbaab0ea230814f1f1485d919285deac13794dc215000eb39a47ac32bfc07299a0475049be2e'

console.log(x11.groestl('The great experiment continues.'));
// -> '6cea044acf31194eab7d1adb704712c34dd4f0b6a470b0f297832addab691faa459474c651efdbebddb138a2a9adb41705e0fb75741775314ddd8e5449ace986'

console.log(x11.jh('The great experiment continues.'));
// -> '90c7090e9d9a45bc79f476ae7fa3e7e4416d1c26b127d1d418ee9bd96b541933b0f144a0d4c6594944393e39fb6b98ceb54752af55198e00953d638183482521'

console.log(x11.keccak('The great experiment continues.'));
// -> '4c7e9c893fcdc87a2fd604574a4a5b9a0b6864665ed19057dedf24858314690ba45d6bbcfb86cd7182d1677e2d30dad9716ee99eb8ea267c6638f47ef20e0226'

console.log(x11.luffa('The great experiment continues.'));
// -> 'ea531ce38473fc4bd508c5396194dd6201699d47e25bd4d6b0c5dc7ab0627831e01ea027ebe33d80f608f139aa9fd0c6d923f32de9b5d714026300ed1c9a2f48'

console.log(x11.shavite('The great experiment continues.'));
// -> '6fbca2d53a26e22e6df1a8064230bdb98c0a612b64dad958f16757cf8ee8526862a0e4f56be69b98b07f0ea47db7211cf42352443fc806013374e819f26cb923'

console.log(x11.simd('The great experiment continues.'));
// -> '13ae2c08260f7d5abcfa791446800c1eaed8c5332ec437222428a28823aa2ba19a5907a2c860c12c0b894bdf9c0d64f807cb9512f1ed42980d15747ff4a26c1c'

console.log(x11.skein('The great experiment continues.'));
// -> '88a9dd727bb9b7cbd59612edbcd6b321427f473acc5673d7dffb16071dc71821d0cc1b94dccf7e5f71a0a94019a7e764d3315c3f4a40f73aee4ad98c75bcc2f7'

API

x11.digest(str)

Returns a string representation of the x11 hash of an input string str.

str

Type: string

The string to be hashed.

x11.digest(input, inputFormat, outputFormat)

Returns the x11 hash of input with the input and output types variable between a string, 8 bit array or 32 bit array

input

Type: string or array

The input data to be hashed.

inputFormat

Type: number

Specifies the format and type of the input value:

  • 0: string
  • 1: 8 bit array
  • 2: 32 bit array

outputFormat

Type: number

Specifies the format and type of the return value:

  • 0: string
  • 1: 8 bit array
  • 2: 32 bit array

x11-hash-js's People

Contributors

alex-werner avatar andyfreer avatar nmarley avatar quantumexplorer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

x11-hash-js's Issues

Output formats are either inversed or labeled incorrectly.

In index.js at the end of the digest function where the output format is computed we have the following code:

// output 32-bit array
if (outputFormat === 2) {
    return h.int32Buffer2Bytes(a);
}
// output 8-bit array
else if (outputFormat === 1) {
    return a;
}
// output string
return h.int32ArrayToHexString(a);

and in test.js we have these 2 tests:

    it('buffer outputFormat=1 -> 8 bit', function () {
        expect(x11.digest(buffer, 1, 1)).to.deep.equal([
            25431772,
            2140696654,
            1013368572,
            -1390505884,
            708325244,
            481603428,
            -318219067,
            201326592
        ]);
    });

    it('buffer outputFormat=2 -> 32 bit', function () {
        expect(x11.digest(buffer, 1, 2)).to.deep.equal([
            1,
            132,
            14,
            220,
            127,
            152,
            112,
            78,
            60,
            102,
            198,
            252,
            173,
            30,
            144,
            100,
            42,
            56,
            47,
            124,
            28,
            180,
            175,
            100,
            237,
            8,
            92,
            197,
            12,
            0,
            0,
            0
        ]);
    });

which implies that an inversion has happened. Currently the tests pass so it's hard to say what the intended order was. This function is called in dashcore-lib with the outputFormat parameter 1 and its result is then converted into an 8-bit buffer using Buffer.from() but that causes data loss if the input of the function is a 32-bit array so that points to a mistake in the implementation.

I did notice that these output types have been inverted in this commit history of this repo a few times.

x13? x14? x15?

What is the use of x11-hash-js ?

I see x11-hash-js in some repositories with bitcore.

I am porting a coin to bitcore, it is working insight app, but I have not used the hash anyway.

So, why need x11 hash in JS?

Sorry for the silly question.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.