@ledgerhq/react-native-hid 6.32.4 → 6.32.5-nightly.1
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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +18 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +42 -57
- package/lib/index.js.map +1 -1
- package/lib-es/index.d.ts +1 -0
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +43 -59
- package/lib-es/index.js.map +1 -1
- package/package.json +7 -6
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/react-native-hid@6.32.
|
|
3
|
-
> tsc && tsc -m
|
|
2
|
+
> @ledgerhq/react-native-hid@6.32.5-nightly.0 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/react-native-hid
|
|
3
|
+
> tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ledgerhq/react-native-hid
|
|
2
2
|
|
|
3
|
+
## 6.32.5-nightly.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`107f35a`](https://github.com/LedgerHQ/ledger-live/commit/107f35a0650412716b088a3503b86435e6d9cf47)]:
|
|
8
|
+
- @ledgerhq/errors@6.20.0-nightly.1
|
|
9
|
+
- @ledgerhq/devices@8.4.5-nightly.1
|
|
10
|
+
- @ledgerhq/hw-transport@6.31.5-nightly.1
|
|
11
|
+
|
|
12
|
+
## 6.32.5-nightly.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`c6cb1bd`](https://github.com/LedgerHQ/ledger-live/commit/c6cb1bd2a0768ccbeeee96342dc8b872a620f3ac)]:
|
|
17
|
+
- @ledgerhq/errors@6.20.0-nightly.0
|
|
18
|
+
- @ledgerhq/devices@8.4.5-nightly.0
|
|
19
|
+
- @ledgerhq/hw-transport@6.31.5-nightly.0
|
|
20
|
+
|
|
3
21
|
## 6.32.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAI/C,KAAK,SAAS,GAAG;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAiCF;;;;;;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,CAAyC;IAElF;;;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/index.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -25,10 +16,10 @@ const disconnectedErrors = [
|
|
|
25
16
|
"Invalid channel",
|
|
26
17
|
"Permission denied by user for device",
|
|
27
18
|
];
|
|
28
|
-
const listLedgerDevices = () =>
|
|
29
|
-
const devices =
|
|
19
|
+
const listLedgerDevices = async () => {
|
|
20
|
+
const devices = await react_native_1.NativeModules.HID.getDeviceList();
|
|
30
21
|
return devices.filter(d => d.vendorId === devices_1.ledgerUSBVendorId);
|
|
31
|
-
}
|
|
22
|
+
};
|
|
32
23
|
const liveDeviceEventsSubject = new rxjs_1.Subject();
|
|
33
24
|
react_native_1.DeviceEventEmitter.addListener("onDeviceConnect", (device) => {
|
|
34
25
|
if (device.vendorId !== devices_1.ledgerUSBVendorId)
|
|
@@ -59,21 +50,25 @@ const liveDeviceEvents = liveDeviceEventsSubject;
|
|
|
59
50
|
* TransportHID.create().then(transport => ...)
|
|
60
51
|
*/
|
|
61
52
|
class HIDTransport extends hw_transport_1.default {
|
|
53
|
+
id;
|
|
54
|
+
deviceModel;
|
|
62
55
|
constructor(nativeId, productId) {
|
|
63
56
|
super();
|
|
64
57
|
this.id = nativeId;
|
|
65
58
|
this.deviceModel = (0, devices_1.identifyUSBProductId)(productId);
|
|
66
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if the transport is supported (basically true on Android)
|
|
62
|
+
*/
|
|
63
|
+
static isSupported = () => Promise.resolve(!!react_native_1.NativeModules.HID);
|
|
67
64
|
/**
|
|
68
65
|
* List currently connected devices.
|
|
69
66
|
* @returns Promise of devices
|
|
70
67
|
*/
|
|
71
|
-
static list() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return yield listLedgerDevices();
|
|
76
|
-
});
|
|
68
|
+
static async list() {
|
|
69
|
+
if (!react_native_1.NativeModules.HID)
|
|
70
|
+
return Promise.resolve([]);
|
|
71
|
+
return await listLedgerDevices();
|
|
77
72
|
}
|
|
78
73
|
/**
|
|
79
74
|
* Listen to ledger devices events
|
|
@@ -92,60 +87,50 @@ class HIDTransport extends hw_transport_1.default {
|
|
|
92
87
|
/**
|
|
93
88
|
* Open a the transport with a Ledger device
|
|
94
89
|
*/
|
|
95
|
-
static open(deviceObj) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
static async open(deviceObj) {
|
|
91
|
+
try {
|
|
92
|
+
const nativeObj = await react_native_1.NativeModules.HID.openDevice(deviceObj);
|
|
93
|
+
return new HIDTransport(nativeObj.id, deviceObj.productId);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (disconnectedErrors.includes(error.message)) {
|
|
97
|
+
throw new errors_1.DisconnectedDevice(error.message);
|
|
100
98
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
throw new errors_1.DisconnectedDevice(error.message);
|
|
104
|
-
}
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
108
101
|
}
|
|
109
102
|
/**
|
|
110
103
|
* @param {*} apdu input value
|
|
111
104
|
* @returns Promise of apdu response
|
|
112
105
|
*/
|
|
113
|
-
exchange(apdu) {
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
throw new errors_1.DisconnectedDeviceDuringOperation(error.message);
|
|
128
|
-
}
|
|
129
|
-
throw error;
|
|
106
|
+
async exchange(apdu) {
|
|
107
|
+
return this.exchangeAtomicImpl(async () => {
|
|
108
|
+
try {
|
|
109
|
+
const apduHex = apdu.toString("hex");
|
|
110
|
+
(0, logs_1.log)("apdu", "=> " + apduHex);
|
|
111
|
+
const resultHex = await react_native_1.NativeModules.HID.exchange(this.id, apduHex);
|
|
112
|
+
const res = Buffer.from(resultHex, "hex");
|
|
113
|
+
(0, logs_1.log)("apdu", "<= " + resultHex);
|
|
114
|
+
return res;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (disconnectedErrors.includes(error.message)) {
|
|
118
|
+
this.emit("disconnect", error);
|
|
119
|
+
throw new errors_1.DisconnectedDeviceDuringOperation(error.message);
|
|
130
120
|
}
|
|
131
|
-
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
132
123
|
});
|
|
133
124
|
}
|
|
134
125
|
/**
|
|
135
126
|
* Close the transport
|
|
136
127
|
* @returns Promise
|
|
137
128
|
*/
|
|
138
|
-
close() {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return react_native_1.NativeModules.HID.closeDevice(this.id);
|
|
142
|
-
});
|
|
129
|
+
async close() {
|
|
130
|
+
await this.exchangeBusyPromise;
|
|
131
|
+
return react_native_1.NativeModules.HID.closeDevice(this.id);
|
|
143
132
|
}
|
|
144
133
|
setScrambleKey() { }
|
|
145
134
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Check if the transport is supported (basically true on Android)
|
|
148
|
-
*/
|
|
149
|
-
HIDTransport.isSupported = () => Promise.resolve(!!react_native_1.NativeModules.HID);
|
|
150
135
|
exports.default = HIDTransport;
|
|
151
136
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,+CAAiE;AACjE,+CAA4E;AAE5E,6CAAyF;AACzF,yCAAqC;AACrC,0EAA+C;AAE/C,+BAA6C;AAC7C,8CAA0C;AAK1C,MAAM,kBAAkB,GAAG;IACzB,WAAW;IACX,mHAAmH;IACnH,iBAAiB;IACjB,sCAAsC;CACvC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,IAAI,EAAE;IACnC,MAAM,OAAO,GAAG,MAAM,4BAAa,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IACxD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,2BAAiB,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAkC,IAAI,cAAO,EAAE,CAAC;AAC7E,iCAAkB,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC,MAAW,EAAE,EAAE;IAChE,IAAI,MAAM,CAAC,QAAQ,KAAK,2BAAiB;QAAE,OAAO;IAClD,MAAM,WAAW,GAAG,IAAA,8BAAoB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3D,uBAAuB,CAAC,IAAI,CAAC;QAC3B,IAAI,EAAE,KAAK;QACX,UAAU,EAAE,MAAM;QAClB,WAAW;KACZ,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AACH,iCAAkB,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC,MAAW,EAAE,EAAE;IACnE,IAAI,MAAM,CAAC,QAAQ,KAAK,2BAAiB;QAAE,OAAO;IAClD,MAAM,WAAW,G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,IAAI,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC/C,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;oBAC/B,MAAM,IAAI,0CAAiC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC7D,CAAC;gBAED,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,mBAAmB,CAAC;QAC/B,OAAO,4BAAa,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,cAAc,KAAI,CAAC;;AAjGrB,+BAkGC"}
|
package/lib-es/index.d.ts
CHANGED
package/lib-es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAI/C,KAAK,SAAS,GAAG;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAiCF;;;;;;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,CAAyC;IAElF;;;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
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { NativeModules, DeviceEventEmitter } from "react-native";
|
|
11
2
|
import { ledgerUSBVendorId, identifyUSBProductId } from "@ledgerhq/devices";
|
|
12
3
|
import { DisconnectedDeviceDuringOperation, DisconnectedDevice } from "@ledgerhq/errors";
|
|
@@ -20,10 +11,10 @@ const disconnectedErrors = [
|
|
|
20
11
|
"Invalid channel",
|
|
21
12
|
"Permission denied by user for device",
|
|
22
13
|
];
|
|
23
|
-
const listLedgerDevices = () =>
|
|
24
|
-
const devices =
|
|
14
|
+
const listLedgerDevices = async () => {
|
|
15
|
+
const devices = await NativeModules.HID.getDeviceList();
|
|
25
16
|
return devices.filter(d => d.vendorId === ledgerUSBVendorId);
|
|
26
|
-
}
|
|
17
|
+
};
|
|
27
18
|
const liveDeviceEventsSubject = new Subject();
|
|
28
19
|
DeviceEventEmitter.addListener("onDeviceConnect", (device) => {
|
|
29
20
|
if (device.vendorId !== ledgerUSBVendorId)
|
|
@@ -53,22 +44,26 @@ const liveDeviceEvents = liveDeviceEventsSubject;
|
|
|
53
44
|
* ...
|
|
54
45
|
* TransportHID.create().then(transport => ...)
|
|
55
46
|
*/
|
|
56
|
-
class HIDTransport extends Transport {
|
|
47
|
+
export default class HIDTransport extends Transport {
|
|
48
|
+
id;
|
|
49
|
+
deviceModel;
|
|
57
50
|
constructor(nativeId, productId) {
|
|
58
51
|
super();
|
|
59
52
|
this.id = nativeId;
|
|
60
53
|
this.deviceModel = identifyUSBProductId(productId);
|
|
61
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if the transport is supported (basically true on Android)
|
|
57
|
+
*/
|
|
58
|
+
static isSupported = () => Promise.resolve(!!NativeModules.HID);
|
|
62
59
|
/**
|
|
63
60
|
* List currently connected devices.
|
|
64
61
|
* @returns Promise of devices
|
|
65
62
|
*/
|
|
66
|
-
static list() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return yield listLedgerDevices();
|
|
71
|
-
});
|
|
63
|
+
static async list() {
|
|
64
|
+
if (!NativeModules.HID)
|
|
65
|
+
return Promise.resolve([]);
|
|
66
|
+
return await listLedgerDevices();
|
|
72
67
|
}
|
|
73
68
|
/**
|
|
74
69
|
* Listen to ledger devices events
|
|
@@ -87,60 +82,49 @@ class HIDTransport extends Transport {
|
|
|
87
82
|
/**
|
|
88
83
|
* Open a the transport with a Ledger device
|
|
89
84
|
*/
|
|
90
|
-
static open(deviceObj) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
static async open(deviceObj) {
|
|
86
|
+
try {
|
|
87
|
+
const nativeObj = await NativeModules.HID.openDevice(deviceObj);
|
|
88
|
+
return new HIDTransport(nativeObj.id, deviceObj.productId);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (disconnectedErrors.includes(error.message)) {
|
|
92
|
+
throw new DisconnectedDevice(error.message);
|
|
95
93
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
throw new DisconnectedDevice(error.message);
|
|
99
|
-
}
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
103
96
|
}
|
|
104
97
|
/**
|
|
105
98
|
* @param {*} apdu input value
|
|
106
99
|
* @returns Promise of apdu response
|
|
107
100
|
*/
|
|
108
|
-
exchange(apdu) {
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
throw new DisconnectedDeviceDuringOperation(error.message);
|
|
123
|
-
}
|
|
124
|
-
throw error;
|
|
101
|
+
async exchange(apdu) {
|
|
102
|
+
return this.exchangeAtomicImpl(async () => {
|
|
103
|
+
try {
|
|
104
|
+
const apduHex = apdu.toString("hex");
|
|
105
|
+
log("apdu", "=> " + apduHex);
|
|
106
|
+
const resultHex = await NativeModules.HID.exchange(this.id, apduHex);
|
|
107
|
+
const res = Buffer.from(resultHex, "hex");
|
|
108
|
+
log("apdu", "<= " + resultHex);
|
|
109
|
+
return res;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (disconnectedErrors.includes(error.message)) {
|
|
113
|
+
this.emit("disconnect", error);
|
|
114
|
+
throw new DisconnectedDeviceDuringOperation(error.message);
|
|
125
115
|
}
|
|
126
|
-
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
127
118
|
});
|
|
128
119
|
}
|
|
129
120
|
/**
|
|
130
121
|
* Close the transport
|
|
131
122
|
* @returns Promise
|
|
132
123
|
*/
|
|
133
|
-
close() {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return NativeModules.HID.closeDevice(this.id);
|
|
137
|
-
});
|
|
124
|
+
async close() {
|
|
125
|
+
await this.exchangeBusyPromise;
|
|
126
|
+
return NativeModules.HID.closeDevice(this.id);
|
|
138
127
|
}
|
|
139
128
|
setScrambleKey() { }
|
|
140
129
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Check if the transport is supported (basically true on Android)
|
|
143
|
-
*/
|
|
144
|
-
HIDTransport.isSupported = () => Promise.resolve(!!NativeModules.HID);
|
|
145
|
-
export default HIDTransport;
|
|
146
130
|
//# sourceMappingURL=index.js.map
|
package/lib-es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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,EAAE,iCAAiC,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzF,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,MAAM,kBAAkB,GAAG;IACzB,WAAW;IACX,mHAAmH;IACnH,iBAAiB;IACjB,sCAAsC;CACvC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,IAAI,EAAE;IACnC,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IACxD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,iBAAiB,CAAC,CAAC;AAC/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B,CAAC,KAAK,IAAI,EAAE;YACxC,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACrC,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC;gBAC7B,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;gBACrE,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;gBAC1C,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;gBAC/B,OAAO,GAAG,CAAC;YACb,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC/C,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;oBAC/B,MAAM,IAAI,iCAAiC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC7D,CAAC;gBAED,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,mBAAmB,CAAC;QAC/B,OAAO,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,cAAc,KAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/react-native-hid",
|
|
3
|
-
"version": "6.32.
|
|
3
|
+
"version": "6.32.5-nightly.1",
|
|
4
4
|
"nativePackage": true,
|
|
5
5
|
"description": "Ledger Hardware Wallet Web implementation of the communication layer, using U2F api",
|
|
6
6
|
"keywords": [
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"rxjs": "^7.8.1",
|
|
33
|
-
"@ledgerhq/devices": "
|
|
34
|
-
"@ledgerhq/errors": "^6.
|
|
35
|
-
"@ledgerhq/hw-transport": "^6.31.
|
|
33
|
+
"@ledgerhq/devices": "8.4.5-nightly.1",
|
|
34
|
+
"@ledgerhq/errors": "^6.20.0-nightly.1",
|
|
35
|
+
"@ledgerhq/hw-transport": "^6.31.5-nightly.1",
|
|
36
36
|
"@ledgerhq/logs": "^6.12.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/jest": "^29.5.10",
|
|
40
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^22.10.10",
|
|
41
41
|
"documentation": "14.0.2",
|
|
42
42
|
"jest": "^29.7.0",
|
|
43
43
|
"rimraf": "^4.4.1",
|
|
@@ -52,9 +52,10 @@
|
|
|
52
52
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
53
53
|
"scripts": {
|
|
54
54
|
"clean": "rimraf lib lib-es",
|
|
55
|
-
"build": "tsc && tsc -m
|
|
55
|
+
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
|
|
56
56
|
"prewatch": "pnpm build",
|
|
57
57
|
"watch": "tsc --watch",
|
|
58
|
+
"watch:es": "tsc --watch -m esnext --moduleResolution bundler --outDir lib-es",
|
|
58
59
|
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
59
60
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
60
61
|
"lint:fix": "pnpm lint --fix",
|