Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
keefertaylor committed Oct 1, 2019
1 parent 8e5de83 commit c8850ab
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 12 deletions.
193 changes: 182 additions & 11 deletions README.md
Expand Up @@ -2,36 +2,207 @@
[![Coverage](https://coveralls.io/repos/github/xpring-eng/Xpring-JS/badge.svg?branch=master&t=DkDKCV)](https://coveralls.io/github/xpring-eng/Xpring-JS?branch=master)

# Xpring-JS
Xpring-JS provides a JavasScript based SDK for interacting with the XRP Ledger.

# Setup
Xpring-JS is the JavaScript client side library of the Xpring SDK.

These instructions assume you are using MacOS.
## Features
Xpring-JS provides the following features:
- Wallet generation and derivation (Seed or HD Wallet based)
- Address validation
- Account balance retrieval
- Sending XRP payments

## Installation

Xpring-JS utilizes two components to access the Xpring platform.
1) The Xpring-JS client side library (This library)
2) A server side component that handles requests from this library and proxies them to an XRP node.

### Client Side Library
Xpring-JS is available as an NPM package. Simply install with:

```shell
# Install Homebrew
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ npm i xpring-js
```

### Server Side Component
The server side component sends client-side requests to an XRP Node.

To get developers started right away, Xpring currently provides the server side component as a hosted service, which proxies requests from client side libraries to a a hosted XRP Node. Developers can reach the endpoint at:
```
grpc.xpring.tech:80
```

Xpring is working on building a zero-config way for XRP node users to deploy and use the adapter as an open-source component of [rippled](https://github.com/ripple/rippled). Watch this space.

## Usage
### Wallets
A wallet is a fundamental model object in XRP-JS which provides key management, address derivation, and signing functionality. Wallets can be derived from either a seed or a mnemonic and derivation path.

#### Wallet Derivation
Xpring-JS can derive a wallet from a seed or it can derive a hierarchical deterministic wallet (HDWallet) from a mnemonic and derivation path.

##### Hierarchical Deterministic Wallets
A hierarchical deterministic wallet is created using a mnemonic and a derivation path. Simply pass the mnemonic and derivation path to the wallet generation function. Note that you can omit the derivation path and have a default path be used.

```javascript
const { Wallet } = require("xpring-js");

const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";

const hdWallet1 = Wallet.generateWalletFromMnemonic(mnemonic); // Has default derivation path
const hdWallet2 = Wallet.generateWalletFromMnemonic(mnemonic, Wallet.getDefaultDerivationPath()); // Same as hdWallet1

const hdWallet = Wallet.generateWalletFromMnemonic(mnemonic, "m/44'/144'/0'/0/1"); // Wallet with custom derivation path.
```

##### Seed Based Wallets
You can construct a seed based wallet by passing a base58check encoded seed string.

```javascript
const { Wallet } = require("xpring-js");

const seedWallet = Wallet.generateWalletFromSeed("snRiAJGeKCkPVddbjB3zRwiYDBm1M");
```

#### Wallet Generation
XRP-JS can generate a new and random HD Wallet. The result of a wallet generation call is a tuple which contains the following:
- A randomly generated mnemonic
- The derivation path used, which is the default path
- A reference to the new wallet

```javascript
const { Wallet } = require("xpring-js");

// Generate a random wallet.
const generationResult = Wallet.generateRandomWallet();
const newWallet = generationResult.wallet

// Wallet can be recreated with the artifacts of the initial generation.
const copyOfNewWallet = Wallet.generateWalletFromMnemonic(generationResult.mnemonic, generationResult.derivationPath)
```

#### Wallet Properties
A generated wallet can provide its public key, private key, and address on the XRP ledger.

```javascript
const { Wallet } = require("xpring-js");

const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";

const wallet = Wallet.generateWalletFromMnemonic(mnemonic);

console.log(wallet.getAddress()); // rHsMGQEkVNJmpGWs8XUBoTBiAAbwxZN5v3
console.log(wallet.getPublicKey()); // 031D68BC1A142E6766B2BDFB006CCFE135EF2E0E2E94ABB5CF5C9AB6104776FBAE
console.log(wallet.getPrivateKey()); // 0090802A50AA84EFB6CDB225F17C27616EA94048C179142FECF03F4712A07EA7A4
```

#### Signing / Verifying

A wallet can also sign and verify arbitrary hex messages. Generally, users should use the functions on XRPClient to perform cryptographic functions rather than using these low level APIs.

```javascript
const { Wallet } = require("xpringkit-js");

# Clone repo
$ git clone https://github.com/xpring-eng/Xpring-JS.git
$ cd Xpring-JS
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
const message = "deadbeef";

const wallet = Wallet.generateWalletFromMnemonic(mnemonic);

const signature = wallet.sign(message);
wallet.verify(message, signature); // true
```

### XpringClient

XpringClient is a gateway into the XRP Ledger. XpringClient is initialized with a single parameter, which is the URL of the remote adapter (see: ‘Server Side Component’ section above).

```javascript
const { XpringClient } = require("xpring-js");

const remoteURL = "grpc.xpring.tech:80";
const xpringClient = new XpringClient(remoteURL);
```

#### Retrieving a Balance

A `XpringClient` can check the balance of an account on the ledger.

```javascript
const { XpringClient } = require("xpring-js");

const remoteURL = "grpc.xpring.tech:80";
const xpringClient = new XpringClient(remoteURL);

const address = "rHsMGQEkVNJmpGWs8XUBoTBiAAbwxZN5v3";

const balance = await xpringClient.getBalance(address);
console.log(balance.drops); // Logs a balance in drops of XRP
```

#### Sending XRP

A `XpringClient` can send XRP to other accounts on the ledger.

```javascript
const { Wallet, XRPAmount, XRPClient } = require("xpring-js");

const remoteURL = "grpc.xpring.tech:80";
const xpringClient = new XpringClient(remoteURL);

// Wallet which will send XRP
const senderWallet = Wallet.generateRandomWallet();

// Destination address.
const address = "rHsMGQEkVNJmpGWs8XUBoTBiAAbwxZN5v3";

// Amount of XRP to send
const amount = new XRPAmount();
amount.setDrops("10");

const result = await xpringClient.send(senderWallet, amount, destinationAddress);
```

### Utilities
#### Address validation

The Utils object provides an easy way to validate addresses.

```javascript
const { Utils } = require("xpring-js")

const rippleAddress = rnysDDrRXxz9z66DmCmfWpq4Z5s4TyUP3G;
const bitcoinAddress = 1DiqLtKZZviDxccRpowkhVowsbLSNQWBE8;

Utils.isValidAddress(rippleAddress); // returns true
Utils.siValidAddress(bitcoinAddress); // returns false
```

## Development
To get set up for development on XRP-JS, use the following steps:

```shell
# Clone repository
$ git clone https://github.com/xpring-eng/xrp-js.git
$ cd xrp-js

# Pull submodules
$ git submodule init
$ git submodule update --remote

# Install Protocol Buffers
# OSX
$ brew install protobuf
# Linux
$ sudo apt install protobuf-compiler

# Install GRPC
$ brew tap grpc/grpc
$ brew install grpc

# Install required modules.
$ npm i
$ npm i

# Run tests
# Run tests And generate intermediate code artifacts)
$ npm test
```

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "xpring-js",
"version": "1.0.3",
"version": "1.0.4",
"description": "XpringJS provides a Javascript based SDK for interacting with the Ripple Ledger.",
"main": "build/src/index.js",
"repository": {
Expand Down

0 comments on commit c8850ab

Please sign in to comment.