Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.exchangeAtomicImpl(async () => {
const { channel, packetSize } = this;
log("apdu", "=> " + apdu.toString("hex"));
const framing = hidFraming(channel, packetSize);
// Write...
const blocks = framing.makeBlocks(apdu);
for (let i = 0; i < blocks.length; i++) {
log("hid-frame", "=> " + blocks[i].toString("hex"));
await this.writeHID(blocks[i]);
}
// Read...
let result;
let acc;
while (!(result = framing.getReducedResult(acc))) {
const buffer = await this.readHID();
log("hid-frame", "<= " + buffer.toString("hex"));
acc = framing.reduceResponse(acc, buffer);
}
this.exchangeAtomicImpl(async () => {
const { channel, packetSize } = this;
log("apdu", "=> " + apdu.toString("hex"));
const framing = hidFraming(channel, packetSize);
// Write...
const blocks = framing.makeBlocks(apdu);
for (let i = 0; i < blocks.length; i++) {
log("hid-frame", "=> " + blocks[i].toString("hex"));
await this.device.sendReport(0, blocks[i]);
}
// Read...
let result;
let acc;
while (!(result = framing.getReducedResult(acc))) {
const buffer = await this.read();
log("hid-frame", "<= " + buffer.toString("hex"));
acc = framing.reduceResponse(acc, buffer);
}
this.exchangeAtomicImpl(async () => {
const { channel, packetSize } = this;
log("apdu", "=> " + apdu.toString("hex"));
const framing = hidFraming(channel, packetSize);
// Write...
const blocks = framing.makeBlocks(apdu);
for (let i = 0; i < blocks.length; i++) {
log("hid-frame", "=> " + blocks[i].toString("hex"));
await this.device.transferOut(endpointNumber, blocks[i]);
}
// Read...
let result;
let acc;
while (!(result = framing.getReducedResult(acc))) {
const r = await this.device.transferIn(endpointNumber, packetSize);
const buffer = Buffer.from(r.data.buffer);
log("hid-frame", "<= " + buffer.toString("hex"));
acc = framing.reduceResponse(acc, buffer);