import { executeCommand } from './execute/execute' ; import Transport from '../transport' ; import { commands } from "./execute/command" ; import { target } from '../config/param' ; import { CODE } from '../config/status/code' ; import { APDUError } from '../error/errorHandle' ; param { Transport } transport param { string } data return { Promise < string > } export const echo = async ( transport , data ) : Promise < string > => { console . log ( 'data :' , data ) ; const { outputData , statusCode , msg } = await executeCommand ( transport , commands . ECHO , target . SE , data ) ; if ( statusCode === CODE . _9000 ) { return outputData ; } else { throw new APDUError ( commands . ECHO , statusCode , msg ) ; } } ; param { Transport } transport param { string } appId return { Promise < boolean > } export const hi = async ( transport , appId ) : Promise < boolean > => { try { const { statusCode } = await executeCommand ( transport , commands . SAY_HI , target . SE , appId ) ; return statusCode === CODE . _9000 ; } catch ( error ) { return false ; } } ; param { Transport } transport return { Promise < string > } export const getNonce = async ( transport ) : Promise < string > => { const { outputData : nonce , statusCode , msg } = await executeCommand ( transport , commands . GET_NONCE , target . SE ) ; if ( statusCode === CODE . _9000 ) { return nonce ; } else { throw new APDUError ( commands . GET_NONCE , statusCode , msg ) ; } } ; param { Transport } transport returns { Promise < Number > } export const getSEVersion = async ( transport ) : Promise < number > => { try { const { outputData , statusCode , msg } = await executeCommand ( transport , commands . GET_SE_VERSION , target . SE ) ; if ( outputData ) { return parseInt ( outputData , 16 ) ; } else { throw new APDUError ( commands . GET_SE_VERSION , statusCode , msg ) ; } } catch ( e ) { return 0 ; } } ; param { Transport } transport return { Promise < boolean > } export const resetCard = async ( transport ) : Promise < boolean > => { const { statusCode , msg } = await executeCommand ( transport , commands . RESET_PAIR , target . SE ) ; if ( statusCode === CODE . _9000 ) { return true ; } else { throw new APDUError ( commands . GET_NONCE , statusCode , msg ) ; } } ; param { Transport } transport return { Promise < boolean > } export const getCardId = async ( transport ) : Promise < string > => { const { statusCode , msg , outputData } = await executeCommand ( transport , commands . GET_CARD_ID , target . SE ) ; if ( statusCode === CODE . _9000 ) { return outputData ; } else { throw new APDUError ( commands . GET_CARD_ID , statusCode , msg ) ; } } ;