Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function calculateChecksum(payload) {
// This code calculates CRC16-XModem checksum of payload
// and returns it as Buffer in little-endian order.
const checksum = Buffer.alloc(2);
checksum.writeUInt16LE(crc.crc16xmodem(payload), 0);
return checksum;
}
function isValid(message) {
if (!Constants.equals(message.slice(4, 16))) return false;
var checksum = message.readUInt16BE(message.length - 2);
return checksum === crc(message.slice(16, -2));
}
target: target,
data: data
});
debug(command.toString());
try {
content = command.message;
} catch (err) {
return callback(err);
}
var checksum = new Buffer(2);
checksum.writeUInt16BE(crc(content), 0);
var message = Buffer.concat([this.address, Constants, content, checksum]);
this.socket.send(message, 0, message.length,
this.port, this.gateway, callback);
};
)
)
var data = [
f(ID_PAYLOAD_FORMAT, PAYLOAD_FORMAT_EMV_QRCPS_MERCHANT_PRESENTED_MODE),
f(ID_POI_METHOD, amount ? POI_METHOD_DYNAMIC : POI_METHOD_STATIC),
f(ID_MERCHANT_INFORMATION_BOT, serialize([
f(MERCHANT_INFORMATION_TEMPLATE_ID_GUID, GUID_PROMPTPAY),
f(targetType, formatTarget(target))
])),
f(ID_COUNTRY_CODE, COUNTRY_CODE_TH),
f(ID_TRANSACTION_CURRENCY, TRANSACTION_CURRENCY_THB),
amount && f(ID_TRANSACTION_AMOUNT, formatAmount(amount))
]
var dataToCrc = serialize(data) + ID_CRC + '04'
data.push(f(ID_CRC, formatCrc(crc.crc16xmodem(dataToCrc, 0xffff))))
return serialize(data)
}