@ledgerhq/react-native-hid 6.3.0 → 6.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +8 -8
- package/lib/index.js.map +1 -1
- package/package.json +11 -7
- package/lib-es/index.d.ts +0 -49
- package/lib-es/index.d.ts.map +0 -1
- package/lib-es/index.js +0 -231
- package/lib-es/index.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -80,7 +80,7 @@ var liveDeviceEventsSubject = new rxjs_1.Subject();
|
|
|
80
80
|
react_native_1.DeviceEventEmitter.addListener("onDeviceConnect", function (device) {
|
|
81
81
|
if (device.vendorId !== devices_1.ledgerUSBVendorId)
|
|
82
82
|
return;
|
|
83
|
-
var deviceModel = devices_1.identifyUSBProductId(device.productId);
|
|
83
|
+
var deviceModel = (0, devices_1.identifyUSBProductId)(device.productId);
|
|
84
84
|
liveDeviceEventsSubject.next({
|
|
85
85
|
type: "add",
|
|
86
86
|
descriptor: device,
|
|
@@ -90,7 +90,7 @@ react_native_1.DeviceEventEmitter.addListener("onDeviceConnect", function (devic
|
|
|
90
90
|
react_native_1.DeviceEventEmitter.addListener("onDeviceDisconnect", function (device) {
|
|
91
91
|
if (device.vendorId !== devices_1.ledgerUSBVendorId)
|
|
92
92
|
return;
|
|
93
|
-
var deviceModel = devices_1.identifyUSBProductId(device.productId);
|
|
93
|
+
var deviceModel = (0, devices_1.identifyUSBProductId)(device.productId);
|
|
94
94
|
liveDeviceEventsSubject.next({
|
|
95
95
|
type: "remove",
|
|
96
96
|
descriptor: device,
|
|
@@ -110,7 +110,7 @@ var HIDTransport = /** @class */ (function (_super) {
|
|
|
110
110
|
function HIDTransport(nativeId, productId) {
|
|
111
111
|
var _this = _super.call(this) || this;
|
|
112
112
|
_this.id = nativeId;
|
|
113
|
-
_this.deviceModel = devices_1.identifyUSBProductId(productId);
|
|
113
|
+
_this.deviceModel = (0, devices_1.identifyUSBProductId)(productId);
|
|
114
114
|
return _this;
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -138,11 +138,11 @@ var HIDTransport = /** @class */ (function (_super) {
|
|
|
138
138
|
return {
|
|
139
139
|
unsubscribe: function () { }
|
|
140
140
|
};
|
|
141
|
-
return rxjs_1.concat(rxjs_1.from(listLedgerDevices()).pipe(operators_1.mergeMap(function (devices) {
|
|
142
|
-
return rxjs_1.from(devices.map(function (device) { return ({
|
|
141
|
+
return (0, rxjs_1.concat)((0, rxjs_1.from)(listLedgerDevices()).pipe((0, operators_1.mergeMap)(function (devices) {
|
|
142
|
+
return (0, rxjs_1.from)(devices.map(function (device) { return ({
|
|
143
143
|
type: "add",
|
|
144
144
|
descriptor: device,
|
|
145
|
-
deviceModel: devices_1.identifyUSBProductId(device.productId)
|
|
145
|
+
deviceModel: (0, devices_1.identifyUSBProductId)(device.productId)
|
|
146
146
|
}); }));
|
|
147
147
|
})), liveDeviceEvents).subscribe(observer);
|
|
148
148
|
};
|
|
@@ -186,12 +186,12 @@ var HIDTransport = /** @class */ (function (_super) {
|
|
|
186
186
|
case 0:
|
|
187
187
|
_a.trys.push([0, 2, , 3]);
|
|
188
188
|
apduHex = apdu.toString("hex");
|
|
189
|
-
logs_1.log("apdu", "=> " + apduHex);
|
|
189
|
+
(0, logs_1.log)("apdu", "=> " + apduHex);
|
|
190
190
|
return [4 /*yield*/, react_native_1.NativeModules.HID.exchange(this.id, apduHex)];
|
|
191
191
|
case 1:
|
|
192
192
|
resultHex = _a.sent();
|
|
193
193
|
res = Buffer.from(resultHex, "hex");
|
|
194
|
-
logs_1.log("apdu", "<= " + resultHex);
|
|
194
|
+
(0, logs_1.log)("apdu", "<= " + resultHex);
|
|
195
195
|
return [2 /*return*/, res];
|
|
196
196
|
case 2:
|
|
197
197
|
error_2 = _a.sent();
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;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AQ,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,EAAA;;oCAA9D,SAAS,GAAG,SAAkD;oCAC9D,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;oCAC1C,IAAA,UAAG,EAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;oCAC/B,sBAAO,GAAG,EAAC;;;oCAEX,IAAI,kBAAkB,CAAC,QAAQ,CAAC,OAAK,CAAC,OAAO,CAAC,EAAE;wCAC9C,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAK,CAAC,CAAC;wCAC/B,MAAM,IAAI,0CAAiC,CAAC,OAAK,CAAC,OAAO,CAAC,CAAC;qCAC5D;oCAED,MAAM,OAAK,CAAC;;;;yBAEf,CAAC,EAAC;;;KACJ;IAED;;;OAGG;IACG,4BAAK,GAAX;;;;4BACE,qBAAM,IAAI,CAAC,mBAAmB,EAAA;;wBAA9B,SAA8B,CAAC;wBAC/B,sBAAO,4BAAa,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAC;;;;KAC/C;IAED,qCAAc,GAAd,cAAkB,CAAC;IAxFnB;;OAEG;IACI,wBAAW,GAAG;QACnB,OAAA,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,4BAAa,CAAC,GAAG,CAAC;IAApC,CAAoC,CAAC;IAqFzC,mBAAC;CAAA,AAnGD,CAA0C,yBAAS,GAmGlD;qBAnGoB,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/react-native-hid",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.9.0",
|
|
4
4
|
"nativePackage": true,
|
|
5
5
|
"description": "Ledger Hardware Wallet Web implementation of the communication layer, using U2F api",
|
|
6
6
|
"keywords": [
|
|
@@ -29,21 +29,25 @@
|
|
|
29
29
|
"types": "lib/index.d.ts",
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ledgerhq/devices": "^6.
|
|
32
|
+
"@ledgerhq/devices": "^6.7.0",
|
|
33
33
|
"@ledgerhq/errors": "^6.2.0",
|
|
34
|
-
"@ledgerhq/hw-transport": "^6.
|
|
34
|
+
"@ledgerhq/hw-transport": "^6.7.0",
|
|
35
35
|
"@ledgerhq/logs": "^6.2.0",
|
|
36
|
-
"react-native": "^0.63.4",
|
|
37
36
|
"rxjs": "6"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@types/react-native": "^0.
|
|
39
|
+
"@types/react-native": "^0.65.1",
|
|
40
|
+
"yarn-add-no-save": "^1.0.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react-native": "*"
|
|
41
44
|
},
|
|
42
45
|
"scripts": {
|
|
46
|
+
"peers": "add-no-save --peer-deps",
|
|
43
47
|
"clean": "bash ../../script/clean.sh",
|
|
44
|
-
"build": "bash ../../script/build.sh",
|
|
48
|
+
"build": "yarn peers && bash ../../script/build.sh",
|
|
45
49
|
"watch": "bash ../../script/watch.sh",
|
|
46
50
|
"doc": "bash ../../script/doc.sh"
|
|
47
51
|
},
|
|
48
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "893232aae6b4cc238504e6093bd2d7cc7a3be138"
|
|
49
53
|
}
|
package/lib-es/index.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { DeviceModel } from "@ledgerhq/devices";
|
|
3
|
-
import Transport from "@ledgerhq/hw-transport";
|
|
4
|
-
declare type DeviceObj = {
|
|
5
|
-
vendorId: number;
|
|
6
|
-
productId: number;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Ledger's React Native HID Transport implementation
|
|
10
|
-
* @example
|
|
11
|
-
* import TransportHID from "@ledgerhq/react-native-hid";
|
|
12
|
-
* ...
|
|
13
|
-
* TransportHID.create().then(transport => ...)
|
|
14
|
-
*/
|
|
15
|
-
export default class HIDTransport extends Transport {
|
|
16
|
-
id: number;
|
|
17
|
-
deviceModel: DeviceModel | null | undefined;
|
|
18
|
-
constructor(nativeId: number, productId: number);
|
|
19
|
-
/**
|
|
20
|
-
* Check if the transport is supported (basically true on Android)
|
|
21
|
-
*/
|
|
22
|
-
static isSupported: () => Promise<boolean>;
|
|
23
|
-
/**
|
|
24
|
-
* List currently connected devices.
|
|
25
|
-
* @returns Promise of devices
|
|
26
|
-
*/
|
|
27
|
-
static list(): Promise<any[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Listen to ledger devices events
|
|
30
|
-
*/
|
|
31
|
-
static listen(observer: any): any;
|
|
32
|
-
/**
|
|
33
|
-
* Open a the transport with a Ledger device
|
|
34
|
-
*/
|
|
35
|
-
static open(deviceObj: DeviceObj): Promise<HIDTransport>;
|
|
36
|
-
/**
|
|
37
|
-
* @param {*} apdu input value
|
|
38
|
-
* @returns Promise of apdu response
|
|
39
|
-
*/
|
|
40
|
-
exchange(apdu: Buffer): Promise<any>;
|
|
41
|
-
/**
|
|
42
|
-
* Close the transport
|
|
43
|
-
* @returns Promise
|
|
44
|
-
*/
|
|
45
|
-
close(): Promise<any>;
|
|
46
|
-
setScrambleKey(): void;
|
|
47
|
-
}
|
|
48
|
-
export {};
|
|
49
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib-es/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAI/C,aAAK,SAAS,GAAG;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AA+BF;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,SAAS;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;gBAEhC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAM/C;;OAEG;IACH,MAAM,CAAC,WAAW,QAAO,QAAQ,OAAO,CAAC,CACF;IAEvC;;;OAGG;WACU,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAKnC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;IAqBjC;;OAEG;WACU,IAAI,CAAC,SAAS,EAAE,SAAS;IAatC;;;OAGG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAoB1C;;;OAGG;IACG,KAAK;IAKX,cAAc;CACf"}
|
package/lib-es/index.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
-
function step(op) {
|
|
30
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (_) try {
|
|
32
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
-
switch (op[0]) {
|
|
35
|
-
case 0: case 1: t = op; break;
|
|
36
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
-
default:
|
|
40
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
-
if (t[2]) _.ops.pop();
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
import { NativeModules, DeviceEventEmitter } from "react-native";
|
|
53
|
-
import { ledgerUSBVendorId, identifyUSBProductId } from "@ledgerhq/devices";
|
|
54
|
-
import { DisconnectedDeviceDuringOperation, DisconnectedDevice, } from "@ledgerhq/errors";
|
|
55
|
-
import { log } from "@ledgerhq/logs";
|
|
56
|
-
import Transport from "@ledgerhq/hw-transport";
|
|
57
|
-
import { Subject, from, concat } from "rxjs";
|
|
58
|
-
import { mergeMap } from "rxjs/operators";
|
|
59
|
-
var disconnectedErrors = [
|
|
60
|
-
"I/O error",
|
|
61
|
-
"Attempt to invoke virtual method 'int android.hardware.usb.UsbDevice.getDeviceClass()' on a null object reference",
|
|
62
|
-
];
|
|
63
|
-
var listLedgerDevices = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
-
var devices;
|
|
65
|
-
return __generator(this, function (_a) {
|
|
66
|
-
switch (_a.label) {
|
|
67
|
-
case 0: return [4 /*yield*/, NativeModules.HID.getDeviceList()];
|
|
68
|
-
case 1:
|
|
69
|
-
devices = _a.sent();
|
|
70
|
-
return [2 /*return*/, devices.filter(function (d) { return d.vendorId === ledgerUSBVendorId; })];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}); };
|
|
74
|
-
var liveDeviceEventsSubject = new Subject();
|
|
75
|
-
DeviceEventEmitter.addListener("onDeviceConnect", function (device) {
|
|
76
|
-
if (device.vendorId !== ledgerUSBVendorId)
|
|
77
|
-
return;
|
|
78
|
-
var deviceModel = identifyUSBProductId(device.productId);
|
|
79
|
-
liveDeviceEventsSubject.next({
|
|
80
|
-
type: "add",
|
|
81
|
-
descriptor: device,
|
|
82
|
-
deviceModel: deviceModel
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
DeviceEventEmitter.addListener("onDeviceDisconnect", function (device) {
|
|
86
|
-
if (device.vendorId !== ledgerUSBVendorId)
|
|
87
|
-
return;
|
|
88
|
-
var deviceModel = identifyUSBProductId(device.productId);
|
|
89
|
-
liveDeviceEventsSubject.next({
|
|
90
|
-
type: "remove",
|
|
91
|
-
descriptor: device,
|
|
92
|
-
deviceModel: deviceModel
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
var liveDeviceEvents = liveDeviceEventsSubject;
|
|
96
|
-
/**
|
|
97
|
-
* Ledger's React Native HID Transport implementation
|
|
98
|
-
* @example
|
|
99
|
-
* import TransportHID from "@ledgerhq/react-native-hid";
|
|
100
|
-
* ...
|
|
101
|
-
* TransportHID.create().then(transport => ...)
|
|
102
|
-
*/
|
|
103
|
-
var HIDTransport = /** @class */ (function (_super) {
|
|
104
|
-
__extends(HIDTransport, _super);
|
|
105
|
-
function HIDTransport(nativeId, productId) {
|
|
106
|
-
var _this = _super.call(this) || this;
|
|
107
|
-
_this.id = nativeId;
|
|
108
|
-
_this.deviceModel = identifyUSBProductId(productId);
|
|
109
|
-
return _this;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* List currently connected devices.
|
|
113
|
-
* @returns Promise of devices
|
|
114
|
-
*/
|
|
115
|
-
HIDTransport.list = function () {
|
|
116
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
-
return __generator(this, function (_a) {
|
|
118
|
-
switch (_a.label) {
|
|
119
|
-
case 0:
|
|
120
|
-
if (!NativeModules.HID)
|
|
121
|
-
return [2 /*return*/, Promise.resolve([])];
|
|
122
|
-
return [4 /*yield*/, listLedgerDevices()];
|
|
123
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Listen to ledger devices events
|
|
130
|
-
*/
|
|
131
|
-
HIDTransport.listen = function (observer) {
|
|
132
|
-
if (!NativeModules.HID)
|
|
133
|
-
return {
|
|
134
|
-
unsubscribe: function () { }
|
|
135
|
-
};
|
|
136
|
-
return concat(from(listLedgerDevices()).pipe(mergeMap(function (devices) {
|
|
137
|
-
return from(devices.map(function (device) { return ({
|
|
138
|
-
type: "add",
|
|
139
|
-
descriptor: device,
|
|
140
|
-
deviceModel: identifyUSBProductId(device.productId)
|
|
141
|
-
}); }));
|
|
142
|
-
})), liveDeviceEvents).subscribe(observer);
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Open a the transport with a Ledger device
|
|
146
|
-
*/
|
|
147
|
-
HIDTransport.open = function (deviceObj) {
|
|
148
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
-
var nativeObj, error_1;
|
|
150
|
-
return __generator(this, function (_a) {
|
|
151
|
-
switch (_a.label) {
|
|
152
|
-
case 0:
|
|
153
|
-
_a.trys.push([0, 2, , 3]);
|
|
154
|
-
return [4 /*yield*/, NativeModules.HID.openDevice(deviceObj)];
|
|
155
|
-
case 1:
|
|
156
|
-
nativeObj = _a.sent();
|
|
157
|
-
return [2 /*return*/, new HIDTransport(nativeObj.id, deviceObj.productId)];
|
|
158
|
-
case 2:
|
|
159
|
-
error_1 = _a.sent();
|
|
160
|
-
if (disconnectedErrors.includes(error_1.message)) {
|
|
161
|
-
throw new DisconnectedDevice(error_1.message);
|
|
162
|
-
}
|
|
163
|
-
throw error_1;
|
|
164
|
-
case 3: return [2 /*return*/];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* @param {*} apdu input value
|
|
171
|
-
* @returns Promise of apdu response
|
|
172
|
-
*/
|
|
173
|
-
HIDTransport.prototype.exchange = function (apdu) {
|
|
174
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
-
var _this = this;
|
|
176
|
-
return __generator(this, function (_a) {
|
|
177
|
-
return [2 /*return*/, this.exchangeAtomicImpl(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
178
|
-
var apduHex, resultHex, res, error_2;
|
|
179
|
-
return __generator(this, function (_a) {
|
|
180
|
-
switch (_a.label) {
|
|
181
|
-
case 0:
|
|
182
|
-
_a.trys.push([0, 2, , 3]);
|
|
183
|
-
apduHex = apdu.toString("hex");
|
|
184
|
-
log("apdu", "=> " + apduHex);
|
|
185
|
-
return [4 /*yield*/, NativeModules.HID.exchange(this.id, apduHex)];
|
|
186
|
-
case 1:
|
|
187
|
-
resultHex = _a.sent();
|
|
188
|
-
res = Buffer.from(resultHex, "hex");
|
|
189
|
-
log("apdu", "<= " + resultHex);
|
|
190
|
-
return [2 /*return*/, res];
|
|
191
|
-
case 2:
|
|
192
|
-
error_2 = _a.sent();
|
|
193
|
-
if (disconnectedErrors.includes(error_2.message)) {
|
|
194
|
-
this.emit("disconnect", error_2);
|
|
195
|
-
throw new DisconnectedDeviceDuringOperation(error_2.message);
|
|
196
|
-
}
|
|
197
|
-
throw error_2;
|
|
198
|
-
case 3: return [2 /*return*/];
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}); })];
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
/**
|
|
206
|
-
* Close the transport
|
|
207
|
-
* @returns Promise
|
|
208
|
-
*/
|
|
209
|
-
HIDTransport.prototype.close = function () {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
-
return __generator(this, function (_a) {
|
|
212
|
-
switch (_a.label) {
|
|
213
|
-
case 0: return [4 /*yield*/, this.exchangeBusyPromise];
|
|
214
|
-
case 1:
|
|
215
|
-
_a.sent();
|
|
216
|
-
return [2 /*return*/, NativeModules.HID.closeDevice(this.id)];
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
};
|
|
221
|
-
HIDTransport.prototype.setScrambleKey = function () { };
|
|
222
|
-
/**
|
|
223
|
-
* Check if the transport is supported (basically true on Android)
|
|
224
|
-
*/
|
|
225
|
-
HIDTransport.isSupported = function () {
|
|
226
|
-
return Promise.resolve(!!NativeModules.HID);
|
|
227
|
-
};
|
|
228
|
-
return HIDTransport;
|
|
229
|
-
}(Transport));
|
|
230
|
-
export default HIDTransport;
|
|
231
|
-
//# sourceMappingURL=index.js.map
|
package/lib-es/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE5E,OAAO,EACL,iCAAiC,EACjC,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK1C,IAAM,kBAAkB,GAAG;IACzB,WAAW;IACX,mHAAmH;CACpH,CAAC;AAEF,IAAM,iBAAiB,GAAG;;;;oBACR,qBAAM,aAAa,CAAC,GAAG,CAAC,aAAa,EAAE,EAAA;;gBAAjD,OAAO,GAAG,SAAuC;gBACvD,sBAAO,OAAO,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,KAAK,iBAAiB,EAAhC,CAAgC,CAAC,EAAC;;;KAChE,CAAC;AAEF,IAAM,uBAAuB,GAA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