import { Option } from '../config/types' ; import { COIN_TYPE } from '../config/params' ; import * as token from './tokenUtils' ; import { utils } from '@coolwallet/core' ; import { handleHex } from './stringUtil' ; import { Transaction } from '../config/types' ; const Web3 = require ( 'web3' ) ; param transaction export const getTransferArgument = async ( transaction , addressIndex ) => { const argument = handleHex ( transaction . to ) + handleHex ( transaction . value ) . padStart ( 20 , '0' ) + handleHex ( transaction . gasPrice ) . padStart ( 20 , '0' ) + handleHex ( transaction . gasLimit ) . padStart ( 20 , '0' ) + handleHex ( transaction . nonce ) . padStart ( 16 , '0' ) + handleHex ( transaction . chainId . toString ( 16 ) ) . padStart ( 4 , '0' ) ; const path = await utils . getPath ( COIN_TYPE , addressIndex ) ; return '15' + path + argument ; } ; param transaction param tokenSignature export const getERC20Argument = async ( transaction , tokenSignature , addressIndex ) => { const txTokenInfo = transaction . option ; const tokenInfo = token . getSetTokenPayload ( transaction . to , txTokenInfo . info . symbol , parseInt ( txTokenInfo . info . decimals ) ) ; const signature = tokenSignature . slice ( 58 ) . padStart ( 144 , '0' ) ; const toAddress = transaction . data . slice ( 10 , 74 ) . replace ( /\b(0+)/gi , '' ) ; const amount = transaction . data . slice ( 74 ) . replace ( /\b(0+)/gi , '' ) ; const argument = handleHex ( toAddress ) . padStart ( 40 , '0' ) + handleHex ( amount ) . padStart ( 24 , '0' ) + handleHex ( transaction . gasPrice ) . padStart ( 20 , '0' ) + handleHex ( transaction . gasLimit ) . padStart ( 20 , '0' ) + handleHex ( transaction . nonce ) . padStart ( 16 , '0' ) + handleHex ( transaction . chainId . toString ( 16 ) ) . padStart ( 4 , '0' ) + tokenInfo + signature ; return '15' + ( await utils . getPath ( COIN_TYPE , addressIndex ) ) + argument ; } ; param transaction export const getSmartContractArgument = async ( transaction , addressIndex ) => { const argument = handleHex ( transaction . to ) + handleHex ( transaction . value ) . padStart ( 20 , '0' ) + handleHex ( transaction . gasPrice ) . padStart ( 20 , '0' ) + handleHex ( transaction . gasLimit ) . padStart ( 20 , '0' ) + handleHex ( transaction . nonce ) . padStart ( 16 , '0' ) + ( handleHex ( transaction . data ) . length / 2 ) . toString ( 16 ) . padStart ( 8 , '0' ) ; return '15' + ( await utils . getPath ( COIN_TYPE , addressIndex ) ) + argument ; } ; param transaction export const getSignMessageArgument = async ( message , addressIndex ) => { const msgHex = handleHex ( Web3 . utils . toHex ( message ) ) ; const argument = Buffer . from ( ( msgHex . length / 2 ) . toString ( ) ) . toString ( 'hex' ) + msgHex ; return '15' + ( await utils . getPath ( COIN_TYPE , addressIndex ) ) + argument ; } ; param transaction export const getSignTypedDataArgument = async ( domainSeparator , data , addressIndex ) => { const argument = handleHex ( domainSeparator ) . padStart ( 64 , '0' ) + handleHex ( data ) ; return '15' + ( await utils . getPath ( COIN_TYPE , addressIndex ) ) + argument ; } ;