@ledgerhq/react-native-hid 6.27.1 → 6.28.2

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.
@@ -0,0 +1,2 @@
1
+ @ledgerhq/react-native-hid:build: cache hit, replaying output 52863a64600c2098
2
+ @ledgerhq/react-native-hid:build: $ NODE_ENV=production tsc && tsc -m ES6 --outDir lib-es
@@ -1,7 +1,6 @@
1
1
  buildscript {
2
2
  repositories {
3
3
  mavenCentral()
4
- jcenter()
5
4
  google()
6
5
  maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
7
6
  }
@@ -14,7 +13,6 @@ buildscript {
14
13
  allprojects {
15
14
  repositories {
16
15
  mavenCentral()
17
- jcenter()
18
16
  google()
19
17
  maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
20
18
  }
@@ -39,7 +37,6 @@ android {
39
37
 
40
38
  repositories {
41
39
  mavenCentral()
42
- jcenter()
43
40
  google()
44
41
  maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
45
42
  maven {
package/lib-es/index.d.ts CHANGED
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/react-native-hid",
3
- "version": "6.27.1",
3
+ "version": "6.28.2",
4
4
  "nativePackage": true,
5
5
  "description": "Ledger Hardware Wallet Web implementation of the communication layer, using U2F api",
6
6
  "keywords": [
@@ -48,5 +48,5 @@
48
48
  "watch": "bash ../../script/watch.sh",
49
49
  "doc": "bash ../../script/doc.sh"
50
50
  },
51
- "gitHead": "9639f96a970e1f46e9e39d0c2c361ce2289923be"
51
+ "gitHead": "e86a1210a6b9d4271116b21c195bcadbf11b950f"
52
52
  }
@@ -1,156 +0,0 @@
1
- //@flow
2
- import { NativeModules, DeviceEventEmitter } from "react-native";
3
- import { ledgerUSBVendorId, identifyUSBProductId } from "@ledgerhq/devices";
4
- import type { DeviceModel } from "@ledgerhq/devices";
5
- import {
6
- DisconnectedDeviceDuringOperation,
7
- DisconnectedDevice,
8
- } from "@ledgerhq/errors";
9
- import { log } from "@ledgerhq/logs";
10
- import Transport from "@ledgerhq/hw-transport";
11
- import type { DescriptorEvent } from "@ledgerhq/hw-transport";
12
- import { Subject, from, concat } from "rxjs";
13
- import { mergeMap } from "rxjs/operators";
14
-
15
- type DeviceObj = {
16
- vendorId: number,
17
- productId: number,
18
- };
19
-
20
- const disconnectedErrors = [
21
- "I/O error",
22
- "Attempt to invoke virtual method 'int android.hardware.usb.UsbDevice.getDeviceClass()' on a null object reference",
23
- ];
24
-
25
- const listLedgerDevices = async () => {
26
- const devices = await NativeModules.HID.getDeviceList();
27
- return devices.filter((d) => d.vendorId === ledgerUSBVendorId);
28
- };
29
-
30
- const liveDeviceEventsSubject: Subject<DescriptorEvent<*>> = new Subject();
31
-
32
- DeviceEventEmitter.addListener("onDeviceConnect", (device: *) => {
33
- if (device.vendorId !== ledgerUSBVendorId) return;
34
- const deviceModel = identifyUSBProductId(device.productId);
35
- liveDeviceEventsSubject.next({
36
- type: "add",
37
- descriptor: device,
38
- deviceModel,
39
- });
40
- });
41
-
42
- DeviceEventEmitter.addListener("onDeviceDisconnect", (device: *) => {
43
- if (device.vendorId !== ledgerUSBVendorId) return;
44
- const deviceModel = identifyUSBProductId(device.productId);
45
- liveDeviceEventsSubject.next({
46
- type: "remove",
47
- descriptor: device,
48
- deviceModel,
49
- });
50
- });
51
-
52
- const liveDeviceEvents = liveDeviceEventsSubject;
53
-
54
- /**
55
- * Ledger's React Native HID Transport implementation
56
- * @example
57
- * import TransportHID from "@ledgerhq/react-native-hid";
58
- * ...
59
- * TransportHID.create().then(transport => ...)
60
- */
61
- export default class HIDTransport extends Transport<DeviceObj> {
62
- id: number;
63
- deviceModel: ?DeviceModel;
64
-
65
- constructor(nativeId: number, productId: number) {
66
- super();
67
- this.id = nativeId;
68
- this.deviceModel = identifyUSBProductId(productId);
69
- }
70
-
71
- /**
72
- * Check if the transport is supported (basically true on Android)
73
- */
74
- static isSupported = (): Promise<boolean> =>
75
- Promise.resolve(!!NativeModules.HID);
76
-
77
- /**
78
- * List currently connected devices.
79
- * @returns Promise of devices
80
- */
81
- static async list() {
82
- if (!NativeModules.HID) return Promise.resolve([]);
83
- let list = await listLedgerDevices();
84
- return list;
85
- }
86
-
87
- /**
88
- * Listen to ledger devices events
89
- */
90
- static listen(observer: any): any {
91
- if (!NativeModules.HID) return { unsubscribe: () => {} };
92
- return concat(
93
- from(listLedgerDevices()).pipe(
94
- mergeMap((devices) =>
95
- from(
96
- devices.map((device) => ({
97
- type: "add",
98
- descriptor: device,
99
- deviceModel: identifyUSBProductId(device.productId),
100
- }))
101
- )
102
- )
103
- ),
104
- liveDeviceEvents
105
- ).subscribe(observer);
106
- }
107
-
108
- /**
109
- * Open a the transport with a Ledger device
110
- */
111
- static async open(deviceObj: DeviceObj) {
112
- try {
113
- const nativeObj = await NativeModules.HID.openDevice(deviceObj);
114
- return new HIDTransport(nativeObj.id, deviceObj.productId);
115
- } catch (error) {
116
- if (disconnectedErrors.includes(error.message)) {
117
- throw new DisconnectedDevice(error.message);
118
- }
119
- throw error;
120
- }
121
- }
122
-
123
- /**
124
- * @param {*} apdu input value
125
- * @returns Promise of apdu response
126
- */
127
- async exchange(apdu: Buffer) {
128
- return this.exchangeAtomicImpl(async () => {
129
- try {
130
- const apduHex = apdu.toString("hex");
131
- log("apdu", "=> " + apduHex);
132
- const resultHex = await NativeModules.HID.exchange(this.id, apduHex);
133
- const res = Buffer.from(resultHex, "hex");
134
- log("apdu", "<= " + resultHex);
135
- return res;
136
- } catch (error) {
137
- if (disconnectedErrors.includes(error.message)) {
138
- this.emit("disconnect", error);
139
- throw new DisconnectedDeviceDuringOperation(error.message);
140
- }
141
- throw error;
142
- }
143
- });
144
- }
145
-
146
- /**
147
- * Close the transport
148
- * @returns Promise
149
- */
150
- async close() {
151
- await this.exchangeBusyPromise;
152
- return NativeModules.HID.closeDevice(this.id);
153
- }
154
-
155
- setScrambleKey() {}
156
- }