]> zoso.dev Git - nano-pow.git/commitdiff
Update README with new features and improved grammar.
authorChris Duncan <chris@zoso.dev>
Sun, 12 Jan 2025 23:37:35 +0000 (15:37 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 12 Jan 2025 23:37:35 +0000 (15:37 -0800)
README.md

index 2bcd8f4bb257b08ede80dd98fa5189f5f2d8ee29..c0d1ac44bf2796a12de2c42a8c5a65d8e81440ce 100644 (file)
--- a/README.md
+++ b/README.md
@@ -22,22 +22,54 @@ npm i nano-pow
 ```
 
 ## Usage
+### Import
+The easiest way to use NanoPow is to import it directly. Based on the features
+available in the environment, NanoPow will try to use its most performant API.
+
+The following two import statements are equivalent, and both are provided to
+accomodate project style preferences:
+
+```javascript
+import { NanoPow } from 'nano-pow'
+// OR
+import NanoPow from 'nano-pow'
+```
+
+A specific API can be explicitly imported:
 
 ```javascript
 import { NanoPowGpu, NanoPowGl } from 'nano-pow'
+```
 
+Any of these options can also be imported into the global namespace by targeting
+`dist/global.min.js`. For example:
+```html
+<script type="module" src="https://cdn.jsdelivr.net/npm/nano-pow@latest/dist/global.min.js"></script>
+<script type="module">
+  console.log(NanoPow)
+</script>
+```
+### Search
+
+```javascript
 // `hash` is a 64-char hex string
-// `threshold` is optional and defaults to "0xFFFFFFF8"
-const workGpu = await NanoPowGpu.search(hash, threshold)
-// or if WebGPU is unsupported
-const workGl = await NanoPowGl.search(hash, threshold)
+const hash = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
+// `threshold` is optional and defaults to "0xFFFFFFF8" for send/change blocks
+const work = await NanoPow.search(hash, threshold)
+// Result is a 16-char hex string
 ```
 
-You may also embed it in the global namespace by targeting `dist/global.min.js`
+### Validate
 
-## Validation
-NanoPow can also validate previously-generated work values against a block hash.
-Currently this is only implemented in the WebGPU tool and not WebGL.
+```javascript
+// `work` is a 16-char hex string
+const work = 'fedcba0987654321'
+// `hash` is a 64-char hex string
+const hash = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
+// `threshold` is optional and defaults to "0xFFFFFFF8" for send/change blocks
+const isValid = await NanoPow.validate(work, hash, threshold)
+// Result is a boolean
+```
 
 ## Notes
 The `work` field in a Nano transaction block contains an 8-byte nonce that
@@ -54,9 +86,8 @@ hash of the most recent block in the account chain for all other accounts.
 for receive/open/epoch blocks.
 
 The threshold is implemented in code as only the first 32 bits due to WGSL only
-supporting u32 integer types, but the result is the same. For example, if one
-wants to know whether a two-digit number xx > 55, and you know the first digit is
-6, you automatically know it is greather than 55.
+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
+6, it is also automatically known that xx is greater than 55.
 
 The default threshold used is the send/change difficulty. Any other threshold
 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.
@@ -71,7 +102,7 @@ performance out of it.
 speed of this tool. Feel free to check out how your system fares.
 
 ## Building
-* `npm run build`: compile TypeScript, then minify and bundle with esbuild
+* `npm run build` Compile TypeScript, then minify and bundle with esbuild
 
 ## Donations
 If you find this package helpful, please consider tipping the developer.