@onekeyfe/hd-core 1.2.0-alpha.8 → 1.2.0-alpha.9
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__/device-wallet-session-store.test.ts +131 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
- package/__tests__/protocol-v2.test.ts +738 -460
- package/dist/api/ClearSessionCache.d.ts +9 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -0
- package/dist/api/FirmwareUpdateV4.d.ts +7 -6
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +1 -1
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +9 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceWalletSessionStore.d.ts +15 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/index.d.ts +32 -19
- package/dist/index.js +644 -263
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +13 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdate.d.ts +4 -1
- 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 +6 -2
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +10 -0
- package/dist/types/api/sessionCache.d.ts.map +1 -0
- package/dist/types/settings.d.ts +6 -14
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.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/ClearSessionCache.ts +28 -0
- package/src/api/FileRead.ts +2 -2
- package/src/api/FirmwareUpdateV4.ts +269 -210
- package/src/api/index.ts +3 -0
- package/src/api/protocol-v2/DeviceSessionGet.ts +26 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +14 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +4 -1
- package/src/api/protocol-v2/helpers.ts +17 -14
- package/src/data/messages/messages-protocol-v2.json +134 -3
- package/src/data/messages/messages.json +8 -0
- package/src/device/Device.ts +64 -56
- package/src/device/DeviceWalletSessionStore.ts +78 -0
- package/src/inject.ts +5 -2
- package/src/protocols/protocol-v2/index.ts +1 -0
- package/src/protocols/protocol-v2/walletSession.ts +83 -0
- package/src/types/api/firmwareUpdate.ts +8 -2
- package/src/types/api/index.ts +10 -3
- package/src/types/api/protocolV2.ts +16 -2
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/settings.ts +14 -16
- package/src/utils/deviceFeaturesUtils.ts +22 -32
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export class DeviceWalletSessionStore {
|
|
2
|
+
private readonly walletSessions = new Map<string, Map<string, string>>();
|
|
3
|
+
|
|
4
|
+
private readonly pendingSessions = new Map<string, string>();
|
|
5
|
+
|
|
6
|
+
get(deviceKey: string, passphraseState?: string) {
|
|
7
|
+
if (!deviceKey || !passphraseState) return undefined;
|
|
8
|
+
return this.walletSessions.get(deviceKey)?.get(passphraseState);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
set(deviceKey: string, passphraseState?: string, sessionId?: string) {
|
|
12
|
+
if (!deviceKey || !passphraseState || !sessionId) return;
|
|
13
|
+
let deviceSessions = this.walletSessions.get(deviceKey);
|
|
14
|
+
if (!deviceSessions) {
|
|
15
|
+
deviceSessions = new Map<string, string>();
|
|
16
|
+
this.walletSessions.set(deviceKey, deviceSessions);
|
|
17
|
+
}
|
|
18
|
+
deviceSessions.set(passphraseState, sessionId);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setPending(deviceKey: string, sessionId?: string) {
|
|
22
|
+
if (!deviceKey || !sessionId) return;
|
|
23
|
+
this.pendingSessions.set(deviceKey, sessionId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getPending(deviceKey: string) {
|
|
27
|
+
if (!deviceKey) return undefined;
|
|
28
|
+
return this.pendingSessions.get(deviceKey);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
delete(deviceKey: string, passphraseState?: string) {
|
|
32
|
+
if (!deviceKey || !passphraseState) return;
|
|
33
|
+
const deviceSessions = this.walletSessions.get(deviceKey);
|
|
34
|
+
if (!deviceSessions) return;
|
|
35
|
+
deviceSessions.delete(passphraseState);
|
|
36
|
+
if (deviceSessions.size === 0) {
|
|
37
|
+
this.walletSessions.delete(deviceKey);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
deletePending(deviceKey: string) {
|
|
42
|
+
if (!deviceKey) return;
|
|
43
|
+
this.pendingSessions.delete(deviceKey);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
deleteDevice(deviceKey: string) {
|
|
47
|
+
if (!deviceKey) return;
|
|
48
|
+
this.walletSessions.delete(deviceKey);
|
|
49
|
+
this.pendingSessions.delete(deviceKey);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
migrateDeviceKey(from: string, to: string) {
|
|
53
|
+
if (!from || !to || from === to) return;
|
|
54
|
+
|
|
55
|
+
const sourceSessions = this.walletSessions.get(from);
|
|
56
|
+
if (sourceSessions) {
|
|
57
|
+
const targetSessions = this.walletSessions.get(to) ?? new Map<string, string>();
|
|
58
|
+
this.walletSessions.set(to, targetSessions);
|
|
59
|
+
sourceSessions.forEach((sessionId, passphraseState) => {
|
|
60
|
+
targetSessions.set(passphraseState, sessionId);
|
|
61
|
+
});
|
|
62
|
+
this.walletSessions.delete(from);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const pendingSession = this.pendingSessions.get(from);
|
|
66
|
+
if (pendingSession) {
|
|
67
|
+
this.pendingSessions.set(to, pendingSession);
|
|
68
|
+
this.pendingSessions.delete(from);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
clear() {
|
|
73
|
+
this.walletSessions.clear();
|
|
74
|
+
this.pendingSessions.clear();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const deviceWalletSessionStore = new DeviceWalletSessionStore();
|
package/src/inject.ts
CHANGED
|
@@ -100,6 +100,7 @@ export const createCoreApi = (
|
|
|
100
100
|
| 'switchTransport'
|
|
101
101
|
> => ({
|
|
102
102
|
getLogs: () => call({ method: 'getLogs' }),
|
|
103
|
+
clearSessionCache: params => call({ ...params, method: 'clearSessionCache' }),
|
|
103
104
|
/**
|
|
104
105
|
* 搜索设备
|
|
105
106
|
*/
|
|
@@ -155,8 +156,10 @@ export const createCoreApi = (
|
|
|
155
156
|
call({ ...params, connectId, method: 'protocolInfoRequest' }),
|
|
156
157
|
ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
|
|
157
158
|
deviceReboot: (connectId, params) => call({ ...params, connectId, method: 'deviceReboot' }),
|
|
158
|
-
deviceInfoGet: (connectId, params) =>
|
|
159
|
-
|
|
159
|
+
deviceInfoGet: (connectId, params) => call({ ...params, connectId, method: 'deviceInfoGet' }),
|
|
160
|
+
deviceStatusGet: (connectId, params) => call({ ...params, connectId, method: 'deviceStatusGet' }),
|
|
161
|
+
deviceSessionGet: (connectId, params) =>
|
|
162
|
+
call({ ...params, connectId, method: 'deviceSessionGet' }),
|
|
160
163
|
deviceFirmwareUpdate: (connectId, params) =>
|
|
161
164
|
call({ ...params, connectId, method: 'deviceFirmwareUpdate' }),
|
|
162
165
|
deviceGetFirmwareUpdateStatus: (connectId, params) =>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import type { Device } from '../../device/Device';
|
|
4
|
+
|
|
5
|
+
const getErrorText = (error: unknown) => {
|
|
6
|
+
if (error instanceof Error) return `${error.name} ${error.message}`;
|
|
7
|
+
if (typeof error === 'string') return error;
|
|
8
|
+
if (error && typeof error === 'object') {
|
|
9
|
+
const record = error as Record<string, unknown>;
|
|
10
|
+
return [record.code, record.errorCode, record.message, record.reason]
|
|
11
|
+
.filter(value => value !== undefined && value !== null)
|
|
12
|
+
.join(' ');
|
|
13
|
+
}
|
|
14
|
+
return String(error ?? '');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const isProtocolV2InvalidSessionError = (error: unknown) =>
|
|
18
|
+
getErrorText(error).toLowerCase().includes('failure_invalidsession');
|
|
19
|
+
|
|
20
|
+
export async function requestProtocolV2DeviceStatus(device: Device) {
|
|
21
|
+
const { message } = await device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
22
|
+
return message;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function refreshProtocolV2DeviceStatus(device: Device) {
|
|
26
|
+
const status = await requestProtocolV2DeviceStatus(device);
|
|
27
|
+
return device.updateProtocolV2Status(status);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function getProtocolV2WalletSession(
|
|
31
|
+
device: Device,
|
|
32
|
+
options?: { initSession?: boolean; expectedPassphraseState?: string }
|
|
33
|
+
) {
|
|
34
|
+
if (device.features?.unlocked === false) {
|
|
35
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device is locked');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (options?.initSession) {
|
|
39
|
+
device.clearInternalState();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cachedSessionId =
|
|
43
|
+
typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const { message } = await device.commands.typedCall(
|
|
47
|
+
'DeviceSessionGet',
|
|
48
|
+
'DeviceSession',
|
|
49
|
+
cachedSessionId ? { session_id: cachedSessionId } : {}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
options?.expectedPassphraseState &&
|
|
54
|
+
options.expectedPassphraseState !== message.btc_test_address
|
|
55
|
+
) {
|
|
56
|
+
device.clearInternalState();
|
|
57
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (message.btc_test_address && device.getCurrentPassphraseProtection() !== true) {
|
|
61
|
+
await refreshProtocolV2DeviceStatus(device);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
device.updateInternalState(
|
|
65
|
+
(device.getCurrentPassphraseProtection() ?? false) || Boolean(message.btc_test_address),
|
|
66
|
+
message.btc_test_address,
|
|
67
|
+
device.getCurrentDeviceId(),
|
|
68
|
+
message.session_id,
|
|
69
|
+
options?.initSession ? null : device.features?.sessionId
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
passphraseState: message.btc_test_address,
|
|
74
|
+
newSession: message.session_id,
|
|
75
|
+
unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
|
|
76
|
+
};
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (isProtocolV2InvalidSessionError(error)) {
|
|
79
|
+
device.clearInternalState();
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -81,9 +81,15 @@ export interface FirmwareUpdateV4Params {
|
|
|
81
81
|
se02Binary?: ArrayBuffer;
|
|
82
82
|
se03Binary?: ArrayBuffer;
|
|
83
83
|
se04Binary?: ArrayBuffer;
|
|
84
|
-
/** 资源包通过 FW_MGMT_TARGET_CRATE = 1 安装;Pro2 正常升级推荐传入单个合并 CRATE,多个元素仅用于调试/兼容 */
|
|
85
|
-
resourceBinaries?: ArrayBuffer[];
|
|
86
84
|
forcedUpdateRes?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* RESC bundle okpkg 列表,通过 FilesystemFileWrite 直写到 devicePath(vol0:/bundles/...)。
|
|
87
|
+
* 手动传入模式:SDK 直接 FileWrite 安装,不做版本比对。
|
|
88
|
+
*/
|
|
89
|
+
resourceBundleFiles?: Array<{
|
|
90
|
+
binary: ArrayBuffer;
|
|
91
|
+
devicePath: string;
|
|
92
|
+
}>;
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
export declare function firmwareUpdateV3(
|
package/src/types/api/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
deviceFirmwareUpdate,
|
|
3
2
|
deviceFactoryInfoGet,
|
|
4
3
|
deviceFactoryInfoSet,
|
|
5
|
-
|
|
4
|
+
deviceFirmwareUpdate,
|
|
6
5
|
deviceGetFirmwareUpdateStatus,
|
|
6
|
+
deviceInfoGet,
|
|
7
7
|
deviceReboot,
|
|
8
|
+
deviceSessionGet,
|
|
9
|
+
deviceStatusGet,
|
|
8
10
|
dirList,
|
|
9
11
|
dirMake,
|
|
10
12
|
dirRemove,
|
|
@@ -18,9 +20,9 @@ import type {
|
|
|
18
20
|
filesystemFileDelete,
|
|
19
21
|
filesystemFileRead,
|
|
20
22
|
filesystemFileWrite,
|
|
21
|
-
filesystemPermissionFix,
|
|
22
23
|
filesystemFormat,
|
|
23
24
|
filesystemPathInfoQuery,
|
|
25
|
+
filesystemPermissionFix,
|
|
24
26
|
pathInfo,
|
|
25
27
|
ping,
|
|
26
28
|
protocolInfoRequest,
|
|
@@ -31,6 +33,7 @@ import type { init, updateSettings } from './init';
|
|
|
31
33
|
import type { testInitializeDeviceDuration } from './testInitializeDeviceDuration';
|
|
32
34
|
import type { preInitialize } from './preInitialize';
|
|
33
35
|
import type { getLogs } from './getLogs';
|
|
36
|
+
import type { clearSessionCache } from './sessionCache';
|
|
34
37
|
import type { checkBridgeStatus } from './checkBridgeStatus';
|
|
35
38
|
import type { checkBridgeRelease } from './checkBridgeRelease';
|
|
36
39
|
import type { checkBootloaderRelease } from './checkBootloaderRelease';
|
|
@@ -177,6 +180,7 @@ export type {
|
|
|
177
180
|
DeviceProfileVersions,
|
|
178
181
|
} from './getDeviceInfo';
|
|
179
182
|
export type { GetPassphraseStateParams, GetPassphraseStatePayload } from './getPassphraseState';
|
|
183
|
+
export type { ClearSessionCacheParams, ClearSessionCachePayload } from './sessionCache';
|
|
180
184
|
|
|
181
185
|
export type CoreApi = {
|
|
182
186
|
/**
|
|
@@ -194,6 +198,7 @@ export type CoreApi = {
|
|
|
194
198
|
updateSettings: typeof updateSettings;
|
|
195
199
|
switchTransport: (env: ConnectSettings['env']) => Promise<{ success: boolean }>;
|
|
196
200
|
getLogs: typeof getLogs;
|
|
201
|
+
clearSessionCache: typeof clearSessionCache;
|
|
197
202
|
|
|
198
203
|
/**
|
|
199
204
|
* Test function
|
|
@@ -254,6 +259,8 @@ export type CoreApi = {
|
|
|
254
259
|
ping: typeof ping;
|
|
255
260
|
deviceReboot: typeof deviceReboot;
|
|
256
261
|
deviceInfoGet: typeof deviceInfoGet;
|
|
262
|
+
deviceStatusGet: typeof deviceStatusGet;
|
|
263
|
+
deviceSessionGet: typeof deviceSessionGet;
|
|
257
264
|
deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
|
|
258
265
|
deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
|
|
259
266
|
deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type {
|
|
3
|
-
DeviceFirmwareUpdateStatus,
|
|
4
3
|
DeviceFactoryInfo,
|
|
4
|
+
DeviceFirmwareUpdateStatus,
|
|
5
|
+
DeviceSession,
|
|
6
|
+
DeviceStatus,
|
|
5
7
|
ProtocolInfo,
|
|
6
8
|
ProtocolV2DeviceInfo,
|
|
7
9
|
Success,
|
|
8
10
|
} from '@onekeyfe/hd-transport';
|
|
9
11
|
import type {
|
|
12
|
+
DeviceFactoryInfoSetParams,
|
|
10
13
|
DeviceFirmwareUpdateParams,
|
|
11
14
|
DeviceFirmwareUpdateStatusGetParams,
|
|
12
15
|
DeviceRebootParams,
|
|
13
|
-
DeviceFactoryInfoSetParams,
|
|
14
16
|
} from '../../api/protocol-v2/helpers';
|
|
15
17
|
import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
|
|
18
|
+
import type { DeviceSessionGetParams } from '../../api/protocol-v2/DeviceSessionGet';
|
|
16
19
|
|
|
17
20
|
// 参数类型单源:以 api/protocol-v2 的实现为准(type-only re-export,无运行时依赖)
|
|
18
21
|
export type {
|
|
@@ -28,6 +31,7 @@ export type {
|
|
|
28
31
|
DeviceInfoGetTargets,
|
|
29
32
|
DeviceInfoGetTypes,
|
|
30
33
|
} from '../../api/protocol-v2/DeviceInfoGet';
|
|
34
|
+
export type { DeviceSessionGetParams } from '../../api/protocol-v2/DeviceSessionGet';
|
|
31
35
|
|
|
32
36
|
// ── Shared response shapes (Protocol V2 file system) ────────────────────
|
|
33
37
|
|
|
@@ -88,6 +92,16 @@ export declare function deviceInfoGet(
|
|
|
88
92
|
params?: CommonParams & DeviceInfoGetParams
|
|
89
93
|
): Response<ProtocolV2DeviceInfo>;
|
|
90
94
|
|
|
95
|
+
export declare function deviceStatusGet(
|
|
96
|
+
connectId: string,
|
|
97
|
+
params?: CommonParams
|
|
98
|
+
): Response<DeviceStatus>;
|
|
99
|
+
|
|
100
|
+
export declare function deviceSessionGet(
|
|
101
|
+
connectId: string,
|
|
102
|
+
params?: CommonParams & DeviceSessionGetParams
|
|
103
|
+
): Response<DeviceSession>;
|
|
104
|
+
|
|
91
105
|
export declare function deviceFirmwareUpdate(
|
|
92
106
|
connectId: string,
|
|
93
107
|
params: CommonParams & DeviceFirmwareUpdateParams
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Response } from '../params';
|
|
2
|
+
|
|
3
|
+
export type ClearSessionCacheParams = {
|
|
4
|
+
deviceId?: string;
|
|
5
|
+
passphraseState?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ClearSessionCachePayload = {
|
|
9
|
+
cleared: true;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export declare function clearSessionCache(
|
|
13
|
+
params?: ClearSessionCacheParams
|
|
14
|
+
): Response<ClearSessionCachePayload>;
|
package/src/types/settings.ts
CHANGED
|
@@ -49,34 +49,31 @@ export type IProtocolV2FirmwareComponentTarget =
|
|
|
49
49
|
| 'SE01'
|
|
50
50
|
| 'SE02'
|
|
51
51
|
| 'SE03'
|
|
52
|
-
| 'SE04'
|
|
53
|
-
| 'CRATE';
|
|
52
|
+
| 'SE04';
|
|
54
53
|
|
|
55
54
|
export type IProtocolV2FirmwareComponent = {
|
|
56
55
|
target: IProtocolV2FirmwareComponentTarget;
|
|
57
56
|
url: string;
|
|
58
57
|
fingerprint?: string;
|
|
59
58
|
version?: IVersionArray;
|
|
60
|
-
resourceManifest?: IProtocolV2ResourceManifest;
|
|
61
59
|
};
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
/** Pro2 RESC bundle okpkg 描述,用于 FileWrite 直写方式增量同步资源 */
|
|
62
|
+
export type IProtocolV2ResourceBundle = {
|
|
63
|
+
/** bundle 名称,如 images / animation / translations / fonts_roobert */
|
|
64
|
+
name: string;
|
|
65
|
+
/** 下载 URL */
|
|
66
|
+
url: string;
|
|
67
|
+
/** 设备上的目标路径,如 vol0:/bundles/images/images.okpkg */
|
|
68
|
+
devicePath: string;
|
|
69
|
+
/** okpkg container 的 payload_version(用于 FileRead 比对跳过) */
|
|
67
70
|
version?: IVersionArray;
|
|
68
|
-
|
|
71
|
+
/** okpkg container 的 payload_hash(SHA3-512,用于 FileRead 比对) */
|
|
69
72
|
payloadHash?: string;
|
|
73
|
+
/** okpkg container 的 header_hash(SHA3-512,用于 FileRead 比对) */
|
|
70
74
|
headerHash?: string;
|
|
71
75
|
};
|
|
72
76
|
|
|
73
|
-
export type IProtocolV2ResourceManifest = {
|
|
74
|
-
format?: 'okpkg-crate' | string;
|
|
75
|
-
target?: 'CRATE' | string;
|
|
76
|
-
version?: IVersionArray;
|
|
77
|
-
packages: IProtocolV2ResourceManifestPackage[];
|
|
78
|
-
};
|
|
79
|
-
|
|
80
77
|
/** STM32 firmware config */
|
|
81
78
|
export type IFirmwareReleaseInfo = {
|
|
82
79
|
required: boolean;
|
|
@@ -98,7 +95,8 @@ export type IFirmwareReleaseInfo = {
|
|
|
98
95
|
upgradeType?: 'payload-package-set' | string;
|
|
99
96
|
components?: Record<string, IProtocolV2FirmwareComponent>;
|
|
100
97
|
installOrder?: string[];
|
|
101
|
-
|
|
98
|
+
/** Pro2 RESC bundle 列表(FileWrite 直写增量同步模式) */
|
|
99
|
+
resourceBundles?: IProtocolV2ResourceBundle[];
|
|
102
100
|
bootloaderChangelog?: {
|
|
103
101
|
[k in ILocale]: string;
|
|
104
102
|
};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import { isNaN } from 'lodash';
|
|
3
3
|
import { EDeviceType, type EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
4
|
-
import {
|
|
5
|
-
Enum_Capability,
|
|
6
|
-
type DeviceSessionGet,
|
|
7
|
-
type GetPassphraseState,
|
|
8
|
-
} from '@onekeyfe/hd-transport';
|
|
4
|
+
import { Enum_Capability, type GetPassphraseState } from '@onekeyfe/hd-transport';
|
|
9
5
|
|
|
10
6
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
11
7
|
import { DeviceModelToTypes, DeviceTypeToModels } from '../types';
|
|
@@ -17,12 +13,11 @@ import { PROTOBUF_MESSAGE_CONFIG } from '../data-manager/MessagesConfig';
|
|
|
17
13
|
import { getDeviceType } from './deviceInfoUtils';
|
|
18
14
|
import { getDeviceFirmwareVersion } from './deviceVersionUtils';
|
|
19
15
|
import { existCapability } from './capabilitieUtils';
|
|
16
|
+
import { getProtocolV2WalletSession } from '../protocols/protocol-v2/walletSession';
|
|
20
17
|
|
|
21
18
|
import type { Device } from '../device/Device';
|
|
22
19
|
import type { Features, IDeviceType, SupportFeatureType } from '../types';
|
|
23
20
|
|
|
24
|
-
type DeviceSessionGetMessage = DeviceSessionGet;
|
|
25
|
-
|
|
26
21
|
export const getSupportProtocolV1MessageSchema = (
|
|
27
22
|
features: Features | undefined
|
|
28
23
|
): { messages: JSON; protocolV1MessageSchema: ProtocolV1MessageSchema } => {
|
|
@@ -98,6 +93,21 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
98
93
|
initSession?: boolean;
|
|
99
94
|
}
|
|
100
95
|
) => {
|
|
96
|
+
if (device.isProtocolV2()) {
|
|
97
|
+
if (!device.features) {
|
|
98
|
+
return {
|
|
99
|
+
passphraseState: undefined,
|
|
100
|
+
newSession: undefined,
|
|
101
|
+
unlockedAttachPin: undefined,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return getProtocolV2WalletSession(device, {
|
|
106
|
+
initSession: options?.initSession,
|
|
107
|
+
expectedPassphraseState: options?.expectPassphraseState,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
const { features } = device;
|
|
102
112
|
const locked = features?.unlocked === false;
|
|
103
113
|
const deviceType = device.getCurrentDeviceType();
|
|
@@ -172,29 +182,10 @@ export const getPassphraseState = async (
|
|
|
172
182
|
const deviceType = device.getCurrentDeviceType();
|
|
173
183
|
|
|
174
184
|
if (device.isProtocolV2()) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
payload.session_id = cachedSessionId;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const { message, type } = await commands.typedCall(
|
|
183
|
-
'DeviceSessionGet',
|
|
184
|
-
'DeviceSession',
|
|
185
|
-
payload
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
// @ts-expect-error
|
|
189
|
-
if (type === 'CallMethodError') {
|
|
190
|
-
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
passphraseState: message.btc_test_address,
|
|
195
|
-
newSession: message.session_id,
|
|
196
|
-
unlockedAttachPin: features.unlockedAttachPin ?? undefined,
|
|
197
|
-
};
|
|
185
|
+
return getProtocolV2WalletSession(device, {
|
|
186
|
+
initSession: options?.initSession,
|
|
187
|
+
expectedPassphraseState: options?.expectPassphraseState,
|
|
188
|
+
});
|
|
198
189
|
}
|
|
199
190
|
|
|
200
191
|
const supportAttachPinCapability = existCapability(
|
|
@@ -202,8 +193,7 @@ export const getPassphraseState = async (
|
|
|
202
193
|
Enum_Capability.Capability_AttachToPin
|
|
203
194
|
);
|
|
204
195
|
const supportGetPassphraseState =
|
|
205
|
-
supportAttachPinCapability ||
|
|
206
|
-
supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion);
|
|
196
|
+
supportAttachPinCapability || supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion);
|
|
207
197
|
|
|
208
198
|
if (supportGetPassphraseState) {
|
|
209
199
|
const payload: GetPassphraseState = options?.onlyMainPin
|