Node JS module

From ArdorDocs
Jump to: navigation, search
This page contains changes which are not marked for translation.
Other languages:

Introduction

Existing client API library for Ardor suffer from the following limitations:

  1. The API library sends the passphrase directly to the remote node in order to sign transactions, this means that the remote node has to be trusted which limits the usability of the API library.
  2. Some client libraries does implement local transaction signing but still were unable to validate unsigned bytes data returned from a random remote node thus still making it somewhat insecure to submit transactions to a random remote node.
  3. Client API libraries are developed by 3rd party developers so sometimes lag behind recent changes.

To address these problems we introduced a simple Node JS module which can be used for JavaScript application development using the Ardor platform APIs.

This node JS module is now integral part of the core. It is wrapper of the existing Ardor Wallet JavaScript code configured as a node JS module.

The official Ardor NPM package link is the following https://www.npmjs.com/package/ardor


Use Cases

  1. The Node JS module is able to work securely against any random Ardor node without trusting the node.
  2. When submitting a transaction, data submitted to a remote node is validated against the returned unsigned bytes.
  3. Transactions are signed locally so that the account passphrase is never submitted to a remote node.
  4. Message encrytption can be performed client side.
  5. API calls work at a higher level compared to the APIs provided by the existing test page, so that for example, complex numeric conversions and various formatting functions are already implemented by the API library.
  6. Updates to this API library will follow the standard Ardor release process and will be maintained by core developers.


Getting Started

To quickly get started using the node JS module, see instructions for Setup using Ardor installation or the setup using the official NPM Ardor package


Setup using NPM

  • npm i ardor
  • echo n | copy /-y node_modules\ardor\sample\*.* *.* - copy the Ardor samples without overwriting existing files


Setup using Ardor installation

  • Install the Ardor software (no need to download the blockchain)
  • Install Node JS and NPM from nodejs.org
  • Open a command prompt
  • Navigate to the Ardor installation folder
    • cd html/www/js - make sure the folder has write permissions
    • npm install
    • cd sample


Run Examples

  • Configure the remote node, Ardor account and default chain by editing the config.json file
  • Invoke any of the available samples using node, for example node send.money.js


Packaging and Distribution

If installed from Ardor installation, the Ardor package no longer depends on a local Ardor node. You can use the content of the html/www/js folder as a standalone module.


Warning

Your passphrase or private key are submitted to a remote node only when invoking specific APIs which require them to operate like the startForging API.

We recommend that you avoid using these APIs in your scripts when connecting to an untrusted remote node.