EsecuBit-wallet-sdk
Introduction
EsecuBit Wallet SDK is a JavaScript SDK for EsecuBit digital currency wallet. Supporting Apps: EsecuBit React Native Wallet (Android, iOS), EsecuBit Chrome Wallet.
EsecuBit Wallet SDK supports both hardware wallet (EsecuBit hardware wallet) and software wallet (default software wallet). But the security of software wallet is not guaranteed, the seed is stored in plain text in database. It's just for test usage.
EsecuBit Wallet SDK supports mainnet and testnet (default testnet).
EsecuBit Wallet SDK using ES6/7 features.
Supported Digital Currencies
- Bitcoin (BTC)
- Ethereum (ETH)
- EOS (EOS)
COMING SOON
- Bitcoin Cash (BCH)
- Litecoin (LTC)
- Dash (DASH)
- ZCash (ZEC)
- Ripple (XRP)
Blockchain Browser API Provider
BTC:
- blockchain.com (default)
- chain.so (not fully tested)
ETH:
EOS:
Other API Provider
BTC Fee:
ETH Fee:
Digital Currency Exchange:
Import SDK
npm install esecuBit-wallet-sdk // latest released version// ornpm install git+ssh://github.com/EsecuBit/EsecuBit-wallet-sdk.git // newest version on GitHub //
Usage
1. SDK Configuration
Configuration should do before new EsWallet()
.
// configure it before call EsWalletDtestjsWallet = true // use javascript wallet, default false (hardware wallet)Dtestcoin = true // use testnet, dafault false (mainnet) // configure supported coins, default supports BTC, ETH, EOSD { return Dtestcoin ? DcointestbtcTestNet3 DcointestethRinkeby DcointesteosJungle : Dcoinmainbtc Dcoinmaineth Dcoinmaineos} // configure recover coins on first init, deault follows D.supportedCoinTypesD D
2. Connect Device and Initialize
let esWallet = // return wallet singleton esWallet esWallet
3. Initialize without Connecting Device
let esWallet = // return wallet singleton esWallet
4. Use Wallet after Initialization
let coinTypes = EsWallet// return supported coins. e.g. ['btc', 'eth'] or ['btc_testnet3', 'eth_rinkeby'] for testnet// available coins are listed in D.coin let legals = EsWallet// return supported legals. e.g. ['USD', 'EUR', 'CNY', 'JPY']// available legals are listed in D.unit.legal let esWallet = // return wallet singletonlet walletInfo = await esWallet// return version info of wallet let value = esWallet// convert value from A unit to B unit. support convertion of digital <=> legal let coinTypes = await esWallet// return available coin types that can generate new account. only the first account and // account that last account has transations can be created.let account = await esWallet// return new account if the coin type is available to create new account
5. Use Accounts after Initialization
let accounts = await esWalletlet account = accounts0// get all accounts that may have different coin types await account// check out new transaction for this account let txInfos = await account// get all transactions of this account let address qrAddress = await account// get address that can receive coins. qrAddress is data show in QR code let fee = account// return suggested fee level e.g. {fast: 1, normal: 2, ecomic: 4}// EOS transfer transaction without fee, so it's unavailable for EOS. account// checkout whether address is legal.// btc supported address: P2PBK address, P2SH address, P2PK (xpub/tpub)// throw D.error.noAddressCheckSum if eth address don't have checksum(all upper/lower case)// throw D.error.invalidAddressChecksum if address checksum incorrect// throw D.error.invalidAddress if address has invalid format // send transaction // BTClet details = feeRate: '1' // santoshi per byte outputs: address:'mqaNwCJA6GU6X8wM48p8QxPJ8aghYaK7e1' // testnet address value: '100000' // santoshi // ETHdetails = feeRate: '1000000000' // wei outputs: address:'0x641C134F546A138805191866877E74f84aeef194' value: '1000000000000000' // wei let prepareTx = await account// return the fee that need to pay and utxos that going to uselet signedTx = await account// return the signedTx that going to boardcast// you need to input pin and confirm the transaction if you are using hardware walletawait account// boardcast the tx // for EOS onlylet isRegistered = accountlet permission = await account// Return permissions that relative to this account. Return default permissions// if isRegistered = false. // check EOS permission changelet permissionChanged = await account // If the threhold or weight of permissions is changed, permissionChanged will// also be true. but these changes don't need device confirmation so the callback// won't return anything. These changes are stored in local database.if permissionChanged console else console // EOS transactiondetails = type: 'tokenTransfer' // see D.coin.params.eos.actionTypes token: 'EOS' // only support EOS token for now, will add custom token function in future outputs: account:'esecubit1111' value: '2.12' let prepareTx = await account// return the raw transaction to be signed // or use specific interfaceprepareTx = await account// others like: prepareDelegate, prepareBuyRam, prepareVote, prepareOther are also supported let signedTx = await account// return the signedTx that going to boardcast// you need to input pin and confirm the transaction if you are using hardware walletawait account// boardcast the tx
Layout
.
├── build // webpack build config
├── dist
│ └── eswallet.js // compiled sdk (no ES6/7)
├── src
│ ├── sdk
│ │ ├── D.js // constant and utils
│ │ ├── EsWallet.js // implementation of Wallet
│ │ ├── Provider.js // define the implementation class of database, transmitter and driver
│ │ ├── Settings.js // storing app preferences
| | ├── account
│ │ | ├── BtcAccount.js // implementation of BTC account management
│ │ | ├── BtcCoinSelect.js // algorithm of selecting utxos
│ │ │ ├── EthAccount.js // implementation of ETH account management
│ │ │ ├── EOSAccount.js // implementation of EOS account management
│ │ │ └── IAccount.js // base class of account management
│ │ ├── data
│ │ │ ├── CoinData.js // blockchain data manager
│ │ │ ├── database
│ │ │ │ ├── IDatabase.js // base class of database
│ │ │ │ └── IndexedDB.js // implementation of database based on IndexedDB
│ │ │ └── network
│ │ │ ├── BlockChainInfo.js // implementation btc blockchain network based on blockchain.info
│ │ │ ├── ChainSo.js // implementation BTC blockchain network based on chain.so
│ │ │ ├── EtherScanIo.js // implementation ETH network based on etherscan.io
│ │ │ ├── EosPeer.js // implementation EOS network based on standard EOS peer
│ │ │ ├── ICoinNetwork.js // base class of blockchain network
│ │ │ ├── exchange
│ │ │ │ └── ExchangeCryptoCompareCom.js // getting exchange from cryptocompare.com
│ │ │ └── fee
│ │ │ ├── EthGasStationInfo.js // getting ETH suggested fee from ethgasstation.info
│ │ │ └── FeeBitCoinEarn.js // getting BTC suggested fee from bitcoinearn.com
│ │ └── device
│ │ ├── CoreWallet.js // the device managerment interface
│ │ └── implements
│ │ ├── JsWallet.js // implementation of software wallet
│ │ ├── S300Wallet.js // implementation of MK12/S300 hardware wallet
│ │ ├── NetBankWallet.js // implementation of native hardware wallet
│ │ ├── transmitter
│ │ │ ├── CcidTransmitter.js // transmit command to device through CCID protocol
│ │ │ ├── HidTransmitter.js // transmit command to device through HID protocol
│ │ │ ├── JsTransmitter.js // JsWallet virtual transmitter
│ │ │ ├── MockTransmitter.js // mock transmitter
│ │ │ ├── io
│ │ │ │ ├── ChromeHidDevice.js // Chrome HID driver
│ │ │ │ ├── ChromeUsbDevice.js // Chrome USB driver (unreliable)
│ │ │ │ └── MockDevice.js // mock driver
│ │ ├── protocol
│ │ │ ├── Authenticate.js // implementation of Bluetooth device custom authenticate protocol
│ │ │ ├── Crypto.js // implementation of cyrpto algorithms
│ │ │ ├── EosFcBuffer.js // EOS transaction serial protocol
│ │ │ ├── HandleShare.js // hardware device SSL
│ │ │ └── jsencrypt.js // implementation of RSA encryption
│ └── test // test files (unreliable for now)
└── test // mocha test framework