npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@secux/app-trx

v3.0.6

Published

SecuX Hardware Wallet TRX API

Downloads

34

Readme

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

  1. 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);

*/
  1. 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);
  1. 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);

*/
  1. 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

| Param | Type | | --- | --- | | publickey | string | Buffer |

SecuxTRX.toHexAddress(address) ⇒ string

Convert TRX address to hex representation

Returns: string - TRX address (hex)

| Param | Type | Description | | --- | --- | --- | | address | string | TRX address |

SecuxTRX.prepareAddress(path) ⇒ communicationData

Prepare data for address generation.

Returns: communicationData - data for sending to device

| Param | Type | Description | | --- | --- | --- | | path | string | m/44'/195'/... |

SecuxTRX.resolveAddress(response) ⇒ string

Generate address from response data.

Returns: string - TRX address

| Param | Type | Description | | --- | --- | --- | | response | communicationData | data from device |

SecuxTRX.preparePublickey(path) ⇒ communicationData

Prepare data for secp256k1 publickey.

Returns: communicationData - data for sending to device

| Param | Type | Description | | --- | --- | --- | | path | string | m/44'/195'/... |

SecuxTRX.resolvePublickey(response) ⇒ string

Resolve secp256k1 publickey from response data.

Returns: string - secp256k1 publickey

| Param | Type | Description | | --- | --- | --- | | response | communicationData | data from device |

SecuxTRX.prepareXPublickey(path) ⇒ communicationData

Prepare data for xpub.

Returns: communicationData - data for sending to device

| Param | Type | Description | | --- | --- | --- | | path | string | m/44'/195'/... |

SecuxTRX.resolveXPublickey(response, path) ⇒

Resolve xpub from response data.

Returns: xpub

| Param | Type | Description | | --- | --- | --- | | response | communicationData | data from device | | path | string | m/44'/195'/... |

SecuxTRX.prepareSign(path, content) ⇒ prepared

Prepare data for signing.

Returns: prepared - prepared object

| Param | Type | Description | | --- | --- | --- | | path | string | m/44'/195'/... | | content | transferData | trc10_Data | trc20_Data | transaction object |

SecuxTRX.resolveSignature(response) ⇒ string

Resolve signature from response data.

Returns: string - signature (hex string)

| Param | Type | Description | | --- | --- | --- | | response | communicationData | data from device |

SecuxTRX.resolveTransaction(response, serialized) ⇒ string

Resolve transaction for broadcasting.

Returns: string - signed raw transaction

| Param | Type | Description | | --- | --- | --- | | response | communicationData | data from device | | serialized | communicationData | raw transaction |

transferData : object

Properties

| Name | Type | Description | | --- | --- | --- | | from | string | sending address | | to | string | receiving address | | amount | number | transfer amount | | blockID | string | | | blockNumber | number | | | timestamp | number | | | [feeLimit] | number | | | [expiration] | number | |

trc10_Data : object

Properties

| Name | Type | Description | | --- | --- | --- | | from | string | sending address | | to | string | receiving address | | token | string | number | token id number | | amount | number | transfer amount | | blockID | string | | | blockNumber | number | | | timestamp | number | | | [feeLimit] | number | | | [expiration] | number | |

trc20_Data : object

Properties

| Name | Type | Description | | --- | --- | --- | | from | string | sending address | | to | string | receiving address | | amount | number | string | transfer amount | | contract | string | contract address | | [data] | string | abi encoded string | | blockID | string | | | blockNumber | number | | | timestamp | number | | | [callValue] | number | amount of TRX to send to the contract when triggers. | | [tokenId] | number | id of TRC-10 token to be sent to the contract. | | [tokenValue] | number | amount of TRC-10 token to send to the contract when triggers. | | [feeLimit] | number | | | [expiration] | number | |

prepared : object

Properties

| Name | Type | Description | | --- | --- | --- | | commandData | communicationData | data for sending to device | | rawTx | communicationData | unsigned raw transaction |


© 2018-21 SecuX Technology Inc.

authors: [email protected]