From: Chris Duncan Date: Sun, 22 Mar 2026 09:48:47 +0000 (-0700) Subject: Polish for first release. X-Git-Tag: v1.0.0~3 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=dc2ace35a0d9aaf4b265e35e35b5c50cd7830f2d;p=nano25519.git Polish for first release. Rename project for accuracy. Separate async/sync modules. Add tons of tests. Zero out memory when no longer needed. Reduce global static variables by using WASM linear memory directly. --- diff --git a/AUTHORS.md b/AUTHORS.md index f53d78c..037ceac 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -5,7 +5,7 @@ SPDX-License-Identifier: GPL-3.0-or-later # Authors -[nano-nacl](https://codecow.com/nano-nacl.git) +[nano25519](https://codecow.com/nano25519.git) - Chris Duncan (codecow.com) diff --git a/CHANGELOG.md b/CHANGELOG.md index e26e789..15aeaa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,13 +3,21 @@ SPDX-FileCopyrightText: 2026 Chris Duncan SPDX-License-Identifier: GPL-3.0-or-later --> +# Changelog + ## v0.0.1 ### Notable Changes -Written in Javascript and AssemblyScript, NanoNaCl leverages WebAssembly to sign -Nano cryptocurrency transaction blocks and validate block signatures. +Written in TypeScript and AssemblyScript, nano25519 leverages WebAssembly to +derive public keys, sign transactions, and validate signatures for Nano +cryptocurrency. -- Works entirely offline and locally on the device. +- Fastest available implementation of Ed25519+BLAKE2b required by Nano. +- Works in both the browser and NodeJS. +- Optionally import separate modules for fast synchronous functions or + non-blocking asynchronous functions. +- Zero networking. All results are computed entirely offline and locally on the + device. - Zero external dependencies. - Released under the GPLv3 license. diff --git a/README.md b/README.md index a7c378f..f564061 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ SPDX-FileCopyrightText: 2026 Chris Duncan SPDX-License-Identifier: GPL-3.0-or-later --> -# nano-nacl +# nano25519 _Block signing and validation for Nano cryptocurrency using WebAssembly._ -NanoNaCl is an AssemblyScript implementation of select Ed25519 functions used by +nano25519 is an AssemblyScript implementation of select Ed25519 functions used by the Nano cryptocurrency. It is modified to hash using BLAKE2b instead of SHA-512 and can derive public keys from private keys, sign blocks, and verify block signatures. All processing takes place client-side and offline. @@ -24,28 +24,28 @@ For more information about the block format defined for hashing and signing, see ## Installation ```console -npm i nano-nacl +npm i nano25519 ``` ### Browser -NanoNaCl can be used directly on a webpage with a script module: +nano25519 can be used directly on a webpage with a script module: ```html ``` ### NodeJS -NanoNaCl can be imported into NodeJS projects: +nano25519 can be imported into NodeJS projects: ```javascript -import { derive, sign, verify } from "nano-nacl"; +import { derive, sign, verify } from "nano25519"; ``` ## Usage @@ -62,7 +62,7 @@ versions require hex strings and return the same. ```javascript // `prv` is a 32-byte Uint8Array private key const prv = new Uint8Array(32); -const pub = NanoNaCl.derive(prvBytes); +const pub = nano25519.derive(prvBytes); // `pub` is a 32-byte Uint8Array public key for a Nano account ``` @@ -71,7 +71,7 @@ const pub = NanoNaCl.derive(prvBytes); ```javascript // `prv` is a 64-character hex string private key const prv = "0000000000000000000000000000000000000000000000000000000000000000"; -const pub = await NanoNaCl.deriveAsync(prv); +const pub = await nano25519.deriveAsync(prv); // `pub` is a 64-character hex string public key for a Nano account ``` @@ -83,11 +83,11 @@ const msg = new Uint8Array(32); // `prv` is a 32-byte Uint8Array private key const prv = new Uint8Array(32); // `pub` is a 32-byte Uint8Array public key derived from `prv` -const pub = NanoNaCl.derive(prv); +const pub = nano25519.derive(prv); // `sk` is a 64-byte Uint8Array secret key joining private and public keys const sk = new Uint8Array([...prv, ...pub]); -const sig = NanoNaCl.sign(msg, sk); +const sig = nano25519.sign(msg, sk); // `sig` is a 64-byte Uint8Array signature for the block hash ``` @@ -99,11 +99,11 @@ const msg = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; // `prv` is a 64-char hex string private key const prv = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; // `pub` is a 64-char hex string public key derived from `prv` -const pub = await NanoNaCl.deriveAsync(prv); +const pub = await nano25519.deriveAsync(prv); // `sk` is a 128-char hex string secret key joining private and public keys const sk = prv + pub; -const sig = await NanoNaCl.signAsync(msg, sk); +const sig = await nano25519.signAsync(msg, sk); // `sig` is a 128-char hex string signature for the block hash ``` @@ -117,7 +117,7 @@ const msg = new Uint8Array(32); // `pub` is a 32-byte Uint8Array public key for a Nano account const pub = new Uint8Array(32); -const v = NanoNaCl.verify(sig, msg, pub); +const v = nano25519.verify(sig, msg, pub); // `v` is a boolean 'true' if the same `prv` that derives `pub` was also used to create `sig` by signing `msg`, else 'false' ``` @@ -132,14 +132,14 @@ const msg = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; // `pub` is a 64-char hex string public key for a Nano account const pub = "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210"; -const v = await NanoNaCl.verifyAsync(sig, msg, pub); +const v = await nano25519.verifyAsync(sig, msg, pub); // `v` is a boolean 'true' if the same `prv` that derives `pub` was also used to create `sig` by signing `msg`, else 'false' ``` ## Notes The tweetnacl-js implementation was originally selected as the basis for -NanoNaCl due to its historical reliability and security. Over time, however, it +nano25519 due to its historical reliability and security. Over time, however, it became clear that tweetnacl was designed to optimize size and not speed. Soon after, libsodium became the reference from which functionality was ported. @@ -164,14 +164,14 @@ A few basic tests are availabe in the source repository. 1. Compile, minify, and bundle ```console -git clone https://codecow.com/nano-nacl.git -cd nano-nacl +git clone https://codecow.com/nano25519.git +cd nano25519 npm i ``` ## Reporting Bugs -Email: +Email: ## Acknowledgements diff --git a/asconfig.json b/asconfig.json index 2828ae2..1fa1753 100644 --- a/asconfig.json +++ b/asconfig.json @@ -1,7 +1,7 @@ { "options": { - "outFile": "./build/nano-nacl.wasm", - "textFile": "./build/nano-nacl.wat", + "outFile": "./build/nano25519.wasm", + "textFile": "./build/nano25519.wat", "optimizeLevel": 3, "shrinkLevel": 0, "converge": true, diff --git a/esbuild/config.mjs b/esbuild/config.mjs index 344e640..96e8502 100644 --- a/esbuild/config.mjs +++ b/esbuild/config.mjs @@ -31,7 +31,7 @@ export const browserOptions = { platform: 'browser', target: 'esnext', entryPoints: [ - { in: './index.ts', out: 'browser' } + { in: './src/index.ts', out: 'browser' } ], dropLabels: ['NODE'] } @@ -44,7 +44,9 @@ export const nodeOptions = { platform: 'node', target: 'node22', entryPoints: [ - { in: './index.ts', out: 'index' } + { in: './src/index.ts', out: 'index' }, + { in: './src/async.ts', out: 'async' }, + { in: './src/sync.ts', out: 'sync' } ], packages: 'external', dropLabels: ['BROWSER'] diff --git a/index.html b/index.html index db7ef49..b72e2b1 100644 --- a/index.html +++ b/index.html @@ -15,23 +15,23 @@ SPDX-License-Identifier: GPL-3.0-or-later