dpos-ledger-api
Options
All
  • Public
  • Public/Protected
  • All
Menu

Communication Protocol class.

example

import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
import { DposLedger, LedgerAccount } from 'dpos-ledger-ts';

const account = new LedgerAccount();
TransportNodeHid.create()
  .then((transport) => new DposLedger(transport))
  .then((instance) => instance.getPubKey(account));
  .then(({publicKey}) => console.log(`pubKey: ${publicKey}`);

Hierarchy

  • DposLedger

Index

Constructors

constructor

  • Parameters

    • transport: ITransport

      transport class.

    • Default value chunkSize: number = 240

      lets you specify the chunkSize for each communication.
      DO not change if you don't know what you're doing.

    Returns DposLedger

Methods

exchange

  • exchange(hexData: string | Buffer | number | Array<string | number | Buffer>): Promise<Buffer[]>
  • Raw exchange protocol handling. It's exposed but it is meant for internal usage only.

    Parameters

    • hexData: string | Buffer | number | Array<string | number | Buffer>

    Returns Promise<Buffer[]>

    Raw response buffers.

getPubKey

  • getPubKey(account: LedgerAccount | Buffer, showOnLedger?: boolean): Promise<object>
  • Retrieves a publicKey associated to an account

    example
    
    instance.getPubKey(account)
      .then((resp) => {
        console.log(resp.publicKey);
        console.log(resp.address);
      });
    

    Parameters

    • account: LedgerAccount | Buffer

      or bip32 buffer

    • Default value showOnLedger: boolean = false

      ask ledger to show the address.

    Returns Promise<object>

    }

ping

  • ping(): Promise<void>
  • Simple ping utility. It won't throw if ping suceeded.

    Returns Promise<void>

signMSG

  • signMSG(account: LedgerAccount | Buffer, what: string | Buffer): Promise<Buffer>
  • Signs a message. The message can be passed as a string or buffer. Note that if buffer contains "non-printable" characters, then the ledger will probably have some issues Displaying the message to the user.

    example
    
    instance.signMSG(account, 'vekexasia rules', false)
      .then((signature) => {
        console.log('Signature is: ', signature.toString('hex'));
      });
    

    Parameters

    • account: LedgerAccount | Buffer

      or raw bip32 buffer

    • what: string | Buffer

      the message to sign

    Returns Promise<Buffer>

    the "non-detached" signature. Signature goodness can be verified using sodium. See tests.

signTX

  • signTX(account: LedgerAccount | Buffer, buff: Buffer, hasRequesterPKey?: boolean): Promise<Buffer>
  • Signs a transaction. Transaction must be provided as a buffer using getBytes.

    see

    https://github.com/vekexasia/dpos-offline/blob/master/src/trxTypes/BaseTx.ts#L52

    example
    
    instance.signTX(account, transaction.getBytes(), false)
      .then((signature) => {
        console.log('Signature is: ', signature.toString('hex'));
      });
    

    Parameters

    • account: LedgerAccount | Buffer

      or raw bip32 buffer

    • buff: Buffer

      buffer containing the bytes of a transaction

    • Default value hasRequesterPKey: boolean = false

      use true if the tx also includes a requesterPublicKey. This cannot be derived using static analysis of the content included in the bytes.

    Returns Promise<Buffer>

    signature.

version

  • version(): Promise<object>
  • Gets Ledger App Version

    example
    
    instance.version()
      .then((resp) => {
        console.log('CoinID is: ', resp.coinID);
        console.log('Version is: ', resp.version);
      });
    

    Returns Promise<object>

    see example