@onekeyfe/hd-core 1.2.0-alpha.22 → 1.2.0-alpha.24
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__/DeviceCommands.test.ts +43 -8
- package/__tests__/connectSettings.test.ts +5 -47
- package/__tests__/device-lifecycle-events.test.ts +59 -0
- package/__tests__/device-settings.test.ts +1 -1
- package/__tests__/device-wallet-session-store.test.ts +41 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +30 -39
- package/__tests__/logBlockEvent.test.ts +17 -0
- package/__tests__/open-wallet-session.test.ts +233 -111
- package/__tests__/protocol-v2-ping.test.ts +28 -0
- package/__tests__/protocol-v2.test.ts +513 -313
- package/__tests__/public-pro2-api-boundary.test.ts +22 -0
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +0 -11
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +3 -7
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +5 -21
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts +1 -8
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +0 -7
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +0 -7
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +0 -2
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +1 -9
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/Ping.d.ts +2 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +0 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +3 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/device.d.ts +1 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +1 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +98 -278
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +876 -2647
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +2 -3
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +12 -0
- 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 +0 -3
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -4
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +0 -69
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +4 -10
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +0 -12
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +4 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/settings.d.ts +0 -13
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.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/CheckAllFirmwareRelease.ts +3 -16
- package/src/api/FirmwareUpdateV2.ts +119 -284
- package/src/api/FirmwareUpdateV3.ts +55 -248
- package/src/api/FirmwareUpdateV4.ts +293 -751
- package/src/api/GetPassphraseState.ts +11 -5
- package/src/api/OpenWalletSession.ts +23 -86
- package/src/api/device/DeviceUpdateBootloader.ts +6 -114
- package/src/api/device/DeviceWipe.ts +2 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +0 -50
- package/src/api/firmware/updateBootloader.ts +4 -19
- package/src/api/firmware/uploadFirmware.ts +22 -140
- package/src/api/index.ts +1 -0
- package/src/api/protocol-v2/Ping.ts +32 -1
- package/src/core/index.ts +40 -7
- package/src/data/messages/messages-protocol-v2.json +49 -56
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +0 -11
- package/src/device/Device.ts +29 -8
- package/src/device/DeviceCommands.ts +43 -151
- package/src/events/device.ts +1 -0
- package/src/events/logBlockEvent.ts +1 -15
- package/src/events/ui-request.ts +1 -0
- package/src/index.ts +0 -5
- package/src/inject.ts +4 -22
- package/src/lowLevelInject.ts +1 -5
- package/src/protocols/protocol-v2/deviceSession.ts +1 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +0 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +20 -3
- package/src/protocols/protocol-v2/walletSession.ts +57 -18
- package/src/topLevelInject.ts +1 -5
- package/src/types/api/checkAllFirmwareRelease.ts +0 -3
- package/src/types/api/deviceUpdateBootloader.ts +0 -6
- package/src/types/api/export.ts +0 -18
- package/src/types/api/firmwareUpdate.ts +0 -76
- package/src/types/api/getPassphraseState.ts +4 -3
- package/src/types/api/index.ts +3 -14
- package/src/types/api/openWalletSession.ts +0 -19
- package/src/types/api/protocolV2.ts +10 -0
- package/src/types/settings.ts +0 -13
- package/src/utils/deviceInfoUtils.ts +2 -3
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
- package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
- package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -326
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -200
- package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -26
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -24
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -25
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +0 -27
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
- package/src/api/firmware/FirmwareHostBinding.ts +0 -100
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -621
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -378
- package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
- package/src/types/api/firmwareUpdatePlan.ts +0 -36
- package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LoggerNames, getLogger } from '../../utils';
|
|
2
2
|
import { isDeviceLockedError } from './lockedError';
|
|
3
3
|
import { isProtocolV2UiEnabled, resolveProtocolV2UiInteraction } from './uiInteraction';
|
|
4
|
+
import { restoreProtocolV2WalletSession } from './walletSession';
|
|
4
5
|
|
|
5
6
|
import type { BaseMethod } from '../../api/BaseMethod';
|
|
6
7
|
import type { Device } from '../../device/Device';
|
|
@@ -10,9 +11,14 @@ const Log = getLogger(LoggerNames.Core);
|
|
|
10
11
|
|
|
11
12
|
type RunnableMethod = Pick<
|
|
12
13
|
BaseMethod,
|
|
13
|
-
|
|
14
|
+
| 'run'
|
|
15
|
+
| 'unlockPolicy'
|
|
16
|
+
| 'protocolV2UiInteraction'
|
|
17
|
+
| 'protocolV2UiMode'
|
|
18
|
+
| 'params'
|
|
19
|
+
| 'payload'
|
|
20
|
+
| 'useDevicePassphraseState'
|
|
14
21
|
> & { name?: string };
|
|
15
|
-
type UnlockableDevice = Pick<Device, 'isProtocolV2' | 'unlockDevice' | 'features'>;
|
|
16
22
|
type UiInteractionCoordinator = Pick<
|
|
17
23
|
ProtocolV2UiInteractionCoordinator,
|
|
18
24
|
'enterMethodInteraction' | 'enterUnlockInteraction' | 'resumeMethodInteraction'
|
|
@@ -20,7 +26,7 @@ type UiInteractionCoordinator = Pick<
|
|
|
20
26
|
|
|
21
27
|
export async function runMethodWithUnlockRetry(
|
|
22
28
|
method: RunnableMethod,
|
|
23
|
-
device:
|
|
29
|
+
device: Device,
|
|
24
30
|
uiCoordinator?: UiInteractionCoordinator
|
|
25
31
|
) {
|
|
26
32
|
const shouldEmitUi = isProtocolV2UiEnabled(method);
|
|
@@ -59,6 +65,17 @@ export async function runMethodWithUnlockRetry(
|
|
|
59
65
|
}
|
|
60
66
|
await device.unlockDevice();
|
|
61
67
|
Log.debug('Protocol V2 unlock completed', { method: method.name });
|
|
68
|
+
const expectedPassphraseState = method.payload?.useEmptyPassphrase
|
|
69
|
+
? undefined
|
|
70
|
+
: method.payload?.passphraseState ?? device.passphraseState;
|
|
71
|
+
if (
|
|
72
|
+
method.useDevicePassphraseState &&
|
|
73
|
+
typeof expectedPassphraseState === 'string' &&
|
|
74
|
+
expectedPassphraseState.length > 0
|
|
75
|
+
) {
|
|
76
|
+
await restoreProtocolV2WalletSession(device, expectedPassphraseState);
|
|
77
|
+
Log.debug('Protocol V2 wallet session restored after unlock', { method: method.name });
|
|
78
|
+
}
|
|
62
79
|
if (shouldEmitUi) {
|
|
63
80
|
uiCoordinator?.resumeMethodInteraction();
|
|
64
81
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import { DEVICE } from '../../events';
|
|
4
5
|
import { assertCompleteDeviceSession } from './deviceSession';
|
|
5
6
|
import { isDeviceLockedError } from './lockedError';
|
|
6
7
|
|
|
7
|
-
import type {
|
|
8
|
+
import type { DeviceSessionGet } from '@onekeyfe/hd-transport';
|
|
8
9
|
import type { Device } from '../../device/Device';
|
|
9
10
|
|
|
10
11
|
export async function requestProtocolV2DeviceStatus(device: Device) {
|
|
@@ -23,15 +24,33 @@ const negotiateEventlessWalletSession = async (device: Device) => {
|
|
|
23
24
|
});
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
+
const getDeviceSession = async (device: Device, request: DeviceSessionGet) => {
|
|
27
28
|
try {
|
|
28
|
-
return await device.commands.typedCall('
|
|
29
|
+
return await device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
|
|
29
30
|
} catch (error) {
|
|
30
31
|
if (!isDeviceLockedError(error)) {
|
|
31
32
|
throw error;
|
|
32
33
|
}
|
|
33
|
-
await device.unlockDevice();
|
|
34
|
-
return device.commands.typedCall('
|
|
34
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
35
|
+
return device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const askDevicePassphrase = async (device: Device, passphrase?: string) => {
|
|
40
|
+
const request = () =>
|
|
41
|
+
device.commands.typedCall(
|
|
42
|
+
'DeviceSessionAskPassphrase',
|
|
43
|
+
'Success',
|
|
44
|
+
passphrase ? { passphrase } : {}
|
|
45
|
+
);
|
|
46
|
+
try {
|
|
47
|
+
return await request();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (!isDeviceLockedError(error)) {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
53
|
+
return request();
|
|
35
54
|
}
|
|
36
55
|
};
|
|
37
56
|
|
|
@@ -42,13 +61,16 @@ const selectDeviceSession = async (device: Device) => {
|
|
|
42
61
|
reason: 'open-wallet' as const,
|
|
43
62
|
};
|
|
44
63
|
const response = await device.commands.promptPassphrase(
|
|
45
|
-
{
|
|
64
|
+
{
|
|
65
|
+
existsAttachPinUser,
|
|
66
|
+
...metadata,
|
|
67
|
+
},
|
|
46
68
|
{ cancelDeviceOnReject: false }
|
|
47
69
|
);
|
|
48
|
-
const
|
|
49
|
-
typeof response.passphrase === 'string'
|
|
70
|
+
const hasHostPassphrase =
|
|
71
|
+
typeof response.passphrase === 'string' && response.passphrase.length > 0;
|
|
50
72
|
const selections = [
|
|
51
|
-
|
|
73
|
+
hasHostPassphrase,
|
|
52
74
|
response.passphraseOnDevice === true,
|
|
53
75
|
response.attachPinOnDevice === true,
|
|
54
76
|
].filter(Boolean).length;
|
|
@@ -68,17 +90,18 @@ const selectDeviceSession = async (device: Device) => {
|
|
|
68
90
|
);
|
|
69
91
|
}
|
|
70
92
|
device.emit(DEVICE.ATTACH_PIN_ON_DEVICE, device, metadata);
|
|
71
|
-
|
|
93
|
+
await device.unlockDevice(DeviceSessionPinType.AttachToPin);
|
|
94
|
+
return getDeviceSession(device, {});
|
|
72
95
|
}
|
|
73
96
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
return
|
|
97
|
+
if (hasHostPassphrase) {
|
|
98
|
+
await askDevicePassphrase(device, response.passphrase);
|
|
99
|
+
return getDeviceSession(device, {});
|
|
77
100
|
}
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
102
|
+
device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
|
|
103
|
+
await askDevicePassphrase(device);
|
|
104
|
+
return getDeviceSession(device, {});
|
|
82
105
|
};
|
|
83
106
|
|
|
84
107
|
export async function getProtocolV2WalletSession(
|
|
@@ -87,10 +110,12 @@ export async function getProtocolV2WalletSession(
|
|
|
87
110
|
initSession?: boolean;
|
|
88
111
|
expectedPassphraseState?: string;
|
|
89
112
|
onlyMainPin?: boolean;
|
|
113
|
+
resumeOnly?: boolean;
|
|
90
114
|
}
|
|
91
115
|
) {
|
|
92
116
|
if (options?.initSession) {
|
|
93
117
|
device.clearInternalState();
|
|
118
|
+
device.passphraseState = undefined;
|
|
94
119
|
}
|
|
95
120
|
|
|
96
121
|
await negotiateEventlessWalletSession(device);
|
|
@@ -103,7 +128,7 @@ export async function getProtocolV2WalletSession(
|
|
|
103
128
|
: options?.expectedPassphraseState ?? device.passphraseState;
|
|
104
129
|
|
|
105
130
|
if (device.features?.unlocked === false) {
|
|
106
|
-
await device.unlockDevice();
|
|
131
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
107
132
|
}
|
|
108
133
|
|
|
109
134
|
if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
|
|
@@ -122,7 +147,7 @@ export async function getProtocolV2WalletSession(
|
|
|
122
147
|
|
|
123
148
|
if (cachedSessionId && expectedPassphraseState) {
|
|
124
149
|
try {
|
|
125
|
-
response = await
|
|
150
|
+
response = await getDeviceSession(device, { session_id: cachedSessionId });
|
|
126
151
|
resumed = true;
|
|
127
152
|
} catch (error) {
|
|
128
153
|
device.clearInternalState();
|
|
@@ -131,6 +156,10 @@ export async function getProtocolV2WalletSession(
|
|
|
131
156
|
}
|
|
132
157
|
|
|
133
158
|
if (!response) {
|
|
159
|
+
if (options?.resumeOnly) {
|
|
160
|
+
device.clearInternalState();
|
|
161
|
+
throw ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid);
|
|
162
|
+
}
|
|
134
163
|
response = await selectDeviceSession(device);
|
|
135
164
|
}
|
|
136
165
|
|
|
@@ -161,3 +190,13 @@ export async function getProtocolV2WalletSession(
|
|
|
161
190
|
resumed,
|
|
162
191
|
};
|
|
163
192
|
}
|
|
193
|
+
|
|
194
|
+
export async function restoreProtocolV2WalletSession(
|
|
195
|
+
device: Device,
|
|
196
|
+
expectedPassphraseState: string
|
|
197
|
+
) {
|
|
198
|
+
return getProtocolV2WalletSession(device, {
|
|
199
|
+
expectedPassphraseState,
|
|
200
|
+
resumeOnly: true,
|
|
201
|
+
});
|
|
202
|
+
}
|
package/src/topLevelInject.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
|
|
3
3
|
import { createCoreApi } from './inject';
|
|
4
|
-
import { unregisterFirmwareUpdateHostBinding } from './api/firmware/FirmwareHostBinding';
|
|
5
4
|
|
|
6
5
|
import type { ConnectSettings } from './types/settings';
|
|
7
6
|
import type { CoreApi } from './types/api';
|
|
@@ -47,10 +46,7 @@ export const topLevelInject = () => {
|
|
|
47
46
|
lowLevelApi?.removeAllListeners(type);
|
|
48
47
|
},
|
|
49
48
|
|
|
50
|
-
dispose:
|
|
51
|
-
unregisterFirmwareUpdateHostBinding();
|
|
52
|
-
await lowLevelApi?.dispose();
|
|
53
|
-
},
|
|
49
|
+
dispose: () => lowLevelApi?.dispose(),
|
|
54
50
|
|
|
55
51
|
uiResponse: response => lowLevelApi?.uiResponse(response),
|
|
56
52
|
|
|
@@ -2,7 +2,6 @@ import type { IBLEFirmwareReleaseInfo } from '../settings';
|
|
|
2
2
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
3
3
|
import type { CommonParams, Response } from '../params';
|
|
4
4
|
import type { Features, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus } from '../device';
|
|
5
|
-
import type { FirmwareUpdatePlan } from './firmwareUpdatePlan';
|
|
6
5
|
|
|
7
6
|
export type FirmwareRelease = {
|
|
8
7
|
shouldUpdate?: boolean;
|
|
@@ -21,13 +20,11 @@ export type AllFirmwareRelease = {
|
|
|
21
20
|
bootloader?: FirmwareRelease;
|
|
22
21
|
bridge?: FirmwareRelease;
|
|
23
22
|
features?: Features;
|
|
24
|
-
firmwareUpdatePlan?: FirmwareUpdatePlan;
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
export type CheckAllFirmwareReleaseParams = {
|
|
28
26
|
checkBridgeRelease?: boolean;
|
|
29
27
|
firmwareType?: EFirmwareType;
|
|
30
|
-
platform?: 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
|
|
31
28
|
};
|
|
32
29
|
|
|
33
30
|
export declare function checkAllFirmwareRelease(
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import type { Success } from '@onekeyfe/hd-transport';
|
|
2
2
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
3
|
-
import type { FirmwareArtifactReader, FirmwareArtifactReference } from './firmwareUpdate';
|
|
4
|
-
import type { FirmwareUpdatePreparedPlan } from './firmwareUpdatePreparedPlan';
|
|
5
3
|
import type { Response } from '../params';
|
|
6
4
|
|
|
7
5
|
export type DeviceUpdateBootloaderParams = {
|
|
8
|
-
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
9
|
-
hostBindingGeneration?: number;
|
|
10
6
|
binary?: ArrayBuffer;
|
|
11
|
-
artifact?: FirmwareArtifactReference;
|
|
12
|
-
artifactReader?: FirmwareArtifactReader;
|
|
13
7
|
firmwareType?: EFirmwareType;
|
|
14
8
|
};
|
|
15
9
|
|
package/src/types/api/export.ts
CHANGED
|
@@ -25,29 +25,11 @@ export type {
|
|
|
25
25
|
DeviceUploadResourceResponse,
|
|
26
26
|
} from './deviceUploadResource';
|
|
27
27
|
export type {
|
|
28
|
-
FirmwareArtifactReader,
|
|
29
|
-
FirmwareArtifactReference,
|
|
30
|
-
FirmwareUpdateHostBinding,
|
|
31
|
-
FirmwareUpdateArtifactParams,
|
|
32
28
|
FirmwareUpdateParams,
|
|
33
29
|
FirmwareUpdateBinaryParams,
|
|
34
30
|
FirmwareUpdateV3Params,
|
|
35
31
|
FirmwareUpdateV4Params,
|
|
36
|
-
FirmwareUpdateV4Target,
|
|
37
32
|
} from './firmwareUpdate';
|
|
38
|
-
export type {
|
|
39
|
-
FirmwareUpdatePlan,
|
|
40
|
-
FirmwareUpdatePlanArtifact,
|
|
41
|
-
FirmwareUpdatePlanArtifactRole,
|
|
42
|
-
FirmwareUpdatePlanTarget,
|
|
43
|
-
} from './firmwareUpdatePlan';
|
|
44
|
-
export type {
|
|
45
|
-
FirmwareUpdatePreparedArtifact,
|
|
46
|
-
FirmwareUpdatePreparedArtifactInput,
|
|
47
|
-
FirmwareUpdatePreparedEntry,
|
|
48
|
-
FirmwareUpdatePreparedPlan,
|
|
49
|
-
} from './firmwareUpdatePreparedPlan';
|
|
50
|
-
export type { FirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
|
|
51
33
|
export type { AllFirmwareRelease } from './checkAllFirmwareRelease';
|
|
52
34
|
|
|
53
35
|
export type { AllNetworkAddressParams, AllNetworkGetAddressParams } from './allNetworkGetAddress';
|
|
@@ -1,53 +1,14 @@
|
|
|
1
1
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
import type { PROTO } from '../../constants';
|
|
3
3
|
import type { Params, Response } from '../params';
|
|
4
|
-
import type { FirmwareUpdatePreparedPlan } from './firmwareUpdatePreparedPlan';
|
|
5
4
|
|
|
6
5
|
type IUpdateType = 'firmware' | 'ble';
|
|
7
6
|
|
|
8
|
-
export interface FirmwareArtifactReference {
|
|
9
|
-
artifactRef: string;
|
|
10
|
-
size: number;
|
|
11
|
-
sha256: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface FirmwareArtifactReader {
|
|
15
|
-
open(input: { artifactRef: string }): Promise<{
|
|
16
|
-
readerId: string;
|
|
17
|
-
size: number;
|
|
18
|
-
}>;
|
|
19
|
-
read(input: { readerId: string; offset: number; length: number }): Promise<{
|
|
20
|
-
data: ArrayBuffer;
|
|
21
|
-
bytesRead: number;
|
|
22
|
-
eof: boolean;
|
|
23
|
-
}>;
|
|
24
|
-
close(input: { readerId: string }): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface FirmwareUpdateHostBinding {
|
|
28
|
-
artifactReader: FirmwareArtifactReader;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
7
|
export interface FirmwareUpdateBinaryParams {
|
|
32
8
|
binary: ArrayBuffer;
|
|
33
9
|
updateType: IUpdateType;
|
|
34
10
|
}
|
|
35
11
|
|
|
36
|
-
export interface FirmwareUpdateArtifactParams {
|
|
37
|
-
preparedPlan: FirmwareUpdatePreparedPlan;
|
|
38
|
-
hostBindingGeneration: number;
|
|
39
|
-
artifact: FirmwareArtifactReference;
|
|
40
|
-
resourceArtifact?: FirmwareArtifactReference;
|
|
41
|
-
resourceEntries?: Array<{
|
|
42
|
-
entryName: string;
|
|
43
|
-
artifact: FirmwareArtifactReference;
|
|
44
|
-
}>;
|
|
45
|
-
updateType: IUpdateType;
|
|
46
|
-
forcedUpdateRes?: boolean;
|
|
47
|
-
isUpdateBootloader?: boolean;
|
|
48
|
-
firmwareType?: EFirmwareType;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
12
|
export interface FirmwareUpdateParams {
|
|
52
13
|
version?: number[];
|
|
53
14
|
updateType: IUpdateType;
|
|
@@ -76,14 +37,8 @@ export declare function firmwareUpdateV2(
|
|
|
76
37
|
connectId: string | undefined,
|
|
77
38
|
params: Params<FirmwareUpdateBinaryParams & Platform>
|
|
78
39
|
): Response<PROTO.Success>;
|
|
79
|
-
export declare function firmwareUpdateV2(
|
|
80
|
-
connectId: string | undefined,
|
|
81
|
-
params: Params<FirmwareUpdateArtifactParams & Platform>
|
|
82
|
-
): Response<PROTO.Success>;
|
|
83
40
|
|
|
84
41
|
export interface FirmwareUpdateV3Params {
|
|
85
|
-
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
86
|
-
hostBindingGeneration?: number;
|
|
87
42
|
bleVersion?: number[];
|
|
88
43
|
bleBinary?: ArrayBuffer;
|
|
89
44
|
chunkSize?: number;
|
|
@@ -100,17 +55,6 @@ export interface FirmwareUpdateV3Params {
|
|
|
100
55
|
firmwareType?: EFirmwareType;
|
|
101
56
|
|
|
102
57
|
platform: IPlatform;
|
|
103
|
-
|
|
104
|
-
artifactReader?: FirmwareArtifactReader;
|
|
105
|
-
artifacts?: {
|
|
106
|
-
ble?: FirmwareArtifactReference;
|
|
107
|
-
firmware?: FirmwareArtifactReference;
|
|
108
|
-
bootloader?: FirmwareArtifactReference;
|
|
109
|
-
resourceEntries?: Array<{
|
|
110
|
-
entryName: string;
|
|
111
|
-
artifact: FirmwareArtifactReference;
|
|
112
|
-
}>;
|
|
113
|
-
};
|
|
114
58
|
}
|
|
115
59
|
|
|
116
60
|
/**
|
|
@@ -129,14 +73,10 @@ export type FirmwareUpdateV4Target =
|
|
|
129
73
|
| 'se04';
|
|
130
74
|
|
|
131
75
|
export interface FirmwareUpdateV4Params {
|
|
132
|
-
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
133
|
-
hostBindingGeneration?: number;
|
|
134
76
|
platform: IPlatform;
|
|
135
|
-
expectedDeviceId?: string;
|
|
136
77
|
chunkSize?: number;
|
|
137
78
|
firmwareType?: EFirmwareType;
|
|
138
79
|
targetsToUpdate?: FirmwareUpdateV4Target[];
|
|
139
|
-
expectedTargetVersions?: Partial<Record<FirmwareUpdateV4Target, string>>;
|
|
140
80
|
|
|
141
81
|
/** FW_MGMT_TARGET_ROMLOADER = 2; Pro2 cannot install it through firmwareUpdateV4. */
|
|
142
82
|
romloaderBinary?: ArrayBuffer;
|
|
@@ -162,24 +102,8 @@ export interface FirmwareUpdateV4Params {
|
|
|
162
102
|
binary: ArrayBuffer;
|
|
163
103
|
devicePath: string;
|
|
164
104
|
}>;
|
|
165
|
-
artifactReader?: FirmwareArtifactReader;
|
|
166
|
-
componentArtifacts?: Partial<
|
|
167
|
-
Record<Exclude<FirmwareUpdateV4Target, 'resource'>, FirmwareArtifactReference>
|
|
168
|
-
>;
|
|
169
|
-
resourceBundleArtifacts?: Array<{
|
|
170
|
-
name: string;
|
|
171
|
-
artifact: FirmwareArtifactReference;
|
|
172
|
-
}>;
|
|
173
105
|
}
|
|
174
106
|
|
|
175
|
-
export declare function registerFirmwareUpdateHostBinding(
|
|
176
|
-
binding: FirmwareUpdateHostBinding
|
|
177
|
-
): number;
|
|
178
|
-
|
|
179
|
-
export declare function unregisterFirmwareUpdateHostBinding(generation?: number): boolean;
|
|
180
|
-
|
|
181
|
-
export declare function getFirmwareUpdateHostBindingGeneration(): number;
|
|
182
|
-
|
|
183
107
|
export declare function firmwareUpdateV3(
|
|
184
108
|
connectId: string | undefined,
|
|
185
109
|
params: Params<FirmwareUpdateV3Params>
|
|
@@ -3,10 +3,11 @@ import type { CommonParams, Response } from '../params';
|
|
|
3
3
|
export type GetPassphraseStateParams = CommonParams;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Compatibility wallet-state API for existing App integrations.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* and
|
|
8
|
+
* Protocol V1 keeps its parameterless firmware flow. Protocol V2 maps the existing
|
|
9
|
+
* `useEmptyPassphrase` and `initSession` intent to the device-only wallet-session flow.
|
|
10
|
+
* New integrations should prefer `openWalletSession` for explicit wallet intent.
|
|
10
11
|
*/
|
|
11
12
|
export declare function getPassphraseState(
|
|
12
13
|
connectId?: string,
|
package/src/types/api/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
deviceGetOnboardingStatus,
|
|
3
3
|
deviceReboot,
|
|
4
4
|
deviceUploadWallpaper,
|
|
5
|
+
testProtocolV2Ping,
|
|
5
6
|
uploadPortfolio,
|
|
6
7
|
} from './protocolV2';
|
|
7
8
|
import type { off, on, removeAllListeners } from './event';
|
|
@@ -29,15 +30,7 @@ import type {
|
|
|
29
30
|
firmwareUpdateV2,
|
|
30
31
|
firmwareUpdateV3,
|
|
31
32
|
firmwareUpdateV4,
|
|
32
|
-
getFirmwareUpdateHostBindingGeneration,
|
|
33
|
-
registerFirmwareUpdateHostBinding,
|
|
34
|
-
unregisterFirmwareUpdateHostBinding,
|
|
35
33
|
} from './firmwareUpdate';
|
|
36
|
-
import type { getFirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
|
|
37
|
-
import type {
|
|
38
|
-
prepareFirmwareUpdatePlan,
|
|
39
|
-
validateFirmwareUpdatePreparedPlan,
|
|
40
|
-
} from './firmwareUpdatePreparedPlan';
|
|
41
34
|
import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
|
|
42
35
|
import type { deviceReset } from './deviceReset';
|
|
43
36
|
import type { deviceRecovery } from './deviceRecovery';
|
|
@@ -157,6 +150,7 @@ export type { DeviceStateScope, GetDeviceStateParams } from './getDeviceState';
|
|
|
157
150
|
export type { GetPassphraseStateParams } from './getPassphraseState';
|
|
158
151
|
export type { OpenWalletSessionParams, OpenWalletSessionPayload } from './openWalletSession';
|
|
159
152
|
export type { ClearSessionCacheParams, ClearSessionCachePayload } from './sessionCache';
|
|
153
|
+
export type { TestProtocolV2PingParams } from './protocolV2';
|
|
160
154
|
|
|
161
155
|
export type CoreApi = {
|
|
162
156
|
/**
|
|
@@ -180,6 +174,7 @@ export type CoreApi = {
|
|
|
180
174
|
* Test function
|
|
181
175
|
*/
|
|
182
176
|
testInitializeDeviceDuration: typeof testInitializeDeviceDuration;
|
|
177
|
+
testProtocolV2Ping: typeof testProtocolV2Ping;
|
|
183
178
|
preInitialize: typeof preInitialize;
|
|
184
179
|
|
|
185
180
|
/**
|
|
@@ -227,12 +222,6 @@ export type CoreApi = {
|
|
|
227
222
|
firmwareUpdateV2: typeof firmwareUpdateV2;
|
|
228
223
|
firmwareUpdateV3: typeof firmwareUpdateV3;
|
|
229
224
|
firmwareUpdateV4: typeof firmwareUpdateV4;
|
|
230
|
-
registerFirmwareUpdateHostBinding: typeof registerFirmwareUpdateHostBinding;
|
|
231
|
-
unregisterFirmwareUpdateHostBinding: typeof unregisterFirmwareUpdateHostBinding;
|
|
232
|
-
getFirmwareUpdateHostBindingGeneration: typeof getFirmwareUpdateHostBindingGeneration;
|
|
233
|
-
getFirmwareUpdateCapabilities: typeof getFirmwareUpdateCapabilities;
|
|
234
|
-
prepareFirmwareUpdatePlan: typeof prepareFirmwareUpdatePlan;
|
|
235
|
-
validateFirmwareUpdatePreparedPlan: typeof validateFirmwareUpdatePreparedPlan;
|
|
236
225
|
cipherKeyValue: typeof cipherKeyValue;
|
|
237
226
|
|
|
238
227
|
/**
|
|
@@ -5,35 +5,16 @@ export type OpenWalletSessionParams =
|
|
|
5
5
|
mode: 'standard';
|
|
6
6
|
deviceId?: never;
|
|
7
7
|
passphraseState?: never;
|
|
8
|
-
useEmptyPassphrase?: never;
|
|
9
|
-
initSession?: never;
|
|
10
8
|
}
|
|
11
9
|
| {
|
|
12
10
|
mode: 'select-hidden';
|
|
13
11
|
deviceId?: never;
|
|
14
12
|
passphraseState?: never;
|
|
15
|
-
useEmptyPassphrase?: never;
|
|
16
|
-
initSession?: never;
|
|
17
13
|
}
|
|
18
14
|
| {
|
|
19
15
|
mode: 'resume-hidden';
|
|
20
16
|
deviceId: string;
|
|
21
17
|
passphraseState: string;
|
|
22
|
-
useEmptyPassphrase?: never;
|
|
23
|
-
initSession?: never;
|
|
24
|
-
}
|
|
25
|
-
| {
|
|
26
|
-
/**
|
|
27
|
-
* Compatibility form. `useEmptyPassphrase: true` opens the standard wallet;
|
|
28
|
-
* otherwise `initSession: true` starts a fresh hidden-wallet selection, a
|
|
29
|
-
* complete wallet binding resumes a hidden wallet, and no binding starts the
|
|
30
|
-
* hidden-wallet selection flow.
|
|
31
|
-
*/
|
|
32
|
-
mode?: undefined;
|
|
33
|
-
useEmptyPassphrase?: boolean;
|
|
34
|
-
initSession?: boolean;
|
|
35
|
-
deviceId?: string;
|
|
36
|
-
passphraseState?: string;
|
|
37
18
|
};
|
|
38
19
|
|
|
39
20
|
type OpenWalletSessionPayloadBase = {
|
|
@@ -27,6 +27,16 @@ export type FileInfo = {
|
|
|
27
27
|
|
|
28
28
|
// ── Method signatures ─────────────────────────────────────────────────────
|
|
29
29
|
|
|
30
|
+
export type TestProtocolV2PingParams = CommonParams & {
|
|
31
|
+
/** Firmware diagnostic echo payload, limited to 63 UTF-8 bytes. */
|
|
32
|
+
message?: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export declare function testProtocolV2Ping(
|
|
36
|
+
connectId: string,
|
|
37
|
+
params?: TestProtocolV2PingParams
|
|
38
|
+
): Response<Success>;
|
|
39
|
+
|
|
30
40
|
export declare function deviceReboot(
|
|
31
41
|
connectId: string,
|
|
32
42
|
params: CommonParams & DeviceRebootParams
|
package/src/types/settings.ts
CHANGED
|
@@ -31,8 +31,6 @@ export type ConnectSettings = {
|
|
|
31
31
|
timestamp: number;
|
|
32
32
|
isFrame?: boolean;
|
|
33
33
|
preRelease?: boolean;
|
|
34
|
-
firmwareManifestMode?: 'sdk-managed' | 'external-only';
|
|
35
|
-
preloadedConfig?: RemoteConfigResponse;
|
|
36
34
|
fetchConfig?: boolean;
|
|
37
35
|
extension?: string;
|
|
38
36
|
configFetcher?: (url: string) => Promise<RemoteConfigResponse | null>;
|
|
@@ -57,7 +55,6 @@ export type IProtocolV2FirmwareComponent = {
|
|
|
57
55
|
target: IProtocolV2FirmwareComponentTarget;
|
|
58
56
|
url: string;
|
|
59
57
|
fingerprint?: string;
|
|
60
|
-
expectedSize?: number;
|
|
61
58
|
version?: IVersionArray;
|
|
62
59
|
};
|
|
63
60
|
|
|
@@ -67,8 +64,6 @@ export type IProtocolV2ResourceBundle = {
|
|
|
67
64
|
name: string;
|
|
68
65
|
/** Download URL. */
|
|
69
66
|
url: string;
|
|
70
|
-
fingerprint?: string;
|
|
71
|
-
expectedSize?: number;
|
|
72
67
|
/** Device target path, such as vol0:/bundles/images/images.okpkg. */
|
|
73
68
|
devicePath: string;
|
|
74
69
|
/** okpkg payload_version used to skip matching content after FileRead. */
|
|
@@ -90,16 +85,10 @@ export type IFirmwareReleaseInfo = {
|
|
|
90
85
|
firmwareType?: EFirmwareType;
|
|
91
86
|
/** Firmware UI resource */
|
|
92
87
|
resource?: string;
|
|
93
|
-
resourceFingerprint?: string;
|
|
94
|
-
resourceExpectedSize?: number;
|
|
95
88
|
/** Firmware full UI resource */
|
|
96
89
|
fullResource?: string;
|
|
97
|
-
fullResourceFingerprint?: string;
|
|
98
|
-
fullResourceExpectedSize?: number;
|
|
99
90
|
fullResourceRange?: string[];
|
|
100
91
|
bootloaderResource?: string;
|
|
101
|
-
bootloaderFingerprint?: string;
|
|
102
|
-
bootloaderExpectedSize?: number;
|
|
103
92
|
bootloaderVersion?: IVersionArray;
|
|
104
93
|
displayBootloaderVersion?: IVersionArray;
|
|
105
94
|
bootloaderRelatedFirmwareVersion?: IVersionArray;
|
|
@@ -112,7 +101,6 @@ export type IFirmwareReleaseInfo = {
|
|
|
112
101
|
[k in ILocale]: string;
|
|
113
102
|
};
|
|
114
103
|
fingerprint: string;
|
|
115
|
-
expectedSize?: number;
|
|
116
104
|
version: IVersionArray;
|
|
117
105
|
changelog: {
|
|
118
106
|
[k in ILocale]: string;
|
|
@@ -128,7 +116,6 @@ export type IBLEFirmwareReleaseInfo = {
|
|
|
128
116
|
webUpdate: string;
|
|
129
117
|
fingerprint: string;
|
|
130
118
|
fingerprintWeb: string;
|
|
131
|
-
expectedSize?: number;
|
|
132
119
|
version: IVersionArray;
|
|
133
120
|
changelog: {
|
|
134
121
|
[k in ILocale]: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isEmpty } from 'lodash';
|
|
2
1
|
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
3
2
|
|
|
4
3
|
import { DeviceModelToTypes } from '../types';
|
|
@@ -64,12 +63,12 @@ export const getDeviceLabel = (features?: DeviceFeaturesInput) => {
|
|
|
64
63
|
const deviceType = getDeviceType(features);
|
|
65
64
|
if (deviceType == null) return null;
|
|
66
65
|
|
|
67
|
-
if ('label' in features && typeof features.label === 'string' &&
|
|
66
|
+
if ('label' in features && typeof features.label === 'string' && features.label.length > 0) {
|
|
68
67
|
return features.label;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
const bleName = getDeviceBleName(features);
|
|
72
|
-
if (
|
|
71
|
+
if (bleName) return bleName;
|
|
73
72
|
|
|
74
73
|
if (deviceType === EDeviceType.ClassicPure) {
|
|
75
74
|
return 'OneKey Classic 1S';
|