From: Chris Duncan Date: Mon, 13 Jan 2025 15:35:34 +0000 (-0800) Subject: Refactor pipeline to use tsc to generate definition files only and manually manage... X-Git-Tag: v1.2.3~2 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=52f418e2470c59af1b40fb7591b785ea27d68919;p=nano-pow.git Refactor pipeline to use tsc to generate definition files only and manually manage the global types. --- diff --git a/.gitignore b/.gitignore index f0cedc5..657bd01 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ node_modules/ # Build artifacts build/ dist/ +types/ diff --git a/esbuild.mjs b/esbuild.mjs index 3a092e1..be1bb8d 100644 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -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', diff --git a/package.json b/package.json index 240ece6..e67ebdf 100644 --- a/package.json +++ b/package.json @@ -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", @@ -51,7 +51,10 @@ "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" } diff --git a/tsconfig.json b/tsconfig.json index 82d452f..ba7d00a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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 index 0000000..14f4538 --- /dev/null +++ b/types.d.ts @@ -0,0 +1,53 @@ +import "@webgpu/types" + +declare const NanoPow: typeof NanoPowGl | typeof NanoPowGpu | null + +export declare class NanoPowGl { + #private + /** Compile */ + static init (): Promise + /** + * 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 + /** + * 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 +} + +/** +* Nano proof-of-work using WebGPU. +*/ +export declare class NanoPowGpu { + #private + static init (): Promise + 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 + /** + * 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 +} + +export declare const NanoPowGlFragmentShader: string +export declare const NanoPowGlVertexShader: string +export declare const NanoPowGpuComputeShader: any