UNPKG

@secux/app-trx

Version:
159 lines (155 loc) 5.88 kB
/*! Copyright 2022 SecuX Technology Inc Copyright Chen Wei-En Copyright Wu Tsung-Yu Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /// <reference types="node" /> import { ITransport } from '@secux/transport'; import { communicationData } from "@secux/utility/lib/communication"; import { txDetail, transferData, trc10_Data, trc20_Data } from './interface'; export { SecuxTRX, transferData, trc10_Data, trc20_Data }; /** * TRX package for SecuX device */ declare class SecuxTRX { /** * Convert secp256k1 publickey to TRX address. * @param {string|Buffer} publickey * @returns {string} TRX address */ static addressConvert(publickey: string | Buffer): string; /** * Convert TRX address to hex representation * @param {string} address TRX address * @returns {string} TRX address (hex) */ static toHexAddress(address: string): string; /** * Prepare data for address generation. * @param {string} path m/44'/195'/... * @returns {communicationData} data for sending to device */ static prepareAddress(path: string): communicationData; /** * Generate address from response data. * @param {communicationData} response data from device * @returns {string} TRX address */ static resolveAddress(response: communicationData): string; /** * Prepare data for secp256k1 publickey. * @param {string} path m/44'/195'/... * @returns {communicationData} data for sending to device */ static preparePublickey(path: string): communicationData; /** * Resolve secp256k1 publickey from response data. * @param {communicationData} response data from device * @returns {string} secp256k1 publickey */ static resolvePublickey(response: communicationData): string; /** * Prepare data for xpub. * @param {string} path m/44'/195'/... * @returns {communicationData} data for sending to device */ static prepareXPublickey(path: string): communicationData; /** * Resolve xpub from response data. * @param {communicationData} response data from device * @param {string} path m/44'/195'/... * @returns xpub */ static resolveXPublickey(response: communicationData, path: string): string; /** * Prepare data for signing. * @param {string} path m/44'/195'/... * @param {transferData | trc10_Data | trc20_Data} content transaction object * @returns {prepared} prepared object */ static prepareSign(path: string, content: txDetail): { commandData: communicationData; rawTx: communicationData; }; /** * Resolve signature from response data. * @param {communicationData} response data from device * @returns {string} signature (hex string) */ static resolveSignature(response: communicationData): string; /** * Resolve transaction for broadcasting. * @param {communicationData} response data from device * @param {communicationData} serialized raw transaction * @returns {string} signed raw transaction */ static resolveTransaction(response: communicationData, serialized: communicationData): string; static getAddress(this: ITransport, path: string): Promise<string>; static getPublickey(this: ITransport, path: string): Promise<string>; static getXPublickey(this: ITransport, path: string): Promise<string>; static sign(this: ITransport, path: string, content: txDetail): Promise<{ raw_tx: string; signature: string; }>; } /** * Data type for transmission. * @typedef {string|Buffer} communicationData */ /** * The payment object. * @typedef {object} transferData * @property {string} from sending address * @property {string} to receiving address * @property {number} amount transfer amount * @property {string} blockID * @property {number} blockNumber * @property {number} timestamp * @property {number} [feeLimit] * @property {number} [expiration] */ /** * The payment object for TRC-10. * @typedef {object} trc10_Data * @property {string} from sending address * @property {string} to receiving address * @property {string | number} token token id number * @property {number} amount transfer amount * @property {string} blockID * @property {number} blockNumber * @property {number} timestamp * @property {number} [feeLimit] * @property {number} [expiration] */ /** * The payment object for TRC-20. * @typedef {object} trc20_Data trc20 object * @property {string} from sending address * @property {string} to receiving address * @property {number | string} amount transfer amount * @property {string} contract contract address * @property {string} [data] abi encoded string * @property {string} blockID * @property {number} blockNumber * @property {number} timestamp * @property {number} [callValue] amount of TRX to send to the contract when triggers. * @property {number} [tokenId] id of TRC-10 token to be sent to the contract. * @property {number} [tokenValue] amount of TRC-10 token to send to the contract when triggers. * @property {number} [feeLimit] * @property {number} [expiration] */ /** * Object for the signing and validation. * @typedef {object} prepared * @property {communicationData} commandData data for sending to device * @property {communicationData} rawTx unsigned raw transaction */