Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@secux/app-trx

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secux/app-trx

SecuX Hardware Wallet TRX API

latest
npmnpm
Version
3.0.6
Version published
Maintainers
2
Created
Source

lerna view on npm npm module downloads

@secux/app-trx

SecuX Hardware Wallet TRX API

Usage

import { SecuxTRX } from "@secux/app-trx";

First, create instance of ITransport


Examples

  • Get address of bip44 path
const path = "m/44'/195'/0'/0/0";
const address = await device.getAddress(path);

/*

// transfer data to hardware wallet by custom transport layer.
const data = SecuxTRX.prepareAddress(path);
const response = await device.Exchange(data);
const address =  SecuxTRX.resolveAddress(response);

*/
  • Sign transaction (TransferContract)
const TronWeb = require("tronweb");

// fetch block data
const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io' });
const block = await tronWeb.trx.getConfirmedCurrentBlock();

const content = {
    to: "TJKiYicrKqB7PR2wywfWKkNMppNRqd6tXt",
    amount: 1e5,
    blockID: block.blockID,
    blockNumber: block.block_header.raw_data.number,
    timestamp: block.block_header.raw_data.timestamp
};

// sign
const { raw_tx, signature } = await device.sign("m/44'/195'/0'/0/0", content);

/*

// transfer data to hardware wallet by custom transport layer.
const { commandData, rawTx } = SecuxTRX.prepareSign("m/44'/195'/0'/0/0", content);
const response = await device.Exchange(commandData);
const raw_tx = SecuxTRX.resolveTransaction(response, rawTx);

*/

// broadcast
const response = await tronWeb.trx.sendHexTransaction(raw_tx);
  • Sign TRC10 transaction (TransferAssetContract)
const content = {
    to: "TJKiYicrKqB7PR2wywfWKkNMppNRqd6tXt",
    token: 1002000,
    amount: 1e5,
    blockID: block.blockID,
    blockNumber: block.block_header.raw_data.number,
    timestamp: block.block_header.raw_data.timestamp
};

const { raw_tx, signature } = await device.sign("m/44'/195'/0'/0/0", content);

/*

// transfer data to hardware wallet by custom transport layer.
const { commandData, rawTx } = SecuxTRX.prepareSign("m/44'/195'/0'/0/0", content);
const response = await device.Exchange(commandData);
const raw_tx = SecuxTRX.resolveTransaction(response, rawTx);

*/
  • Sign TRC20 transaction (TriggerSmartContract)
    • [tokenId]: the TRC10 asset ID that transfered to the contract while calling the contract.
    • [tokenValue]: the amount of TRC10 asset that transfered to the contract while calling the contract.
    • [callValue]: the amount of TRX that transfered to the contract while calling the contract, the unit is sun.
const content = {
    contract: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
    // data field can use abi encoded string optionally
    data: [
        { type: "address", value: "TJKiYicrKqB7PR2wywfWKkNMppNRqd6tXt" },
        { type: "uint256", value: 1e5 }
    ],
    blockID: block.blockID,
    blockNumber: block.block_header.raw_data.number,
    timestamp: block.block_header.raw_data.timestamp
};

const { raw_tx, signature } = await device.sign("m/44'/195'/0'/0/0", content);

/*

// transfer data to hardware wallet by custom transport layer.
const { commandData, rawTx } = SecuxTRX.prepareSign("m/44'/195'/0'/0/0", content);
const response = await device.Exchange(commandData);
const raw_tx = SecuxTRX.resolveTransaction(response, rawTx);

*/

API Reference

TRX package for SecuX device

Kind: global class


SecuxTRX.addressConvert(publickey) ⇒ string

Convert secp256k1 publickey to TRX address.

Returns: string - TRX address

ParamType
publickeystring | Buffer

SecuxTRX.toHexAddress(address) ⇒ string

Convert TRX address to hex representation

Returns: string - TRX address (hex)

ParamTypeDescription
addressstringTRX address

SecuxTRX.prepareAddress(path) ⇒ communicationData

Prepare data for address generation.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/195'/...

SecuxTRX.resolveAddress(response) ⇒ string

Generate address from response data.

Returns: string - TRX address

ParamTypeDescription
responsecommunicationDatadata from device

SecuxTRX.preparePublickey(path) ⇒ communicationData

Prepare data for secp256k1 publickey.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/195'/...

SecuxTRX.resolvePublickey(response) ⇒ string

Resolve secp256k1 publickey from response data.

Returns: string - secp256k1 publickey

ParamTypeDescription
responsecommunicationDatadata from device

SecuxTRX.prepareXPublickey(path) ⇒ communicationData

Prepare data for xpub.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/195'/...

SecuxTRX.resolveXPublickey(response, path) ⇒

Resolve xpub from response data.

Returns: xpub

ParamTypeDescription
responsecommunicationDatadata from device
pathstringm/44'/195'/...

SecuxTRX.prepareSign(path, content) ⇒ prepared

Prepare data for signing.

Returns: prepared - prepared object

ParamTypeDescription
pathstringm/44'/195'/...
contenttransferData | trc10_Data | trc20_Datatransaction object

SecuxTRX.resolveSignature(response) ⇒ string

Resolve signature from response data.

Returns: string - signature (hex string)

ParamTypeDescription
responsecommunicationDatadata from device

SecuxTRX.resolveTransaction(response, serialized) ⇒ string

Resolve transaction for broadcasting.

Returns: string - signed raw transaction

ParamTypeDescription
responsecommunicationDatadata from device
serializedcommunicationDataraw transaction



transferData : object

Properties

NameTypeDescription
fromstringsending address
tostringreceiving address
amountnumbertransfer amount
blockIDstring
blockNumbernumber
timestampnumber
[feeLimit]number
[expiration]number

trc10_Data : object

Properties

NameTypeDescription
fromstringsending address
tostringreceiving address
tokenstring | numbertoken id number
amountnumbertransfer amount
blockIDstring
blockNumbernumber
timestampnumber
[feeLimit]number
[expiration]number

trc20_Data : object

Properties

NameTypeDescription
fromstringsending address
tostringreceiving address
amountnumber | stringtransfer amount
contractstringcontract address
[data]stringabi encoded string
blockIDstring
blockNumbernumber
timestampnumber
[callValue]numberamount of TRX to send to the contract when triggers.
[tokenId]numberid of TRC-10 token to be sent to the contract.
[tokenValue]numberamount of TRC-10 token to send to the contract when triggers.
[feeLimit]number
[expiration]number

prepared : object

Properties

NameTypeDescription
commandDatacommunicationDatadata for sending to device
rawTxcommunicationDataunsigned raw transaction

© 2018-21 SecuX Technology Inc.

authors:
andersonwu@secuxtech.com

Keywords

secux

FAQs

Package last updated on 14 Jul 2022

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