nano-pow 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -15
- package/dist/global.min.js +187 -111
- package/dist/main.min.js +190 -98
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
4
4
|
-->
|
|
5
5
|
|
|
6
6
|
# nano-pow
|
|
7
|
+
_Proof-of-work generation and validation with WebGPU/WebGL for Nano cryptocurrency._
|
|
8
|
+
|
|
7
9
|
NanoPow uses WebGPU to generate proof-of-work nonces meeting the requirements
|
|
8
10
|
of the Nano cryptocurrency. WebGPU is cutting edge technology, so for browsers
|
|
9
11
|
which do not yet support it, a WebGL 2.0 implementation is also included.
|
|
@@ -14,23 +16,58 @@ proof-of-work equation defined by Nano, see
|
|
|
14
16
|
https://docs.nano.org/integration-guides/work-generation/#work-calculation-details
|
|
15
17
|
|
|
16
18
|
## Installation
|
|
17
|
-
|
|
18
19
|
```console
|
|
19
20
|
npm i nano-pow
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
## Usage
|
|
24
|
+
### Import
|
|
25
|
+
The easiest way to use NanoPow is to import it directly. Based on the features
|
|
26
|
+
available in the environment, NanoPow will try to use its most performant API.
|
|
27
|
+
|
|
28
|
+
The following two import statements are equivalent, and both are provided to
|
|
29
|
+
accomodate project style preferences:
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { NanoPow } from 'nano-pow'
|
|
33
|
+
// OR
|
|
34
|
+
import NanoPow from 'nano-pow'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
A specific API can be explicitly imported:
|
|
23
38
|
|
|
24
39
|
```javascript
|
|
25
40
|
import { NanoPowGpu, NanoPowGl } from 'nano-pow'
|
|
41
|
+
```
|
|
26
42
|
|
|
43
|
+
Any of these options can also be imported into the global namespace by targeting
|
|
44
|
+
`dist/global.min.js`. For example:
|
|
45
|
+
```html
|
|
46
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/nano-pow@latest/dist/global.min.js"></script>
|
|
47
|
+
<script type="module">
|
|
48
|
+
console.log(NanoPow)
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Search
|
|
53
|
+
```javascript
|
|
27
54
|
// `hash` is a 64-char hex string
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
55
|
+
const hash = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
56
|
+
// `threshold` is optional and defaults to "0xFFFFFFF8" for send/change blocks
|
|
57
|
+
const work = await NanoPow.search(hash, threshold)
|
|
58
|
+
// Result is a 16-char hex string
|
|
31
59
|
```
|
|
32
60
|
|
|
33
|
-
|
|
61
|
+
### Validate
|
|
62
|
+
```javascript
|
|
63
|
+
// `work` is a 16-char hex string
|
|
64
|
+
const work = 'fedcba0987654321'
|
|
65
|
+
// `hash` is a 64-char hex string
|
|
66
|
+
const hash = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
67
|
+
// `threshold` is optional and defaults to "0xFFFFFFF8" for send/change blocks
|
|
68
|
+
const isValid = await NanoPow.validate(work, hash, threshold)
|
|
69
|
+
// Result is a boolean
|
|
70
|
+
```
|
|
34
71
|
|
|
35
72
|
## Notes
|
|
36
73
|
The `work` field in a Nano transaction block contains an 8-byte nonce that
|
|
@@ -47,9 +84,8 @@ hash of the most recent block in the account chain for all other accounts.
|
|
|
47
84
|
for receive/open/epoch blocks.
|
|
48
85
|
|
|
49
86
|
The threshold is implemented in code as only the first 32 bits due to WGSL only
|
|
50
|
-
supporting u32 integer types, but the result is the same. For example, if
|
|
51
|
-
|
|
52
|
-
6, you automatically know it is greather than 55.
|
|
87
|
+
supporting u32 integer types, but the result is the same. For example, if checking whether a two-digit number xx > 55, and it is known that the first digit is
|
|
88
|
+
6, it is also automatically known that xx is greater than 55.
|
|
53
89
|
|
|
54
90
|
The default threshold used is the send/change difficulty. Any other threshold
|
|
55
91
|
can be specified in practice. Also, NanoPow technically compares the nonce to see if it is only greater than, and not necessarily equal to, the threshold, but the difference is trivial for a range of 2⁶⁴-1 nonces.
|
|
@@ -59,18 +95,22 @@ due to the very narrow use case to which it is applied. The compute shader is
|
|
|
59
95
|
consequently immense, but the goal is to squeeze every last bit of speed and
|
|
60
96
|
performance out of it.
|
|
61
97
|
|
|
62
|
-
## Validating work
|
|
63
|
-
Although the nonces generated by this package have been tested extensively, a
|
|
64
|
-
validation function is not currently implemented. There are other tools
|
|
65
|
-
available to perform this trivial task, but if there is demand for it, then it
|
|
66
|
-
can be delivered in a future update.
|
|
67
|
-
|
|
68
98
|
## Tests
|
|
69
99
|
`test.html` in the source repository contains some basic tests to compare the
|
|
70
100
|
speed of this tool. Feel free to check out how your system fares.
|
|
71
101
|
|
|
72
102
|
## Building
|
|
73
|
-
|
|
103
|
+
1. Clone source
|
|
104
|
+
1. Enter the directory
|
|
105
|
+
1. Install dev dependencies
|
|
106
|
+
1. Compile, minify, and bundle
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
git clone https://zoso.dev/nano-pow.git
|
|
110
|
+
cd nano-pow
|
|
111
|
+
npm i
|
|
112
|
+
npm run build
|
|
113
|
+
```
|
|
74
114
|
|
|
75
115
|
## Donations
|
|
76
116
|
If you find this package helpful, please consider tipping the developer.
|