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