Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return this.exchangeAtomicImpl(async () => {
try {
const apduHex = apdu.toString("hex");
log("apdu", "=> " + apduHex);
const resultHex = await NativeModules.HID.exchange(this.id, apduHex);
const res = Buffer.from(resultHex, "hex");
log("apdu", "<= " + resultHex);
return res;
} catch (error) {
if (disconnectedErrors.includes(error.message)) {
this.emit("disconnect", error);
throw new DisconnectedDeviceDuringOperation(error.message);
}
throw error;
}
});
}
write = async (buffer: Buffer, txid?: ?string) => {
log("ble-frame", "=> " + buffer.toString("hex"));
try {
await this.writeCharacteristic.writeWithResponse(
buffer.toString("base64"),
txid
);
} catch (e) {
throw new DisconnectedDeviceDuringOperation(e.message);
}
};
}).catch(e => {
if (e && e.message && e.message.includes("write")) {
this._emitDisconnect(e);
throw new DisconnectedDeviceDuringOperation(e.message);
}
throw e;
});
write = async (buffer: Buffer) => {
log("ble-frame", "=> " + buffer.toString("hex"));
try {
await write(this.writeCharacteristic, buffer);
} catch (e) {
throw new DisconnectedDeviceDuringOperation(e.message);
}
};
const onDisconnect = e => {
transport.off("disconnect", onDisconnect);
o.error(new DisconnectedDeviceDuringOperation((e && e.message) || ""));
};
transport.on("disconnect", onDisconnect);
}).catch(e => {
if (e && e.message && e.message.includes("disconnected")) {
this._emitDisconnect(e);
throw new DisconnectedDeviceDuringOperation(e.message);
}
throw e;
});