]> zoso.dev Git - nano-pow.git/commitdiff
Refactor pipeline to use tsc to generate definition files only and manually manage...
authorChris Duncan <chris@zoso.dev>
Mon, 13 Jan 2025 15:35:34 +0000 (07:35 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 13 Jan 2025 15:35:34 +0000 (07:35 -0800)
.gitignore
esbuild.mjs
package.json
tsconfig.json
types.d.ts [new file with mode: 0644]

index f0cedc5593598c35b9b7bb3f431b84368b90e657..657bd01f944941ccb7abb3822ddf0758c42f4fd2 100644 (file)
@@ -18,3 +18,4 @@ node_modules/
 # Build artifacts\r
 build/\r
 dist/\r
+types/\r
index 3a092e19ee8f4783ad72683707fb8fd81f2f4b83..be1bb8d008ab502e5d08f78f886afc67f795a761 100644 (file)
@@ -6,8 +6,8 @@ import { glsl } from "esbuild-plugin-glsl"
 
 await build({
        entryPoints: [
-               { out: 'main.min', in: 'dist/main.js' },
-               { out: 'global.min', in: 'dist/global.js' }
+               { out: 'main.min', in: './src/main.js' },
+               { out: 'global.min', in: './src/global.js' }
        ],
        outdir: 'dist',
        target: 'esnext',
index 240ece6a92e458258bb2748c2f96ccfbf0a77553..e67ebdf6f066ef868be729fb59784bc58182ac6b 100644 (file)
@@ -40,7 +40,7 @@
                "url": "git+https://zoso.dev/nano-pow.git"
        },
        "scripts": {
-               "build": "rm -rf dist && tsc && node esbuild.mjs"
+               "build": "rm -rf types && tsc && node esbuild.mjs && cp types.d.ts dist"
        },
        "devDependencies": {
                "@types/node": "^22.10.5",
                "typescript": "^5.7.3"
        },
        "type": "module",
-       "exports": "./dist/main.js",
-       "types": "dist/main.d.ts",
+       "exports": [
+               "./dist/main.min.js",
+               "./types.d.ts"
+       ],
+       "types": "types.d.ts",
        "unpkg": "dist/main.min.js"
 }
index 82d452f670206f966d1ce285ef58851b8df30dde..ba7d00adb4c2d840d0cd00d09f4d4e22000d2cfa 100644 (file)
@@ -4,8 +4,8 @@
                "module": "ESNext",
                "moduleResolution": "Bundler",
                "declaration": true,
-               "noEmit": false,
-               "outDir": "./dist",
+               "emitDeclarationOnly": true,
+               "declarationDir": "./types",
                "alwaysStrict": true,
                "downlevelIteration": false,
                "esModuleInterop": true,
diff --git a/types.d.ts b/types.d.ts
new file mode 100644 (file)
index 0000000..14f4538
--- /dev/null
@@ -0,0 +1,53 @@
+import "@webgpu/types"
+
+declare const NanoPow: typeof NanoPowGl | typeof NanoPowGpu | null
+
+export declare class NanoPowGl {
+       #private
+       /** Compile */
+       static init (): Promise<void>
+       /**
+       * Finds a nonce that satisfies the Nano proof-of-work requirements.
+       *
+       * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
+       * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
+       */
+       static search (hash: string, threshold?: number): Promise<string>
+       /**
+       * Validates that a nonce satisfies Nano proof-of-work requirements.
+       *
+       * @param {string} work - Hexadecimal proof-of-work value to validate
+       * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
+       * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
+       */
+       static validate (work: string, hash: string, threshold?: number): Promise<boolean>
+}
+
+/**
+* Nano proof-of-work using WebGPU.
+*/
+export declare class NanoPowGpu {
+       #private
+       static init (): Promise<void>
+       static setup (): void
+       static reset (): void
+       /**
+       * Finds a nonce that satisfies the Nano proof-of-work requirements.
+       *
+       * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
+       * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
+       */
+       static search (hash: string, threshold?: number): Promise<string>
+       /**
+       * Validates that a nonce satisfies Nano proof-of-work requirements.
+       *
+       * @param {string} work - Hexadecimal proof-of-work value to validate
+       * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
+       * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
+       */
+       static validate (work: string, hash: string, threshold?: number): Promise<boolean>
+}
+
+export declare const NanoPowGlFragmentShader: string
+export declare const NanoPowGlVertexShader: string
+export declare const NanoPowGpuComputeShader: any