1.1.7 • Published 1 year ago

@coolwallet/bsc v1.1.7

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

CoolWallet Binance Smart Chain (BSC) SDK

Typescript library with support for the integration of BSC for third party application, include the functionalities of generation of addresses and signed transactions.

Install

npm install @coolwallet/bsc

Usage

import BSC from '@coolwallet/bsc'
import { crypto } from '@coolwallet/core';
import { createTransport } from '@coolwallet/transport-web-ble';

const bsc = new BSC();

const transport = await createTransport();

const { privateKey: appPrivateKey } = crypto.key.generateKeyPair();

const appId = 'appId that had been registered by wallet';

const addressIndex = 0;

const address = await bsc.getAddress(transport, appPrivateKey, appId, addressIndex);

const transaction = {
    nonce: "0x87",
    gasPrice: "0x12a05f200",
    gasLimit: "0xcf08",
    to: "0x8A1628c2397F6cA75579A45E81EE3e17DF19720e",
    value: "xe8d4a51000",
    data: "",
    chainId: 56
}

const signTxData = {
    transport,
    appPrivateKey,
    appId,
    transaction,
    addressIndex
}

const normalTx = await bsc.signTransaction(signTxData);

const bep20Transaction = {
    nonce: "0x87",
    gasPrice: "0x12a05f200",
    gasLimit: "0x5208",
    to: "0x55d398326f99059ff775485246999027b3197955",
    value: "0x0",
    data: "0xa9059cbb000000000000000000000000BDCc4DBd6",
    chainId: 56,
    option: {
      symbol: "USDT",
      unit: "18"
    }
}

const bep20SignTxData = {
    transport,
    appPrivateKey,
    appId,
    transaction: bep20Transaction,
    addressIndex
}

const bep20Tx = await bsc.signBEP20Transaction(bep20SignTxData);

Methods

getAddress

Description

The address generated is compatible to BIP44 with account and change set to 0, which means calling getAddress with addressIndex = i will get the address of folllowing BIP44 path:

m/44'/60'/0'/0/{i}

In the design of current hardware, we only support path m/44'/60'/0'/0/{i} for speed optimization. This might change in the future and we will then open a more general interface to deal with custom path.

async getAddress(
    transport: types.Transport,
    appPrivateKey: string,
    appId: string,
    addressIndex: number
): Promise<string>

Arguments

ArgDescriptionTypeRequired
transportObject to communicate with CoolWallet deviceTransportTrue
appPrivateKeyPrivate key for the connected applicationstringTrue
appIdID for the connected applicationstringTrue
addressIndexThe from address index in BIP44 derivationnumberTrue

signTransaction

Description

Sign BSC Transaction. If the transaction has non-empty data field, the card will display SMART instead of transfering amount.

async signTransaction(signTxData: types.signTx)

signTx Arguments

ArgDescriptionTypeRequired
transportObject to communicate with CoolWallet deviceTransportTrue
appPrivateKeyPrivate key for the connected applicationstringTrue
appIdID for the connected applicationstringTrue
transactionEssential information/property for BSC TransactionTransactionTrue
addressIndexThe from address index in BIP44 derivationnumberTrue
publicKeyPublic key of the from addressstringTrue
confirmCBCallback of confirmation data to the connected applicationFunctionFalse
authorizedCBCallback of authorized transaction data to the connected applicationFunctionFalse

signMessage

Description

Perform BSC personal_sign.

async signMessage(signMsgData: types.signMsg): Promise<string> 

signMsg Arguments

ArgDescriptionTypeRequired
transportObject to communicate with CoolWallet deviceTransportTrue
appPrivateKeyPrivate key for the connected applicationstringTrue
appIdID for the connected applicationstringTrue
messageMessage to signstringTrue
addressIndexThe from address index in BIP44 derivationnumberTrue
confirmCBCallback of confirmation data to the connected applicationFunctionFalse
authorizedCBCallback of authorized data to the connected applicationFunctionFalse

signTypedData

Description

Perform BSC sign_typed_data.

async signTypedData(typedData: types.signTyped): Promise<string>

signTyped Arguments

ArgDescriptionTypeRequired
transportObject to communicate with CoolWallet deviceTransportTrue
appPrivateKeyPrivate key for the connected applicationstringTrue
appIdID for the connected applicationstringTrue
typedDataTyped structured data to be signedanyTrue
addressIndexThe from address index in BIP44 derivationnumberTrue
confirmCBCallback of confirmation data to the connected applicationFunctionFalse
authorizedCBCallback of authorized data to the connected applicationFunctionFalse
1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.10

2 years ago

1.0.7

2 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.2-beta.0

3 years ago

1.0.1

3 years ago

1.0.1-beta.0

3 years ago