/**
* 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)
}
*
* @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)
}
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)
// 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()
// 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()
}
// 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)
// 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}`)
}
* 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) {