Skip to content
Branch: master
Find file History

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
__tests__
lib
src
README.md
package.json
tsconfig.json

README.md

makkii-core

Generic interfaces

Installation

$ npm install @makkii/makkii-core

Usage

import { ApiClient, KeystoreClient } from '@makkii/makkii-core';
import { AionApiClient, AionKeystoreClient, AionLedger} from '@makkii/app-aion';
import { BtcApiClient, BtcKeystoreClient } from '@makkii/app-btc';

// api client usage
const api_client = new ApiClient();
api_client.addCoin('aion', new AionApiClient({
    network: 'mainnet',
    jsonrpc: '***'
}));
api_client.addCoin('btc', new BtcApiClient({
    network: 'BTC',
    insight_api: '***'
}));
api_client.getBalance('aion', '0x...')
    .then(console.log)
    .catch(error=>console.log(error));

// keystore client usage
const keystore_client = new KeystoreClient();
keystore_client.addCoin('aion', new AionKeystoreClient());
keystore_client.addCoin('btc', new BtcKeystoreClient('BTC'));

api_client.buildTransaction(
    'aion', 
    '0x...', // from address
    '0x...', // to address
    0, // amount
    {
        gasPrice: 10,
        gasLimit: 21000,
        isTokenTransfer: false
    }
).then(function(unsignedTx) {
    keystore_client.signTransaction('aion', unsignedTx, new AionLedger(), {
        index: 0 
    }).then(function(signedTx) {
        console.log(signedTx);
    });
});

API

Table of Contents

IHardware

Extends IkeystoreSigner

Hardware wallet interface

getAccount

Get account from hardware wallet.

Parameters
  • index number index path in hd wallet

Returns Promise<LedgerKeypair> key pair

getHardwareStatus

Get hardware wallet status.

Parameters
  • params additional parameters that may affect hardware status

Returns Promise<boolean> boolean status of connect/app status.

CoinPrice

Examples

{"crypto":"AION","fiat":"USD","price":0.06133475939999999}

IApiClient

Api client interface that manages multiple chains' api client and expose all functions.

addCoin

Register an api client.

Parameters
  • coinType string a key name for the added api client, you will specify the coinType for other operations.
  • client (IsingleApiClient | IsingleApiFullClient) api client that implements IsingleApiClient or IsingleApiFullClient

Returns void

removeCoin

Remove a registered api client

Parameters
  • coinType string api client key name

Returns boolean if remove api client successfully

getBlockByNumber

Get block information by the given block number

Parameters
  • coinType string coin type name you specified in addCoin
  • blockNumber string block number. integer or hex string depends on kernel rpc implementation.

Returns Promise<any> depends on different chains' block structure

getBlockNumber

Get latest block number of the given chain

Parameters
  • coinType string coin type name you specified in addCoin

Returns Promise<any> latest block number whose type should be biginteger or hex string

getBalance

Get balance of the given account

Parameters
  • coinType string coin type name you specified in addCoin
  • address string account's public address

Returns Promise<any> balance in hex string or biginteger

getTransactionStatus

Get transation status

Parameters
  • coinType string coin type name you specified in addCoin
  • hash string transaction hash

Returns Promise<any> transaction status, depends on different api client's implementation

getTransactionExplorerUrl

Get web page url that can display transaction details.

The url should be able to access from web browser by plain HTTP GET request.

Parameters
  • coinType string coin type name you specified in addCoin
  • hash any transaction hash

Returns string web page url that display transaction details

getTransactionsByAddress

Get the given account's recent transactions by page.

Parameters
  • coinType string coin type name you specified in addCoin
  • address string account's public address
  • page number page number
  • size number how mnay transactions to get in this page
  • timestamp number?

Returns Promise<any>

buildTransaction

Build up transaction object to sign. transaction nonce should be encapsulated into transaction object.

Parameters
  • coinType string coin type name you specified in addCoin
  • from string transaction sender
  • to string amount receiver. this field isn't alway transaction's to field. if the transaction is a token transfer, transaction to field is token contract address, this field is encoded in contract method parameters.
  • value BigNumber amount value. this field isn't alwasy transaction's value field. if the transaction is a token transfer, transaction value field is zero, this field is encoded in contract method parameters.
  • options any common options could be: gas limit, gas price, contract address, is token transfer, data, etc.

Returns Promise<any>

sendTransaction

Broadcast transaction.

Parameters
  • coinType string coin type name you specified in addCoin
  • unsignedTx any unsigned transaction object. User can call buildTransaction to get unsigned transaction.
  • signer T implementation of IkeystoreSigner
  • signerParams any sign parameters for differernt implementation IkeystoreSigner

Returns Promise<any> transaction hash

sameAddress

Check if two address are the same account.

Parameters
  • coinType string coin type name you specified in addCoin
  • address1 string first address to compare
  • address2 string second address to compare

Returns boolean if two address are the same account.

getTokenIconUrl

Get token icon url.

Parameters
  • coinType string coin type name you specified in addCoin
  • tokenSymbol string token symbol
  • contractAddress string token creation contract address

Returns string token icon url

getTokenDetail

Get token details. In general token details contains: contractAddress, symbol, name, tokenDecimals

Parameters
  • coinType string coin type name you specified in addCoin
  • contractAddress string token contract address

Returns Promise<any> toke details

getAccountTokenTransferHistory

Get token transfer history of the given account. For pagination, user could use combination of page + size or timestamp + size.

Parameters
  • coinType string coin type name you specified in addCoin
  • address string account address
  • symbolAddress string token contract address
  • page number? page number
  • size number? number of transfer records in this page
  • timestamp number? get transfer records earlier than this timestamp

Returns Promise<any>

getAccountTokens

Get tokens whose balance > 0 for the given account.

Parameters
  • coinType string coin type name you specified in addCoin
  • address string account address

Returns Promise<any>

getAccountTokenBalance

Get token balance of the given account

Parameters
  • coinType string coin type name you specified in addCoin
  • contractAddress string token contract address
  • address string account address

Returns Promise<any>

getTopTokens

Get top tokens.

Parameters
  • coinType string coin type name you specified in addCoin
  • topN number? number of tokens to get

Returns Promise<any>

searchTokens

Search token by keyword.

Parameters
  • coinType string coin type name you specified in addCoin
  • keyword string keyword

Returns Promise<any>

getCoinPrices

Get coin prices

Parameters
  • currency string fiat currency

Returns Promise<Array<CoinPrice>> array of coin price

IsingleKeystoreClient

Interface that handle key store operations.

signTransaction

Sign transaction.

Parameters
  • tx any transaction object
  • signer T singer that implement [[IkeystoreSigner]] interface
  • signerParams any sign parameters

Returns Promise<any> signed transaction

generateMnemonic

Randomly generate 12 words mnemonic.

Returns string 12 words mnemonic

getAccountFromMnemonic

Get specified account from mnemonic phrase

Parameters
  • address_index number address index in hierachy determinist wallet
  • mnemonic string mnemonic phrase

Returns Promise<any> account

getAccountFromHardware

Get account from hardware wallet.

Parameters
  • index number indexPath in hardwallet wallet
  • hardware IHardware harware wallet that implements IHardware interface

Returns Promise<any> account

recoverKeyPairByPrivateKey

Recover account from private key.

Parameters
  • priKey string private key
  • options any? options that affect recovery algorithm

Returns Promise<any> key pair

validatePrivateKey

Check if private key is valid.

Parameters

Returns boolean if private key is valid

validateAddress

Check if address is valid.

Parameters
  • address string address to validate

Returns boolean if address is valid.

Token

token

Keypair

Key pair

LedgerKeypair

Ledger key pair

IkeystoreSigner

Interface for sign transaction.

signTransaction

Sign transaction.

Parameters
  • tx any transaction object to sign
  • params any sign parameters such as private key or index path

Returns Promise<SignedTx> signed transaction

IkeystoreClient

Keystore interface that manages multiple keystore clients and expose all functions.

addCoin

Register keystore client.

Parameters
  • coinType string a key name for the added keystore client, you will specify the coinType for other operations.
  • client IsingleKeystoreClient

Returns void

removeCoin

Remove a registered keystore client

Parameters
  • coinType string keystore client key name

Returns boolean if remoe keystore client successfully.

signTransaction

Sign transaction.

Parameters
  • coinType string coin type name you specified in addCoin
  • tx any transaction object to sign
  • signer T signer that implement [[IkeystoreSigner]] interface
  • signerParams any sign parameters

Returns Promise<any> signed transaction

generateMnemonic

Randomly generate 12 words mnemonic phrases.

Parameters
  • coinType string coin type name you specified in addCoin

Returns string 12 words mnemonic phrases

recoverKeyPairByPrivateKey

Recover key pair from private key

Parameters
  • coinType string coin type name you specified in addCoin
  • priKey string private key
  • options any? options required by recovery algorithm

Returns Promise<any> recovered account

validatePrivateKey

Check if private key is valid.

Parameters
  • coinType string coin type name you specified in addCoin
  • privateKey (string | Buffer) private key

Returns boolean if private key is valid.

validateAddress

Check if an address is valid

Parameters
  • coinType string coin type name you specified in addCoin
  • address string address to be validated

Returns boolean if an address is valid.

getAccountFromMnemonic

Get specified account from mnemonic phrase

Parameters
  • coinType string coin type name you specified in addCoin
  • ddress_index number
  • mnemonic string mnemonic phrase
  • address_index address index in hierachy determinist wallet

Returns Promise<any> account

getAccountFromHardware

Get account from hardware wallet.

Parameters
  • coinType string coin type name you specified in addCoin
  • index number indexPath in hardwallet wallet
  • hardware IHardware harware wallet that implements IHardware interface

Returns Promise<any> account

IsingleApiClient

Interface that defines basic api client functions: network configuration, block, transaction, balance, etc.

config

Configuration property.

Type: any

symbol

Coin symbol eg: 'AION', 'BTC' ...

Type: string

updateConfiguration

Update configuration.

Parameters
  • config any configuration

Returns void

getNetwork

get network name.

Returns string network name

getBlockByNumber

Get block information by the given block number

Parameters
  • blockNumber string block number. integer or hex string depends on kernel rpc implementation.

Returns Promise<any> depends on different chains' block structure

getBlockNumber

Get latest block number of the given chain

Returns Promise<any> latest block number whose type should be biginteger or hex string

getTransactionStatus

Get transation status

Parameters
  • hash string transaction hash

Returns Promise<any> transaction status, depends on different api client's implementation

getTransactionExplorerUrl

Get web page url that can display transaction details.

The url should be able to access from web browser by plain HTTP GET request.

Parameters
  • hash any transaction hash

Returns string web page url that display transaction details

getBalance

Get balance of the given account

Parameters
  • address string account's public address

Returns Promise<any> balance in hex string or biginteger

getTransactionsByAddress

Get the given account's recent transactions by page.

Parameters
  • address string account's public address
  • page number page number
  • size number how mnay transactions to get in this page
  • timestamp number?

Returns Promise<any>

buildTransaction

Build up transaction object to sign. transaction nonce should be encapsulated into transaction object.

Parameters
  • from string transaction sender
  • to string amount receiver. this field isn't alway transaction's to field. if the transaction is a token transfer, transaction to field is token contract address, this field is encoded in contract method parameters.
  • value BigNumber amount value. this field isn't alwasy transaction's value field. if the transaction is a token transfer, transaction value field is zero, this field is encoded in contract method parameters.
  • options any common options could be: gas limit, gas price, contract address, is token transfer, data, etc.

Returns Promise<Transaction>

sendTransaction

Broadcast transaction.

Parameters
  • unsignedTx any unsigned transaction object. User can call [[buildTransaction]] to get unsigned transaction.
  • signer T implementation of IkeystoreSigner
  • signerParams any sign parameters for differernt implementation IkeystoreSigner

Returns Promise<any> transaction hash

sameAddress

Check if two address are the same account.

Parameters
  • address1 string first address to compare
  • address2 string second address to compare

Returns boolean if two address are the same account.

IsingleApiTokenClient

Interface that defines token related functions.

tokenSupport

is token supported

Type: boolean

getTokenIconUrl

Get token icon url.

Parameters
  • tokenSymbol string token symbol
  • contractAddress string token creation contract address

Returns string token icon url

getTokenDetail

Get token details. In general token details contains: contractAddress, symbol, name, tokenDecimals

Parameters
  • contractAddress string token contract address

Returns Promise<any> toke details

getAccountTokenTransferHistory

Get token transfer history of the given account. For pagination, user could use combination of page + size or timestamp + size.

Parameters
  • address string account address
  • cointractAddress string
  • page number? optional, page number
  • size number? optional, number of transfer records in this page
  • timestamp number? optional, get transfer records earlier than this timestamp
  • symbolAddress token contract address

Returns Promise<any>

getAccountTokens

Get tokens whose balance > 0 for the given account.

Parameters
  • address string account address

Returns Promise<any>

getAccountTokenBalance

Get token balance of the given account

Parameters
  • contractAddress string token contract address
  • address string account address

Returns Promise<any>

getTopTokens

Get top tokens.

Parameters
  • topN number? number of tokens to get

Returns Promise<any>

searchTokens

Search token by keyword.

Parameters

Returns Promise<any>

IsingleApiFullClient

Extends IsingleApiClient, IsingleApiTokenClient

Interface that defines basic api client and token functions.

You can’t perform that action at this time.