@ledgerhq/swift-bridge-hw-transport-ble
Version:
Package to expose the Swift BLE transport to JS
44 lines • 1.37 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport"));
/**
* iOS Bluetooth Transport implementation
*/
class TransportBLESwift extends hw_transport_1.default {
/**
* SwiftTransport lives in the `global` scope and gets injected by the Swift Native Module
*/
transport;
constructor() {
super();
this.transport = SwiftTransport.create();
}
/**
* communicate with a BLE transport
*/
async exchange(apdu) {
const response = await this.promisify(this.transport.exchange(apdu));
return Buffer.from(response);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
promisify(callback) {
return new Promise((resolve, reject) => {
callback(function (response, error) {
if (response) {
resolve(response);
}
else {
reject(error);
}
});
});
}
arrayToBuffer(int8Array) {
return Buffer.from(int8Array);
}
}
exports.default = TransportBLESwift;
//# sourceMappingURL=TransportBLESwift.js.map