# ripajs

> JavaScript library for sending Ripa transactions from the client or server

Latest version **0.2.1** (published 2018-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install ripajs
pnpm add ripajs
yarn add ripajs
bun add ripajs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2018-09-26 |
| First published | 2018-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 16 |
| Unpacked size | 566.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | gobled |
| Maintainers | gobled |
| Keywords | api, ripa, exchange, blockchain, client, cryptocurrency, javascript, server, transaction |

## Links

- npm: https://www.npmjs.com/package/ripajs
- Repository: https://github.com/RipaEx/ripa-js
- Issues: https://github.com/RipaEx/ripa-js/issues
- npm.io page: https://npm.io/package/ripajs

## Dependencies (16)

- [wif](https://npm.io/package/wif.md) ^2.0.6
- [bigi](https://npm.io/package/bigi.md) ^1.4.2
- [bip66](https://npm.io/package/bip66.md) ^1.1.5
- [ecdsa](https://npm.io/package/ecdsa.md) ^0.7.0
- [buffer](https://npm.io/package/buffer.md) ^5.0.8
- [ecurve](https://npm.io/package/ecurve.md) ^1.0.5
- [js-nacl](https://npm.io/package/js-nacl.md) ^1.2.2
- [bs58check](https://npm.io/package/bs58check.md) ^2.0.2
- [secp256k1](https://npm.io/package/secp256k1.md) ^3.3.0
- [typeforce](https://npm.io/package/typeforce.md) ^1.11.7
- [bytebuffer](https://npm.io/package/bytebuffer.md) ^5.0.1
- [create-hash](https://npm.io/package/create-hash.md) ^1.1.3
- [create-hmac](https://npm.io/package/create-hmac.md) ^1.1.6
- [randombytes](https://npm.io/package/randombytes.md) ^2.0.5
- [browserify-bignum](https://npm.io/package/browserify-bignum.md) ^1.3.0-2
- [crypto-browserify](https://npm.io/package/crypto-browserify.md) ^3.12.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2018-09-26

## README

![RIPA JavaScript](./banner_medium_js.jpg)


[![Build Status](https://travis-ci.org/RipaEx/ripa-js.svg?branch=master)](https://travis-ci.org/RipaEx/ripa-js)

# RIPA JS

RIPA JS is a JavaScript library for sending RIPA transactions. It's main benefit is that it does not require a locally installed RIPA node, and instead utilizes the existing peers on the network. It can be used from the client as a [browserify](http://browserify.org/) compiled module, or on the server as a standard Node.js module.

## Installation

[![npm package](https://nodei.co/npm/ripajs.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/ripajs/)

## Building

Build the browserify module for client use:

```sh
npm build:browserify
```

Clean:

```sh
npm clean:browserify
```

## Tests

```
npm test
```

Tests written using mocha + schedule.js.

***

## Usage

On the client:

```html
<script src="node_modules/ripajs/bundle.min.js"></script>
```

On the server:

```js
var ripajs = require("ripajs");
```

### Generating a key pair

To generate a public / private key pair from a given passphrase:

```js
var keys = ripajs.crypto.getKeys("passphrase");
```

Returning:

```js
{
  publicKey: "02e012f0a7cac12a74bdc17d844cbc9f637177b470019c32a53cef94c7a56e2ea9",
  privateKey: ""
}
```

To get the private key:

```js
keys.d.toBuffer().toString("hex");
```

Returning:
```
1e089e3c5323ad80a90767bdd5907297b4138163f027097fd3bdbeab528d2d68
```


### Generating an address

To generate a unique RIPA address from a given public key:

```js
var address = ripajs.crypto.getAddress("5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09");
```

Returning:

```
AGihocTkwDygiFvmg6aG8jThYTic47GzU9
```

### Creating a transaction

To create a signed transaction object, which can then be broadcasted onto the network:

```js
var amount      = 1000 * Math.pow(10, 8); // 100000000000
var transaction = ripajs.transaction.createTransaction("AGihocTkwDygiFvmg6aG8jThYTic47GzU9", amount, null, "passphrase", "secondPassphrase");
```

Returning:

```js
{
  type: 0, // Transaction type. 0 = Normal transaction.
  amount: 100000000000, // The amount to send expressed as an integer value.
  asset: {}, // Transaction asset, dependent on tx type.
  fee: 100000000, // 0.1 RIPA expressed as an integer value.
  id: "500224999259823996", // Transaction ID.
  recipientId: "AGihocTkwDygiFvmg6aG8jThYTic47GzU9", // Recipient ID.
  senderPublicKey: "56e106a1d4a53dbe22cac52fefd8fc4123cfb4ee482f8f25a4fc72eb459b38a5", // Sender's public key.
  signSignature: "03fdd33bed30270b97e77ada44764cc8628f6ad3bbd84718571695262a5a18baa37bd76a62dd25bc21beacd61eaf2c63af0cf34edb0d191d225f4974cd3aa509", // Sender's second passphrase signature.
  signature: "9419ca3cf11ed2e3fa4c63bc9a4dc18b5001648e74522bc0f22bda46a188e462da4785e5c71a43cfc0486af08d447b9340ba8b93258c4c7f50798060fff2d709", // Transaction signature.
  timestamp: 27953413 // Based on UTC time of genesis since epoch.
}
```

### Network identification with Nethash

You need to obtain the nethash in order to be sure you are broadcasting to the right network (testnet, mainnet or others). The nethash is simply the payload hash from the genesisBlock. If no nethash or wrong nethash is provided in the headers, the request will be rejected returning the expected nethash.

```json
{ "success": false, "message": "Request is made on the wrong network", "expected":"e2f8f69ec6ab4b12550a314bd867c46e64e429961bb427514a3a534c602ff467", "received":"wrong-nethash" }
```

The nethash for a given network can be obtained at the following API endpoint:

```
/api/blocks/getNetHash
```

You can also get the nethash from a peer this way:

On the client using [jQuery](https://jquery.com/):

```js
var nethash;
$.ajax({
  url: "https://api.ripaex.io/peer/transactions/",
  data: JSON.stringify({}),
  dataType: "json",
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "os": "linux3.2.0-4-amd64",
    "version": "0.3.0",
    "port": 1,
    "nethash": "wrong-nethash"
  },
  success: function(data) {
    nethash = data.body.expected;
  }
});
```

From a server using [Request](https://github.com/request/request):

```js
var nethash;
request({
  url: "https://api.ripaex.io/peer/transactions",
  json: { },
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "os": "linux3.2.0-4-amd64",
    "version": "0.3.0",
    "port": 1,
    "nethash": "wrong-nethash"
  }
}, function(error, response, body) {
    nethash = body.expected;
  });
```

### Posting a transaction

Transaction objects are sent to `/peer/transactions`, using the `POST` method.

Example:

```js
Method: POST
Content-Type: application/json

{
    "transactions" : [{
        ...
    }]
}
```

#### Sending transaction on the Client

Using [jQuery](https://jquery.com/):

```js
var success = function(data) {
  console.log(data);
};

$.ajax({
  url: "https://api.ripaex.io/peer/transactions",
  data: JSON.stringify({ transactions: [transaction] }),
  dataType: "json",
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "os": "linux3.2.0-4-amd64",
    "version": "0.3.0",
    "port": 1,
    "nethash":nethash
  },
  success: success
});
```

#### Sending transaction on the Server

Using [Request](https://github.com/request/request):


```js
var request = require("request");

var callback = function(error, response, body) {
  console.log(error || body);
};

request({
  url: "https://api.ripaex.io/peer/transactions",
  json: { transactions: [transaction] },
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "os": "linux3.2.0-4-amd64",
    "version": "0.3.0",
    "port": 1,
    "nethash": nethash
  }
}, callback);
```

#### Peer Response

Upon successfully accepting a transaction, the receiving node will respond with:

```json
{ "success": true, "result": "5318121831703437738" }
```

If the transaction is deemed invalid, or an error is encountered, the receiving node will respond with:

```json
{ "success": false, "message": "Error message" }
```

***

### Other transaction types

#### Creating a delegate transaction

```js
var transaction = ripajs.delegate.createDelegate("secret", "username", "secondSecret");
```

#### Creating a second signature transaction

```js
var transaction = ripajs.signature.createSignature("secret", "secondSecret");
```

#### Creating a vote transaction

```js
var transaction = ripajs.vote.createVote("secret", ["+58199578191950019299181920120128129"], "secondSecret");
```

***

## Authors
- Giovanni Silvestri <gsit80@gmail.com>
- FX Thoorens <fx@ark.io>
- Guillaume Verbal <doweig@ark.io>

## License

RIPAEX is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.

---
_Source: https://npm.io/package/ripajs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
