nano-pow 2.0.0 β 3.0.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 +38 -16
- package/dist/main.min.js +487 -329
- package/dist/types.d.ts +18 -1
- package/package.json +5 -5
- package/dist/classes/gl.d.ts +0 -20
- package/dist/classes/gl.js +0 -232
- package/dist/classes/gpu.d.ts +0 -24
- package/dist/classes/gpu.js +0 -236
- package/dist/classes/index.d.ts +0 -4
- package/dist/classes/index.js +0 -23
- package/dist/global.d.ts +0 -1
- package/dist/global.js +0 -6
- package/dist/global.min.js +0 -801
- package/dist/main.d.ts +0 -3
- package/dist/main.js +0 -5
- package/dist/shaders/gl-fragment.d.ts +0 -1
- package/dist/shaders/gl-fragment.js +0 -206
- package/dist/shaders/gl-vertex.d.ts +0 -1
- package/dist/shaders/gl-vertex.js +0 -16
- package/dist/shaders/index.d.ts +0 -4
- package/dist/shaders/index.js +0 -6
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ _Proof-of-work generation and validation with WebGPU/WebGL for Nano cryptocurren
|
|
|
8
8
|
|
|
9
9
|
NanoPow uses WebGPU to generate proof-of-work nonces meeting the requirements
|
|
10
10
|
of the Nano cryptocurrency. WebGPU is cutting edge technology, so for browsers
|
|
11
|
-
which do not yet support it, a WebGL 2.0 implementation is
|
|
11
|
+
which do not yet support it, a WebGL 2.0 implementation is used as a fallback.
|
|
12
12
|
|
|
13
13
|
All calculations take place client-side, so nonces can be generated offline and
|
|
14
14
|
cached for the next transaction block. For more information about the
|
|
@@ -40,12 +40,15 @@ A specific API can be explicitly imported:
|
|
|
40
40
|
import { NanoPowGpu, NanoPowGl } from 'nano-pow'
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
Use it directly on a webpage with a script module:
|
|
44
|
+
|
|
45
45
|
```html
|
|
46
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/nano-pow@latest/dist/global.min.js"></script>
|
|
47
46
|
<script type="module">
|
|
48
|
-
|
|
47
|
+
(async () => {
|
|
48
|
+
const { NanoPow } = await import('https://cdn.jsdelivr.net/npm/nano-pow@latest')
|
|
49
|
+
const work = await NanoPow.search(some_hash)
|
|
50
|
+
console.log(work)
|
|
51
|
+
})()
|
|
49
52
|
</script>
|
|
50
53
|
```
|
|
51
54
|
|
|
@@ -53,8 +56,7 @@ Any of these options can also be imported into the global namespace by targeting
|
|
|
53
56
|
```javascript
|
|
54
57
|
// `hash` is a 64-char hex string
|
|
55
58
|
const hash = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
56
|
-
|
|
57
|
-
const work = await NanoPow.search(hash, threshold)
|
|
59
|
+
const work = await NanoPow.search(hash)
|
|
58
60
|
// Result is a 16-char hex string
|
|
59
61
|
```
|
|
60
62
|
|
|
@@ -64,11 +66,23 @@ const work = await NanoPow.search(hash, threshold)
|
|
|
64
66
|
const work = 'fedcba0987654321'
|
|
65
67
|
// `hash` is a 64-char hex string
|
|
66
68
|
const hash = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
67
|
-
|
|
68
|
-
const isValid = await NanoPow.validate(work, hash, threshold)
|
|
69
|
+
const isValid = await NanoPow.validate(work, hash)
|
|
69
70
|
// Result is a boolean
|
|
70
71
|
```
|
|
71
72
|
|
|
73
|
+
### Options
|
|
74
|
+
```javascript
|
|
75
|
+
const options = {
|
|
76
|
+
// default 0xFFFFFFF8 for send/change blocks
|
|
77
|
+
threshold: number,
|
|
78
|
+
// default 8, valid range 1-32
|
|
79
|
+
effort: number,
|
|
80
|
+
// default false
|
|
81
|
+
debug: true
|
|
82
|
+
}
|
|
83
|
+
const work = await NanoPow.search(hash, options)
|
|
84
|
+
```
|
|
85
|
+
|
|
72
86
|
## Notes
|
|
73
87
|
The `work` field in a Nano transaction block contains an 8-byte nonce that
|
|
74
88
|
satisfies the following equation:
|
|
@@ -78,17 +92,18 @@ satisfies the following equation:
|
|
|
78
92
|
* π£ππ’π¬π¦2π£() is the cryptographic hash function BLAKE2b.
|
|
79
93
|
* π―π°π―π€π¦, an 8-byte value, is generated for the transaction.
|
|
80
94
|
* || is concatenation.
|
|
81
|
-
* π£ππ°π€π¬π©π’π΄π©, a 32-byte value, is either the public key of brand new accounts
|
|
82
|
-
hash of the most recent block in the account chain
|
|
95
|
+
* π£ππ°π€π¬π©π’π΄π©, a 32-byte value, is either the public key of brand new accounts
|
|
96
|
+
without transactions or the hash of the most recent block in the account chain
|
|
97
|
+
for all other accounts.
|
|
83
98
|
* π΅π©π³π¦π΄π©π°ππ₯ is 0xFFFFFFF800000000 for send/change blocks and 0xFFFFFE0000000000
|
|
84
99
|
for receive/open/epoch blocks.
|
|
85
100
|
|
|
86
101
|
The threshold is implemented in code as only the first 32 bits due to WGSL only
|
|
87
|
-
supporting u32 integer types, but the result is the same. For example, if
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
supporting u32 integer types, but the result is the same. For example, if
|
|
103
|
+
checking whether a two-digit number xx > 55, and it is known that the first
|
|
104
|
+
digit is 6, it is also automatically known that xx is greater than 55. The
|
|
105
|
+
default threshold used is the send/change difficulty. Any other threshold can be
|
|
106
|
+
specified in practice.
|
|
92
107
|
|
|
93
108
|
The BLAKE2b implementation has been optimized to the extreme for this package
|
|
94
109
|
due to the very narrow use case to which it is applied. The compute shader is
|
|
@@ -112,6 +127,13 @@ npm i
|
|
|
112
127
|
npm run build
|
|
113
128
|
```
|
|
114
129
|
|
|
130
|
+
## Acknowledgements
|
|
131
|
+
[numtel/nano-webgl-pow](https://github.com/numtel/nano-webgl-pow) for his WebGL
|
|
132
|
+
implementation
|
|
133
|
+
|
|
134
|
+
## Licenses
|
|
135
|
+
GPLv3 (or later) & MIT
|
|
136
|
+
|
|
115
137
|
## Donations
|
|
116
138
|
If you find this package helpful, please consider tipping the developer.
|
|
117
139
|
```
|