npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nanopow-rs-node

v0.4.2

Published

A wrapper for nanopow-rs for Node to provide fast, fully multithreaded Nano proof-of-work generation in Node.js.

Downloads

17

Readme

nanopow-rs-node

NPM Version Build Status

A JavaScript wrapper for nanopow-rs to provide fast, safe, fully multithreaded Nano proof-of-work generation in Node.js.

Usage

First: Install Rust

See https://www.rustup.rs/ for instructions on installing Rust for your system.

With Node

$ yarn add nanopow-rs-node
$ yarn install

In Electron App

Basically same as above, see https://guides.neon-bindings.com/electron-apps/

Example

// Require as usual
const nanopow = require('nanopow-rs-node')

// The hash is either the hash of the previous block in the account's chain
// or the account's public key if there are no previous blocks.
const hash = 'AC101449364C84CDD7562AA724BE52757EF06BCE834C50CF610DD2949291B0D9'

// Asynchronously (non-blocking) with no limit
nanopow.generateWork(hash)
  .then(work => {
    const isValid = nanopow.checkWork(hash, work) // true
  })

// Asynchronously (non-blocking) with limit
nanopow.generateWork(hash, 10000000) // 10 million
  .then(work => {
    const isValid = nanopow.checkWork(hash, work) // true
    console.log(`Found valid work: ${work}`)
  })
  .catch(err => {
    console.error(`Failed to find work in 10 million iterations`)
  })

// Asynchronously using async/await with no limit
async function myTransactionFunction (hash) {
  const work = await nanopow.generateWork(hash)
  const isValid = nanopow.checkWork(hash, work) // true
}

// Asynchronously using async/await with limit
async function myTransactionFunction (hash) {
  try {
    const work = await nanopow.generateWork(hash, 10000000) // 10 million
    const isValid = nanopow.checkWork(hash, work) // true
    console.log(`Found valid work: ${work}`)
  } catch (e) {
    console.error(`Failed to find work in 10 million iterations`)
  }
}

// Synchronously (blocking) no limit
const work = nanopow.generateWorkSync(hash) // no limit
const isValid = nanopow.checkWork(hash, work) // true

// Synchronously (blocking) no limit
const work = nanopow.generateWorkSync(hash, 10000000) // 10 million
const isValid = nanopow.checkWork(hash, work) // Could be false if valid work was not found

API Reference

/**
 * Attempts to generate valid work for a given hash.
 * @param hash A 32-byte (64-character) hex-encoded string. This will either be the previous block hash, or, if there is no previous block, the account's public key.
 * @param maxIters (optional) The maximum iterations to try before returning. If this parameter is omitted, is null, or is 0, it will run until valid work is found.
 * @return A Promise that is resolved with an 8-byte (16-character) hex-encoded string that is the work found. If no work is found in maxIters, the promise is rejected.
 */
nanopow.generateWork (hash, maxIters)

/**
 * Attempts to generate valid work for a given hash.
 * @param hash A 32-byte (64-character) hex-encoded string. This will either be the previous block hash, or, if there is no previous block, the account's public key.
 * @param maxIters (optional) The maximum iterations to try before returning. If this parameter is omitted, is null, or is 0, it will run until valid work is found.
 * @return An 8-byte (16-character) hex-encoded string that is the work found. If no valid work was found in maxIters, returns '0000000000000000'
 */
nanopow.generateWorkSync (hash, maxIters)

/**
 * Checks whether given work is valid for a given hash.
 * @param hash A 32-byte (64-character) hex-encoded string. This will either be the previous block hash, or, if there is no previous block, the account's public key.
 * @param work An 8-byte (16-character) hex-encoded string that is the work to be verified.
 * @return Boolean representing whether the given work was valid for the given hash.
 */
nanopow.checkWork(hash, work)

Development

Install needed deps with

$ yarn install

Tests in test/test.js, perfom tests with

$ yarn test

Reference

See Neon docs and examples in their tests directory on GitHub