From: Chris Duncan Date: Mon, 16 Jun 2025 13:33:46 +0000 (-0700) Subject: Fix config silently failing due to type assertion if no options object is passed. X-Git-Tag: v5.0.0~16 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=926f6c7d39f4ad515feec43ac09903f43c714a6e;p=nano-pow.git Fix config silently failing due to type assertion if no options object is passed. --- diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 7575d1c..5eb7667 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -54,7 +54,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign API if valid value passed static async #getValidApi (input: Record): Promise { - if (input.api != null) { + if (input != null && input.api != null) { if (typeof input.api === 'string') { try { input.api = input.api.toLowerCase() @@ -79,7 +79,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign debug if valid value passed static #getValidDebug (input: Record): boolean { - if (input.debug != null) { + if (input != null && input.debug != null) { if (typeof input.debug === 'bigint' || typeof input.debug === 'number') { input.debug = input.debug.toString() } @@ -96,7 +96,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign difficulty if valid value passed static #getValidDifficulty (input: Record): bigint { - if (input.difficulty != null) { + if (input != null && input.difficulty != null) { if (typeof input.difficulty === 'string') { try { input.difficulty = bigintFrom(input.difficulty, 'hex') @@ -115,7 +115,7 @@ class NanoPowConfigConstructor implements NanoPowOptions { // Assign effort if valid value passed static #getValidEffort (input: Record): number { - if (input.effort != null) { + if (input != null && input.effort != null) { if (typeof input.effort !== 'number') { throw new Error(`Invalid effort (${typeof input.effort})${input.effort}`) }