UNPKG

@secux/app-eth

Version:
216 lines (212 loc) 8.9 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" /> /// <reference types="node" /> import { TransactionType } from "@secux/protocol-transaction/lib/interface"; import { tx155, tx1559, JsonString } from './interface'; import { ETHTransactionBuilder } from './transaction'; import { communicationData } from "@secux/utility/lib/communication"; import { ERC20 } from "./erc20"; import { ERC721 } from "./erc721"; import { ERC1155 } from "./erc1155"; import { ITransport } from "@secux/transport"; export { SecuxETH, tx155, tx1559, ETHTransactionBuilder }; /** * ETH package for SecuX device */ declare class SecuxETH { static get ERC20(): typeof ERC20; static get ERC721(): typeof ERC721; static get ERC1155(): typeof ERC1155; /** * Convert publickey to ETH address. * @param {string|Buffer} publickey secp256k1 publickey * @returns {string} EIP55 address */ static addressConvert(publickey: string | Buffer): string; /** * Prepare data for address generation. * @param {string} path m/44'/60'/... * @returns {communicationData} data for sending to device */ static prepareAddress(path: string): communicationData; /** * Resolve address from response data. * @param {communicationData} response data from device * @returns {string} EIP55 address */ static resolveAddress(response: communicationData): string; /** * Prepare data for secp256k1 publickey. * @param {string} path m/44'/60'/... * @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 (hex string) */ static resolvePublickey(response: communicationData): string; /** * Prepare data for xpub generation. * @param {string} path m/44'/60'/... * @returns {communicationData} data for sending to device */ static prepareXPublickey(path: string): communicationData; /** * Generate xpub with response data. * @param {communicationData} response data from device * @param {string} path m/44'/60'/... * @returns {string} xpub */ static resolveXPublickey(response: communicationData, path: string): string; /** * Convert unsigned transaction to command data. * @param {string} path m/44'/60'/... * @param {communicationData} serialized unsigned transaction * @param {TransactionType} [txType] transaction type * @returns {prepared} prepared object */ static prepareSignSerialized(path: string, serialized: communicationData, txType?: TransactionType): { commandData: communicationData; rawTx: communicationData; }; /** * Reslove signature from response data. * @param {communicationData} response data from device * @returns {string} signature (hex string) */ static resolveSignature(response: communicationData): string; /** * Serialize transaction wtih signature for broadcasting. * @param {communicationData} response data from device * @param {communicationData} serialized unsigned transaction * @returns {string} signed raw transaction */ static resolveTransaction(response: communicationData, serialized: communicationData): string; /** * Prepare data for signing. * @param {string} path m/44'/60'/... * @param {tx155} content EIP-155 transaction object * @param {TransactionType} [txType] transaction type * @returns {prepared} prepared object */ static prepareSignEIP155(path: string, content: tx155, txType?: TransactionType): { commandData: communicationData; rawTx: communicationData; }; /** * Reslove signature and follow ethereum signature standard. * @param {communicationData} response data from device * @param {number} [chainId] if give a chainId, the signature will be EIP-155 applied * @returns {string} signature (hex string) */ static resolveSignatureEIP155(response: communicationData, chainId?: number): string; /** * Prepare data for signing (London Hard Fork). * @param {string} path m/44'/60'/... * @param {tx1559} content EIP-1559 transaction object * @param {TransactionType} [txType] transaction type * @returns {prepared} prepared object */ static prepareSignEIP1559(path: string, content: tx1559, txType?: TransactionType): { commandData: communicationData; rawTx: communicationData; }; /** * Prepare data for signing. * @param {string} path m/44'/60'/... * @param {string | Buffer} message * @returns {communicationData} data for sending to device */ static prepareSignMessage(path: string, message: string | Buffer): communicationData; /** * Prepare data for signing. * @param {string} path m/44'/60'/... * @param {JsonString} data EIP712 * @returns {communicationData} data for sending to device */ static prepareSignTypedData(path: string, typedData: JsonString): communicationData; /** * Prepare data for signing using WalletConnect protocol. * @param {string} path m/44'/60'/... * @param {tx155 | tx1559} content transaction object * @returns {prepared} prepared object */ static prepareSignWalletConnectTransaction(path: string, content: tx155 | tx1559): { commandData: communicationData; rawTx: communicationData; }; 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: tx155, txType?: TransactionType): Promise<{ raw_tx: string; signature: string; }>; static sign(this: ITransport, path: string, content: tx1559, txType?: TransactionType): Promise<{ raw_tx: string; signature: string; }>; static sign(this: ITransport, path: string, serialized: communicationData, txType?: TransactionType): Promise<{ raw_tx: string; signature: string; }>; static sign(this: ITransport, path: string, message: string, chainId?: number): Promise<{ signature: string; }>; static sign(this: ITransport, path: string, typedData: JsonString, chainId?: number): Promise<{ signature: string; }>; } export declare function prepareSign(path: string, builder: ETHTransactionBuilder, tp?: TransactionType): { commandData: communicationData; rawTx: communicationData; }; /** * Data type for transmission. * @typedef {string|Buffer} communicationData */ /** * The payment object for EIP-155. * @typedef {object} tx155 * @property {number | string} chainId network for ethereum ecosystem * @property {string} to receiving address * @property {number | string} value sending amount * @property {number | string} nonce the number of transactions sent from this address * @property {number | string} gasPrice the price of gas (unit: wei) * @property {number | string} gasLimit the maximum amount of gas you are willing to consume * @property {string} [data] abi-encoded data payload */ /** * The payment object for EIP-1559. * @typedef {object} tx1559 * @property {number | string} chainId network for ethereum ecosystem * @property {string} to receiving address * @property {number | string} value sending amount * @property {number | string} nonce the number of transactions sent from this address * @property {number | string} maxPriorityFeePerGas the maximum priority fee of gas (unit: wei) * @property {number | string} maxFeePerGas the maximum price of gas (unit: wei) * @property {number | string} gasLimit the maximum amount of gas you are willing to consume * @property {Array<any>} [content.accessList] * @property {string} [data] abi-encoded data payload */ /** * Object for the signing and validation. * @typedef {object} prepared * @property {communicationData} commandData data for sending to device * @property {communicationData} serialized unsigned transaction */