@onekeyfe/hd-core 1.2.0-alpha.67 → 1.2.0-alpha.68
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__/AllNetworkGetAddressBase.tracing.test.ts +313 -0
- package/__tests__/DeviceCommands.test.ts +59 -13
- package/__tests__/DeviceEventRegistration.test.ts +6 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +198 -3
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +81 -0
- package/__tests__/device-lifecycle-events.test.ts +105 -3
- package/__tests__/device-pool-state.test.ts +22 -0
- package/__tests__/device-settings.test.ts +39 -18
- package/__tests__/device-state-contract.test.ts +1 -0
- package/__tests__/device-state-mapper.test.ts +13 -1
- package/__tests__/device-utils.test.ts +48 -1
- package/__tests__/deviceSettings.test.ts +11 -1
- package/__tests__/deviceUploadNft.test.ts +316 -0
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +5 -0
- package/__tests__/get-device-state.test.ts +132 -12
- package/__tests__/homescreen.test.ts +41 -1
- package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +3 -26
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +19 -0
- package/__tests__/open-wallet-session.test.ts +568 -37
- package/__tests__/pro2Nft.test.ts +108 -0
- package/__tests__/protocol-binding.test.ts +89 -0
- package/__tests__/protocol-v2-resources.test.ts +340 -0
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +300 -37
- package/__tests__/protocol-v2.test.ts +1449 -867
- package/__tests__/protocolV2FileWrite.test.ts +152 -0
- package/__tests__/protocolV2UiInteraction.test.ts +63 -0
- package/__tests__/public-pro2-api-boundary.test.ts +1 -0
- package/__tests__/search-devices.test.ts +12 -3
- package/__tests__/tron-sign-message-init.test.ts +2 -2
- package/__tests__/uiProgressThrottle.test.ts +74 -0
- package/__tests__/uiPromiseRegistry.test.ts +115 -0
- package/dist/api/BaseMethod.d.ts +3 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +2 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +11 -4
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -2
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -3
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +9 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
- package/dist/api/polkadot/networks.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +2 -2
- package/dist/api/sui/SuiGetAddress.d.ts +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +2 -2
- package/dist/api/tron/TronSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +2 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +6 -0
- package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
- package/dist/data-manager/DataManager.d.ts +9 -3
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +29 -5
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
- package/dist/events/device.d.ts +4 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +4 -2
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +31 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +10 -2
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +243 -69
- package/dist/index.js +2563 -1217
- package/dist/inject.d.ts +6 -1
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +0 -4
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/resources.d.ts +30 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +6 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/types/api/deviceUnlock.d.ts +5 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +4 -2
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +6 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +38 -8
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +4 -0
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Nft.d.ts +31 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -0
- package/dist/utils/pro2Wallpaper.d.ts +10 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/dist/utils/uiProgressThrottle.d.ts +3 -0
- package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +8 -10
- package/src/api/CheckAllFirmwareRelease.ts +61 -11
- package/src/api/DetectDeviceConnectProtocol.ts +18 -0
- package/src/api/FirmwareUpdate.ts +6 -2
- package/src/api/FirmwareUpdateV2.ts +5 -2
- package/src/api/FirmwareUpdateV3.ts +6 -2
- package/src/api/FirmwareUpdateV4.ts +463 -258
- package/src/api/GetPassphraseState.ts +7 -1
- package/src/api/OpenWalletSession.ts +71 -17
- package/src/api/SearchDevices.ts +3 -1
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +36 -11
- package/src/api/device/DeviceSettings.ts +5 -4
- package/src/api/device/DeviceUnlock.ts +8 -3
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -12
- package/src/api/firmware/uploadFirmware.ts +17 -4
- package/src/api/helpers/protocolV2FileWrite.ts +202 -63
- package/src/api/index.ts +2 -0
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +2 -13
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignMessage.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/api/ton/TonGetAddress.ts +1 -1
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/api/ton/TonSignProof.ts +1 -1
- package/src/api/tron/TronSignMessage.ts +2 -2
- package/src/api/tron/TronSignTransaction.ts +1 -1
- package/src/core/deviceEventRegistration.ts +4 -0
- package/src/core/index.ts +213 -111
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +25 -0
- package/src/data-manager/DataManager.ts +88 -11
- package/src/data-manager/TransportManager.ts +6 -0
- package/src/device/Device.ts +273 -43
- package/src/device/DeviceCommands.ts +31 -4
- package/src/device/DeviceConnector.ts +33 -13
- package/src/device/DevicePool.ts +21 -7
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
- package/src/events/device.ts +4 -0
- package/src/events/logBlockEvent.ts +1 -0
- package/src/events/ui-promise.ts +4 -2
- package/src/events/ui-request.ts +36 -2
- package/src/events/ui-response.ts +12 -2
- package/src/inject.ts +58 -2
- package/src/lowLevelInject.ts +6 -3
- package/src/protocols/protocol-v2/features.ts +10 -7
- package/src/protocols/protocol-v2/firmware.ts +2 -0
- package/src/protocols/protocol-v2/resources.ts +390 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
- package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +131 -0
- package/src/protocols/protocol-v2/walletSession.ts +214 -36
- package/src/topLevelInject.ts +6 -3
- package/src/types/api/checkAllFirmwareRelease.ts +3 -1
- package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
- package/src/types/api/deviceUnlock.ts +12 -1
- package/src/types/api/export.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +6 -3
- package/src/types/api/index.ts +13 -0
- package/src/types/api/protocolV2.ts +13 -0
- package/src/types/device.ts +15 -3
- package/src/types/params.ts +7 -1
- package/src/types/settings.ts +60 -9
- package/src/utils/deviceFeaturesCompat.ts +5 -0
- package/src/utils/deviceFeaturesUtils.ts +14 -3
- package/src/utils/deviceInfoUtils.ts +2 -0
- package/src/utils/deviceSettings.ts +3 -0
- package/src/utils/homescreen.ts +32 -6
- package/src/utils/index.ts +6 -1
- package/src/utils/pro2Nft.ts +142 -0
- package/src/utils/pro2Wallpaper.ts +35 -8
- package/src/utils/uiProgressThrottle.ts +63 -0
- package/dist/api/firmware/progressThrottle.d.ts +0 -3
- package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
|
@@ -14,7 +14,7 @@ import type { OneKeyDeviceInfo as DeviceDescriptor, Transport } from '@onekeyfe/
|
|
|
14
14
|
const Log = getLogger(LoggerNames.DeviceConnector);
|
|
15
15
|
|
|
16
16
|
export default class DeviceConnector {
|
|
17
|
-
transport
|
|
17
|
+
transport?: Transport;
|
|
18
18
|
|
|
19
19
|
listenTimestamp = 0;
|
|
20
20
|
|
|
@@ -30,9 +30,21 @@ export default class DeviceConnector {
|
|
|
30
30
|
DevicePool.setConnector(this);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
private getActiveTransport(): Transport {
|
|
34
|
+
const transport = this.transport ?? TransportManager.getTransport();
|
|
35
|
+
if (!transport) {
|
|
36
|
+
throw ERRORS.TypedError(
|
|
37
|
+
HardwareErrorCode.TransportNotConfigured,
|
|
38
|
+
'Device connector was created before transport initialization'
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
this.transport = transport;
|
|
42
|
+
return transport;
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
async enumerate() {
|
|
34
46
|
try {
|
|
35
|
-
const descriptors = await this.
|
|
47
|
+
const descriptors = await this.getActiveTransport().enumerate();
|
|
36
48
|
this.upcoming = descriptors;
|
|
37
49
|
this._reportDevicesChange();
|
|
38
50
|
return { descriptors } as DeviceDescriptorDiff;
|
|
@@ -50,11 +62,10 @@ export default class DeviceConnector {
|
|
|
50
62
|
let descriptors: DeviceDescriptor[];
|
|
51
63
|
|
|
52
64
|
try {
|
|
65
|
+
const transport = this.getActiveTransport();
|
|
53
66
|
Log.debug('Start listening', current);
|
|
54
67
|
this.listenTimestamp = new Date().getTime();
|
|
55
|
-
descriptors = waitForEvent
|
|
56
|
-
? await this.transport.listen(current)
|
|
57
|
-
: await this.transport.enumerate();
|
|
68
|
+
descriptors = waitForEvent ? await transport.listen(current) : await transport.enumerate();
|
|
58
69
|
if (!this.listening) return; // do not continue if stop() was called
|
|
59
70
|
|
|
60
71
|
this.upcoming = descriptors;
|
|
@@ -88,16 +99,17 @@ export default class DeviceConnector {
|
|
|
88
99
|
Log.debug('acquire', path, session, expectedProtocol, protocolHint);
|
|
89
100
|
const env = DataManager.getSettings('env');
|
|
90
101
|
try {
|
|
102
|
+
const transport = this.getActiveTransport();
|
|
91
103
|
let res;
|
|
92
104
|
if (DataManager.isBleConnect(env)) {
|
|
93
|
-
res = await
|
|
105
|
+
res = await transport.acquire({
|
|
94
106
|
uuid: path,
|
|
95
107
|
forceCleanRunPromise,
|
|
96
108
|
expectedProtocol,
|
|
97
109
|
protocolHint,
|
|
98
110
|
});
|
|
99
111
|
} else {
|
|
100
|
-
res = await
|
|
112
|
+
res = await transport.acquire({
|
|
101
113
|
path,
|
|
102
114
|
previous: session ?? null,
|
|
103
115
|
expectedProtocol,
|
|
@@ -105,7 +117,13 @@ export default class DeviceConnector {
|
|
|
105
117
|
});
|
|
106
118
|
}
|
|
107
119
|
if (expectedProtocol) {
|
|
108
|
-
|
|
120
|
+
// The acquire response is the stable snapshot from this active probe. A delayed
|
|
121
|
+
// disconnect from an older generation may clear caches, so do not rely on cache alone.
|
|
122
|
+
const acquiredProtocol =
|
|
123
|
+
typeof res === 'object' && res !== null
|
|
124
|
+
? (res as DeviceDescriptor).protocolType
|
|
125
|
+
: undefined;
|
|
126
|
+
const detectedProtocol = acquiredProtocol ?? transport.getProtocolType(path);
|
|
109
127
|
if (detectedProtocol !== expectedProtocol) {
|
|
110
128
|
throw ERRORS.TypedError(
|
|
111
129
|
HardwareErrorCode.RuntimeError,
|
|
@@ -122,7 +140,7 @@ export default class DeviceConnector {
|
|
|
122
140
|
|
|
123
141
|
async release(session: string, onclose: boolean) {
|
|
124
142
|
try {
|
|
125
|
-
const res = await this.
|
|
143
|
+
const res = await this.getActiveTransport().release(session, onclose);
|
|
126
144
|
return res;
|
|
127
145
|
} catch (error) {
|
|
128
146
|
safeThrowError(error);
|
|
@@ -131,8 +149,9 @@ export default class DeviceConnector {
|
|
|
131
149
|
|
|
132
150
|
async disconnect(session: string | undefined | null) {
|
|
133
151
|
try {
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
const transport = this.getActiveTransport();
|
|
153
|
+
if (transport.disconnect && !!session) {
|
|
154
|
+
await transport.disconnect(session);
|
|
136
155
|
}
|
|
137
156
|
} catch (error) {
|
|
138
157
|
safeThrowError(error);
|
|
@@ -140,10 +159,11 @@ export default class DeviceConnector {
|
|
|
140
159
|
}
|
|
141
160
|
|
|
142
161
|
promptDeviceAccess(): Promise<USBDevice | BluetoothDevice | null> {
|
|
143
|
-
|
|
162
|
+
const transport = this.getActiveTransport();
|
|
163
|
+
if (!transport.promptDeviceAccess) {
|
|
144
164
|
return Promise.resolve(null);
|
|
145
165
|
}
|
|
146
|
-
return
|
|
166
|
+
return transport.promptDeviceAccess();
|
|
147
167
|
}
|
|
148
168
|
|
|
149
169
|
_reportDevicesChange() {
|
package/src/device/DevicePool.ts
CHANGED
|
@@ -103,7 +103,7 @@ export class DevicePool extends EventEmitter {
|
|
|
103
103
|
const device = this.devicesCache[connectId];
|
|
104
104
|
if (device) {
|
|
105
105
|
const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
|
|
106
|
-
if (exist) {
|
|
106
|
+
if (exist && !initOptions?.forceProtocolDetection) {
|
|
107
107
|
// Log.debug('find existed Device: ', connectId);
|
|
108
108
|
device.updateDescriptor(exist, true);
|
|
109
109
|
await this._refreshRuntimeState(device, initOptions);
|
|
@@ -151,12 +151,23 @@ export class DevicePool extends EventEmitter {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
static async _createDevice(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
static async _createDevice(
|
|
155
|
+
descriptor: DeviceDescriptor,
|
|
156
|
+
initOptions?: InitOptions
|
|
157
|
+
): Promise<Device> {
|
|
158
|
+
const cachedDevice = this.getDeviceByPath(descriptor.path);
|
|
159
|
+
const forceProtocolDetection = initOptions?.forceProtocolDetection === true;
|
|
160
|
+
const isNewDevice = !cachedDevice;
|
|
161
|
+
const device = cachedDevice ?? Device.fromDescriptor(descriptor);
|
|
162
|
+
if (isNewDevice || forceProtocolDetection) {
|
|
158
163
|
device.deviceConnector = this.connector;
|
|
159
|
-
|
|
164
|
+
if (forceProtocolDetection && !isNewDevice) {
|
|
165
|
+
await device.acquire(initOptions?.connectProtocol, { forceProtocolDetection: true });
|
|
166
|
+
} else {
|
|
167
|
+
await device.connect(initOptions?.connectProtocol, {
|
|
168
|
+
forceProtocolDetection: initOptions?.forceProtocolDetection,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
160
171
|
try {
|
|
161
172
|
await device.initialize(initOptions);
|
|
162
173
|
if (initOptions?.refreshRuntimeState && device.isProtocolV2()) {
|
|
@@ -181,7 +192,10 @@ export class DevicePool extends EventEmitter {
|
|
|
181
192
|
refreshError = error;
|
|
182
193
|
}
|
|
183
194
|
},
|
|
184
|
-
{
|
|
195
|
+
{
|
|
196
|
+
connectProtocol: initOptions.connectProtocol,
|
|
197
|
+
forceProtocolDetection: initOptions.forceProtocolDetection,
|
|
198
|
+
}
|
|
185
199
|
);
|
|
186
200
|
if (refreshError instanceof Error) throw refreshError;
|
|
187
201
|
if (refreshError) throw new Error(String(refreshError));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
1
|
+
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
resolveDeviceBleFirmwareVersion,
|
|
@@ -386,7 +386,7 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
386
386
|
device_id: deviceId ?? undefined,
|
|
387
387
|
session_id: cached?.sessionId ?? undefined,
|
|
388
388
|
ble_name: bleName ?? undefined,
|
|
389
|
-
onekey_device_type:
|
|
389
|
+
onekey_device_type: deviceType === EDeviceType.Unknown ? undefined : deviceType.toUpperCase(),
|
|
390
390
|
passphrase_protection: passphraseProtection ?? undefined,
|
|
391
391
|
bootloader_mode: bootloaderMode,
|
|
392
392
|
passphraseState: cached?.passphraseState,
|
|
@@ -26,6 +26,9 @@ export const resolveProtocolV2DeviceIdentity = (
|
|
|
26
26
|
case DeviceType.PRO2:
|
|
27
27
|
case 'PRO2':
|
|
28
28
|
return { deviceType: EDeviceType.Pro2, model: 'pro2' };
|
|
29
|
+
case DeviceType.NEO:
|
|
30
|
+
case 'NEO':
|
|
31
|
+
return { deviceType: EDeviceType.Neo, model: 'neo' };
|
|
29
32
|
default:
|
|
30
33
|
return { deviceType: EDeviceType.Unknown, model: null };
|
|
31
34
|
}
|
package/src/events/device.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MessageFactoryFn } from './utils';
|
|
2
|
+
import type { HardwareUiInteractionMeta } from './ui-request';
|
|
2
3
|
import type { PROTO } from '../constants';
|
|
3
4
|
import type {
|
|
4
5
|
KnownDevice as Device,
|
|
@@ -26,6 +27,8 @@ export const DEVICE = {
|
|
|
26
27
|
// onekey-transport events in protobuf format
|
|
27
28
|
BUTTON: 'button',
|
|
28
29
|
PIN: 'pin',
|
|
30
|
+
PIN_ON_DEVICE: 'pin_on_device',
|
|
31
|
+
PIN_ON_DEVICE_COMPLETE: 'pin_on_device_complete',
|
|
29
32
|
PASSPHRASE: 'passphrase',
|
|
30
33
|
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
31
34
|
ATTACH_PIN_ON_DEVICE: 'attach_pin_on_device',
|
|
@@ -58,6 +61,7 @@ export type PassphraseRequestPayload = {
|
|
|
58
61
|
source?: 'wallet-session-coordinator';
|
|
59
62
|
reason?: 'open-wallet' | 'session-recovery';
|
|
60
63
|
expectedPassphraseState?: string;
|
|
64
|
+
interaction?: HardwareUiInteractionMeta;
|
|
61
65
|
};
|
|
62
66
|
|
|
63
67
|
export interface DeviceButtonRequest {
|
package/src/events/ui-promise.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
2
2
|
import type { DEVICE } from './device';
|
|
3
3
|
import type { Device } from '../device/Device';
|
|
4
|
-
import type { UiResponseEvent } from './ui-response';
|
|
4
|
+
import type { UiResponseCorrelation, UiResponseEvent } from './ui-response';
|
|
5
5
|
|
|
6
6
|
export type UiPromiseResponse =
|
|
7
7
|
| UiResponseEvent
|
|
@@ -11,4 +11,6 @@ export type UiPromise<T extends UiPromiseResponse['type']> = Deferred<
|
|
|
11
11
|
Extract<UiPromiseResponse, { type: T }>,
|
|
12
12
|
T,
|
|
13
13
|
Device
|
|
14
|
-
|
|
14
|
+
> & {
|
|
15
|
+
responseCorrelation?: UiResponseCorrelation;
|
|
16
|
+
};
|
package/src/events/ui-request.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PROTO } from '../constants';
|
|
2
2
|
import type { Device } from '../types';
|
|
3
3
|
import type { DeviceButtonRequest } from './device';
|
|
4
|
+
import type { UiResponseCorrelation } from './ui-response';
|
|
4
5
|
import type { MessageFactoryFn } from './utils';
|
|
5
6
|
|
|
6
7
|
export const UI_EVENT = 'UI_EVENT';
|
|
@@ -56,6 +57,17 @@ export type ProtocolV2UiEventSource =
|
|
|
56
57
|
|
|
57
58
|
export type ProtocolV2UiCompletion = 'page-accepted' | 'operation-completed';
|
|
58
59
|
|
|
60
|
+
export type HardwareUiInteractionMeta = {
|
|
61
|
+
interactionId: string;
|
|
62
|
+
phaseId: string;
|
|
63
|
+
sequence: number;
|
|
64
|
+
phase: 'pin' | 'passphrase' | 'passphrase-on-device' | 'button' | 'processing';
|
|
65
|
+
transition: 'start' | 'complete' | 'finish';
|
|
66
|
+
outcome?: 'submitted' | 'succeeded' | 'failed' | 'cancelled' | 'disconnected';
|
|
67
|
+
protocol: 'V2';
|
|
68
|
+
device?: Device;
|
|
69
|
+
};
|
|
70
|
+
|
|
59
71
|
export type ProtocolV2UiEventMetadata = {
|
|
60
72
|
source?: ProtocolV2UiEventSource;
|
|
61
73
|
reason?: string;
|
|
@@ -64,12 +76,29 @@ export type ProtocolV2UiEventMetadata = {
|
|
|
64
76
|
method?: string;
|
|
65
77
|
page?: string | number;
|
|
66
78
|
operation?: string;
|
|
79
|
+
interaction?: HardwareUiInteractionMeta;
|
|
67
80
|
};
|
|
68
81
|
|
|
82
|
+
export type UiRequestWindowClose =
|
|
83
|
+
| {
|
|
84
|
+
type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
|
|
85
|
+
payload: HardwareUiInteractionMeta;
|
|
86
|
+
}
|
|
87
|
+
| {
|
|
88
|
+
type: typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW;
|
|
89
|
+
payload: HardwareUiInteractionMeta;
|
|
90
|
+
}
|
|
91
|
+
| {
|
|
92
|
+
type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
|
|
93
|
+
payload?: undefined;
|
|
94
|
+
}
|
|
95
|
+
| {
|
|
96
|
+
type: typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW;
|
|
97
|
+
payload?: undefined;
|
|
98
|
+
};
|
|
99
|
+
|
|
69
100
|
export interface UiRequestWithoutPayload {
|
|
70
101
|
type:
|
|
71
|
-
| typeof UI_REQUEST.CLOSE_UI_WINDOW
|
|
72
|
-
| typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW
|
|
73
102
|
| typeof UI_REQUEST.BLUETOOTH_PERMISSION
|
|
74
103
|
| typeof UI_REQUEST.BLUETOOTH_UNSUPPORTED
|
|
75
104
|
| typeof UI_REQUEST.BLUETOOTH_POWERED_OFF
|
|
@@ -93,6 +122,7 @@ export type UiRequestDeviceAction = {
|
|
|
93
122
|
payload: ProtocolV2UiEventMetadata & {
|
|
94
123
|
device: Device;
|
|
95
124
|
type?: PROTO.PinMatrixRequestType | 'ButtonRequest_PinEntry' | 'ButtonRequest_AttachPin';
|
|
125
|
+
responseCorrelation?: UiResponseCorrelation;
|
|
96
126
|
};
|
|
97
127
|
};
|
|
98
128
|
|
|
@@ -111,6 +141,8 @@ export interface UiRequestPassphrase {
|
|
|
111
141
|
source?: 'wallet-session-coordinator';
|
|
112
142
|
reason?: 'open-wallet' | 'session-recovery';
|
|
113
143
|
expectedPassphraseState?: string;
|
|
144
|
+
interaction?: HardwareUiInteractionMeta;
|
|
145
|
+
responseCorrelation?: UiResponseCorrelation;
|
|
114
146
|
};
|
|
115
147
|
}
|
|
116
148
|
|
|
@@ -121,6 +153,7 @@ export interface UiRequestPassphraseOnDevice {
|
|
|
121
153
|
passphraseState?: string;
|
|
122
154
|
source?: 'wallet-session-coordinator';
|
|
123
155
|
reason?: 'open-wallet' | 'session-recovery';
|
|
156
|
+
interaction?: HardwareUiInteractionMeta;
|
|
124
157
|
};
|
|
125
158
|
}
|
|
126
159
|
|
|
@@ -191,6 +224,7 @@ export interface PreviousAddressResult {
|
|
|
191
224
|
|
|
192
225
|
export type UiEvent =
|
|
193
226
|
| UiRequestWithoutPayload
|
|
227
|
+
| UiRequestWindowClose
|
|
194
228
|
| UiRequestDeviceAction
|
|
195
229
|
| UiRequestButton
|
|
196
230
|
| UiRequestPassphraseOnDevice
|
|
@@ -11,12 +11,22 @@ export const UI_RESPONSE = {
|
|
|
11
11
|
'ui-receive_select-device-for-switch-firmware-web-device',
|
|
12
12
|
} as const;
|
|
13
13
|
|
|
14
|
-
export interface
|
|
14
|
+
export interface UiResponseCorrelation {
|
|
15
|
+
interactionId: string;
|
|
16
|
+
deviceId: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface UiResponseCorrelationFields {
|
|
20
|
+
interactionId?: string;
|
|
21
|
+
deviceId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UiResponsePin extends UiResponseCorrelationFields {
|
|
15
25
|
type: typeof UI_RESPONSE.RECEIVE_PIN;
|
|
16
26
|
payload: string;
|
|
17
27
|
}
|
|
18
28
|
|
|
19
|
-
export interface UiResponsePassphrase {
|
|
29
|
+
export interface UiResponsePassphrase extends UiResponseCorrelationFields {
|
|
20
30
|
type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;
|
|
21
31
|
payload: {
|
|
22
32
|
value: string;
|
package/src/inject.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
unregisterFirmwareUpdateHostBinding,
|
|
10
10
|
} from './api/firmware/FirmwareHostBinding';
|
|
11
11
|
|
|
12
|
+
import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
12
13
|
import type { EventEmitter } from 'events';
|
|
13
14
|
import type { CallMethod } from './events';
|
|
14
15
|
import type { Unsuccessful } from './types';
|
|
@@ -50,6 +51,50 @@ export interface InjectApi {
|
|
|
50
51
|
switchTransport: CoreApi['switchTransport'];
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
const normalizeConnectId = (connectId: string) => connectId.trim().toLowerCase();
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Keeps verified protocols isolated per transport endpoint and injects them at
|
|
58
|
+
* the single public call boundary, including APIs that do not expose params.
|
|
59
|
+
*/
|
|
60
|
+
export const createProtocolAwareCall = (rawCall: CoreApi['call']) => {
|
|
61
|
+
const protocolByConnectId = new Map<string, HardwareConnectProtocol>();
|
|
62
|
+
|
|
63
|
+
const setDeviceConnectProtocol: CoreApi['setDeviceConnectProtocol'] = (
|
|
64
|
+
connectId,
|
|
65
|
+
connectProtocol
|
|
66
|
+
) => {
|
|
67
|
+
const normalizedConnectId = normalizeConnectId(connectId);
|
|
68
|
+
if (!normalizedConnectId) return;
|
|
69
|
+
if (connectProtocol) {
|
|
70
|
+
protocolByConnectId.set(normalizedConnectId, connectProtocol);
|
|
71
|
+
} else {
|
|
72
|
+
protocolByConnectId.delete(normalizedConnectId);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const call: CoreApi['call'] = params => {
|
|
77
|
+
if (!params || typeof params !== 'object') {
|
|
78
|
+
return rawCall(params);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const connectId = typeof params.connectId === 'string' ? params.connectId : undefined;
|
|
82
|
+
const boundProtocol = connectId
|
|
83
|
+
? protocolByConnectId.get(normalizeConnectId(connectId))
|
|
84
|
+
: undefined;
|
|
85
|
+
if (
|
|
86
|
+
boundProtocol &&
|
|
87
|
+
params.connectProtocol === undefined &&
|
|
88
|
+
params.forceProtocolDetection !== true
|
|
89
|
+
) {
|
|
90
|
+
return rawCall({ ...params, connectProtocol: boundProtocol });
|
|
91
|
+
}
|
|
92
|
+
return rawCall(params);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return { call, setDeviceConnectProtocol };
|
|
96
|
+
};
|
|
97
|
+
|
|
53
98
|
export const inject = ({
|
|
54
99
|
call,
|
|
55
100
|
cancel,
|
|
@@ -60,6 +105,7 @@ export const inject = ({
|
|
|
60
105
|
switchTransport,
|
|
61
106
|
uiResponse,
|
|
62
107
|
}: InjectApi): CoreApi => {
|
|
108
|
+
const protocolAwareCall = createProtocolAwareCall(call);
|
|
63
109
|
const api: CoreApi = {
|
|
64
110
|
on: <T extends string, P extends (...args: any[]) => any>(type: T, fn: P) => {
|
|
65
111
|
eventEmitter.on(type, fn);
|
|
@@ -77,7 +123,9 @@ export const inject = ({
|
|
|
77
123
|
|
|
78
124
|
init,
|
|
79
125
|
|
|
80
|
-
call,
|
|
126
|
+
call: protocolAwareCall.call,
|
|
127
|
+
|
|
128
|
+
setDeviceConnectProtocol: protocolAwareCall.setDeviceConnectProtocol,
|
|
81
129
|
|
|
82
130
|
dispose: async () => {
|
|
83
131
|
unregisterFirmwareUpdateHostBinding();
|
|
@@ -92,7 +140,7 @@ export const inject = ({
|
|
|
92
140
|
|
|
93
141
|
switchTransport,
|
|
94
142
|
|
|
95
|
-
...createCoreApi(call),
|
|
143
|
+
...createCoreApi(protocolAwareCall.call),
|
|
96
144
|
};
|
|
97
145
|
return api;
|
|
98
146
|
};
|
|
@@ -107,6 +155,7 @@ export const createCoreApi = (
|
|
|
107
155
|
| 'removeAllListeners'
|
|
108
156
|
| 'init'
|
|
109
157
|
| 'call'
|
|
158
|
+
| 'setDeviceConnectProtocol'
|
|
110
159
|
| 'dispose'
|
|
111
160
|
| 'uiResponse'
|
|
112
161
|
| 'cancel'
|
|
@@ -125,6 +174,12 @@ export const createCoreApi = (
|
|
|
125
174
|
* 搜索设备
|
|
126
175
|
*/
|
|
127
176
|
searchDevices: params => call({ ...params, method: 'searchDevices' }),
|
|
177
|
+
detectDeviceConnectProtocol: connectId =>
|
|
178
|
+
call({
|
|
179
|
+
connectId,
|
|
180
|
+
method: 'detectDeviceConnectProtocol',
|
|
181
|
+
forceProtocolDetection: true,
|
|
182
|
+
}),
|
|
128
183
|
|
|
129
184
|
/**
|
|
130
185
|
* 获取设备信息
|
|
@@ -182,6 +237,7 @@ export const createCoreApi = (
|
|
|
182
237
|
call({ ...params, connectId, method: 'deviceGetOnboardingStatus' }),
|
|
183
238
|
deviceUploadWallpaper: (connectId, params) =>
|
|
184
239
|
call({ ...params, connectId, method: 'deviceUploadWallpaper' }),
|
|
240
|
+
deviceUploadNft: (connectId, params) => call({ ...params, connectId, method: 'deviceUploadNft' }),
|
|
185
241
|
uploadPortfolio: (connectId, params) => call({ ...params, connectId, method: 'uploadPortfolio' }),
|
|
186
242
|
deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
|
|
187
243
|
deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
|
package/src/lowLevelInject.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCoreApi } from './inject';
|
|
1
|
+
import { createCoreApi, createProtocolAwareCall } from './inject';
|
|
2
2
|
import { unregisterFirmwareUpdateHostBinding } from './api/firmware/FirmwareHostBinding';
|
|
3
3
|
|
|
4
4
|
import type { EventEmitter } from 'events';
|
|
@@ -34,6 +34,7 @@ export const lowLevelInject = ({
|
|
|
34
34
|
switchTransport,
|
|
35
35
|
addHardwareGlobalEventListener,
|
|
36
36
|
}: LowLevelInjectApi): LowLevelCoreApi => {
|
|
37
|
+
const protocolAwareCall = createProtocolAwareCall(call);
|
|
37
38
|
const api: LowLevelCoreApi = {
|
|
38
39
|
addHardwareGlobalEventListener,
|
|
39
40
|
removeAllListeners: type => {
|
|
@@ -42,7 +43,9 @@ export const lowLevelInject = ({
|
|
|
42
43
|
|
|
43
44
|
init,
|
|
44
45
|
|
|
45
|
-
call,
|
|
46
|
+
call: protocolAwareCall.call,
|
|
47
|
+
|
|
48
|
+
setDeviceConnectProtocol: protocolAwareCall.setDeviceConnectProtocol,
|
|
46
49
|
|
|
47
50
|
dispose: async () => {
|
|
48
51
|
unregisterFirmwareUpdateHostBinding();
|
|
@@ -59,7 +62,7 @@ export const lowLevelInject = ({
|
|
|
59
62
|
|
|
60
63
|
emit: () => {},
|
|
61
64
|
|
|
62
|
-
...createCoreApi(call),
|
|
65
|
+
...createCoreApi(protocolAwareCall.call),
|
|
63
66
|
};
|
|
64
67
|
return api;
|
|
65
68
|
};
|
|
@@ -107,10 +107,6 @@ export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
|
107
107
|
hw: true,
|
|
108
108
|
fw: true,
|
|
109
109
|
coprocessor: true,
|
|
110
|
-
se1: true,
|
|
111
|
-
se2: true,
|
|
112
|
-
se3: true,
|
|
113
|
-
se4: true,
|
|
114
110
|
},
|
|
115
111
|
types: {
|
|
116
112
|
version: true,
|
|
@@ -157,7 +153,7 @@ export const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
|
|
|
157
153
|
};
|
|
158
154
|
|
|
159
155
|
export const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
|
|
160
|
-
export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS =
|
|
156
|
+
export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 30 * 1000;
|
|
161
157
|
|
|
162
158
|
export async function requestProtocolV2ProtocolInfo({
|
|
163
159
|
commands,
|
|
@@ -168,8 +164,15 @@ export async function requestProtocolV2ProtocolInfo({
|
|
|
168
164
|
}): Promise<ProtocolInfo> {
|
|
169
165
|
const response =
|
|
170
166
|
timeoutMs === undefined
|
|
171
|
-
? await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
|
|
172
|
-
|
|
167
|
+
? await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
|
|
168
|
+
eventless_wallet_session: true,
|
|
169
|
+
})
|
|
170
|
+
: await commands.typedCall(
|
|
171
|
+
'ProtocolInfoRequest',
|
|
172
|
+
'ProtocolInfo',
|
|
173
|
+
{ eventless_wallet_session: true },
|
|
174
|
+
{ timeoutMs }
|
|
175
|
+
);
|
|
173
176
|
return response.message;
|
|
174
177
|
}
|
|
175
178
|
|
|
@@ -15,5 +15,7 @@ export const ProtocolV2FirmwareTargetType = {
|
|
|
15
15
|
FW_MGMT_TARGET_SE04: 10,
|
|
16
16
|
} as const;
|
|
17
17
|
|
|
18
|
+
// 这里有意同时导出同名值与类型,以保持现有公共 API 不变。
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
18
20
|
export type ProtocolV2FirmwareTargetType =
|
|
19
21
|
(typeof ProtocolV2FirmwareTargetType)[keyof typeof ProtocolV2FirmwareTargetType];
|