]> git.codecow.com Git - nano25519.git/commitdiff
Add Bytes type alias for legibility.
authorChris Duncan <chris@zoso.dev>
Mon, 7 Sep 2026 07:24:41 +0000 (00:24 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 7 Sep 2026 07:24:41 +0000 (00:24 -0700)
src/index.ts
src/lib/wasm.ts

index 38cb81cf3f278ea0863fd72fd3638a1a0f0c50dc..2e90dd3421d795998715e3f5a4c1d40cbaed7527 100644 (file)
@@ -5,70 +5,74 @@ import * as nano25519 from './lib'
 
 export { constants } from './lib'
 
+declare global {
+       type Bytes = Uint8Array<ArrayBuffer>
+}
+
 /**
  * Nano public key derivation using WebAssembly. If byte output is required,
  * pass a target buffer as a second argument.
- * @param {(Uint8Array<ArrayBuffer> | string)} prv - 32-byte private key
+ * @param {(Bytes | string)} prv - 32-byte private key
  * @returns 32-byte public key
  */
-export function derive (prv: Uint8Array<ArrayBuffer> | string): string
+export function derive (prv: Bytes | string): string
 /**
  * Nano public key derivation using WebAssembly. Instead of allocating an output
  * buffer internally for the return value, public key bytes are written to the
  * the user-supplied output buffer.
- * @param {(Uint8Array<ArrayBuffer> | string)} prv - 32-byte private key
- * @param {Uint8Array<ArrayBuffer>} out - buffer to receive 32-byte public key
+ * @param {(Bytes | string)} prv - 32-byte private key
+ * @param {Bytes} out - buffer to receive 32-byte public key
  */
-export function derive (prv: Uint8Array<ArrayBuffer> | string, out: Uint8Array<ArrayBuffer>): void
-export function derive (prv: Uint8Array<ArrayBuffer> | string, out?: Uint8Array<ArrayBuffer>): string | void {
+export function derive (prv: Bytes | string, out: Bytes): void
+export function derive (prv: Bytes | string, out?: Bytes): string | void {
        return nano25519.derive(prv, out)
 }
 
 /**
  * Signing using WebAssembly. To sign Nano blocks, the message should be a
  * 32-byte block hash.
- * @param {(Uint8Array<ArrayBuffer> | string)} msg - Variable-byte-length message up to 64 KiB
- * @param {(Uint8Array<ArrayBuffer> | string)} prv - 32-byte private key
- * @param {(Uint8Array<ArrayBuffer> | string)} pub - 32-byte public key
+ * @param {(Bytes | string)} msg - Variable-byte-length message up to 64 KiB
+ * @param {(Bytes | string)} prv - 32-byte private key
+ * @param {(Bytes | string)} pub - 32-byte public key
  * @returns 64-byte detached signature
  */
-export function sign (msg: Uint8Array<ArrayBuffer> | string, prv: Uint8Array<ArrayBuffer> | string, pub: Uint8Array<ArrayBuffer> | string): string
+export function sign (msg: Bytes | string, prv: Bytes | string, pub: Bytes | string): string
 /**
  * Signing using WebAssembly. To sign Nano blocks, the message should be a
  * 32-byte block hash. Instead of allocating an output buffer internally for the
  * return value, signature bytes are written to the the user-supplied output
  * buffer.
- * @param {(Uint8Array<ArrayBuffer> | string)} msg - Variable-byte-length message up to 64 KiB
- * @param {(Uint8Array<ArrayBuffer> | string)} prv - 32-byte private key
- * @param {(Uint8Array<ArrayBuffer> | string)} pub - 32-byte public key
- * @param {(Uint8Array<ArrayBuffer> | string)} out - buffer to receive 64-byte detached signature
+ * @param {(Bytes | string)} msg - Variable-byte-length message up to 64 KiB
+ * @param {(Bytes | string)} prv - 32-byte private key
+ * @param {(Bytes | string)} pub - 32-byte public key
+ * @param {(Bytes | string)} out - buffer to receive 64-byte detached signature
  */
-export function sign (msg: Uint8Array<ArrayBuffer> | string, prv: Uint8Array<ArrayBuffer> | string, pub: Uint8Array<ArrayBuffer> | string, out: Uint8Array<ArrayBuffer>): void
-export function sign (msg: Uint8Array<ArrayBuffer> | string, prv: Uint8Array<ArrayBuffer> | string, pub: Uint8Array<ArrayBuffer> | string, out?: Uint8Array<ArrayBuffer>): string | void {
+export function sign (msg: Bytes | string, prv: Bytes | string, pub: Bytes | string, out: Bytes): void
+export function sign (msg: Bytes | string, prv: Bytes | string, pub: Bytes | string, out?: Bytes): string | void {
        return nano25519.sign(msg, prv, pub, out)
 }
 
 /**
  * Signature verification using WebAssembly. To verify Nano block signatures,
  * use `verify_blocks()` instead.
- * @param {(Uint8Array<ArrayBuffer> | string)} sig - 64-byte detached signature
- * @param {(Uint8Array<ArrayBuffer> | string)} msg - Variable-byte-length message up to 64 KiB
- * @param {(Uint8Array<ArrayBuffer> | string)} pub - 32-byte public key
+ * @param {(Bytes | string)} sig - 64-byte detached signature
+ * @param {(Bytes | string)} msg - Variable-byte-length message up to 64 KiB
+ * @param {(Bytes | string)} pub - 32-byte public key
  * @returns true if signature matches block hash and public key, else false
  */
-export function verify (sig: Uint8Array<ArrayBuffer> | string, msg: Uint8Array<ArrayBuffer> | string, pub: Uint8Array<ArrayBuffer> | string): boolean {
+export function verify (sig: Bytes | string, msg: Bytes | string, pub: Bytes | string): boolean {
        return nano25519.verify(sig, msg, pub)
 }
 
 /**
  * Nano block signature bulk verification using WebAssembly.
- * @param {(Uint8Array<ArrayBuffer> | string)} publicKey - 32-byte public key
+ * @param {(Bytes | string)} publicKey - 32-byte public key
  * @param {object[]} blocks - Array of up to 64 block signature/hash pairs
- * @param {(Uint8Array<ArrayBuffer> | string)} blocks.signature - 64-byte block signature
- * @param {(Uint8Array<ArrayBuffer> | string)} blocks.hash - 32-byte block hash
+ * @param {(Bytes | string)} blocks.signature - 64-byte block signature
+ * @param {(Bytes | string)} blocks.hash - 32-byte block hash
  * @returns Array of results with, for each case, true if signature matches block hash and public key, else false
  */
-export function verify_blocks (publicKey: Uint8Array<ArrayBuffer> | string, blocks: { signature: Uint8Array<ArrayBuffer> | string, hash: Uint8Array<ArrayBuffer> | string }[]): boolean[] {
+export function verify_blocks (publicKey: Bytes | string, blocks: { signature: Bytes | string, hash: Bytes | string }[]): boolean[] {
        return nano25519.verify_blocks(publicKey, blocks)
 }
 
index 4de956703185bb0f6ac460db54f2d2131937dd6b..38e6ae100c8f742acd012012626ab5b9f1644813 100644 (file)
@@ -45,7 +45,7 @@ export const Mutex = {
  */
 export const memory = new WebAssembly.Memory({ initial: 4 })
 
-const wasm: Uint8Array<ArrayBuffer> = Uint8Array.from(nano25519_wasm)
+const wasm: Bytes = Uint8Array.from(nano25519_wasm)
 const module = new WebAssembly.Module(wasm)
 
 export const { exports } = new WebAssembly.Instance(module, {