1.1.21 • Published 7 months ago

@coolwallet/eth v1.1.21

Weekly downloads
22
License
Apache-2.0
Repository
github
Last release
7 months ago

CoolWallet Ethereum SDK

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

Install

npm install @coolwallet/eth

Usage

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

const eth = new ETH();

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 eth.getAddress(transport, appPrivateKey, appId, addressIndex);

const transaction = {
    nonce: "0x21d",
    gasPrice: "0x59682f00",
    gasLimit: "0x5208",
    to: "0x81bb32e4A7e4d0500d11A52F3a5F60c9A6Ef126C",
    value: "0x5af3107a4000",
    data: "0x00",
    chainId: 1
}

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

const normalTx = await eth.signTransaction(signTxData);

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

const erc20Transaction = {
    nonce: "0x85",
    gasPrice: "0x23a427985a",
    gasLimit: "0x72c2",
    to: "0xe41d2489571d322189246dafa5ebde1f4699f498",
    value: "0x0",
    data: "0x00",
    chainId: 1,
    option: {
      symbol: "USDT",
      unit: "6"
    }
}

const erc20SignTxData = {
    transport,
    appPrivateKey,
    appId,
    transaction: erc20Transaction,
    addressIndex
}

const erc20Tx = await eth.signERC20Transaction(erc20SignTxData);

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 Ethereum Transaction. If the transaction has non-empty data field, the card will display SMART instead of transfering amount.

async signTransaction(signTxData: types.signTx): Promise<string>

signTx Arguments

ArgDescriptionTypeRequired
transportObject to communicate with CoolWallet deviceTransportTrue
appPrivateKeyPrivate key for the connected applicationstringTrue
appIdID for the connected applicationstringTrue
transactionEssential information/property for Ethereum TransactionTransactionTrue
addressIndexThe from address index in BIP44 derivationnumberTrue
publicKeyPublic key of the from addressstringTrue

signMessage

Description

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

signTypedData

Description

Perform ethereum 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
1.1.21

7 months ago

1.1.20

10 months ago

1.1.19

11 months ago

1.1.16

12 months ago

1.1.15

12 months ago

1.1.14

1 year ago

1.1.18

11 months ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.9

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.20

2 years ago

1.1.1

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10-beta.2

3 years ago

1.0.10

3 years ago

1.0.10-beta.0

3 years ago

1.0.10-beta.1

3 years ago

1.0.9

3 years ago

1.0.9-beta.1

3 years ago

1.0.9-beta.2

3 years ago

1.0.9-beta.0

3 years ago

1.0.8-beta.1

3 years ago

1.0.8

3 years ago

1.0.8-beta.0

3 years ago

1.0.7

3 years ago

1.0.7-beta.0

3 years ago

1.0.6

3 years ago

1.0.6-beta.3

3 years ago

1.0.6-beta.1

3 years ago

1.0.6-beta.0

3 years ago

1.0.6-beta.2

3 years ago

1.0.5

3 years ago

1.0.4-beta.7

3 years ago

1.0.4-beta.8

3 years ago

1.0.4

3 years ago

1.0.4-beta.1

3 years ago

1.0.4-beta.2

3 years ago

1.0.3-beta.2

3 years ago

1.0.4-beta.3

3 years ago

1.0.4-beta.4

3 years ago

1.0.3-beta.4

3 years ago

1.0.4-beta.5

3 years ago

1.0.3-beta.3

3 years ago

1.0.4-beta.6

3 years ago

1.0.3-beta.1

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

3 years ago

1.0.1-beta.0

3 years ago

0.1.0

3 years ago

0.1.0-beta.21

3 years ago

0.1.0-beta.22

3 years ago

0.1.0-beta.20

3 years ago

0.1.0-beta.19

3 years ago

0.1.0-beta.18

3 years ago

0.1.0-beta.17

3 years ago

0.1.0-beta.16

3 years ago

0.1.0-beta.15

3 years ago

0.1.0-beta.14

3 years ago

0.1.0-beta.13

3 years ago

0.1.0-beta.12

3 years ago

0.1.0-beta.10

3 years ago

0.1.0-beta.11

3 years ago

0.1.0-beta.9

3 years ago

0.1.0-beta.8

3 years ago

0.1.0-beta.7

4 years ago

0.1.0-beta.6

4 years ago

0.1.0-beta.5

4 years ago

0.1.0-beta.4

4 years ago

0.1.0-beta.3

4 years ago

0.1.0-beta.2

4 years ago

0.1.0-beta.1

4 years ago

0.1.0-beta.0

4 years ago