]> git.codecow.com Git - nano-pow.git/commitdiff
Move typings and update comment block style.
authorChris Duncan <chris@codecow.com>
Tue, 7 Apr 2026 04:40:38 +0000 (21:40 -0700)
committerChris Duncan <chris@codecow.com>
Tue, 7 Apr 2026 04:40:38 +0000 (21:40 -0700)
src/index.d.ts
src/index.ts
src/lib/config/index.ts

index 53862e9fb14ed3f568b02679bbe0ba1ee4d6f7ed..b845df75e49f53eaef5ab468957df37aeb19d6b4 100644 (file)
@@ -1,55 +1,8 @@
 //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
-declare global {
-       interface Window {
-               NanoPow: typeof NanoPow
-       }
-}
-
-export declare class NanoPow {
-       /**
-       * Finds a nonce that satisfies the Nano proof-of-work requirements.
-       *
-       * @param {bigint | string} hash - Hexadecimal hash of previous block, or public key for new accounts
-       * @param {object} [options] - Used to configure execution
-       * @param {string} [options.api] - Specifies how work is generated. Default: best available
-       * @param {boolean} [options.debug=false] - Enables additional debug logging to the console. Default: false
-       * @param {number} [options.effort=0x4] - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
-       * @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
-       */
-       static work_generate (hash: bigint | string, options?: NanoPowOptions): Promise<WorkGenerateResponse | WorkErrorResponse>
-       /**
-       * Validates that a nonce satisfies Nano proof-of-work requirements.
-       *
-       * @param {(bigint|string)} work - Value to validate against hash and difficulty
-       * @param {(bigint|string)} hash - Hash of previous block, or public key for new accounts
-       * @param {object} [options] - Used to configure execution
-       * @param {boolean} [options.debug=false] - Enables additional debug logging to the console. Default: false
-       * @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
-       */
-       static work_validate (work: bigint | string, hash: bigint | string, options?: NanoPowOptions): Promise<WorkValidateResponse | WorkErrorResponse>
-}
-export { NanoPow as default }
-
-/**
-* Input for configuring NanoPow. Must be validated prior to usage, so types are
-* `unknown`, but JSDoc indicates expected data types.
-*
-* @param {string} [api=cpu] - Specifies how work is generated. Default: cpu
-* @param {boolean} [debug=false] - Enables additional debug logging to the console. Default: false
-* @param {(bigint|string)} [difficulty=0xFFFFFFF800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
-* @param {number} [effort=0x4] - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
-*/
-export type NanoPowOptions = {
-       api?: unknown
-       debug?: unknown
-       difficulty?: unknown
-       effort?: unknown
-}
-
 /**
-* Usee to provide consumer with error information in response to request.
+* Provide consumer with error information in response to request.
 *
 * @param {string} error - Informative message about error.
 */
index 9555e0eb76795ed54093899c1f87b55f48817edc..b745051e01dfd578efa7ee71bac17cc2f3669970 100644 (file)
@@ -1,32 +1,33 @@
 //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
-import { NanoPowOptions, WorkErrorResponse, WorkGenerateResponse, WorkValidateResponse } from '#types'
+import { NanoPowOptions } from '#lib/config'
+import { WorkErrorResponse, WorkGenerateResponse, WorkValidateResponse } from '#types'
 import { generate, validate } from './lib'
 
 /**
-* Finds a nonce that satisfies the Nano proof-of-work requirements.
-*
-* @param {bigint | string} hash - Hexadecimal hash of previous block, or public key for new accounts
-* @param {object} [options] - Used to configure execution
-* @param {string} [options.api] - Specifies how work is generated. Default: best available
-* @param {boolean} [options.debug=false] - Enables additional debug logging to the console. Default: false
-* @param {number} [options.effort=0x4] - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
-* @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
-*/
+ * Finds a nonce that satisfies the Nano proof-of-work requirements.
+ *
+ * @param {bigint | string} hash - Hexadecimal hash of previous block, or public key for new accounts
+ * @param {object} [options] - Used to configure execution
+ * @param {string} [options.api] - Specifies how work is generated. Default: best available
+ * @param {boolean} [options.debug=false] - Enables additional debug logging to the console. Default: false
+ * @param {number} [options.effort=0x4] - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
+ * @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
+ */
 async function work_generate (hash: bigint | string, options: NanoPowOptions): Promise<WorkGenerateResponse | WorkErrorResponse> {
        return generate(hash, options)
 }
 
 /**
-* Validates that a nonce satisfies Nano proof-of-work requirements.
-*
-* @param {(bigint|string)} work - Value to validate against hash and difficulty
-* @param {(bigint|string)} hash - Hash of previous block, or public key for new accounts
-* @param {object} [options] - Used to configure execution
-* @param {boolean} [options.debug=false] - Enables additional debug logging to the console. Default: false
-* @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
-*/
+ * Validates that a nonce satisfies Nano proof-of-work requirements.
+ *
+ * @param {(bigint|string)} work - Value to validate against hash and difficulty
+ * @param {(bigint|string)} hash - Hash of previous block, or public key for new accounts
+ * @param {object} [options] - Used to configure execution
+ * @param {boolean} [options.debug=false] - Enables additional debug logging to the console. Default: false
+ * @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
+ */
 async function work_validate (work: bigint | string, hash: bigint | string, options: NanoPowOptions): Promise<WorkValidateResponse | WorkErrorResponse> {
        return validate(work, hash, options)
 }
index 1339822695709939e543174bcd8575e92744ab01..0c1ccc6d7ab5bb0236944414f661a80a67b56dfe 100644 (file)
@@ -1,11 +1,26 @@
 //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
-import { NanoPowOptions } from '#types'
 import { ApiSupport, bigintFrom, bigintToHex, SEND } from '#utils'
 
 type ApiSupportedTypes = keyof typeof ApiSupport
 
+/**
+ * Input for configuring NanoPow. Must be validated prior to usage, so types are
+ * `unknown`, but JSDoc indicates expected data types.
+ *
+ * @param {string} [api=cpu] - Specifies how work is generated. Default: cpu
+ * @param {boolean} [debug=false] - Enables additional debug logging to the console. Default: false
+ * @param {(bigint|string)} [difficulty=0xFFFFFFF800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
+ * @param {number} [effort=0x4] - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
+ */
+export type NanoPowOptions = {
+       api?: unknown
+       debug?: unknown
+       difficulty?: unknown
+       effort?: unknown
+}
+
 class NanoPowConfigConstructor implements NanoPowOptions {
        static #isInternal: boolean = false
        static get isInternal (): boolean { return this.#isInternal }
@@ -132,14 +147,14 @@ class NanoPowConfigConstructor implements NanoPowOptions {
 }
 
 /**
-* Validated NanoPowOptions object used to guarantee values and types. Attempting
-* to call using `new` with throw a TypeError.
-*
-* @param {string} api - Specifies how work is generated. Default: best available
-* @param {boolean} debug - Enables additional debug logging to the console. Default: false
-* @param {bigint} difficulty - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
-* @param {number} effort - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
-*/
+ * Validated NanoPowOptions object used to guarantee values and types.
+ * Attempting to call using `new` with throw a TypeError.
+ *
+ * @param {string} api - Specifies how work is generated. Default: best available
+ * @param {boolean} debug - Enables additional debug logging to the console. Default: false
+ * @param {bigint} difficulty - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
+ * @param {number} effort - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
+ */
 export const NanoPowConfig = (options: any): Promise<NanoPowConfigConstructor> => {
        try {
                return NanoPowConfigConstructor.create(options)