@onekeyfe/hd-core 1.2.0-alpha.16 → 1.2.0-alpha.18
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__/DeviceEventRegistration.test.ts +3 -0
- package/__tests__/deviceFeaturesUtils.test.ts +27 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +3 -0
- package/__tests__/homescreen.test.ts +24 -0
- package/__tests__/kaspaSignTransaction.test.ts +591 -0
- package/__tests__/protocol-v2.test.ts +1006 -204
- package/__tests__/protocolV2FileWrite.test.ts +28 -3
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/dist/api/BaseMethod.d.ts +4 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceInfo.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/device/DeviceCancel.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +5 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +28 -0
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +1 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +3 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +7 -5
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +2 -2
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -2
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -2
- package/dist/deviceProfile/buildDeviceProfile.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/ui-request.d.ts +18 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +85 -15
- package/dist/index.js +1515 -554
- package/dist/protocols/protocol-v2/features.d.ts +6 -18
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -1
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +39 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +5 -3
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +2 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -1
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/kaspaSignTransaction.d.ts +27 -2
- package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +4 -2
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.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/BaseMethod.ts +10 -2
- package/src/api/FirmwareUpdateV4.ts +27 -73
- package/src/api/GetDeviceInfo.ts +9 -2
- package/src/api/GetPassphraseState.ts +5 -2
- package/src/api/UploadPortfolio.ts +2 -0
- package/src/api/device/DeviceCancel.ts +1 -0
- package/src/api/device/DeviceChangePin.ts +23 -0
- package/src/api/device/DeviceLock.ts +1 -0
- package/src/api/device/DeviceUnlock.ts +9 -0
- package/src/api/device/DeviceWipe.ts +18 -0
- package/src/api/helpers/protocolV2FileWrite.ts +35 -11
- package/src/api/index.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +341 -22
- package/src/api/kaspa/helpers/TransferSerialize.ts +14 -0
- package/src/api/protocol-v2/DeviceInfoGet.ts +0 -1
- package/src/api/protocol-v2/DeviceSessionOpen.ts +100 -0
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +9 -1
- package/src/api/protocol-v2/DeviceSettingsSet.ts +11 -1
- package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +2 -1
- package/src/core/deviceEventRegistration.ts +2 -0
- package/src/core/index.ts +36 -3
- package/src/data/messages/messages-protocol-v2.json +122 -23
- package/src/data/messages/messages.json +286 -1
- package/src/device/Device.ts +33 -41
- package/src/device/DeviceCommands.ts +22 -4
- package/src/device/DevicePool.ts +14 -6
- package/src/deviceProfile/buildDeviceFeatures.ts +21 -9
- package/src/deviceProfile/buildDeviceProfile.ts +27 -11
- package/src/events/device.ts +4 -0
- package/src/events/ui-request.ts +24 -2
- package/src/inject.ts +2 -2
- package/src/protocols/protocol-v2/features.ts +27 -20
- package/src/protocols/protocol-v2/index.ts +0 -1
- package/src/protocols/protocol-v2/uiInteraction.ts +209 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +43 -3
- package/src/protocols/protocol-v2/walletSession.ts +122 -31
- package/src/types/api/getDeviceInfo.ts +6 -1
- package/src/types/api/index.ts +2 -2
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/protocolV2.ts +5 -3
- package/src/types/device.ts +6 -1
- package/src/utils/deviceFeaturesUtils.ts +13 -0
- package/src/utils/homescreen.ts +10 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +0 -1
- package/src/api/protocol-v2/DeviceSessionGet.ts +0 -15
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
|
+
import { DEVICE, type PassphraseRequestPayload } from '../../events';
|
|
3
4
|
import { isDeviceLockedError } from './lockedError';
|
|
4
5
|
|
|
6
|
+
import type { DeviceSessionOpen } from '@onekeyfe/hd-transport';
|
|
5
7
|
import type { Device } from '../../device/Device';
|
|
8
|
+
import type { PassphrasePromptResponse } from '../../device/DeviceCommands';
|
|
6
9
|
|
|
7
10
|
const getErrorText = (error: unknown) => {
|
|
8
11
|
if (error instanceof Error) return `${error.name} ${error.message}`;
|
|
@@ -19,6 +22,17 @@ const getErrorText = (error: unknown) => {
|
|
|
19
22
|
export const isProtocolV2InvalidSessionError = (error: unknown) =>
|
|
20
23
|
getErrorText(error).toLowerCase().includes('failure_invalidsession');
|
|
21
24
|
|
|
25
|
+
const normalizeHostPassphrase = (passphrase: string | undefined) => {
|
|
26
|
+
const normalized = (passphrase ?? '').normalize('NFKD');
|
|
27
|
+
if (!normalized || normalized.includes('\0') || normalized.length > 50) {
|
|
28
|
+
throw ERRORS.TypedError(
|
|
29
|
+
HardwareErrorCode.CallMethodInvalidParameter,
|
|
30
|
+
'Invalid hidden wallet passphrase.'
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return normalized;
|
|
34
|
+
};
|
|
35
|
+
|
|
22
36
|
export async function requestProtocolV2DeviceStatus(device: Device) {
|
|
23
37
|
const { message } = await device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
24
38
|
return message;
|
|
@@ -29,54 +43,131 @@ export async function refreshProtocolV2DeviceStatus(device: Device) {
|
|
|
29
43
|
return device.updateProtocolV2Status(status);
|
|
30
44
|
}
|
|
31
45
|
|
|
46
|
+
const openDeviceSession = async (device: Device, request: DeviceSessionOpen) => {
|
|
47
|
+
try {
|
|
48
|
+
return await device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (!isDeviceLockedError(error)) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
await device.unlockDevice();
|
|
54
|
+
return device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const createHiddenWalletRequest = (
|
|
59
|
+
response: PassphrasePromptResponse
|
|
60
|
+
): {
|
|
61
|
+
request: DeviceSessionOpen;
|
|
62
|
+
deviceEvent?: typeof DEVICE.PASSPHRASE_ON_DEVICE | typeof DEVICE.ATTACH_PIN_ON_DEVICE;
|
|
63
|
+
} => {
|
|
64
|
+
if (response.attachPinOnDevice) {
|
|
65
|
+
return {
|
|
66
|
+
request: {
|
|
67
|
+
select: {
|
|
68
|
+
attach_pin_on_device: {},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
deviceEvent: DEVICE.ATTACH_PIN_ON_DEVICE,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (response.passphraseOnDevice) {
|
|
76
|
+
return {
|
|
77
|
+
request: {
|
|
78
|
+
select: {
|
|
79
|
+
passphrase_on_device: {},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
deviceEvent: DEVICE.PASSPHRASE_ON_DEVICE,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
request: {
|
|
88
|
+
select: {
|
|
89
|
+
host_passphrase: { passphrase: normalizeHostPassphrase(response.passphrase) },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const openSelectedHiddenWallet = async (
|
|
96
|
+
device: Device,
|
|
97
|
+
promptPayload: PassphraseRequestPayload
|
|
98
|
+
) => {
|
|
99
|
+
const response = await device.commands.promptPassphrase(promptPayload, {
|
|
100
|
+
cancelDeviceOnReject: false,
|
|
101
|
+
});
|
|
102
|
+
const { request, deviceEvent } = createHiddenWalletRequest(response);
|
|
103
|
+
|
|
104
|
+
if (deviceEvent) {
|
|
105
|
+
device.emit(deviceEvent, device, promptPayload);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return openDeviceSession(device, request);
|
|
109
|
+
};
|
|
110
|
+
|
|
32
111
|
export async function getProtocolV2WalletSession(
|
|
33
112
|
device: Device,
|
|
34
|
-
options?: {
|
|
113
|
+
options?: {
|
|
114
|
+
initSession?: boolean;
|
|
115
|
+
expectedPassphraseState?: string;
|
|
116
|
+
onlyMainPin?: boolean;
|
|
117
|
+
}
|
|
35
118
|
) {
|
|
36
119
|
if (options?.initSession) {
|
|
37
120
|
device.clearInternalState();
|
|
38
121
|
}
|
|
39
122
|
|
|
40
|
-
|
|
41
|
-
typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
|
|
123
|
+
const expectedPassphraseState = options?.expectedPassphraseState ?? device.passphraseState;
|
|
42
124
|
|
|
43
125
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
126
|
+
// 锁屏时的 passphrase_enabled 不可信。先完成 PIN 解锁,unlockDevice 会立即
|
|
127
|
+
// 获取并合并一份新的 DeviceStatus,之后再决定打开主钱包还是隐藏钱包。
|
|
128
|
+
if (device.features?.unlocked === false) {
|
|
129
|
+
await device.unlockDevice();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
|
|
133
|
+
return {
|
|
134
|
+
passphraseState: undefined,
|
|
135
|
+
newSession: undefined,
|
|
136
|
+
unlockedAttachPin: false,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const cachedSessionId =
|
|
141
|
+
typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
|
|
142
|
+
let response;
|
|
143
|
+
let recoveryFailed = false;
|
|
144
|
+
|
|
145
|
+
if (cachedSessionId && expectedPassphraseState) {
|
|
52
146
|
try {
|
|
53
|
-
|
|
147
|
+
response = await openDeviceSession(device, {
|
|
148
|
+
resume: { session_id: cachedSessionId },
|
|
149
|
+
});
|
|
54
150
|
} catch (error) {
|
|
55
|
-
if (!
|
|
151
|
+
if (!isProtocolV2InvalidSessionError(error)) {
|
|
56
152
|
throw error;
|
|
57
153
|
}
|
|
58
154
|
device.clearInternalState();
|
|
59
|
-
|
|
60
|
-
return requestDeviceSession();
|
|
155
|
+
recoveryFailed = true;
|
|
61
156
|
}
|
|
62
|
-
}
|
|
157
|
+
}
|
|
63
158
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
await device
|
|
72
|
-
response = await requestWalletSession();
|
|
159
|
+
if (!response) {
|
|
160
|
+
const promptPayload: PassphraseRequestPayload = {
|
|
161
|
+
source: 'wallet-session-coordinator',
|
|
162
|
+
reason: recoveryFailed ? 'session-recovery' : 'open-wallet',
|
|
163
|
+
expectedPassphraseState,
|
|
164
|
+
existsAttachPinUser: device.features?.attachToPinEnabled === true,
|
|
165
|
+
};
|
|
166
|
+
response = await openSelectedHiddenWallet(device, promptPayload);
|
|
73
167
|
}
|
|
74
|
-
const { message } = response;
|
|
75
168
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
options.expectedPassphraseState !== message.btc_test_address
|
|
79
|
-
) {
|
|
169
|
+
const { message } = response;
|
|
170
|
+
if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
|
|
80
171
|
device.clearInternalState();
|
|
81
172
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
82
173
|
}
|
|
@@ -86,7 +177,7 @@ export async function getProtocolV2WalletSession(
|
|
|
86
177
|
}
|
|
87
178
|
|
|
88
179
|
device.updateInternalState(
|
|
89
|
-
|
|
180
|
+
true,
|
|
90
181
|
message.btc_test_address,
|
|
91
182
|
device.getCurrentDeviceId(),
|
|
92
183
|
message.session_id,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type { Features, IDeviceType, OnekeyFeatures } from '../device';
|
|
3
3
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
DeviceStatus,
|
|
6
|
+
ProtocolType,
|
|
7
|
+
ProtocolV2DeviceInfo,
|
|
8
|
+
} from '@onekeyfe/hd-transport';
|
|
5
9
|
|
|
6
10
|
// 协议类型单源:从 hd-transport 的 ProtocolType 派生,只额外允许 'unknown'。
|
|
7
11
|
export type DeviceInfoProtocol = ProtocolType | 'unknown';
|
|
@@ -78,6 +82,7 @@ export type DeviceProfileRaw = {
|
|
|
78
82
|
features?: Features;
|
|
79
83
|
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
80
84
|
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
85
|
+
protocolV2DeviceStatus?: DeviceStatus;
|
|
81
86
|
};
|
|
82
87
|
|
|
83
88
|
export type DeviceProfile = {
|
package/src/types/api/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
deviceGetOnboardingStatus,
|
|
7
7
|
deviceInfoGet,
|
|
8
8
|
deviceReboot,
|
|
9
|
-
|
|
9
|
+
deviceSessionOpen,
|
|
10
10
|
deviceSettingsGet,
|
|
11
11
|
deviceSettingsPageShow,
|
|
12
12
|
deviceSettingsSet,
|
|
@@ -267,7 +267,7 @@ export type CoreApi = {
|
|
|
267
267
|
deviceInfoGet: typeof deviceInfoGet;
|
|
268
268
|
deviceStatusGet: typeof deviceStatusGet;
|
|
269
269
|
deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
|
|
270
|
-
|
|
270
|
+
deviceSessionOpen: typeof deviceSessionOpen;
|
|
271
271
|
deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
|
|
272
272
|
deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
|
|
273
273
|
deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
|
|
@@ -13,15 +13,47 @@ export type KaspaSignInputParams = {
|
|
|
13
13
|
sequenceNumber: number | string;
|
|
14
14
|
output: {
|
|
15
15
|
satoshis: number | string;
|
|
16
|
-
|
|
16
|
+
// Required by the legacy host-prehash flow; unused by the streaming protocol.
|
|
17
|
+
script?: string;
|
|
17
18
|
};
|
|
18
19
|
sigOpCount?: number;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export type KaspaSignOutputParams = {
|
|
22
23
|
satoshis: number | string;
|
|
24
|
+
// Streaming protocol describes outputs by address; the device builds the script itself.
|
|
25
|
+
// `address` for an external output, `addressN` (BIP-32 path) for a change output.
|
|
26
|
+
address?: string;
|
|
27
|
+
addressN?: string | number[];
|
|
28
|
+
// Legacy host-prehash fields, unused by the streaming protocol but kept for compatibility.
|
|
29
|
+
script?: string;
|
|
30
|
+
scriptVersion?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Referenced (previous) transactions for the streaming protocol's input
|
|
34
|
+
// verification: the device may ask for the transactions the inputs spend from
|
|
35
|
+
// (selected by prev_tx_id) to verify input amounts on-device.
|
|
36
|
+
export type KaspaRefTransactionInput = {
|
|
37
|
+
prevTxId: string;
|
|
38
|
+
outputIndex: number;
|
|
39
|
+
sequenceNumber: number | string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type KaspaRefTransactionOutput = {
|
|
43
|
+
satoshis: number | string;
|
|
44
|
+
scriptVersion?: number;
|
|
23
45
|
script: string;
|
|
24
|
-
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type KaspaRefTransaction = {
|
|
49
|
+
txId: string;
|
|
50
|
+
version: number;
|
|
51
|
+
inputs: KaspaRefTransactionInput[];
|
|
52
|
+
outputs: KaspaRefTransactionOutput[];
|
|
53
|
+
lockTime?: number | string;
|
|
54
|
+
subNetworkID?: string;
|
|
55
|
+
gas?: number | string;
|
|
56
|
+
payload?: string;
|
|
25
57
|
};
|
|
26
58
|
|
|
27
59
|
export type KaspaSignTransactionParams = {
|
|
@@ -32,6 +64,12 @@ export type KaspaSignTransactionParams = {
|
|
|
32
64
|
sigHashType?: SignatureType;
|
|
33
65
|
sigOpCount?: number;
|
|
34
66
|
subNetworkID?: string;
|
|
67
|
+
// Optional transaction payload (hex), streamed to the device in chunks.
|
|
68
|
+
payload?: string;
|
|
69
|
+
gas?: number | string;
|
|
70
|
+
// Previous transactions referenced by the inputs, required only when the
|
|
71
|
+
// device requests them for on-device input-amount verification.
|
|
72
|
+
refTxs?: KaspaRefTransaction[];
|
|
35
73
|
scheme?: string;
|
|
36
74
|
prefix?: string;
|
|
37
75
|
useTweak?: boolean; // default is true
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type {
|
|
3
|
+
DevOnboardingStatus,
|
|
3
4
|
DeviceFactoryInfo,
|
|
4
5
|
DeviceFirmwareUpdateStatus,
|
|
5
|
-
DevOnboardingStatus,
|
|
6
6
|
DeviceSession,
|
|
7
7
|
DeviceSettings,
|
|
8
8
|
DeviceStatus,
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
DeviceRebootParams,
|
|
18
18
|
} from '../../api/protocol-v2/helpers';
|
|
19
19
|
import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
|
|
20
|
+
import type { DeviceSessionOpenParams } from '../../api/protocol-v2/DeviceSessionOpen';
|
|
20
21
|
import type { DeviceSettingsSetParams } from '../../api/protocol-v2/DeviceSettingsSet';
|
|
21
22
|
import type { DeviceSettingsPageShowParams } from '../../api/protocol-v2/DeviceSettingsPageShow';
|
|
22
23
|
import type {
|
|
@@ -38,6 +39,7 @@ export type {
|
|
|
38
39
|
DeviceInfoGetTargets,
|
|
39
40
|
DeviceInfoGetTypes,
|
|
40
41
|
} from '../../api/protocol-v2/DeviceInfoGet';
|
|
42
|
+
export type { DeviceSessionOpenParams } from '../../api/protocol-v2/DeviceSessionOpen';
|
|
41
43
|
export type { DeviceSettingsSetParams } from '../../api/protocol-v2/DeviceSettingsSet';
|
|
42
44
|
export type {
|
|
43
45
|
DeviceSettingsPageShowParams,
|
|
@@ -117,9 +119,9 @@ export declare function deviceGetOnboardingStatus(
|
|
|
117
119
|
params?: CommonParams
|
|
118
120
|
): Response<DevOnboardingStatus>;
|
|
119
121
|
|
|
120
|
-
export declare function
|
|
122
|
+
export declare function deviceSessionOpen(
|
|
121
123
|
connectId: string,
|
|
122
|
-
params
|
|
124
|
+
params: CommonParams & DeviceSessionOpenParams
|
|
123
125
|
): Response<DeviceSession>;
|
|
124
126
|
|
|
125
127
|
export declare function deviceFirmwareUpdate(
|
package/src/types/device.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { EDeviceType, type EFirmwareType } from '@onekeyfe/hd-shared';
|
|
|
2
2
|
|
|
3
3
|
import type { IVersionArray } from './settings';
|
|
4
4
|
import type { PROTO } from '../constants';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
DeviceStatus as ProtocolV2DeviceStatus,
|
|
7
|
+
OneKeyDeviceCommType,
|
|
8
|
+
ProtocolV2DeviceInfo,
|
|
9
|
+
} from '@onekeyfe/hd-transport';
|
|
6
10
|
|
|
7
11
|
export type DeviceStatus = 'available' | 'occupied' | 'used';
|
|
8
12
|
|
|
@@ -127,6 +131,7 @@ export type DeviceFeaturesRaw = {
|
|
|
127
131
|
protocolV1Features?: PROTO.Features;
|
|
128
132
|
protocolV1OneKeyFeatures?: OnekeyFeatures;
|
|
129
133
|
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
134
|
+
protocolV2DeviceStatus?: ProtocolV2DeviceStatus;
|
|
130
135
|
};
|
|
131
136
|
|
|
132
137
|
export type NormalizedFeatures = {
|
|
@@ -30,6 +30,17 @@ export const getSupportProtocolV1MessageSchema = (
|
|
|
30
30
|
const currentDeviceVersion = getDeviceFirmwareVersion(features).join('.');
|
|
31
31
|
const deviceType = getDeviceType(features);
|
|
32
32
|
|
|
33
|
+
if (
|
|
34
|
+
features.bootloaderMode === true &&
|
|
35
|
+
features.firmwarePresent === false &&
|
|
36
|
+
DeviceModelToTypes.model_mini.includes(deviceType)
|
|
37
|
+
) {
|
|
38
|
+
return {
|
|
39
|
+
messages: DataManager.messages.v1CurrentSchema,
|
|
40
|
+
protocolV1MessageSchema: 'v1CurrentSchema',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
const deviceVersionConfigs =
|
|
34
45
|
PROTOBUF_MESSAGE_CONFIG[deviceType] ||
|
|
35
46
|
(DeviceTypeToModels[deviceType] &&
|
|
@@ -104,6 +115,7 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
104
115
|
return getProtocolV2WalletSession(device, {
|
|
105
116
|
initSession: options?.initSession,
|
|
106
117
|
expectedPassphraseState: options?.expectPassphraseState,
|
|
118
|
+
onlyMainPin: options?.onlyMainPin,
|
|
107
119
|
});
|
|
108
120
|
}
|
|
109
121
|
|
|
@@ -183,6 +195,7 @@ export const getPassphraseState = async (
|
|
|
183
195
|
return getProtocolV2WalletSession(device, {
|
|
184
196
|
initSession: options?.initSession,
|
|
185
197
|
expectedPassphraseState: options?.expectPassphraseState,
|
|
198
|
+
onlyMainPin: options?.onlyMainPin,
|
|
186
199
|
});
|
|
187
200
|
}
|
|
188
201
|
|
package/src/utils/homescreen.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
|
3
3
|
|
|
4
4
|
import { getDeviceType } from './deviceInfoUtils';
|
|
5
5
|
import { getDeviceFirmwareVersion } from './deviceVersionUtils';
|
|
6
|
+
import { PRO2_WALLPAPER_HEIGHT, PRO2_WALLPAPER_WIDTH } from './pro2Wallpaper';
|
|
6
7
|
|
|
7
8
|
import type { Features, IDeviceType } from '../types';
|
|
8
9
|
|
|
@@ -310,6 +311,15 @@ export const getHomeScreenSize = ({
|
|
|
310
311
|
homeScreenType: 'WallPaper' | 'Nft';
|
|
311
312
|
thumbnail?: boolean;
|
|
312
313
|
}) => {
|
|
314
|
+
if (deviceType === EDeviceType.Pro2) {
|
|
315
|
+
return thumbnail
|
|
316
|
+
? undefined
|
|
317
|
+
: {
|
|
318
|
+
width: PRO2_WALLPAPER_WIDTH,
|
|
319
|
+
height: PRO2_WALLPAPER_HEIGHT,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
313
323
|
const sizes: Partial<
|
|
314
324
|
Record<
|
|
315
325
|
IDeviceType,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceSessionGet.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceSessionGet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU;IACtD,IAAI;IAOE,GAAG;CAIV"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
|
|
3
|
-
export default class DeviceSessionGet extends BaseMethod {
|
|
4
|
-
init() {
|
|
5
|
-
this.requireProtocolV2 = true;
|
|
6
|
-
this.useDevicePassphraseState = false;
|
|
7
|
-
this.skipForceUpdateCheck = true;
|
|
8
|
-
this.params = undefined;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async run() {
|
|
12
|
-
const { message } = await this.device.commands.typedCall('DeviceSessionGet', 'DeviceSession', {});
|
|
13
|
-
return message;
|
|
14
|
-
}
|
|
15
|
-
}
|