npm package: @moonstake/moonstakejs
Description: Library for staking to Moonstake
Author: Moonstake
Latest version: 1.4.0

# Introduction
This SDK is implemented to support developers quickly integrate with Moonstake system. The Moonstake is a great staking pool which supports individual users, Moonstake partners and exchanges to stake and earn blockchain rewards.

In the this release, the SDK only supports the following platforms
- Cardano ADA
- Tezos

# How to use SDK
- First of all, you should register to Moonstake system to become a partner and get staking information such as staking memo and Infinito Blockchain Platform API token. Infinito Blockchain Platform (IBP) is a platform support integrate with multi Blockchain networks by one interface.

- After getting enough necessary information from the Moonstake, you can follow example in this SDK to familiar with staking process.

# Structure of SDK
- The SDK contains two main modules:
    - Firstly, a wallet module manages blockchain key pairs, create transaction raw, sign transaction.
    - To collect data for transaction creation and broadcast transaction, you can use API module. At the first time, this SDK only uses IBP and will be integrated more different providers in future.

# Staking flow
- Get staking info
- Make staking blockchain transaction
- Make a tracking voting request to Moonstake in order to remark

# Examples
- Developer can see many examples how to use SDK on examples folder.

- Configure API keys

```javascript
const { wallet } = require('@moonstake/moonstakejs');

// https://platform.infinito.io/
const ipbConfig = {
  apiKey: '<-- YOUR INFINITO BLOCKCHAIN PLATFORM API KEY -->',
  secret: '<-- YOUR INFINITO BLOCKCHAIN PLATFORM SECRET KEY -->'
};

// https://moonstake.io/
const moonstakeConfig = {
  apiKey: '<-- YOUR MOONSTAKE API KEY -->',
  secret: '<-- YOUR MOONSTAKE SECRET KEY -->'
};
```

- Example for ADA staking

```javascript
async function main () {
    // Initialize wallet
    let adaWallet = new wallet.ADA({
        mnemonic: '<-- YOUR MNEMONIC -->'
    });

    // Initialize IBP api
    adaWallet.initIBPApi(ipbConfig);
    // Initialize Moonstake api
    adaWallet.initMoonstakeApi(moonstakeConfig);

    // Set memo
    adaWallet.setMemo('<-- YOUR PARTNER MEMO -->');

    // Create and send staking transaction
    await adaWallet.createAndSendStakingTx();

    // Create and send claiming reward transaction
    await adaWallet.createAndSendClaimRewardTx();
}

main().catch(console.error).finally(() => process.exit());
```

- Example for TEZOS staking

```javascript
async function main () {
  // Initialize wallet
  let xtzWallet = new wallet.XTZ({
    mnemonic: '<-- YOUR MNEMONIC -->'
  });
  await xtzWallet.createKeyStore();

  // Initialize Conseil api
  xtzWallet.initApi({
    conseilUrl: '<-- YOUR CONSEIL URL -->', // Default is https://conseil-prod.cryptonomic-infra.tech
    conseilApiKey: '<-- YOUR CONSEIL API KEY -->', // Get api key from https://nautilus.cloud/
    conseilNetwork: '<-- YOUR NETWORK -->', // Default is mainnet
    tezosNode: '<-- YOUR TEZOS NODE -->' // Default is https://tezos-prod.cryptonomic-infra.tech
  });
  // Initialize Moonstake api
  xtzWallet.initMoonstakeApi(moonstakeConfig);

  // Set memo
  xtzWallet.setMemo('<-- YOUR PARTNER MEMO -->');

  // Create and send staking transaction
  await xtzWallet.sendAndDelegateTx();
}

main().catch(console.error).finally(() => process.exit());
```

# API References

- Please run the following command in project folder to generate API references by jsdoc.

```
npm run jsdoc
```

# Security overview

Within the usage context of the SDK, there are two sensitive assets that need to be secured: wallet private keys and API secret keys. Leaking the private keys could lead to clients’ assets being stolen. Meanwhile, leaking the API secret keys will not impact the clients’ assets, but the privacy of the exchange. For instance, unauthorized access to the API secret keys could leak the staking information details. 

To secure the wallet private keys, the SDK performs transaction signing at the caller side (e.g., the exchange servers). There is no transmission of private keys to Moonstake’s server or elsewhere. Assuming that the exchanges’ servers are secure, it is almost impossible for  private keys being stolen via the SDK usage..

To secure the API secret keys, the connection between the caller side and Moonstake system is secured by the SSL (using https protocol), which is assumed to be secure at the time of writing). Under that assumption, the API secret keys are secured.

An additional security layer could be applied at the Moonstake system to reinforce the security of the API secret keys. This is to whitelist IP addresses for particular API secret keys. In other words, API calls associated with particular secret keys should originate from pre-registered IP(s).