# rn-wallet-sdk-test

> react native wallet sdk by namnh270

Latest version **1.1.0** (published 2020-03-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install rn-wallet-sdk-test
pnpm add rn-wallet-sdk-test
yarn add rn-wallet-sdk-test
bun add rn-wallet-sdk-test
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-03-05 |
| First published | 2019-09-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 44.2 KB |
| Known vulnerabilities | 0 (+36 in 1 direct dependencies) |
| Install scripts | no |
| Author | Nam Nguyen |
| Maintainers | namnh270 |
| Keywords | blockchain, sdk, react-native |

## Links

- npm: https://www.npmjs.com/package/rn-wallet-sdk-test
- Repository: git@gitlab-new.bap.jp:namnh/react-native-wallet-sdk
- npm.io page: https://npm.io/package/rn-wallet-sdk-test

## Dependencies (7)

- [web3](https://npm.io/package/web3.md) ^1.2.4
- [sha.js](https://npm.io/package/sha.js.md) ^2.4.11
- [node-forge](https://npm.io/package/node-forge.md) ^0.9.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.0.0
- [react-native-bip39](https://npm.io/package/react-native-bip39.md) ^2.3.0
- [react-native-crypto-js](https://npm.io/package/react-native-crypto-js.md) ^1.0.0
- [react-native-randombytes](https://npm.io/package/react-native-randombytes.md) ^3.5.3

## Recent versions

- 1.1.0 (latest) — 2020-03-05
- 1.0.9 — 2020-03-05
- 1.0.8 — 2019-11-22
- 1.0.7 — 2019-11-21
- 1.0.6 — 2019-11-14
- 1.0.5 — 2019-11-13
- 1.0.4 — 2019-11-06
- 1.0.3 — 2019-10-02
- 1.0.2 — 2019-10-02
- 1.0.1 — 2019-10-01
- 1.0.0 — 2019-09-26

## README

# WALLET SDK
## Install package
1. run ```npm install rn-wallet-sdk-test``` or ```yarn add rn-wallet-sdk-test```
2. To use this package, you will need to install [React Native Nodeify](https://www.npmjs.com/package/rn-nodeify)
to use node core modules and npm modules that use them in your React Native app by the following command line
```npm install rn-nodeify``` or ```yarn add rn-nodeify```
3. run ```rn-nodeify --install --hack``` if you use npm, add ```--yarn``` if you want to use yarn
4. run ```cd ios && pod install && cd ..``` to install package on iOS
5. you can run your project now ```react-native run-ios``` or ```react-native run-android```

## API
### Wallet
- `generateMnemonic()`
    + Returns:
        + Success: mnemonic 24 words.
        + Error: 'Generate mnemonic failed'.
- `generateWallet(mnemonic, password)`
    + Parameters:
        + mnemonic: mnemonic 24 words.
        + password: password for encrypting private key and mnemonic.
    + Returns:
        + Success: (Promise) wallet object with public key, address, encryption of mnemonic and encryption of private key.
        + Error: 
            + 'Get address from public key failed'.
            + 'Encrypt failed'.
            + Others.
- `encryptString(privateString, password)`
    + Parameters:
        + privateString: private string will be encrypted.
        + password: password will be used to when encrypting.
    + Return :
        + Success: encryption of private string with password.
        + Error: 'Encrypt failed'.
- `decryptString(cipherText, password)`
    + Parameters:
        + cipherText: encryption of private string.
        + password: password is used for decryption.
    + Return :
        + Success: decryption of cipherText with password.
        + Error: 'Encrypt failed'.
- `restoreWallet(mnemonic, password)`
    + Parameters:
        + mnemonic: mnemonic passphrase will be used to restore wallet, examples: `abandon abandon ...`
        + password: password will be used to encrypt private key.
    + Returns: 
        + Success: (Promise) wallet object with public key, address, encryption of mnemonic and encryption of private key.
        + Error: 
            + 'Get address from public key failed'.
            + 'Encrypt failed'.
            + Others.
- `getAddressFromPublicKey(publicKey)`
    + Parameters:
        + publicKey: public key of wallet.
    + Returns:
        + Success: address from public key.
        + Error: 'Get address from public key failed'.
- `getPublicKeyOffline(privateKey, curveType)`
    + Parameters:
        + privateKey: private key of wallet.
        + curveType: type of curve algorithm.
    + Returns:
        + Success: public key from private key.
        + Error: null.
- `signatureOffline(txData, privateKey)`
    + Parameters:
        + txData: data will be signed.
        + privateKey: private key will be used to signing txData.
    + Returns:
        + Success: signature.
        + Error: null.
- `verifyTransaction(tx)`
    + Parameters:
        + tx: transaction need verifying.
    + Returns:
        + True: if transaction is valid.
        + False: otherwise.

### API
- Properties
   + api: uri of api server.
- Constructor
   + `new API(api)` : create new instance API.
- Methods
    - `getBlock(height)`
        + Parameters: 
            + height: height of block.
        + Returns: 
            + Success:(Promise) block at height.
            + Error: 'Get block failed'.
    - `getTransaction(txHash)`
        + Parameters:
            + txHash: hash of transaction.
        + Returns:
            + Success:(Promise) The transaction has transaction hash as input. 
            + Error: 'Get transaction failed'.
    - `getAccountDetail(address)`
        + Parameters:
            + address: address of account (hex string, length = 40).
        + Returns: 
            + Success: details of account has address as input.
            + Error: 'Get details account failed'.
    - `getHistoryTransaction({address, page, limit = 10})`
        + Parameters
            + address: address want to get history
            + page: number of pages
            + limit: default is 10, amount of transactions will be returned in response.
        + Returns:
            + Success:(Promise) transactions of address.
            + Error: 'Get transaction history failed'.
    - `getSequence(address)`
        + Parameters:
            + address: address of account wants to get sequence number.
        + Returns:
            + Success: (Promise) sequence of address.
            + Error: 
                + 'Get sequence failed'.
                + 'Get details account failed'.
    - `getBalance(address)`
        + Parameters:
            + address: address of account wants to get balance.
        + Returns:
            + Success: (Promise) balance of address.
            + Error: 
                + 'Get balance failed'.
                + 'Get details account failed'.
    - `getPermission(address)`
        + Parameters:
            + address: address wants to get permission.
        + Returns:
            + Success: (Promise) permission of address.
            + Error: 
                + 'Get permission failed'.
                + 'Get details account failed'.
    - `getParams(method, body, headers, uri)` : static function
        + Parameters:
            + method: method of request( GET, POST, ...)
            + body: body of request
            + headers: header of request
            + uri: uri of request.
        + Returns:
            + Success: request as a JSON.
    - `sendTransaction(tx)`
        + Parameters:
            + tx: transaction will be sent to blockchain network.
        + Returns:
            + Success: (Promise) transaction hash of transaction.
            + Error: 'Send transaction failed'.
    - `getTransactionFee()`
        + Returns:
            + Success: (Promise) fee and address of receiver.
            + Error: 'Get transaction fee failed'.
    - `requestAPI(endpoint, method, body, headers)`
        + Parameters: 
            + endpoint: request will be sent to endpoint
            + method: method of request (GET, POST)
            + body: body of request
            + headers: headers of request
        + Returns:
            + Success: response of request
            + Error: 'Error when request data'

### Transaction
- Properties
    - webAPI : instance of class API
    - wallet : instance of Wallet
    - utils : instance of Utils
    - CHAINID : chain identify of blockchain.
- Constructor
    - `new Transaction(chainId, urlAPI)`
        + Parameters:
            + chainId: chain id of blockchain
            + urlAPI: uri of api server
        + Returns: instance of class Transaction    
- Methods
    - `createSendTx(from, to , amount, privateKey)`
        + Parameters:
            + from: address of sender
            + to: address of receiver
            + amount: amount of token will be sent
            + privateKey : private key of sender, which is used to sign transaction.
        + Returns:
            + Success:(Promise) transaction hash of transaction.
            + Other: Error

## Usage
```javascript
import WalletSDK from 'rn-wallet-sdk-test'

const mnemonic = WalletSDK.Wallet.generateMnemonic()
const wallet = await WalletSDK.Wallet.restoreWallet(mnemonic, password)
const wallet = await WalletSDK.Wallet.generateWallet(mnemonic, password)
const mnemonicEncrypt = WalletSDK.Wallet.encryptString(mnemonic, password)      
const mnemonic = WalletSDK.Wallet.decryptString(mnemonicEncrypt, password)      

```

## Troubleshooting
### Nodejs libraries error
If you continue install some packages on your project, please run ```rn-nodeify --install --hack``` after install them.

### @babel/plugin-proposal-throw-expressions
Install this library if your project haven't had it yet to catch throw error

run ```npm install --dev @babel/plugin-proposal-throw-expressions``` or ```yarn add --dev @babel/plugin-proposal-throw-expressions```

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