Options
All
  • Public
  • Public/Protected
  • All
Menu

nanocurrency

npm version Test

A battle-tested toolkit for the Nano cryptocurrency.

If you are looking for legacy blocks, you will want the ^1.0.0 versions.

Code showcase

The documentation is available locally in docs/ or online at https://marvinroger.github.io/nanocurrency-js/packages/nanocurrency/docs/.


Features

  • Generate seeds
  • Derive secret keys, public keys and addresses
  • Hash blocks
  • Sign and verify blocks
  • Compute and test proofs of work
  • Check the format of seeds, secret keys, public keys, addresses, amounts, etc.
  • Convert Nano units
  • CLI doing all of the above

Usage

To install the library:

npm install nanocurrency
# or yarn add nanocurrency
import * as nanocurrency from 'nanocurrency'

Performance

You might be wondering how fast is the work generation. There's a pow-benchmark example in the examples/ directory. On an Intel Core i7-8550U CPU, with 100 iterations, the average computation time is 18.5s per work.

Considering you can pre-compute and cache the work prior to an actual transaction, this should be satisfying for a smooth user experience.


Contribute

Contributions are very welcome. To develop, make use of the following commands (using Yarn):

  • yarn build:dev: build the C++ code to WebAssembly and bundle the files into the dist/ directory, without optimization so that it is fast while developing. Note that you'll need to have Docker installed

  • yarn test: test the code

  • yarn lint: lint the code against JavaScript Standard Style

  • yarn generate-docs: generate the docs/ website from the JSDoc annotations


Donations

If you like the project, feel free to donate some nano:

xrb_3mrogerjhkdyj6mzf4e7aatf3xs3gp4stwc9yt9ymgasw7kr7g17t4jwwwy8

Index

Type aliases

BlockData

State block data.

Variables

Const DEFAULT_WORK_THRESHOLD

DEFAULT_WORK_THRESHOLD: "ffffffc000000000" = "ffffffc000000000"

Functions

checkAddress

  • checkAddress(address: string): boolean
  • Check if the given address is valid.

    Note: it checks the format and the checksum of the address. It does not check whether or not the address does exist on the network.

    Parameters

    • address: string

      The address to check

    Returns boolean

    Valid

checkAmount

  • checkAmount(amount: string): boolean
  • Check if the given amount is valid.

    Note: a valid amount means that it can be embedded into a block balance.

    Parameters

    • amount: string

      The amount to check

    Returns boolean

    Valid

checkHash

  • checkHash(hash: string): boolean
  • Check if the given hash is valid.

    Note: it only checks the format of the hash.

    Parameters

    • hash: string

      The hash to check

    Returns boolean

    Valid

checkIndex

  • checkIndex(index: number): boolean
  • Check if the given index is valid.

    Note: it only checks the format of the index.

    Parameters

    • index: number

    Returns boolean

    Valid

checkKey

  • checkKey(key: string): boolean
  • Check if the given public or secret key is valid.

    Note: it only checks the format of the key. It does not check whether or not the key does exist on the network.

    Parameters

    • key: string

      The key to check

    Returns boolean

    Valid

checkSeed

  • checkSeed(seed: string): boolean
  • Check if the given seed is valid.

    Note: it only checks the format of the seed.

    Parameters

    • seed: string

      The seed to check

    Returns boolean

    Valid

checkSignature

  • checkSignature(signature: string): boolean
  • Check if the given signature is valid.

    Note: it only checks the format of the signature.

    Parameters

    • signature: string

      The signature to check

    Returns boolean

    Valid

checkThreshold

  • checkThreshold(threshold: string): boolean
  • Check if the given threshold is valid.

    Note: it only checks the format of the threshold.

    Parameters

    • threshold: string

      The threshold to check

    Returns boolean

    Valid

checkWork

  • checkWork(work: string): boolean
  • Check if the given work is valid.

    Note: it only checks the format of the work, not its difficulty.

    Parameters

    • work: string

      The work to check

    Returns boolean

    Valid

computeWork

  • Find a work value that meets the difficulty for the given hash. Require WebAssembly support.

    Parameters

    • blockHash: string

      The block hash to find a work for

    • Default value params: ComputeWorkParams = {}

      Parameters

    Returns Promise<string | null>

    Work, in hexadecimal format, or null if no work has been found (very unlikely)

convert

  • Convert a value from one Nano unit to another.

    Parameters

    • value: string

      The value to convert

    • params: ConvertParams

      Params

    Returns string

    Converted number

createBlock

  • Create a state block.

    Parameters

    • secretKey: string

      The secret key to create the block from, in hexadecimal format

    • data: BlockData

      Block data

    Returns Block

    Block

deriveAddress

  • Derive address from a public key.

    Parameters

    • publicKey: string

      The public key to generate the address from, in hexadecimal format

    • Default value params: DeriveAddressParams = {}

      Parameters

    Returns string

    Address

derivePublicKey

  • derivePublicKey(secretKeyOrAddress: string): string
  • Derive a public key from a secret key.

    Parameters

    • secretKeyOrAddress: string

      The secret key or address to generate the public key from, in hexadecimal or address format

    Returns string

    Public key, in hexadecimal format

deriveSecretKey

  • deriveSecretKey(seed: string, index: number): string
  • Derive a secret key from a seed, given an index.

    Parameters

    • seed: string

      The seed to generate the secret key from, in hexadecimal format

    • index: number

      The index to generate the secret key from

    Returns string

    Secret key, in hexadecimal format

generateSeed

  • generateSeed(): Promise<string>
  • Generate a cryptographically secure seed.

    Returns Promise<string>

    Promise fulfilled with seed, in hexadecimal format

hashBlock

  • Hash a state block.

    Parameters

    Returns string

    Hash, in hexadecimal format

signBlock

validateWork

  • Validate whether or not the work value meets the difficulty for the given hash.

    Parameters

    Returns boolean

    Valid

verifyBlock

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc