]> git.codecow.com Git - nano-pow.git/commitdiff
Fix type definitions since options should be optional.
authorChris Duncan <chris@codecow.com>
Fri, 31 Jul 2026 18:54:40 +0000 (11:54 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 31 Jul 2026 18:54:40 +0000 (11:54 -0700)
src/index.ts
src/lib/config/index.ts

index 7df4686eefd896fa4626fc5ffe0c0307e3fc67a7..b2faeb99ee0f29b284b185e5b59b7ffd6dd8093d 100644 (file)
@@ -57,14 +57,14 @@ export type WorkValidateResponse = {
 /**
  * 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 {(bigint|string)} hash - Hexadecimal hash of previous block, or public key for new accounts
+ * @param {NanoPowOptions} [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
  */
-export async function work_generate (hash: bigint | string, options: NanoPowOptions): Promise<WorkGenerateResponse | WorkErrorResponse> {
+export async function work_generate (hash: bigint | string, options?: NanoPowOptions): Promise<WorkGenerateResponse | WorkErrorResponse> {
        return generate(hash, options)
 }
 
@@ -73,11 +73,11 @@ export async function work_generate (hash: bigint | string, options: NanoPowOpti
  *
  * @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 {NanoPowOptions} [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
  */
-export async function work_validate (work: bigint | string, hash: bigint | string, options: NanoPowOptions): Promise<WorkValidateResponse | WorkErrorResponse> {
+export async function work_validate (work: bigint | string, hash: bigint | string, options?: NanoPowOptions): Promise<WorkValidateResponse | WorkErrorResponse> {
        return validate(work, hash, options)
 }
 
index 3ffd796f980041dfd119aedca72070e3cc85748c..66e8bbc168ae0a34fb0f083580a089aa17bb09fa 100644 (file)
@@ -48,8 +48,8 @@ class NanoPowConfigConstructor implements NanoPowOptions {
                this.effort = effort
        }
 
-       static async create (options: { api: unknown, debug: unknown, difficulty: unknown, effort: unknown } | unknown): Promise<NanoPowConfigConstructor> {
-               const input = options as Record<keyof NanoPowOptions, unknown>
+       static async create (options: NanoPowOptions | unknown): Promise<NanoPowConfigConstructor> {
+               const input = (options ?? {}) as Record<keyof NanoPowOptions, unknown>
 
                const api = await this.#getValidApi(input)
                const debug = this.#getValidDebug(input)
@@ -72,7 +72,7 @@ class NanoPowConfigConstructor implements NanoPowOptions {
 
        // Assign API if valid value passed
        static async #getValidApi (input: Record<string, unknown>): Promise<ApiSupportedTypes> {
-               if (input != null && input.api != null) {
+               if (input.api != null) {
                        if (typeof input.api === 'string') {
                                try {
                                        input.api = input.api.toLowerCase()
@@ -97,7 +97,7 @@ class NanoPowConfigConstructor implements NanoPowOptions {
 
        // Assign debug if valid value passed
        static #getValidDebug (input: Record<string, unknown>): boolean {
-               if (input != null && input.debug != null) {
+               if (input.debug != null) {
                        if (typeof input.debug === 'bigint' || typeof input.debug === 'number') {
                                input.debug = input.debug.toString()
                        }
@@ -114,7 +114,7 @@ class NanoPowConfigConstructor implements NanoPowOptions {
 
        // Assign difficulty if valid value passed
        static #getValidDifficulty (input: Record<string, unknown>): bigint {
-               if (input != null && input.difficulty != null) {
+               if (input.difficulty != null) {
                        if (typeof input.difficulty === 'string') {
                                try {
                                        input.difficulty = big(input.difficulty)
@@ -133,7 +133,7 @@ class NanoPowConfigConstructor implements NanoPowOptions {
 
        // Assign effort if valid value passed
        static #getValidEffort (input: Record<string, unknown>): number {
-               if (input != null && input.effort != null) {
+               if (input.effort != null) {
                        if (typeof input.effort !== 'number') {
                                throw new Error(`Invalid effort (${typeof input.effort})${input.effort}`)
                        }
@@ -150,12 +150,13 @@ 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
+ * @param {unknown} [options] - Object with zero or more properties for configuring NanoPow.
+ * @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> => {
+export const NanoPowConfig = (options: unknown): Promise<NanoPowConfigConstructor> => {
        try {
                return NanoPowConfigConstructor.create(options)
        } catch (err) {