New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@coolwallet/bsc

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coolwallet/bsc

Coolwallet BSC sdk

  • 1.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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

FAQs

Package last updated on 09 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc