import { SDKError , APDUError } from '../error/errorHandle' ; import { sign } from '../crypto/sign' ; import { CommandType } from "../apdu/execute/command" ; import * as control from '../apdu/mcu/control' ; import * as setting from '../apdu/setting' ; import * as general from '../apdu/general' ; import * as info from '../apdu/informational' ; import Transport from '../transport' ; param { Transport } transport param { string } appId param { string } appPrivateKey param { String } commandName param { String } data param { String } params1 param { String } params2 returns { Promise < { signature : string , forceUseSC : boolean } > } export const getCommandSignature = async ( transport , appId , appPrivateKey , command , data = '' , params1 = '00' , params2 = '00' ) : Promise < string > => { const nonce = await general . getNonce ( transport ) ; console . debug ( "- nonce: " , nonce ) ; const P1 = params1 || command . P1 ; const P2 = params2 || command . P2 ; const apduHeader = command . CLA + command . INS + P1 + P2 ; const dataPackets = data || '' ; console . debug ( "- dataPackets: " , dataPackets ) ; const signatureParams = apduHeader + dataPackets + nonce ; console . debug ( "- signatureParams: " , signatureParams ) ; const signature = sign ( signatureParams , appPrivateKey ) . toString ( 'hex' ) ; console . debug ( "- signature: " , signature ) ; const appIdWithSignature = appId + signature . padStart ( 144 , '0' ) ; console . debug ( "- appIdWithSignature: " + appIdWithSignature ) ; return appIdWithSignature ; } ; param { Transport } transport param { number } requiredSEVersion export const versionCheck = async ( transport , requiredSEVersion ) => { const SEVersion = await general . getSEVersion ( transport ) ; if ( SEVersion < requiredSEVersion ) throw new SDKError ( versionCheck . name , `Firmware version too low. Please update to ${ requiredSEVersion }` ) ; } ;