## Usage
Each primitive implementation is synchronous. Inputs can be passed as Uint8Array
-byte arrays (preferable) or strings. The output will return the same type as the
-input. A preallocated output buffer can be passed as an additional optional'
-argument for `derive()` and `sign()`, and the result bytes will be written into
-it.
+byte arrays, ArrayBuffers, or hexadecimal strings; `derive()` and `sign()`
+return a hexadecimal string. To receive bytes instead, pass a preallocated
+output buffer as an additional optional argument; the result bytes are written
+into it directly, and the return value is `undefined` instead of a string.
### Derive (bytes)
const v = nano25519.verify(sig, msg, pub);
```
+### Verify blocks (up to 64)
+
+```javascript
+// `pub` is the 32-byte public key of the account that signed every block
+const pub = new Uint8Array(usersPublicKeyBuffer);
+// `blocks` is an array pairing a 32-byte block hash with its 64-byte signature
+const blocks = [
+ {
+ hash: new Uint8Array(blockHashBuffer1),
+ signature: new Uint8Array(signatureBuffer1)
+ },
+ {
+ hash: new Uint8Array(blockHashBuffer2),
+ signature: new Uint8Array(signatureBuffer2)
+ }
+];
+
+// `v` is an array of booleans, one per block in the same order, 'true' where
+// the Nano network would accept the signature for that block
+const v = nano25519.verify_blocks(pub, blocks);
+```
+
+`verify_blocks()` checks up to `nano25519.constants.MAX_VERIFY_BLOCKS` (64)
+blocks from one account per call, decoding the public key once for the whole
+batch. It throws a `RangeError` for an empty or oversized batch and a
+`TypeError` for a malformed block. A public key that cannot be decoded makes
+every result `false`.
+
+`verify()` and `verify_blocks()` deliberately answer different questions, and
+they disagree on some real blocks cemented in the Nano ledger:
+
+- `verify()` asks _"is this a sound Ed25519 signature?"_ It is as strict as
+ possible: it rejects small-order and non-canonical public keys and nonces, and
+ it requires the scalar `S` to be fully reduced.
+- `verify_blocks()` asks _"does the Nano network accept this block?"_ It matches
+ the ed25519-donna rules used by `nano_node`, so it accepts a small-order
+ public key, accepts a signature whose `S` is not fully reduced, and never
+ decodes the nonce.
+
+### Constants
+
+`nano25519.constants` exports the byte lengths and feature limits enforced by
+the API functions.
+
+| Constant | Value | Meaning |
+| ------------------------------ | ----- | ------------------------------------------ |
+| `BLOCKHASH_BYTELENGTH` | 32 | Nano block hash |
+| `KEY_BYTELENGTH` | 32 | Private or public key |
+| `SIGNATURE_BYTELENGTH` | 64 | Signature |
+| `MAX_VERIFY_BLOCKS` | 64 | Blocks per `verify_blocks()` call |
+| `MAX_VERIFY_BLOCKS_BYTELENGTH` | 6144 | Signatures and hashes of a full batch |
+| `MAX_MESSAGE_BYTELENGTH` | 65536 | Largest message `sign()`/`verify()` accept |
+
## Notes
The tweetnacl-js implementation was originally selected as the basis for
`Words` class to emulate toggled endianness.
- `vectors.mjs` is generated by `esbuild` using the files found in
`test/vectors`.
+- `mutants.mjs` builds copies of the module with known defects and checks that
+ the self-tests built into the module refuse to load every one of them.
Tests are run with a debug build using `npm t` and a production build with
-`npm run test:prod`.
+`npm run test:prod`. Mutation tests are run with `npm run test:mutants`.
## Building