# ethashjs

> an ethash implementation in JS

Latest version **0.0.8** (published 2020-06-10) · MPL-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ethashjs
pnpm add ethashjs
yarn add ethashjs
bun add ethashjs
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2020-06-10 |
| First published | 2015-07-28 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 46.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | mjbecze |
| Maintainers | holgerd77, null_radix |
| Keywords | ethash, ethereum, POW |

## Links

- npm: https://www.npmjs.com/package/ethashjs
- Repository: https://github.com/ethereumjs/ethashjs
- Homepage: https://github.com/ethereumjs/ethashjs#readme
- Issues: https://github.com/ethereumjs/ethashjs/issues
- npm.io page: https://npm.io/package/ethashjs

## Dependencies (4)

- [async](https://npm.io/package/async.md) ^2.1.2
- [buffer-xor](https://npm.io/package/buffer-xor.md) ^2.0.1
- [miller-rabin](https://npm.io/package/miller-rabin.md) ^4.0.0
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^7.0.2

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2020-06-10
- 0.0.7 — 2016-03-01
- 0.0.6 — 2016-01-08
- 0.0.5 — 2015-11-27
- 0.0.4 — 2015-10-01
- 0.0.3 — 2015-08-13
- 0.0.2 — 2015-08-10
- 0.0.1 — 2015-08-10
- 0.0.0 — 2015-07-28

## README

# SYNOPSIS

[![NPM Package](https://img.shields.io/npm/v/ethashjs.svg)](https://www.npmjs.org/package/ethashjs)
[![Actions Status](https://github.com/ethereumjs/ethashjs/workflows/Build/badge.svg)](https://github.com/ethereumjs/ethashjs/actions)
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethashjs.svg)](https://coveralls.io/r/ethereumjs/ethashjs)
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg)](https://gitter.im/ethereum/ethereumjs-lib)

Implements [Ethash](https://github.com/ethereum/wiki/wiki/Ethash).

# INSTALL

`npm install ethashjs`

# USAGE

```javascript
const Ethash = require('ethashjs')
const Block = require('ethereumjs-block')
const levelup = require('levelup')
const memdown = require('memdown')

var cacheDB = levelup('', {
  db: memdown
})

var ethash = new Ethash(cacheDB)
var validblockRlp =
  'f90667f905fba0a8d5b7a4793baaede98b5236954f634a0051842df6a252f6a80492fd888678bda01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0f93c8db1e931daa2e22e39b5d2da6fb4074e3d544094857608536155e3521bc1a0bb7495628f9160ddbcf6354380ee32c300d594e833caec3a428041a66e7bade1a0c7778a7376099ee2e5c455791c1885b5c361b95713fddcbe32d97fd01334d296b90100000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000400000000000000000000000000000000000000000000000000000008302000001832fefd882560b84559c17b9b9040001020304050607080910111213141516171819202122232410000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000100000000000000000002000000000000000000030000000000000000000400000000000000000005000000000000000000060000000000000000000700000000000000000008000000000000000000090000000000000000000100000000000000000001000000000000000000020000000000000000000300000000000000000004000000000000000000050000000000000000000600000000000000000007000000000000000000080000000000000000000900000000000000000001000000000000000000010000000000000000000200000000000000000003000000000000000000040000000000000000000500000000000000000006000000000000000000070000000000000000000800000000000000000009000000000000000000010000000000000000000a09c7b47112a3afb385c12924bf6280d273c106eea7caeaf5131d8776f61056c148876ae05d46b58d1fff866f864800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d8785012a05f200801ba01d2c92cfaeb04e53acdff2b5d42005ff6aacdb0105e64eb8c30c273f445d2782a01e7d50ffce57840360c57d94977b8cdebde614da23e8d1e77dc07928763cfe21c0'

var validblock = new Block(Buffer.from(validblockRlp, 'hex'))

ethash.verifyPOW(validblock, function (result) {
  console.log(result)
})
```

# BROWSER

Yep, you can [browserify](http://browserify.org/) it.

# API

- [`new Ethash([cacheDB])`](#newethashcachedb)
- [`ethash.verifyPOW(block, cb)`](#ethashverifypowblock-cb)
- [`ethash.mkcache(cacheSize, seed)`](#ethashmkcachecachesize-seed)
- [`ethash.run(val, nonce, fullsize)`](#ethashrunval-nonce-fullsize)

### `new Ethash([cacheDB])`

Creates a new instance of `Ethash`.

**Parameters**

- `cacheDB` - an instance of a levelup db which is used to store the cache(s)

### `ethash.verifyPOW(block, cb)`

Verifies the POW on a block and its uncles

**Parameters**

- `block` - the [block](https://github.com/ethereum/ethereumjs-block) to verify
- `cb` - the callback which is given a `Boolean` determining the validaty of the block

### `ethash.mkcache(cacheSize, seed)`

Creates a cache. NOTE: this is automatically done for in - [`ethash.verifyPOW(block, cb)`](#ethashverifypowblock-cb) so you do not need to use this function if you are just validating blocks

**Parameters**

- `cachSize` - the size of the cach
- `seed` - the seed as a `Buffer`

### `ethash.run(val, nonce, fullsize)`

Runs ethash on a give val/nonce pair. NOTE: you need to run [`ethash.mkcache(cacheSize, seed)`](#ethashverifypowcachesize-seed) first before using this function.

**Parameters**

- `val` - value to run ethash on e.g. the header hash
- `nonce` - the nonce used for this hash attempt
- `fullsize` - the fullsize of the cache.

**Returns**

An `Object` containing:

- `hash` - the hash of the value
- `mix` - the mis result

# TESTS

`npm test`

# LICENSE

[MPL-2.0](https://www.mozilla.org/MPL/2.0/)

---
_Source: https://npm.io/package/ethashjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
