nano-pow 1.2.4 β†’ 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 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 also included.
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
- Any of these options can also be imported into the global namespace by targeting
44
- `dist/global.min.js`. For example:
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
- console.log(NanoPow)
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
- // `threshold` is optional and defaults to "0xFFFFFFF8" for send/change blocks
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
- // `threshold` is optional and defaults to "0xFFFFFFF8" for send/change blocks
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 without transactions or the
82
- hash of the most recent block in the account chain for all other accounts.
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 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.
89
-
90
- The default threshold used is the send/change difficulty. Any other threshold
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.
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
  ```