@onekeyfe/hd-core 0.1.25 → 0.1.28
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/dist/api/BaseMethod.d.ts +1 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/RequestWebUsbDevice.d.ts +8 -0
- package/dist/api/RequestWebUsbDevice.d.ts.map +1 -0
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/device/DeviceSupportFeatures.d.ts +9 -0
- package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -13
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DeviceList.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +41 -0
- package/dist/device/DevicePool.d.ts.map +1 -0
- package/dist/events/device.d.ts +22 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/index.d.ts +42 -5
- package/dist/index.js +392 -203
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/deviceSupportFeatures.d.ts +7 -0
- package/dist/types/api/deviceSupportFeatures.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +1 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +4 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/requestWebUsbDevice.d.ts +6 -0
- package/dist/types/api/requestWebUsbDevice.d.ts.map +1 -0
- package/dist/types/device.d.ts +3 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +14 -1
- package/src/api/RequestWebUsbDevice.ts +53 -0
- package/src/api/SearchDevices.ts +3 -11
- package/src/api/device/DeviceSupportFeatures.ts +20 -0
- package/src/api/index.ts +3 -0
- package/src/core/index.ts +30 -5
- package/src/data-manager/TransportManager.ts +3 -1
- package/src/device/Device.ts +2 -1
- package/src/device/DeviceCommands.ts +9 -0
- package/src/device/DeviceConnector.ts +7 -76
- package/src/device/DeviceList.ts +3 -44
- package/src/device/DevicePool.ts +243 -0
- package/src/events/device.ts +24 -2
- package/src/inject.ts +2 -0
- package/src/types/api/deviceSupportFeatures.ts +6 -0
- package/src/types/api/export.ts +1 -0
- package/src/types/api/index.ts +5 -0
- package/src/types/api/requestWebUsbDevice.ts +4 -0
- package/src/types/device.ts +4 -0
- package/src/types/settings.ts +1 -1
- package/src/utils/deviceFeaturesUtils.ts +16 -0
- package/src/utils/logger.ts +4 -0
package/src/device/DeviceList.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
import DeviceConnector from './DeviceConnector';
|
|
3
3
|
import { Device } from './Device';
|
|
4
|
-
import {
|
|
5
|
-
import { getLogger, LoggerNames } from '../utils';
|
|
6
|
-
|
|
7
|
-
// const cacheDeviceMap = new Map<string, Device>();
|
|
8
|
-
const cacheDeviceMap: Record<string, Device> = {};
|
|
9
|
-
|
|
10
|
-
const Log = getLogger(LoggerNames.DeviceList);
|
|
4
|
+
import { DevicePool } from './DevicePool';
|
|
11
5
|
|
|
12
6
|
export class DeviceList extends EventEmitter {
|
|
13
7
|
devices: Record<string, Device> = {};
|
|
@@ -23,44 +17,9 @@ export class DeviceList extends EventEmitter {
|
|
|
23
17
|
const descriptorList = deviceDiff?.descriptors ?? [];
|
|
24
18
|
|
|
25
19
|
this.devices = {};
|
|
26
|
-
const deviceList = [];
|
|
27
|
-
Log.debug('get device list');
|
|
28
|
-
|
|
29
|
-
// find existed device
|
|
30
|
-
if (connectId) {
|
|
31
|
-
const device = cacheDeviceMap[connectId];
|
|
32
|
-
if (device) {
|
|
33
|
-
const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
|
|
34
|
-
if (exist) {
|
|
35
|
-
device.updateDescriptor(exist, true);
|
|
36
|
-
Log.debug('find existed Device: ', connectId);
|
|
37
|
-
this.devices[connectId] = device;
|
|
38
|
-
return [device];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for await (const descriptor of descriptorList) {
|
|
44
|
-
let device = Device.fromDescriptor(descriptor);
|
|
45
|
-
device.deviceConnector = this.connector;
|
|
46
|
-
await device.connect();
|
|
47
|
-
await device.initialize();
|
|
48
|
-
await device.release();
|
|
49
|
-
|
|
50
|
-
// clean session after release
|
|
51
|
-
deviceList.push(device);
|
|
52
|
-
if (device.features) {
|
|
53
|
-
const uuid = getDeviceUUID(device.features);
|
|
54
|
-
if (cacheDeviceMap[uuid]) {
|
|
55
|
-
const cache = cacheDeviceMap[uuid];
|
|
56
|
-
cache?.updateFromCache(device);
|
|
57
|
-
device = cache;
|
|
58
|
-
}
|
|
59
|
-
this.devices[uuid] = device;
|
|
60
|
-
cacheDeviceMap[uuid] = device;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
20
|
|
|
21
|
+
const { deviceList, devices } = await DevicePool.getDevices(descriptorList, connectId);
|
|
22
|
+
this.devices = devices;
|
|
64
23
|
return deviceList;
|
|
65
24
|
}
|
|
66
25
|
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
3
|
+
// eslint-disable-next-line import/no-cycle
|
|
4
|
+
import { Device } from './Device';
|
|
5
|
+
import { DEVICE } from '../events';
|
|
6
|
+
import type DeviceConnector from './DeviceConnector';
|
|
7
|
+
import { getDeviceUUID, getLogger, LoggerNames } from '../utils';
|
|
8
|
+
|
|
9
|
+
const Log = getLogger(LoggerNames.DevicePool);
|
|
10
|
+
|
|
11
|
+
export type DeviceDescriptorDiff = {
|
|
12
|
+
didUpdate: boolean;
|
|
13
|
+
connected: DeviceDescriptor[];
|
|
14
|
+
disconnected: DeviceDescriptor[];
|
|
15
|
+
changedSessions: DeviceDescriptor[];
|
|
16
|
+
changedDebugSessions: DeviceDescriptor[];
|
|
17
|
+
acquired: DeviceDescriptor[];
|
|
18
|
+
debugAcquired: DeviceDescriptor[];
|
|
19
|
+
released: DeviceDescriptor[];
|
|
20
|
+
debugReleased: DeviceDescriptor[];
|
|
21
|
+
descriptors: DeviceDescriptor[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getDiff = (
|
|
25
|
+
current: DeviceDescriptor[],
|
|
26
|
+
descriptors: DeviceDescriptor[]
|
|
27
|
+
): DeviceDescriptorDiff => {
|
|
28
|
+
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
29
|
+
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
30
|
+
const changedSessions = descriptors.filter(d => {
|
|
31
|
+
const currentDescriptor = current.find(x => x.path === d.path);
|
|
32
|
+
if (currentDescriptor) {
|
|
33
|
+
// return currentDescriptor.debug ? (currentDescriptor.debugSession !== d.debugSession) : (currentDescriptor.session !== d.session);
|
|
34
|
+
return currentDescriptor.session !== d.session;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
const acquired = changedSessions.filter(d => typeof d.session === 'string');
|
|
39
|
+
const released = changedSessions.filter(
|
|
40
|
+
d =>
|
|
41
|
+
// const session = descriptor.debug ? descriptor.debugSession : descriptor.session;
|
|
42
|
+
typeof d.session !== 'string'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const changedDebugSessions = descriptors.filter(d => {
|
|
46
|
+
const currentDescriptor = current.find(x => x.path === d.path);
|
|
47
|
+
if (currentDescriptor) {
|
|
48
|
+
return currentDescriptor.debugSession !== d.debugSession;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
});
|
|
52
|
+
const debugAcquired = changedSessions.filter(d => typeof d.debugSession === 'string');
|
|
53
|
+
const debugReleased = changedSessions.filter(d => typeof d.debugSession !== 'string');
|
|
54
|
+
|
|
55
|
+
const didUpdate =
|
|
56
|
+
connected.length + disconnected.length + changedSessions.length + changedDebugSessions.length >
|
|
57
|
+
0;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
connected,
|
|
61
|
+
disconnected,
|
|
62
|
+
changedSessions,
|
|
63
|
+
acquired,
|
|
64
|
+
released,
|
|
65
|
+
changedDebugSessions,
|
|
66
|
+
debugAcquired,
|
|
67
|
+
debugReleased,
|
|
68
|
+
didUpdate,
|
|
69
|
+
descriptors,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export class DevicePool extends EventEmitter {
|
|
74
|
+
static current: DeviceDescriptor[] | null = null;
|
|
75
|
+
|
|
76
|
+
static upcoming: DeviceDescriptor[] = [];
|
|
77
|
+
|
|
78
|
+
static connectedPool: DeviceDescriptor[] = [];
|
|
79
|
+
|
|
80
|
+
static disconnectPool: DeviceDescriptor[] = [];
|
|
81
|
+
|
|
82
|
+
static devicesCache: Record<string, Device> = {};
|
|
83
|
+
|
|
84
|
+
static emitter = new EventEmitter();
|
|
85
|
+
|
|
86
|
+
static connector: DeviceConnector;
|
|
87
|
+
|
|
88
|
+
static setConnector(connector: DeviceConnector) {
|
|
89
|
+
this.connector = connector;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static async getDevices(descriptorList: DeviceDescriptor[], connectId?: string) {
|
|
93
|
+
Log.debug('get device list');
|
|
94
|
+
|
|
95
|
+
const devices: Record<string, Device> = {};
|
|
96
|
+
const deviceList = [];
|
|
97
|
+
|
|
98
|
+
// If there is a connectId
|
|
99
|
+
// it means that you only want to get data from cache
|
|
100
|
+
if (connectId) {
|
|
101
|
+
const device = this.devicesCache[connectId];
|
|
102
|
+
if (device) {
|
|
103
|
+
const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
|
|
104
|
+
if (exist) {
|
|
105
|
+
Log.debug('find existed Device: ', connectId);
|
|
106
|
+
device.updateDescriptor(exist, true);
|
|
107
|
+
devices[connectId] = device;
|
|
108
|
+
deviceList.push(device);
|
|
109
|
+
await this._checkDevicePool();
|
|
110
|
+
return { devices, deviceList };
|
|
111
|
+
}
|
|
112
|
+
Log.debug('found device in cache, but path is different: ', connectId);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for await (const descriptor of descriptorList) {
|
|
117
|
+
const device = await this._createDevice(descriptor);
|
|
118
|
+
|
|
119
|
+
if (device.features) {
|
|
120
|
+
const uuid = getDeviceUUID(device.features);
|
|
121
|
+
if (this.devicesCache[uuid]) {
|
|
122
|
+
const cache = this.devicesCache[uuid];
|
|
123
|
+
cache.updateDescriptor(descriptor, true);
|
|
124
|
+
}
|
|
125
|
+
this.devicesCache[uuid] = device;
|
|
126
|
+
devices[uuid] = device;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
deviceList.push(device);
|
|
130
|
+
}
|
|
131
|
+
Log.debug('get devices result : ', devices, deviceList);
|
|
132
|
+
console.log('device poll -> connected: ', this.connectedPool);
|
|
133
|
+
console.log('device poll -> disconnected: ', this.disconnectPool);
|
|
134
|
+
await this._checkDevicePool();
|
|
135
|
+
return { devices, deviceList };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static async _createDevice(descriptor: DeviceDescriptor) {
|
|
139
|
+
let device = this.getDeviceByPath(descriptor.path);
|
|
140
|
+
if (!device) {
|
|
141
|
+
device = Device.fromDescriptor(descriptor);
|
|
142
|
+
device.deviceConnector = this.connector;
|
|
143
|
+
await device.connect();
|
|
144
|
+
await device.initialize();
|
|
145
|
+
await device.release();
|
|
146
|
+
}
|
|
147
|
+
return device;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static async _checkDevicePool() {
|
|
151
|
+
await this._sendConnectMessage();
|
|
152
|
+
this._sendDisconnectMessage();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static async _sendConnectMessage() {
|
|
156
|
+
for (let i = this.connectedPool.length - 1; i >= 0; i--) {
|
|
157
|
+
const descriptor = this.connectedPool[i];
|
|
158
|
+
const device = await this._createDevice(descriptor);
|
|
159
|
+
Log.debug('emit DEVICE.CONNECT: ', device);
|
|
160
|
+
this.emitter.emit(DEVICE.CONNECT, device);
|
|
161
|
+
this.connectedPool.splice(i, 1);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static _sendDisconnectMessage() {
|
|
166
|
+
for (let i = this.disconnectPool.length - 1; i >= 0; i--) {
|
|
167
|
+
const descriptor = this.connectedPool[i];
|
|
168
|
+
const device = this.getDeviceByPath(descriptor.path);
|
|
169
|
+
if (device) {
|
|
170
|
+
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
171
|
+
}
|
|
172
|
+
this.disconnectPool.splice(i, 1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static reportDeviceChange(upcoming: DeviceDescriptor[]) {
|
|
177
|
+
const diff = getDiff(this.current || [], upcoming);
|
|
178
|
+
|
|
179
|
+
this.upcoming = upcoming;
|
|
180
|
+
this.current = this.upcoming;
|
|
181
|
+
|
|
182
|
+
console.log('device pool -> current: ', this.current);
|
|
183
|
+
console.log('device pool -> upcomming: ', this.upcoming);
|
|
184
|
+
console.log('DeviceCache.reportDeviceChange diff: ', diff);
|
|
185
|
+
|
|
186
|
+
if (!diff.didUpdate) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
diff.connected.forEach(d => {
|
|
191
|
+
const device = this.getDeviceByPath(d.path);
|
|
192
|
+
if (!device) {
|
|
193
|
+
this._addConnectedDeviceToPool(d);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
Log.debug('emit DEVICE.CONNECT: ', device);
|
|
197
|
+
this.emitter.emit(DEVICE.CONNECT, device);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
diff.disconnected.forEach(d => {
|
|
201
|
+
this._removeDeviceFromConnectedPool(d.path);
|
|
202
|
+
const device = this.getDeviceByPath(d.path);
|
|
203
|
+
if (!device) {
|
|
204
|
+
this._addDisconnectedDeviceToPool(d);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
Log.debug('emit DEVICE.DISCONNECT: ', device);
|
|
209
|
+
this.emitter.emit(DEVICE.DISCONNECT, device);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static getDeviceByPath(path: string) {
|
|
214
|
+
return Object.values(this.devicesCache).find(d => d.originalDescriptor.path === path);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static _addConnectedDeviceToPool(descriptor: DeviceDescriptor) {
|
|
218
|
+
const existDescriptorIndex = this.connectedPool.findIndex(d => d.path === descriptor.path);
|
|
219
|
+
if (existDescriptorIndex > -1) {
|
|
220
|
+
this.connectedPool.splice(existDescriptorIndex, 1, descriptor);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this.connectedPool.push(descriptor);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static _removeDeviceFromConnectedPool(path: string) {
|
|
228
|
+
const index = this.connectedPool.findIndex(d => d.path === path);
|
|
229
|
+
if (index > -1) {
|
|
230
|
+
this.connectedPool.splice(index, 1);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
static _addDisconnectedDeviceToPool(descriptor: DeviceDescriptor) {
|
|
235
|
+
const existDescriptorIndex = this.disconnectPool.findIndex(d => d.path === descriptor.path);
|
|
236
|
+
if (existDescriptorIndex > -1) {
|
|
237
|
+
this.disconnectPool.splice(existDescriptorIndex, 1, descriptor);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
this.disconnectPool.push(descriptor);
|
|
242
|
+
}
|
|
243
|
+
}
|
package/src/events/device.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PROTO } from '../constants';
|
|
2
|
-
import type { Features, KnownDevice as Device } from '../types/device';
|
|
2
|
+
import type { Features, KnownDevice as Device, SupportFeatures } from '../types/device';
|
|
3
3
|
import { MessageFactoryFn } from './utils';
|
|
4
4
|
|
|
5
5
|
export const DEVICE_EVENT = 'DEVICE_EVENT';
|
|
@@ -24,10 +24,21 @@ export const DEVICE = {
|
|
|
24
24
|
PASSPHRASE: 'passphrase',
|
|
25
25
|
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
26
26
|
WORD: 'word',
|
|
27
|
+
SUPPORT_FEATURES: 'support_features',
|
|
27
28
|
|
|
28
29
|
FEATURES: 'features',
|
|
29
30
|
} as const;
|
|
30
31
|
|
|
32
|
+
export interface DeviceConnnectRequest {
|
|
33
|
+
type: typeof DEVICE.CONNECT;
|
|
34
|
+
payload: { device: Device };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface DeviceDisconnnectRequest {
|
|
38
|
+
type: typeof DEVICE.DISCONNECT;
|
|
39
|
+
payload: { device: Device };
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'code'> {
|
|
32
43
|
code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
|
|
33
44
|
}
|
|
@@ -44,7 +55,18 @@ export interface DeviceSendFeatures {
|
|
|
44
55
|
payload: DeviceFeaturesPayload;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
export type
|
|
58
|
+
export type DeviceSupportFeaturesPayload = SupportFeatures & { device: Device | null };
|
|
59
|
+
export interface DeviceSendSupportFeatures {
|
|
60
|
+
type: typeof DEVICE.SUPPORT_FEATURES;
|
|
61
|
+
payload: DeviceSupportFeaturesPayload;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type DeviceEvent =
|
|
65
|
+
| DeviceButtonRequest
|
|
66
|
+
| DeviceSendFeatures
|
|
67
|
+
| DeviceSendSupportFeatures
|
|
68
|
+
| DeviceDisconnnectRequest
|
|
69
|
+
| DeviceConnnectRequest;
|
|
48
70
|
|
|
49
71
|
export type DeviceEventMessage = DeviceEvent & { event: typeof DEVICE_EVENT };
|
|
50
72
|
|
package/src/inject.ts
CHANGED
|
@@ -85,6 +85,7 @@ export const inject = ({
|
|
|
85
85
|
deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
|
|
86
86
|
deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
|
|
87
87
|
deviceUpdateReboot: connectId => call({ connectId, method: 'deviceUpdateReboot' }),
|
|
88
|
+
deviceSupportFeatures: connectId => call({ connectId, method: 'deviceSupportFeatures' }),
|
|
88
89
|
deviceVerify: (connectId, params) => call({ ...params, connectId, method: 'deviceVerify' }),
|
|
89
90
|
deviceWipe: connectId => call({ connectId, method: 'deviceWipe' }),
|
|
90
91
|
|
|
@@ -141,6 +142,7 @@ export const inject = ({
|
|
|
141
142
|
call({ ...params, connectId, deviceId, method: 'stellarSignTransaction' }),
|
|
142
143
|
|
|
143
144
|
firmwareUpdate: (connectId, params) => call({ ...params, connectId, method: 'firmwareUpdate' }),
|
|
145
|
+
requestWebUsbDevice: () => call({ method: 'requestWebUsbDevice' }),
|
|
144
146
|
};
|
|
145
147
|
return api;
|
|
146
148
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Response } from '../params';
|
|
2
|
+
import type { Device, SupportFeatures } from '../device';
|
|
3
|
+
|
|
4
|
+
export type DeviceSupportFeatures = SupportFeatures & { device: Device | null };
|
|
5
|
+
|
|
6
|
+
export declare function deviceSupportFeatures(connectId?: string): Response<DeviceSupportFeatures>;
|
package/src/types/api/export.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type { DeviceRecoveryParams } from './deviceRecovery';
|
|
|
19
19
|
export type { DeviceResetParams } from './deviceReset';
|
|
20
20
|
export type { DeviceSettingsParams } from './deviceSettings';
|
|
21
21
|
export type { DeviceVerifyParams, DeviceVerifySignature } from './deviceVerify';
|
|
22
|
+
export type { DeviceSupportFeatures } from './deviceSupportFeatures';
|
|
22
23
|
|
|
23
24
|
export type { EVMAddress, EVMGetAddressParams } from './evmGetAddress';
|
|
24
25
|
export type { EVMPublicKey, EVMGetPublicKeyParams } from './evmGetPublicKey';
|
package/src/types/api/index.ts
CHANGED
|
@@ -43,6 +43,8 @@ import { stellarSignTransaction } from './stellarSignTransaction';
|
|
|
43
43
|
import { cipherKeyValue } from './cipherKeyValue';
|
|
44
44
|
import { firmwareUpdate } from './firmwareUpdate';
|
|
45
45
|
import { getLogs } from './getLogs';
|
|
46
|
+
import { deviceSupportFeatures } from './deviceSupportFeatures';
|
|
47
|
+
import { requestWebUsbDevice } from './requestWebUsbDevice';
|
|
46
48
|
|
|
47
49
|
export * from './export';
|
|
48
50
|
|
|
@@ -65,6 +67,8 @@ export type CoreApi = {
|
|
|
65
67
|
*/
|
|
66
68
|
searchDevices: typeof searchDevices;
|
|
67
69
|
|
|
70
|
+
requestWebUsbDevice: typeof requestWebUsbDevice;
|
|
71
|
+
|
|
68
72
|
getFeatures: typeof getFeatures;
|
|
69
73
|
|
|
70
74
|
checkFirmwareRelease: typeof checkFirmwareRelease;
|
|
@@ -85,6 +89,7 @@ export type CoreApi = {
|
|
|
85
89
|
deviceReset: typeof deviceReset;
|
|
86
90
|
deviceSettings: typeof deviceSettings;
|
|
87
91
|
deviceUpdateReboot: typeof deviceUpdateReboot;
|
|
92
|
+
deviceSupportFeatures: typeof deviceSupportFeatures;
|
|
88
93
|
deviceVerify: typeof deviceVerify;
|
|
89
94
|
deviceWipe: typeof deviceWipe;
|
|
90
95
|
|
package/src/types/device.ts
CHANGED
package/src/types/settings.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type ConnectSettings = {
|
|
|
14
14
|
priority: number;
|
|
15
15
|
trustedHost: boolean;
|
|
16
16
|
supportedBrowser?: boolean;
|
|
17
|
-
env: 'node' | 'web' | 'webextension' | 'electron' | 'react-native';
|
|
17
|
+
env: 'node' | 'web' | 'webextension' | 'electron' | 'react-native' | 'webusb';
|
|
18
18
|
timestamp: number;
|
|
19
19
|
isFrame?: boolean;
|
|
20
20
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
1
2
|
import type { Features, IVersionArray, IDeviceType, IDeviceModel } from '../types';
|
|
2
3
|
|
|
3
4
|
export const getDeviceModel = (features?: Features): IDeviceModel => {
|
|
@@ -80,5 +81,20 @@ export const getDeviceBLEFirmwareVersion = (features: Features): IVersionArray |
|
|
|
80
81
|
if (!features.ble_ver) {
|
|
81
82
|
return null;
|
|
82
83
|
}
|
|
84
|
+
if (!semver.valid(features.ble_ver)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
83
87
|
return features.ble_ver.split('.') as unknown as IVersionArray;
|
|
84
88
|
};
|
|
89
|
+
|
|
90
|
+
export const supportInputPinOnSoftware = (features: Features): boolean => {
|
|
91
|
+
if (!features) return false;
|
|
92
|
+
|
|
93
|
+
const deviceType = getDeviceType(features);
|
|
94
|
+
if (deviceType === 'touch') {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const currentVersion = getDeviceFirmwareVersion(features).join('.');
|
|
99
|
+
return semver.gte(currentVersion, '2.3.0');
|
|
100
|
+
};
|
package/src/utils/logger.ts
CHANGED
|
@@ -151,6 +151,8 @@ export enum LoggerNames {
|
|
|
151
151
|
DeviceCommands = 'DeviceCommands',
|
|
152
152
|
DeviceConnector = 'DeviceConnector',
|
|
153
153
|
DeviceList = 'DeviceList',
|
|
154
|
+
DevicePool = 'DevicePool',
|
|
155
|
+
HdCommonConnectSdk = '@onekey/common-connect-sdk',
|
|
154
156
|
HdBleSdk = '@onekey/hd-ble-sdk',
|
|
155
157
|
HdTransportHttp = '@onekey/hd-transport-http',
|
|
156
158
|
HdBleTransport = '@onekey/hd-ble-transport',
|
|
@@ -167,6 +169,7 @@ export const LoggerMap = {
|
|
|
167
169
|
[LoggerNames.DeviceCommands]: initLog(LoggerNames.DeviceCommands),
|
|
168
170
|
[LoggerNames.DeviceConnector]: initLog(LoggerNames.DeviceConnector),
|
|
169
171
|
[LoggerNames.DeviceList]: initLog(LoggerNames.DeviceList),
|
|
172
|
+
[LoggerNames.DevicePool]: initLog(LoggerNames.DevicePool),
|
|
170
173
|
[LoggerNames.HdBleSdk]: initLog(LoggerNames.HdBleSdk),
|
|
171
174
|
[LoggerNames.HdTransportHttp]: initLog(LoggerNames.HdTransportHttp),
|
|
172
175
|
[LoggerNames.HdBleTransport]: initLog(LoggerNames.HdBleTransport),
|
|
@@ -174,6 +177,7 @@ export const LoggerMap = {
|
|
|
174
177
|
[LoggerNames.Iframe]: initLog(LoggerNames.Iframe),
|
|
175
178
|
[LoggerNames.SendMessage]: initLog(LoggerNames.SendMessage),
|
|
176
179
|
[LoggerNames.Method]: initLog(LoggerNames.Method),
|
|
180
|
+
[LoggerNames.HdCommonConnectSdk]: initLog(LoggerNames.Method),
|
|
177
181
|
};
|
|
178
182
|
|
|
179
183
|
export const getLogger = (key: LoggerNames) => LoggerMap[key];
|