@onekeyfe/hd-core 1.2.0-alpha.22 → 1.2.0-alpha.23
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 +8 -8
- package/__tests__/device-settings.test.ts +1 -1
- package/__tests__/device-wallet-session-store.test.ts +41 -0
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +86 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +13 -0
- package/__tests__/logBlockEvent.test.ts +17 -0
- package/__tests__/open-wallet-session.test.ts +90 -31
- package/__tests__/protocol-v2.test.ts +301 -63
- package/dist/api/CheckAllFirmwareRelease.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.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +6 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
- package/dist/core/index.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 +10 -6
- package/dist/index.js +157 -268
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.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 +15 -8
- package/src/api/FirmwareUpdateV2.ts +8 -1
- package/src/api/FirmwareUpdateV3.ts +8 -0
- package/src/api/FirmwareUpdateV4.ts +21 -19
- package/src/api/GetPassphraseState.ts +11 -5
- package/src/api/device/DeviceUpdateBootloader.ts +9 -1
- package/src/api/device/DeviceWipe.ts +2 -0
- package/src/api/firmware/FirmwareArtifactSource.ts +1 -1
- package/src/api/firmware/FirmwareUpdatePlan.ts +1 -1
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +15 -1
- package/src/core/index.ts +1 -0
- package/src/data/messages/messages-protocol-v2.json +18 -57
- package/src/device/Device.ts +30 -7
- package/src/device/DeviceCommands.ts +24 -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/protocols/protocol-v2/deviceSession.ts +1 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +0 -1
- package/src/protocols/protocol-v2/walletSession.ts +41 -20
- package/src/types/api/getPassphraseState.ts +4 -3
- package/src/utils/deviceInfoUtils.ts +3 -16
|
@@ -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,36 @@ 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) => {
|
|
40
|
+
const request = () =>
|
|
41
|
+
device.commands.typedCall(
|
|
42
|
+
'DeviceSessionAskPassphrase',
|
|
43
|
+
'Success',
|
|
44
|
+
{},
|
|
45
|
+
{
|
|
46
|
+
timeoutMs: 120_000,
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
try {
|
|
50
|
+
return await request();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (!isDeviceLockedError(error)) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
56
|
+
return request();
|
|
35
57
|
}
|
|
36
58
|
};
|
|
37
59
|
|
|
@@ -42,13 +64,13 @@ const selectDeviceSession = async (device: Device) => {
|
|
|
42
64
|
reason: 'open-wallet' as const,
|
|
43
65
|
};
|
|
44
66
|
const response = await device.commands.promptPassphrase(
|
|
45
|
-
{ existsAttachPinUser, ...metadata },
|
|
67
|
+
{ existsAttachPinUser, deviceOnly: true, ...metadata },
|
|
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,15 @@ const selectDeviceSession = async (device: Device) => {
|
|
|
68
90
|
);
|
|
69
91
|
}
|
|
70
92
|
device.emit(DEVICE.ATTACH_PIN_ON_DEVICE, device, metadata);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (response.passphraseOnDevice) {
|
|
75
|
-
device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
|
|
76
|
-
return openDeviceSession(device, { select: { passphrase_on_device: {} } });
|
|
93
|
+
await device.unlockDevice(DeviceSessionPinType.AttachToPin);
|
|
94
|
+
return getDeviceSession(device, {});
|
|
77
95
|
}
|
|
78
96
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
97
|
+
// Protocol V2 no longer accepts host-provided passphrase text. A legacy host
|
|
98
|
+
// response is treated only as the user's choice to continue on the device.
|
|
99
|
+
device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
|
|
100
|
+
await askDevicePassphrase(device);
|
|
101
|
+
return getDeviceSession(device, {});
|
|
82
102
|
};
|
|
83
103
|
|
|
84
104
|
export async function getProtocolV2WalletSession(
|
|
@@ -91,6 +111,7 @@ export async function getProtocolV2WalletSession(
|
|
|
91
111
|
) {
|
|
92
112
|
if (options?.initSession) {
|
|
93
113
|
device.clearInternalState();
|
|
114
|
+
device.passphraseState = undefined;
|
|
94
115
|
}
|
|
95
116
|
|
|
96
117
|
await negotiateEventlessWalletSession(device);
|
|
@@ -103,7 +124,7 @@ export async function getProtocolV2WalletSession(
|
|
|
103
124
|
: options?.expectedPassphraseState ?? device.passphraseState;
|
|
104
125
|
|
|
105
126
|
if (device.features?.unlocked === false) {
|
|
106
|
-
await device.unlockDevice();
|
|
127
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
107
128
|
}
|
|
108
129
|
|
|
109
130
|
if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
|
|
@@ -122,7 +143,7 @@ export async function getProtocolV2WalletSession(
|
|
|
122
143
|
|
|
123
144
|
if (cachedSessionId && expectedPassphraseState) {
|
|
124
145
|
try {
|
|
125
|
-
response = await
|
|
146
|
+
response = await getDeviceSession(device, { session_id: cachedSessionId });
|
|
126
147
|
resumed = true;
|
|
127
148
|
} catch (error) {
|
|
128
149
|
device.clearInternalState();
|
|
@@ -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,
|
|
@@ -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';
|
|
@@ -61,21 +60,9 @@ export const getDeviceUUID = getDeviceSerialNo;
|
|
|
61
60
|
export const getDeviceLabel = (features?: DeviceFeaturesInput) => {
|
|
62
61
|
if (!features) return null;
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if ('label' in features && typeof features.label === 'string' && !isEmpty(features.label)) {
|
|
68
|
-
return features.label;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const bleName = getDeviceBleName(features);
|
|
72
|
-
if (!isEmpty(bleName)) return bleName;
|
|
73
|
-
|
|
74
|
-
if (deviceType === EDeviceType.ClassicPure) {
|
|
75
|
-
return 'OneKey Classic 1S';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return `OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
|
|
63
|
+
return 'label' in features && typeof features.label === 'string' && features.label.length > 0
|
|
64
|
+
? features.label
|
|
65
|
+
: null;
|
|
79
66
|
};
|
|
80
67
|
|
|
81
68
|
/**
|