rn-wallet-sdk-test
react native wallet sdk by namnh270
Last updated 7 months ago by namnh270 .
ISC · Repository · Original npm · Tarball · package.json
$ cnpm install rn-wallet-sdk-test 
SYNC missed versions from official npm registry.

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 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

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

Current Tags

  • 1.1.0                                ...           latest (7 months ago)

11 Versions

  • 1.1.0                                ...           7 months ago
  • 1.0.9                                ...           7 months ago
  • 1.0.8                                ...           10 months ago
  • 1.0.7                                ...           10 months ago
  • 1.0.6                                ...           10 months ago
  • 1.0.5                                ...           10 months ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |