]> git.codecow.com Git - nano25519.git/commitdiff
Overload async execution to narrow result typechecking more specifically based on...
authorChris Duncan <chris@codecow.com>
Thu, 14 May 2026 18:03:34 +0000 (11:03 -0700)
committerChris Duncan <chris@codecow.com>
Thu, 14 May 2026 18:03:34 +0000 (11:03 -0700)
src/async.ts
src/lib/nano25519.ts

index b99a1c070535cfe7e20a6fda771aea38a6c150dc..181856547af7a69052e0baf3215f4268fc819752 100644 (file)
@@ -58,5 +58,5 @@ export async function verifyAsync (signature: Uint8Array<ArrayBuffer>, message:
  */
 export async function verifyAsync (signature: string, message: string, publicKey: string): Promise<boolean>
 export async function verifyAsync (signature: string | Uint8Array<ArrayBuffer>, message: string | Uint8Array<ArrayBuffer>, publicKey: string | Uint8Array<ArrayBuffer>): Promise<boolean> {
-       return !!(await run({ action: 'verify', signature, message, publicKey }))
+       return run({ action: 'verify', signature, message, publicKey })
 }
index 5654d22dd418b5de005e38d8d0a5f7f560cfa682..8dfcb433aa55ce18663bfd7796116a9535205561 100644 (file)
@@ -333,7 +333,7 @@ async function start (): Promise<void> {
 }
 
 // Send command and relevant data to nano25519 worker
-async function dispatch (data: { [key: string]: string | ArrayBuffer | Uint8Array<ArrayBuffer> }): Promise<Uint8Array<ArrayBuffer>> {
+async function dispatch (data: { [key: string]: string | ArrayBuffer | Uint8Array<ArrayBuffer> }): Promise<boolean | string | Uint8Array<ArrayBuffer>> {
        return new Promise((resolve, reject) => {
                const transfer: ArrayBuffer[] = []
                for (let k of Object.keys(data)) {
@@ -388,7 +388,10 @@ async function stop (): Promise<void> {
        })
 }
 
-export async function run (data: Record<string, string | Uint8Array<ArrayBuffer>>): Promise<string | Uint8Array<ArrayBuffer>> {
+export async function run (data: Record<"action", "derive"> & Record<string, string | Uint8Array<ArrayBuffer>>): Promise<string | Uint8Array<ArrayBuffer>>
+export async function run (data: Record<"action", "sign"> & Record<string, string | Uint8Array<ArrayBuffer>>): Promise<string | Uint8Array<ArrayBuffer>>
+export async function run (data: Record<"action", "verify"> & Record<string, string | Uint8Array<ArrayBuffer>>): Promise<boolean>
+export async function run (data: Record<string, string | Uint8Array<ArrayBuffer>>): Promise<boolean | string | Uint8Array<ArrayBuffer>> {
        try {
                await start()
        } catch (err: any) {