@onekeyfe/hd-core 1.2.8-alpha.100 → 1.2.8-alpha.102
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/__tests__/core-dispose.test.ts +114 -1
- package/__tests__/core-error-output.test.ts +21 -0
- package/__tests__/device-connector-protocol.test.ts +5 -2
- package/__tests__/device-lifecycle-events.test.ts +22 -3
- package/__tests__/logBlockEvent.test.ts +0 -43
- package/__tests__/usb-identity-probe.test.ts +358 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +21 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +37 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3060 -3229
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +0 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +0 -4
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/device.d.ts +9 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +4 -7
- package/src/api/SearchDevices.ts +172 -7
- package/src/api/index.ts +0 -2
- package/src/core/index.ts +45 -14
- package/src/data/messages/messages-protocol-v2.json +1 -138
- package/src/device/DeviceConnector.ts +4 -4
- package/src/events/logBlockEvent.ts +2 -5
- package/src/index.ts +1 -0
- package/src/inject.ts +0 -4
- package/src/types/api/export.ts +0 -2
- package/src/types/api/index.ts +0 -8
- package/src/types/device.ts +12 -0
- package/__tests__/zcash-sign-pczt.test.ts +0 -212
- package/dist/api/zcash/ZcashGetAddress.d.ts +0 -12
- package/dist/api/zcash/ZcashGetAddress.d.ts.map +0 -1
- package/dist/api/zcash/ZcashSignPczt.d.ts +0 -17
- package/dist/api/zcash/ZcashSignPczt.d.ts.map +0 -1
- package/dist/types/api/zcashGetAddress.d.ts +0 -22
- package/dist/types/api/zcashGetAddress.d.ts.map +0 -1
- package/dist/types/api/zcashSignPczt.d.ts +0 -9
- package/dist/types/api/zcashSignPczt.d.ts.map +0 -1
- package/src/api/zcash/ZcashGetAddress.ts +0 -121
- package/src/api/zcash/ZcashSignPczt.ts +0 -153
- package/src/types/api/zcashGetAddress.ts +0 -36
- package/src/types/api/zcashSignPczt.ts +0 -18
|
@@ -352,13 +352,10 @@ const PROTOCOL_V2_TARGET_STATUS_BY_DECODED_NAME = new Map<string, number>([
|
|
|
352
352
|
['FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS', 10],
|
|
353
353
|
]);
|
|
354
354
|
|
|
355
|
-
const isProtocolV2ReconnectProbeError = (error: unknown) =>
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
message.includes('did not respond to expected protocol')
|
|
360
|
-
);
|
|
361
|
-
};
|
|
355
|
+
const isProtocolV2ReconnectProbeError = (error: unknown) =>
|
|
356
|
+
getProtocolV2ErrorCode(error) === HardwareErrorCode.TransportProtocolProbeFailed &&
|
|
357
|
+
(error as { params?: { expectedProtocol?: unknown } } | undefined)?.params?.expectedProtocol ===
|
|
358
|
+
'V2';
|
|
362
359
|
|
|
363
360
|
const isProtocolV2FirmwareStatusEndpointUnavailable = (error: unknown) => {
|
|
364
361
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -5,10 +5,20 @@ import TransportManager from '../data-manager/TransportManager';
|
|
|
5
5
|
import { DataManager } from '../data-manager';
|
|
6
6
|
import { LoggerNames, getDeviceTypeByBleName, getLogger } from '../utils';
|
|
7
7
|
import { DevicePool } from '../device/DevicePool';
|
|
8
|
+
import { buildProtocolV1FeaturesPayload } from '../deviceProfile/buildDeviceFeatures';
|
|
9
|
+
import { mapProtocolV2DeviceInfoToState } from '../device/DeviceStateMapper';
|
|
10
|
+
import { getSupportProtocolV1MessageSchema } from '../utils/deviceFeaturesUtils';
|
|
11
|
+
import { PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST } from '../protocols/protocol-v2/features';
|
|
8
12
|
|
|
9
|
-
import type { SearchDevice } from '../types/device';
|
|
13
|
+
import type { SearchDevice, UsbDeviceIdentity } from '../types/device';
|
|
14
|
+
import type { PROTO } from '../constants';
|
|
10
15
|
import type DeviceConnector from '../device/DeviceConnector';
|
|
11
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
AcquireInput,
|
|
18
|
+
OneKeyDeviceInfo as DeviceDescriptor,
|
|
19
|
+
ProtocolV2DeviceInfo,
|
|
20
|
+
Transport,
|
|
21
|
+
} from '@onekeyfe/hd-transport';
|
|
12
22
|
import type { Device } from '../device/Device';
|
|
13
23
|
|
|
14
24
|
const Log = getLogger(LoggerNames.DevicePool);
|
|
@@ -18,7 +28,10 @@ type RequestQueueLookup = {
|
|
|
18
28
|
getTask: (requestId: number) => { method: { device?: Device } } | undefined;
|
|
19
29
|
};
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
export type UsbIdentityProbeDescriptor = Pick<DeviceDescriptor, 'path' | 'commType'> &
|
|
32
|
+
Partial<Pick<DeviceDescriptor, 'id' | 'session'>>;
|
|
33
|
+
|
|
34
|
+
const getDescriptorKeys = (descriptor: UsbIdentityProbeDescriptor) =>
|
|
22
35
|
[descriptor.path, descriptor.id].filter(
|
|
23
36
|
(key): key is string => typeof key === 'string' && key.length > 0
|
|
24
37
|
);
|
|
@@ -33,11 +46,11 @@ const isOwnedByActiveWebUsbRequest = (
|
|
|
33
46
|
);
|
|
34
47
|
};
|
|
35
48
|
|
|
36
|
-
const getUsbHandle = (descriptor?:
|
|
49
|
+
const getUsbHandle = (descriptor?: UsbIdentityProbeDescriptor) =>
|
|
37
50
|
(descriptor as { device?: unknown } | undefined)?.device;
|
|
38
51
|
|
|
39
52
|
const getOwningRequestDevice = (
|
|
40
|
-
descriptor:
|
|
53
|
+
descriptor: UsbIdentityProbeDescriptor,
|
|
41
54
|
requestQueue?: RequestQueueLookup
|
|
42
55
|
) => {
|
|
43
56
|
if (!requestQueue) return undefined;
|
|
@@ -60,6 +73,158 @@ const getOwningRequestDevice = (
|
|
|
60
73
|
return undefined;
|
|
61
74
|
};
|
|
62
75
|
|
|
76
|
+
export const getOwnedUsbDeviceIdentity = (
|
|
77
|
+
descriptor: UsbIdentityProbeDescriptor,
|
|
78
|
+
requestQueue: RequestQueueLookup
|
|
79
|
+
): UsbDeviceIdentity | undefined => {
|
|
80
|
+
const owner = getOwningRequestDevice(descriptor, requestQueue);
|
|
81
|
+
if (!owner || descriptor.commType !== 'webusb' || owner.originalDescriptor?.commType !== 'webusb')
|
|
82
|
+
return undefined;
|
|
83
|
+
return {
|
|
84
|
+
path: descriptor.path,
|
|
85
|
+
serialNo: owner.getCurrentSerialNo() || null,
|
|
86
|
+
deviceId: owner.getCurrentDeviceId() || null,
|
|
87
|
+
deviceType: owner.getCurrentDeviceType(),
|
|
88
|
+
connectProtocol: owner.getProtocol(),
|
|
89
|
+
commType: 'webusb',
|
|
90
|
+
mode: owner.features?.mode ?? undefined,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type UsbIdentityProbeTransport = Pick<
|
|
95
|
+
Transport,
|
|
96
|
+
'release' | 'call' | 'getProtocolType' | 'configureProtocolV2'
|
|
97
|
+
> & {
|
|
98
|
+
init: (logger: object) => unknown;
|
|
99
|
+
enumerate: () => Promise<UsbIdentityProbeDescriptor[]>;
|
|
100
|
+
acquire: (input: AcquireInput) => Promise<string | undefined>;
|
|
101
|
+
configure: (signedData: string) => void | Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Identity discovery must not publish device events or log raw Features/session data.
|
|
105
|
+
const identityProbeLogger = {
|
|
106
|
+
debug: () => undefined,
|
|
107
|
+
log: () => undefined,
|
|
108
|
+
info: () => undefined,
|
|
109
|
+
warn: () => undefined,
|
|
110
|
+
error: () => undefined,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Runs on a separate transport; never initializes or switches the current Core. */
|
|
114
|
+
export const probeUsbDeviceIdentitiesWithTransport = async (
|
|
115
|
+
transport: UsbIdentityProbeTransport,
|
|
116
|
+
commType: UsbDeviceIdentity['commType'],
|
|
117
|
+
getOwnedIdentity?: (descriptor: UsbIdentityProbeDescriptor) => UsbDeviceIdentity | undefined
|
|
118
|
+
): Promise<UsbDeviceIdentity[]> => {
|
|
119
|
+
if (commType !== 'webusb') return [];
|
|
120
|
+
await transport.init(identityProbeLogger);
|
|
121
|
+
const defaultMessages = JSON.stringify(DataManager.getProtobufMessages());
|
|
122
|
+
await transport.configure(defaultMessages);
|
|
123
|
+
await transport.configureProtocolV2?.(
|
|
124
|
+
JSON.stringify(DataManager.getProtobufMessages('v2Schema'))
|
|
125
|
+
);
|
|
126
|
+
const descriptors = await transport.enumerate();
|
|
127
|
+
const identities: UsbDeviceIdentity[] = [];
|
|
128
|
+
const readIdentity = async (
|
|
129
|
+
descriptor: UsbIdentityProbeDescriptor
|
|
130
|
+
): Promise<UsbDeviceIdentity | undefined> => {
|
|
131
|
+
const { path } = descriptor;
|
|
132
|
+
if (!path || descriptor.commType !== commType) return undefined;
|
|
133
|
+
if (descriptors.filter(candidate => candidate.path === path).length !== 1) return undefined;
|
|
134
|
+
const owner = getOwnedIdentity?.(descriptor);
|
|
135
|
+
if (owner) {
|
|
136
|
+
return owner;
|
|
137
|
+
}
|
|
138
|
+
// Do not borrow a browser handle or replace a Bridge session owned by another call.
|
|
139
|
+
if (descriptor.session || (getUsbHandle(descriptor) as USBDevice | undefined)?.opened)
|
|
140
|
+
return undefined;
|
|
141
|
+
|
|
142
|
+
let session: string | undefined;
|
|
143
|
+
let identified: UsbDeviceIdentity | undefined;
|
|
144
|
+
try {
|
|
145
|
+
await transport.configure(defaultMessages);
|
|
146
|
+
session = await transport.acquire({ path, previous: null, forceProtocolDetection: true });
|
|
147
|
+
if (!session) return undefined;
|
|
148
|
+
const protocol = transport.getProtocolType(path);
|
|
149
|
+
if (protocol === 'V1') {
|
|
150
|
+
const response = await transport.call(session, 'GetFeatures', {}, { timeoutMs: 3000 });
|
|
151
|
+
if (response.type !== 'Features') return undefined;
|
|
152
|
+
let features = buildProtocolV1FeaturesPayload(response.message as PROTO.Features);
|
|
153
|
+
// Classic-family loaders expose their supported information in Features.
|
|
154
|
+
// Touch/Pro retain their existing vendor-feature query.
|
|
155
|
+
if (
|
|
156
|
+
!features.serialNo &&
|
|
157
|
+
(features.mode !== 'bootloader' ||
|
|
158
|
+
features.deviceType === EDeviceType.Touch ||
|
|
159
|
+
features.deviceType === EDeviceType.Pro)
|
|
160
|
+
) {
|
|
161
|
+
const { messages, protocolV1MessageSchema } = getSupportProtocolV1MessageSchema(features);
|
|
162
|
+
// Legacy V1 has no OnekeyGetFeatures; keep the identity confirmed by GetFeatures.
|
|
163
|
+
if (protocolV1MessageSchema === 'v1CurrentSchema') {
|
|
164
|
+
if (messages) await transport.configure(JSON.stringify(messages));
|
|
165
|
+
const vendor = await transport.call(
|
|
166
|
+
session,
|
|
167
|
+
'OnekeyGetFeatures',
|
|
168
|
+
{},
|
|
169
|
+
{ timeoutMs: 3000 }
|
|
170
|
+
);
|
|
171
|
+
if (vendor.type === 'OnekeyFeatures') {
|
|
172
|
+
features = buildProtocolV1FeaturesPayload({
|
|
173
|
+
...response.message,
|
|
174
|
+
...vendor.message,
|
|
175
|
+
} as PROTO.Features);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
identified = {
|
|
180
|
+
path,
|
|
181
|
+
serialNo: features.serialNo || null,
|
|
182
|
+
deviceId: features.deviceId || null,
|
|
183
|
+
deviceType: features.deviceType,
|
|
184
|
+
connectProtocol: 'V1',
|
|
185
|
+
commType,
|
|
186
|
+
mode: features.mode ?? undefined,
|
|
187
|
+
};
|
|
188
|
+
} else if (protocol === 'V2') {
|
|
189
|
+
const response = await transport.call(
|
|
190
|
+
session,
|
|
191
|
+
'DeviceInfoGet',
|
|
192
|
+
PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST,
|
|
193
|
+
{ timeoutMs: 3000 }
|
|
194
|
+
);
|
|
195
|
+
if (response.type !== 'DeviceInfo') return undefined;
|
|
196
|
+
const { identity } = mapProtocolV2DeviceInfoToState(
|
|
197
|
+
response.message as ProtocolV2DeviceInfo
|
|
198
|
+
);
|
|
199
|
+
identified = {
|
|
200
|
+
path,
|
|
201
|
+
serialNo: identity?.serialNo || null,
|
|
202
|
+
deviceId: identity?.deviceId || null,
|
|
203
|
+
deviceType: identity?.deviceType ?? EDeviceType.Unknown,
|
|
204
|
+
connectProtocol: 'V2',
|
|
205
|
+
commType,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
} catch {
|
|
209
|
+
// Discovery is best effort; a busy/disconnected device cannot confirm identity.
|
|
210
|
+
} finally {
|
|
211
|
+
if (session) {
|
|
212
|
+
try {
|
|
213
|
+
await transport.release(session, false);
|
|
214
|
+
} catch {
|
|
215
|
+
identified = undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return identified;
|
|
220
|
+
};
|
|
221
|
+
for (const descriptor of descriptors) {
|
|
222
|
+
const identity = await readIdentity(descriptor);
|
|
223
|
+
if (identity) identities.push(identity);
|
|
224
|
+
}
|
|
225
|
+
return identities;
|
|
226
|
+
};
|
|
227
|
+
|
|
63
228
|
// A USB path is a routing key (the USB serial, a synthesized usb-vid-pid-name, or the
|
|
64
229
|
// bootloader placeholder), not a hardware identity, so it never fills uuid/serialNo.
|
|
65
230
|
const toSearchDeviceFromDescriptor = (descriptor: DeviceDescriptor): SearchDevice => {
|
|
@@ -81,7 +246,7 @@ const toSearchDevice = (device: Device): SearchDevice | null => {
|
|
|
81
246
|
};
|
|
82
247
|
|
|
83
248
|
export default class SearchDevices extends BaseMethod {
|
|
84
|
-
connector?: DeviceConnector;
|
|
249
|
+
connector?: DeviceConnector = undefined;
|
|
85
250
|
|
|
86
251
|
init() {
|
|
87
252
|
this.useDevice = false;
|
|
@@ -130,7 +295,7 @@ export default class SearchDevices extends BaseMethod {
|
|
|
130
295
|
// BLE discovery cannot provide a physical-device identity before initialization.
|
|
131
296
|
uuid: '',
|
|
132
297
|
deviceId: null,
|
|
133
|
-
name: bleName || device.name,
|
|
298
|
+
name: bleName || device.name || '',
|
|
134
299
|
deviceType: getDeviceTypeByBleName(bleName),
|
|
135
300
|
});
|
|
136
301
|
}
|
package/src/api/index.ts
CHANGED
|
@@ -175,5 +175,3 @@ export { default as benfenSignTransaction } from './benfen/BenfenSignTransaction
|
|
|
175
175
|
|
|
176
176
|
export { default as neoGetAddress } from './neo/NeoGetAddress';
|
|
177
177
|
export { default as neoSignTransaction } from './neo/NeoSignTransaction';
|
|
178
|
-
export { default as zcashGetAddress } from './zcash/ZcashGetAddress';
|
|
179
|
-
export { default as zcashSignPczt } from './zcash/ZcashSignPczt';
|
package/src/core/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
|
+
import { getOwnedUsbDeviceIdentity } from '../api/SearchDevices';
|
|
2
3
|
import EventEmitter from 'events';
|
|
3
4
|
import {
|
|
4
5
|
DeviceSessionPinType,
|
|
@@ -125,6 +126,8 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
|
125
126
|
});
|
|
126
127
|
|
|
127
128
|
let _core: Core | undefined;
|
|
129
|
+
let transportSwitchGeneration = 0;
|
|
130
|
+
let pendingTransportSwitch: Promise<void> = Promise.resolve();
|
|
128
131
|
let _deviceList: DeviceList | undefined;
|
|
129
132
|
let _connector: DeviceConnector | undefined;
|
|
130
133
|
let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui response
|
|
@@ -990,15 +993,11 @@ function canSkipInitialize(method: BaseMethod, device: Device): boolean {
|
|
|
990
993
|
}
|
|
991
994
|
|
|
992
995
|
export function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
|
|
993
|
-
const typedError = error as { errorCode?: unknown;
|
|
994
|
-
const message =
|
|
995
|
-
typeof typedError?.message === 'string' ? typedError.message : String(error ?? '');
|
|
996
|
+
const typedError = error as { errorCode?: unknown; params?: { expectedProtocol?: unknown } };
|
|
996
997
|
return (
|
|
997
998
|
method.payload.connectProtocol === 'V2' &&
|
|
998
|
-
typedError?.errorCode === HardwareErrorCode.
|
|
999
|
-
|
|
1000
|
-
message.includes('expected V2') &&
|
|
1001
|
-
message.includes('did not respond to expected protocol')
|
|
999
|
+
typedError?.errorCode === HardwareErrorCode.TransportProtocolProbeFailed &&
|
|
1000
|
+
typedError.params?.expectedProtocol === 'V2'
|
|
1002
1001
|
);
|
|
1003
1002
|
}
|
|
1004
1003
|
|
|
@@ -1008,7 +1007,7 @@ export function isRetryableBleConnectionError(method: BaseMethod, error: unknown
|
|
|
1008
1007
|
}
|
|
1009
1008
|
const typedError = error as {
|
|
1010
1009
|
errorCode?: unknown;
|
|
1011
|
-
params?: { acquireDeadlineExceeded?: unknown };
|
|
1010
|
+
params?: { acquireDeadlineExceeded?: unknown; expectedProtocol?: unknown };
|
|
1012
1011
|
};
|
|
1013
1012
|
if (
|
|
1014
1013
|
typedError?.errorCode === HardwareErrorCode.BleTimeoutError &&
|
|
@@ -1019,6 +1018,8 @@ export function isRetryableBleConnectionError(method: BaseMethod, error: unknown
|
|
|
1019
1018
|
return (
|
|
1020
1019
|
typedError?.errorCode === HardwareErrorCode.BleTimeoutError ||
|
|
1021
1020
|
typedError?.errorCode === HardwareErrorCode.BleConnectedError ||
|
|
1021
|
+
(typedError?.errorCode === HardwareErrorCode.TransportProtocolProbeFailed &&
|
|
1022
|
+
!typedError.params?.expectedProtocol) ||
|
|
1022
1023
|
isRetryableBleProtocolV2ProbeError(method, error) ||
|
|
1023
1024
|
isMissingDetectedProtocolV2Error(method, error)
|
|
1024
1025
|
);
|
|
@@ -1273,6 +1274,8 @@ const ensureConnected = async (
|
|
|
1273
1274
|
HardwareErrorCode.BridgeTimeoutError,
|
|
1274
1275
|
HardwareErrorCode.BridgeNeedsPermission,
|
|
1275
1276
|
HardwareErrorCode.WebUsbDeviceAccessError,
|
|
1277
|
+
HardwareErrorCode.TransportProtocolProbeFailed,
|
|
1278
|
+
HardwareErrorCode.TransportProtocolMismatch,
|
|
1276
1279
|
].includes(error.errorCode)
|
|
1277
1280
|
) {
|
|
1278
1281
|
_deviceList = undefined;
|
|
@@ -1360,6 +1363,8 @@ const ensureConnected = async (
|
|
|
1360
1363
|
HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
|
|
1361
1364
|
HardwareErrorCode.BridgeNeedsPermission,
|
|
1362
1365
|
HardwareErrorCode.WebUsbDeviceAccessError,
|
|
1366
|
+
HardwareErrorCode.TransportProtocolProbeFailed,
|
|
1367
|
+
HardwareErrorCode.TransportProtocolMismatch,
|
|
1363
1368
|
HardwareErrorCode.DeviceInterruptedFromUser,
|
|
1364
1369
|
HardwareErrorCode.CallQueueActionCancelled,
|
|
1365
1370
|
].includes(error.errorCode) ||
|
|
@@ -1826,6 +1831,10 @@ export default class Core extends EventEmitter {
|
|
|
1826
1831
|
|
|
1827
1832
|
private requestQueue = new RequestQueue();
|
|
1828
1833
|
|
|
1834
|
+
getOwnedUsbDeviceIdentity(descriptor: Parameters<typeof getOwnedUsbDeviceIdentity>[0]) {
|
|
1835
|
+
return getOwnedUsbDeviceIdentity(descriptor, this.requestQueue);
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1829
1838
|
private disposePromise?: Promise<void>;
|
|
1830
1839
|
|
|
1831
1840
|
// background task
|
|
@@ -1959,6 +1968,8 @@ export default class Core extends EventEmitter {
|
|
|
1959
1968
|
|
|
1960
1969
|
private async disposeResources(): Promise<void> {
|
|
1961
1970
|
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
1971
|
+
transportSwitchGeneration += 1;
|
|
1972
|
+
pendingTransportSwitch = Promise.resolve();
|
|
1962
1973
|
pollingManager.stopAll();
|
|
1963
1974
|
this.requestQueue.abortAllRequests();
|
|
1964
1975
|
cleanup();
|
|
@@ -1993,6 +2004,8 @@ export default class Core extends EventEmitter {
|
|
|
1993
2004
|
}
|
|
1994
2005
|
|
|
1995
2006
|
export const initCore = () => {
|
|
2007
|
+
transportSwitchGeneration += 1;
|
|
2008
|
+
pendingTransportSwitch = Promise.resolve();
|
|
1996
2009
|
const core = new Core();
|
|
1997
2010
|
_core = core;
|
|
1998
2011
|
return core;
|
|
@@ -2022,6 +2035,8 @@ export const init = async (
|
|
|
2022
2035
|
plugin?: LowlevelTransportSharedPlugin
|
|
2023
2036
|
) => {
|
|
2024
2037
|
try {
|
|
2038
|
+
transportSwitchGeneration += 1;
|
|
2039
|
+
pendingTransportSwitch = Promise.resolve();
|
|
2025
2040
|
await DataManager.load(settings);
|
|
2026
2041
|
initTransport(Transport, plugin);
|
|
2027
2042
|
enableLog(DataManager.getSettings('debug'));
|
|
@@ -2047,10 +2062,26 @@ export const switchTransport = ({
|
|
|
2047
2062
|
Transport: any;
|
|
2048
2063
|
plugin?: LowlevelTransportSharedPlugin;
|
|
2049
2064
|
}) => {
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2065
|
+
const generation = transportSwitchGeneration;
|
|
2066
|
+
// Preserve request order while native transport cleanup is pending.
|
|
2067
|
+
const switching = pendingTransportSwitch
|
|
2068
|
+
.catch(() => undefined)
|
|
2069
|
+
.then(async () => {
|
|
2070
|
+
if (generation !== transportSwitchGeneration) {
|
|
2071
|
+
throw ERRORS.TypedError(HardwareErrorCode.NotInitialized);
|
|
2072
|
+
}
|
|
2073
|
+
_connector?.stop();
|
|
2074
|
+
await TransportManager.getTransport()?.stop?.();
|
|
2075
|
+
if (generation !== transportSwitchGeneration) {
|
|
2076
|
+
throw ERRORS.TypedError(HardwareErrorCode.NotInitialized);
|
|
2077
|
+
}
|
|
2078
|
+
DataManager.updateEnv(env);
|
|
2079
|
+
TransportManager.setTransport(Transport, plugin);
|
|
2080
|
+
_deviceList = undefined;
|
|
2081
|
+
DevicePool.resetState();
|
|
2082
|
+
_connector = undefined;
|
|
2083
|
+
initConnector();
|
|
2084
|
+
});
|
|
2085
|
+
pendingTransportSwitch = switching;
|
|
2086
|
+
return switching;
|
|
2056
2087
|
};
|
|
@@ -11034,61 +11034,6 @@
|
|
|
11034
11034
|
}
|
|
11035
11035
|
}
|
|
11036
11036
|
},
|
|
11037
|
-
"ZcashSignPczt": {
|
|
11038
|
-
"fields": {
|
|
11039
|
-
"pczt_length": {
|
|
11040
|
-
"rule": "required",
|
|
11041
|
-
"type": "uint32",
|
|
11042
|
-
"id": 1
|
|
11043
|
-
},
|
|
11044
|
-
"pczt_initial_chunk": {
|
|
11045
|
-
"rule": "required",
|
|
11046
|
-
"type": "bytes",
|
|
11047
|
-
"id": 2
|
|
11048
|
-
}
|
|
11049
|
-
}
|
|
11050
|
-
},
|
|
11051
|
-
"ZcashPcztChunkRequest": {
|
|
11052
|
-
"fields": {
|
|
11053
|
-
"chunk_length": {
|
|
11054
|
-
"rule": "required",
|
|
11055
|
-
"type": "uint32",
|
|
11056
|
-
"id": 1
|
|
11057
|
-
}
|
|
11058
|
-
}
|
|
11059
|
-
},
|
|
11060
|
-
"ZcashPcztChunkAck": {
|
|
11061
|
-
"fields": {
|
|
11062
|
-
"data_chunk": {
|
|
11063
|
-
"rule": "required",
|
|
11064
|
-
"type": "bytes",
|
|
11065
|
-
"id": 1
|
|
11066
|
-
}
|
|
11067
|
-
}
|
|
11068
|
-
},
|
|
11069
|
-
"ZcashSignedPczt": {
|
|
11070
|
-
"fields": {
|
|
11071
|
-
"pczt_length": {
|
|
11072
|
-
"rule": "required",
|
|
11073
|
-
"type": "uint32",
|
|
11074
|
-
"id": 1
|
|
11075
|
-
},
|
|
11076
|
-
"pczt_initial_chunk": {
|
|
11077
|
-
"rule": "required",
|
|
11078
|
-
"type": "bytes",
|
|
11079
|
-
"id": 2
|
|
11080
|
-
}
|
|
11081
|
-
}
|
|
11082
|
-
},
|
|
11083
|
-
"ZcashSignedPcztChunkRequest": {
|
|
11084
|
-
"fields": {
|
|
11085
|
-
"chunk_length": {
|
|
11086
|
-
"rule": "required",
|
|
11087
|
-
"type": "uint32",
|
|
11088
|
-
"id": 1
|
|
11089
|
-
}
|
|
11090
|
-
}
|
|
11091
|
-
},
|
|
11092
11037
|
"wire_in": {
|
|
11093
11038
|
"type": "bool",
|
|
11094
11039
|
"id": 50002,
|
|
@@ -11514,11 +11459,6 @@
|
|
|
11514
11459
|
"MessageType_NeoAddress": 12302,
|
|
11515
11460
|
"MessageType_NeoSignTx": 12303,
|
|
11516
11461
|
"MessageType_NeoSignedTx": 12304,
|
|
11517
|
-
"MessageType_ZcashSignPczt": 12402,
|
|
11518
|
-
"MessageType_ZcashSignedPczt": 12403,
|
|
11519
|
-
"MessageType_ZcashPcztChunkRequest": 12404,
|
|
11520
|
-
"MessageType_ZcashPcztChunkAck": 12405,
|
|
11521
|
-
"MessageType_ZcashSignedPcztChunkRequest": 12406,
|
|
11522
11462
|
"MessageType_DeviceFactoryInfoSet": 60000,
|
|
11523
11463
|
"MessageType_DeviceFactoryInfoGet": 60001,
|
|
11524
11464
|
"MessageType_DeviceFactoryInfo": 60002,
|
|
@@ -11571,9 +11511,7 @@
|
|
|
11571
11511
|
"MessageType_PortfolioUpdate": 61400,
|
|
11572
11512
|
"MessageType_NftUpdate": 61500,
|
|
11573
11513
|
"MessageType_OnboardingStatusGet": 61600,
|
|
11574
|
-
"MessageType_OnboardingStatus": 61601
|
|
11575
|
-
"MessageType_ZcashGetAddress": 12400,
|
|
11576
|
-
"MessageType_ZcashAddress": 12401
|
|
11514
|
+
"MessageType_OnboardingStatus": 61601
|
|
11577
11515
|
},
|
|
11578
11516
|
"reserved": [
|
|
11579
11517
|
[90, 92],
|
|
@@ -13792,81 +13730,6 @@
|
|
|
13792
13730
|
}
|
|
13793
13731
|
}
|
|
13794
13732
|
}
|
|
13795
|
-
},
|
|
13796
|
-
"ZcashAddressType": {
|
|
13797
|
-
"values": {
|
|
13798
|
-
"UNIFIED_ORCHARD_P2PKH": 0,
|
|
13799
|
-
"TRANSPARENT_P2PKH": 1,
|
|
13800
|
-
"UNIFIED_ORCHARD": 2
|
|
13801
|
-
}
|
|
13802
|
-
},
|
|
13803
|
-
"ZcashAddressScope": {
|
|
13804
|
-
"values": {
|
|
13805
|
-
"EXTERNAL": 0,
|
|
13806
|
-
"INTERNAL": 1
|
|
13807
|
-
}
|
|
13808
|
-
},
|
|
13809
|
-
"ZcashGetAddress": {
|
|
13810
|
-
"fields": {
|
|
13811
|
-
"address_n": {
|
|
13812
|
-
"rule": "repeated",
|
|
13813
|
-
"type": "uint32",
|
|
13814
|
-
"id": 1,
|
|
13815
|
-
"options": {
|
|
13816
|
-
"packed": false
|
|
13817
|
-
}
|
|
13818
|
-
},
|
|
13819
|
-
"show_display": {
|
|
13820
|
-
"type": "bool",
|
|
13821
|
-
"id": 2
|
|
13822
|
-
},
|
|
13823
|
-
"include_seed_fingerprint": {
|
|
13824
|
-
"type": "bool",
|
|
13825
|
-
"id": 3
|
|
13826
|
-
},
|
|
13827
|
-
"include_ufvk": {
|
|
13828
|
-
"type": "bool",
|
|
13829
|
-
"id": 4
|
|
13830
|
-
},
|
|
13831
|
-
"diversifier_index": {
|
|
13832
|
-
"type": "uint32",
|
|
13833
|
-
"id": 5,
|
|
13834
|
-
"options": {
|
|
13835
|
-
"default": 0
|
|
13836
|
-
}
|
|
13837
|
-
},
|
|
13838
|
-
"address_type": {
|
|
13839
|
-
"type": "ZcashAddressType",
|
|
13840
|
-
"id": 6,
|
|
13841
|
-
"options": {
|
|
13842
|
-
"default": "UNIFIED_ORCHARD_P2PKH"
|
|
13843
|
-
}
|
|
13844
|
-
},
|
|
13845
|
-
"scope": {
|
|
13846
|
-
"type": "ZcashAddressScope",
|
|
13847
|
-
"id": 7,
|
|
13848
|
-
"options": {
|
|
13849
|
-
"default": "EXTERNAL"
|
|
13850
|
-
}
|
|
13851
|
-
}
|
|
13852
|
-
}
|
|
13853
|
-
},
|
|
13854
|
-
"ZcashAddress": {
|
|
13855
|
-
"fields": {
|
|
13856
|
-
"address": {
|
|
13857
|
-
"rule": "required",
|
|
13858
|
-
"type": "string",
|
|
13859
|
-
"id": 1
|
|
13860
|
-
},
|
|
13861
|
-
"ufvk": {
|
|
13862
|
-
"type": "string",
|
|
13863
|
-
"id": 2
|
|
13864
|
-
},
|
|
13865
|
-
"seed_fingerprint": {
|
|
13866
|
-
"type": "bytes",
|
|
13867
|
-
"id": 3
|
|
13868
|
-
}
|
|
13869
|
-
}
|
|
13870
13733
|
}
|
|
13871
13734
|
}
|
|
13872
13735
|
}
|
|
@@ -133,10 +133,10 @@ export default class DeviceConnector {
|
|
|
133
133
|
: undefined;
|
|
134
134
|
const detectedProtocol = acquiredProtocol ?? transport.getProtocolType(path);
|
|
135
135
|
if (detectedProtocol !== expectedProtocol) {
|
|
136
|
-
throw ERRORS.TypedError(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
);
|
|
136
|
+
throw ERRORS.TypedError(HardwareErrorCode.TransportProtocolMismatch, undefined, {
|
|
137
|
+
expectedProtocol,
|
|
138
|
+
detectedProtocol,
|
|
139
|
+
});
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
return res;
|
|
@@ -8,8 +8,8 @@ export const LogBlockEvent: Set<string> = new Set([
|
|
|
8
8
|
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
9
9
|
]);
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
//
|
|
11
|
+
// These resource/file APIs did not exist in 1.1.32. Skip the payload so
|
|
12
|
+
// the log layer does not copy huge Base64 or binary data.
|
|
13
13
|
const LogPayloadBlockMethod: Set<string> = new Set([
|
|
14
14
|
'btcDeriveContextHash',
|
|
15
15
|
'deviceUploadNft',
|
|
@@ -17,9 +17,6 @@ const LogPayloadBlockMethod: Set<string> = new Set([
|
|
|
17
17
|
'uploadPortfolio',
|
|
18
18
|
'fileWrite',
|
|
19
19
|
'fileRead',
|
|
20
|
-
'zcashGetAddress',
|
|
21
|
-
'zcashGetUnifiedAddress',
|
|
22
|
-
'zcashSignPczt',
|
|
23
20
|
]);
|
|
24
21
|
|
|
25
22
|
export function getLogBlockLabel(message: unknown): string | undefined {
|
package/src/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { executeCallback, cleanupCallback };
|
|
|
21
21
|
export { preloadSessionCache } from './device/Device';
|
|
22
22
|
export { projectFeatures as projectDeviceStateFeatures } from './device/DeviceStateProjector';
|
|
23
23
|
export { getMethodSupportedProtocols } from './api/utils';
|
|
24
|
+
export { probeUsbDeviceIdentitiesWithTransport } from './api/SearchDevices';
|
|
24
25
|
export {
|
|
25
26
|
getFirmwareUpdateHostBindingGeneration,
|
|
26
27
|
registerFirmwareUpdateHostBinding,
|
package/src/inject.ts
CHANGED
|
@@ -504,8 +504,4 @@ export const createCoreApi = (
|
|
|
504
504
|
call({ ...params, connectId, deviceId, method: 'neoGetAddress' }),
|
|
505
505
|
neoSignTransaction: (connectId, deviceId, params) =>
|
|
506
506
|
call({ ...params, connectId, deviceId, method: 'neoSignTransaction' }),
|
|
507
|
-
zcashGetAddress: (connectId, deviceId, params) =>
|
|
508
|
-
call({ ...params, connectId, deviceId, method: 'zcashGetAddress' }),
|
|
509
|
-
zcashSignPczt: (connectId, deviceId, params) =>
|
|
510
|
-
call({ ...params, connectId, deviceId, method: 'zcashSignPczt' }),
|
|
511
507
|
});
|
package/src/types/api/export.ts
CHANGED
|
@@ -227,5 +227,3 @@ export type { BenfenAddress, BenfenGetAddressParams } from './benfenGetAddress';
|
|
|
227
227
|
export type { BenfenPublicKey, BenfenGetPublicKeyParams } from './benfenGetPublicKey';
|
|
228
228
|
export type { BenfenSignMessageParams } from './benfenSignMessage';
|
|
229
229
|
export type { BenfenSignedTx, BenfenSignTransactionParams } from './benfenSignTransaction';
|
|
230
|
-
export type { ZcashAddress, ZcashGetAddressParams } from './zcashGetAddress';
|
|
231
|
-
export type { ZcashSignedPczt, ZcashSignPcztParams } from './zcashSignPczt';
|
package/src/types/api/index.ts
CHANGED
|
@@ -154,8 +154,6 @@ import type { benfenSignTransaction } from './benfenSignTransaction';
|
|
|
154
154
|
import type { benfenSignMessage } from './benfenSignMessage';
|
|
155
155
|
import type { neoGetAddress } from './neoGetAddress';
|
|
156
156
|
import type { neoSignTransaction } from './neoSignTransaction';
|
|
157
|
-
import type { zcashGetAddress } from './zcashGetAddress';
|
|
158
|
-
import type { zcashSignPczt } from './zcashSignPczt';
|
|
159
157
|
import type { ConnectSettings } from '../settings';
|
|
160
158
|
import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
161
159
|
|
|
@@ -474,10 +472,4 @@ export type CoreApi = {
|
|
|
474
472
|
*/
|
|
475
473
|
neoGetAddress: typeof neoGetAddress;
|
|
476
474
|
neoSignTransaction: typeof neoSignTransaction;
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* Zcash
|
|
480
|
-
*/
|
|
481
|
-
zcashGetAddress: typeof zcashGetAddress;
|
|
482
|
-
zcashSignPczt: typeof zcashSignPczt;
|
|
483
475
|
};
|
package/src/types/device.ts
CHANGED
|
@@ -85,6 +85,18 @@ export type SearchDevice = {
|
|
|
85
85
|
commType: OneKeyDeviceCommType;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
+
/** Identity confirmed over USB. The descriptor path is only a transport address. */
|
|
89
|
+
export type UsbDeviceIdentity = {
|
|
90
|
+
path: string;
|
|
91
|
+
serialNo: string | null;
|
|
92
|
+
deviceId: string | null;
|
|
93
|
+
deviceType: IDeviceType;
|
|
94
|
+
connectProtocol: HardwareConnectProtocol;
|
|
95
|
+
commType: 'webusb' | 'bridge';
|
|
96
|
+
/** Mode confirmed by the device response; absent when discovery cannot establish it. */
|
|
97
|
+
mode?: DeviceStateMode;
|
|
98
|
+
};
|
|
99
|
+
|
|
88
100
|
// export type UnknownDevice = {
|
|
89
101
|
// type: 'unacquired';
|
|
90
102
|
// id?: null;
|