UNPKG

2.27 kBMarkdownView Raw
1# proof-of-work
2
3Proof of work based on SHA256 and Bloom filter.
4
5## Usage
6
7Solver:
8```js
9const pow = require('proof-of-work');
10
11const solver = new pow.Solver();
12
13// complexity=13
14const nonce = solver.solve(13);
15console.log(nonce);
16```
17
18Verifier:
19```js
20const pow = require('proof-of-work');
21
22const verifier = new pow.Verifier({
23 // bit-size of Bloom filter
24 size: 1024,
25
26 // number of hash functions in a Bloom filter
27 n: 16,
28
29 // target complexity
30 complexity: 13
31});
32
33// Remove staled nonces from Bloom filter
34setInterval(() => {
35 verifier.reset();
36}, 300000);
37
38verifier.verify(nonce);
39```
40
41## CLI
42
43```bash
44$ npm install -g proof-of-work
45
46$ proof-of-work -h
47Usage: proof-of-work <complexity> ,- generate nonce
48 proof-of-work verify <complexity> (nonce)? - verify nonce
49
50$ proof-of-work 13
512808fde24c9104d97f58a604cafa6e8db6661f44b4caf9dc311cbb8140648447
52
53$ proof-of-work verify 13 \
54 2808fde24c9104d97f58a604cafa6e8db6661f44b4caf9dc311cbb8140648447 && \
55 echo success
56success
57
58$ proof-of-work 13 | proof-of-work verify 13 && echo success
59success
60
61$ proof-of-work 0 | proof-of-work verify 32 || echo failure
62failure
63```
64
65## LICENSE
66
67This software is licensed under the MIT License.
68
69Copyright Fedor Indutny, 2016.
70
71Permission is hereby granted, free of charge, to any person obtaining a
72copy of this software and associated documentation files (the
73"Software"), to deal in the Software without restriction, including
74without limitation the rights to use, copy, modify, merge, publish,
75distribute, sublicense, and/or sell copies of the Software, and to permit
76persons to whom the Software is furnished to do so, subject to the
77following conditions:
78
79The above copyright notice and this permission notice shall be included
80in all copies or substantial portions of the Software.
81
82THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
83OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
85NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
86DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
87OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
88USE OR OTHER DEALINGS IN THE SOFTWARE.