1.1.5 • Published 5 months ago

@coolwallet/dot v1.1.5

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

CoolWallet Polkadot (DOT) SDK

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

Install

npm install @coolwallet/dot

Usage

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

const dot = new DOT();

const transport = await createTransport();

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

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

const address = await dot.getAddress(transport, appPrivateKey, appId, 0);

const normalTransaction = {
    fromAddress: "13v5sr4E8TLLfnA6ytPQwkA5HsEivYFpvaBATj5dDyDa38mY",
    blockHash: "0x5c697847b25d385178aa150d29e5ce212339c5624183f74bdf45f4912c89749a",
    blockNumber: "999",
    era: "256",
    genesisHash: "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3",
    nonce: "33",
    specVersion: "666",
    tip: "22",
    transactionVersion: "333",
    version: 4,
    method: {
        destAddress: "14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3",
        value: 10000 
    }
};

const signTxData = {
  transport,
  appPrivateKey,
  appId,
  addressIndex: 0,
  transaction: normalTransaction
}

const normalTx = await dot.signTransaction(signTxData);

Methods

getAddress

Description

Get address by address index.

The DOT 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 path:

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

In the design of current hardware, we only support path m/44'/354'/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

Sign Transaction

Description

CoolWallet currently support various signing methods and contracts based on the type of the transaction. The SignTxData and dotTransaction arguments are the essentail data fields for DOT transactions. Depends on the type of transaction, the extended arguments may vary.

SignTxData 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
confirmCBCallback of confirmation data to the connected applicationFunctionFalse
authorizedCBCallback of authorized transaction data to the connected applicationFunctionFalse

dotTransaction Arguments

ArgDescriptionTypeRequired
fromAddressThe from address of the transactionstringTrue
blockHashThe hash of the checkpoint blockstringTrue
blockNumberThe number of the checkpoint blockstringTrue
eraThe number of blocks after the checkpoint for which a transaction is validstringTrue
genesisHashThe genesis hash of the chainstringTrue
nonceThe nonce of the transactionstringTrue
specVersionThe current spec version for the runtimestringTrue
tipThe tip to increase transaction prioritystringTrue
transactionVersionThe current version for transaction formatstringTrue
versionVersion numbernumberTrue

The extended arguments may vary depend on the type of the transaction. The transaction can be for transfering (signTransaction) or staking (signBondTransaction, signBondExtraTransaction, signUnbondTransaction, signNominateTransaction, signWithdrawUnbondedTransaction, signChillTransaction) purposes.

signTransaction

Description

Sign DOT Transfer Transaction

async signTransaction(signTxData: types.NormalTransferData) 

NormalMethod Arguments

ArgDescriptionTypeRequired
destAddressDestination addressstringTrue
valueValue to transferstringTrue
1.1.5

5 months ago

1.1.4

6 months ago

1.1.5-beta.1

6 months ago

1.1.5-beta.0

6 months ago

1.1.5-beta.3

6 months ago

1.1.5-beta.2

6 months ago

1.1.3

2 years ago

1.1.1

2 years ago

1.0.6

3 years ago

1.0.6-beta.0

3 years ago

1.0.5

3 years ago

1.0.5-beta.0

3 years ago

1.0.4

3 years ago

1.0.4-beta.0

3 years ago

1.0.3

3 years ago

1.0.2-beta.5

3 years ago

1.0.2

3 years ago

1.0.0

3 years ago

1.0.1-beta.2

3 years ago

1.0.1-beta.1

3 years ago

1.0.1-beta.0

3 years ago

1.0.2-beta.4

3 years ago

1.0.1-beta.3

3 years ago

0.1.0

3 years ago

0.1.0-beta.13

3 years ago

0.1.0-beta.12

3 years ago

0.1.0-beta.11

3 years ago

0.1.0-beta.10

3 years ago

0.1.0-beta.9

3 years ago

0.1.0-beta.7

3 years ago

0.1.0-beta.8

3 years ago

0.1.0-beta.6

3 years ago

0.1.0-beta.5

3 years ago

0.1.0-beta.4

3 years ago

0.1.0-beta.3

3 years ago

0.1.0-beta.2

3 years ago