@onekeyfe/hd-core 1.2.0-alpha.21 → 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 +85 -0
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-identity.test.ts +24 -2
- package/__tests__/device-settings.test.ts +2 -2
- package/__tests__/device-wallet-session-store.test.ts +152 -7
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +86 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +326 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +39 -30
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/logBlockEvent.test.ts +17 -0
- package/__tests__/open-wallet-session.test.ts +311 -12
- package/__tests__/pro2Wallpaper.test.ts +7 -18
- package/__tests__/protocol-v2-unlock-policy.test.ts +45 -0
- package/__tests__/protocol-v2.test.ts +685 -177
- package/__tests__/public-device-state-api.test.ts +69 -62
- package/__tests__/public-pro2-api-boundary.test.ts +8 -34
- package/dist/api/BaseMethod.d.ts +2 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +11 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +29 -10
- 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/conflux/ConfluxGetAddress.d.ts +1 -0
- package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessage.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -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 +25 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +7 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +23 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +30 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +7 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -17
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
- package/dist/api/nexa/NexaSignTransaction.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 +1 -0
- 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/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/device/DeviceStateProjector.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 +273 -230
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3060 -1676
- 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/unlockPolicy.d.ts +4 -0
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -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 -0
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +2 -2
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +69 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +27 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +10 -19
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +1 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -76
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +4 -1
- package/dist/types/api/sessionCache.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.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/BaseMethod.ts +8 -3
- package/src/api/CheckAllFirmwareRelease.ts +23 -3
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/FirmwareUpdate.ts +8 -1
- package/src/api/FirmwareUpdateV2.ts +292 -120
- package/src/api/FirmwareUpdateV3.ts +256 -55
- package/src/api/FirmwareUpdateV4.ts +821 -331
- package/src/api/GetPassphraseState.ts +11 -5
- package/src/api/OpenWalletSession.ts +74 -25
- package/src/api/UploadPortfolio.ts +1 -1
- package/src/api/conflux/ConfluxGetAddress.ts +2 -0
- package/src/api/conflux/ConfluxSignMessage.ts +2 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +2 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +2 -0
- package/src/api/device/DeviceChangePin.ts +1 -1
- package/src/api/device/DeviceUnlock.ts +1 -2
- package/src/api/device/DeviceUpdateBootloader.ts +122 -6
- package/src/api/device/DeviceWipe.ts +3 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +50 -0
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +621 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +392 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +140 -22
- package/src/api/helpers/protocolV2FileWrite.ts +6 -0
- package/src/api/index.ts +0 -18
- package/src/api/nexa/NexaSignTransaction.ts +2 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +1 -1
- package/src/core/index.ts +1 -0
- package/src/data/messages/messages-protocol-v2.json +35 -1
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +80 -67
- package/src/device/DeviceCommands.ts +76 -159
- package/src/device/DeviceStateMapper.ts +18 -1
- package/src/device/DeviceStateProjector.ts +7 -1
- package/src/events/device.ts +1 -0
- package/src/events/logBlockEvent.ts +1 -14
- package/src/events/ui-request.ts +1 -0
- package/src/index.ts +5 -0
- package/src/inject.ts +22 -25
- package/src/lowLevelInject.ts +5 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +2 -3
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +1 -3
- package/src/protocols/protocol-v2/walletSession.ts +86 -9
- package/src/topLevelInject.ts +5 -1
- package/src/types/api/checkAllFirmwareRelease.ts +3 -0
- package/src/types/api/deviceUnlock.ts +2 -5
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -0
- package/src/types/api/firmwareUpdate.ts +76 -0
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +36 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/getPassphraseState.ts +4 -3
- package/src/types/api/index.ts +14 -34
- package/src/types/api/openWalletSession.ts +2 -0
- package/src/types/api/protocolV2.ts +3 -156
- package/src/types/api/sessionCache.ts +9 -4
- package/src/types/settings.ts +13 -0
- package/src/utils/deviceFeaturesUtils.ts +5 -1
- package/src/utils/deviceInfoUtils.ts +3 -16
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
4
|
+
import { DEVICE } from '../../events';
|
|
3
5
|
import { assertCompleteDeviceSession } from './deviceSession';
|
|
4
6
|
import { isDeviceLockedError } from './lockedError';
|
|
5
7
|
|
|
@@ -16,6 +18,12 @@ export async function refreshProtocolV2DeviceStatus(device: Device) {
|
|
|
16
18
|
return device.updateProtocolV2Status(status);
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
const negotiateEventlessWalletSession = async (device: Device) => {
|
|
22
|
+
await device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
|
|
23
|
+
eventless_wallet_session: true,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
19
27
|
const getDeviceSession = async (device: Device, request: DeviceSessionGet) => {
|
|
20
28
|
try {
|
|
21
29
|
return await device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
|
|
@@ -23,11 +31,76 @@ const getDeviceSession = async (device: Device, request: DeviceSessionGet) => {
|
|
|
23
31
|
if (!isDeviceLockedError(error)) {
|
|
24
32
|
throw error;
|
|
25
33
|
}
|
|
26
|
-
await device.unlockDevice();
|
|
34
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
27
35
|
return device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
|
|
28
36
|
}
|
|
29
37
|
};
|
|
30
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();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const selectDeviceSession = async (device: Device) => {
|
|
61
|
+
const existsAttachPinUser = device.features?.attachToPinEnabled === true;
|
|
62
|
+
const metadata = {
|
|
63
|
+
source: 'wallet-session-coordinator' as const,
|
|
64
|
+
reason: 'open-wallet' as const,
|
|
65
|
+
};
|
|
66
|
+
const response = await device.commands.promptPassphrase(
|
|
67
|
+
{ existsAttachPinUser, deviceOnly: true, ...metadata },
|
|
68
|
+
{ cancelDeviceOnReject: false }
|
|
69
|
+
);
|
|
70
|
+
const hasHostPassphrase =
|
|
71
|
+
typeof response.passphrase === 'string' && response.passphrase.length > 0;
|
|
72
|
+
const selections = [
|
|
73
|
+
hasHostPassphrase,
|
|
74
|
+
response.passphraseOnDevice === true,
|
|
75
|
+
response.attachPinOnDevice === true,
|
|
76
|
+
].filter(Boolean).length;
|
|
77
|
+
|
|
78
|
+
if (selections !== 1) {
|
|
79
|
+
throw ERRORS.TypedError(
|
|
80
|
+
HardwareErrorCode.RuntimeError,
|
|
81
|
+
'Wallet selection must contain exactly one passphrase access mode.'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (response.attachPinOnDevice) {
|
|
86
|
+
if (!existsAttachPinUser) {
|
|
87
|
+
throw ERRORS.TypedError(
|
|
88
|
+
HardwareErrorCode.RuntimeError,
|
|
89
|
+
'Attach PIN wallet selection is unavailable on this device.'
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
device.emit(DEVICE.ATTACH_PIN_ON_DEVICE, device, metadata);
|
|
93
|
+
await device.unlockDevice(DeviceSessionPinType.AttachToPin);
|
|
94
|
+
return getDeviceSession(device, {});
|
|
95
|
+
}
|
|
96
|
+
|
|
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, {});
|
|
102
|
+
};
|
|
103
|
+
|
|
31
104
|
export async function getProtocolV2WalletSession(
|
|
32
105
|
device: Device,
|
|
33
106
|
options?: {
|
|
@@ -38,18 +111,22 @@ export async function getProtocolV2WalletSession(
|
|
|
38
111
|
) {
|
|
39
112
|
if (options?.initSession) {
|
|
40
113
|
device.clearInternalState();
|
|
114
|
+
device.passphraseState = undefined;
|
|
41
115
|
}
|
|
42
116
|
|
|
43
|
-
|
|
117
|
+
await negotiateEventlessWalletSession(device);
|
|
118
|
+
|
|
119
|
+
if (options?.onlyMainPin) {
|
|
120
|
+
device.passphraseState = undefined;
|
|
121
|
+
}
|
|
122
|
+
const expectedPassphraseState = options?.onlyMainPin
|
|
123
|
+
? undefined
|
|
124
|
+
: options?.expectedPassphraseState ?? device.passphraseState;
|
|
44
125
|
|
|
45
|
-
// Unlock with PIN first. DeviceSessionGet operates on the wallet selected by
|
|
46
|
-
// the device unlock flow; Protocol V2 does not accept a host passphrase here.
|
|
47
126
|
if (device.features?.unlocked === false) {
|
|
48
|
-
await device.unlockDevice();
|
|
127
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
49
128
|
}
|
|
50
129
|
|
|
51
|
-
// A standard wallet needs no DeviceSession. After unlock confirms passphrase is
|
|
52
|
-
// disabled, do not create or forward a hidden-wallet passphraseState.
|
|
53
130
|
if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
|
|
54
131
|
return {
|
|
55
132
|
passphraseState: undefined,
|
|
@@ -75,7 +152,7 @@ export async function getProtocolV2WalletSession(
|
|
|
75
152
|
}
|
|
76
153
|
|
|
77
154
|
if (!response) {
|
|
78
|
-
response = await
|
|
155
|
+
response = await selectDeviceSession(device);
|
|
79
156
|
}
|
|
80
157
|
|
|
81
158
|
const { message } = response;
|
|
@@ -95,7 +172,7 @@ export async function getProtocolV2WalletSession(
|
|
|
95
172
|
message.btc_test_address,
|
|
96
173
|
device.getCurrentDeviceId(),
|
|
97
174
|
message.session_id,
|
|
98
|
-
options?.initSession ? null :
|
|
175
|
+
options?.initSession ? null : cachedSessionId ?? null
|
|
99
176
|
);
|
|
100
177
|
|
|
101
178
|
return {
|
package/src/topLevelInject.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
|
|
3
3
|
import { createCoreApi } from './inject';
|
|
4
|
+
import { unregisterFirmwareUpdateHostBinding } from './api/firmware/FirmwareHostBinding';
|
|
4
5
|
|
|
5
6
|
import type { ConnectSettings } from './types/settings';
|
|
6
7
|
import type { CoreApi } from './types/api';
|
|
@@ -46,7 +47,10 @@ export const topLevelInject = () => {
|
|
|
46
47
|
lowLevelApi?.removeAllListeners(type);
|
|
47
48
|
},
|
|
48
49
|
|
|
49
|
-
dispose: () =>
|
|
50
|
+
dispose: async () => {
|
|
51
|
+
unregisterFirmwareUpdateHostBinding();
|
|
52
|
+
await lowLevelApi?.dispose();
|
|
53
|
+
},
|
|
50
54
|
|
|
51
55
|
uiResponse: response => lowLevelApi?.uiResponse(response),
|
|
52
56
|
|
|
@@ -2,6 +2,7 @@ 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';
|
|
5
6
|
|
|
6
7
|
export type FirmwareRelease = {
|
|
7
8
|
shouldUpdate?: boolean;
|
|
@@ -20,11 +21,13 @@ export type AllFirmwareRelease = {
|
|
|
20
21
|
bootloader?: FirmwareRelease;
|
|
21
22
|
bridge?: FirmwareRelease;
|
|
22
23
|
features?: Features;
|
|
24
|
+
firmwareUpdatePlan?: FirmwareUpdatePlan;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export type CheckAllFirmwareReleaseParams = {
|
|
26
28
|
checkBridgeRelease?: boolean;
|
|
27
29
|
firmwareType?: EFirmwareType;
|
|
30
|
+
platform?: 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
|
|
28
31
|
};
|
|
29
32
|
|
|
30
33
|
export declare function checkAllFirmwareRelease(
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Features } from '../device';
|
|
2
2
|
import type { CommonParams, Response } from '../params';
|
|
3
3
|
|
|
4
|
-
export declare function deviceUnlock(
|
|
5
|
-
connectId: string,
|
|
6
|
-
params?: CommonParams
|
|
7
|
-
): Response<DeviceState>;
|
|
4
|
+
export declare function deviceUnlock(connectId: string, params?: CommonParams): Response<Features>;
|
|
@@ -1,9 +1,15 @@
|
|
|
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';
|
|
3
5
|
import type { Response } from '../params';
|
|
4
6
|
|
|
5
7
|
export type DeviceUpdateBootloaderParams = {
|
|
8
|
+
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
9
|
+
hostBindingGeneration?: number;
|
|
6
10
|
binary?: ArrayBuffer;
|
|
11
|
+
artifact?: FirmwareArtifactReference;
|
|
12
|
+
artifactReader?: FirmwareArtifactReader;
|
|
7
13
|
firmwareType?: EFirmwareType;
|
|
8
14
|
};
|
|
9
15
|
|
package/src/types/api/export.ts
CHANGED
|
@@ -25,11 +25,29 @@ export type {
|
|
|
25
25
|
DeviceUploadResourceResponse,
|
|
26
26
|
} from './deviceUploadResource';
|
|
27
27
|
export type {
|
|
28
|
+
FirmwareArtifactReader,
|
|
29
|
+
FirmwareArtifactReference,
|
|
30
|
+
FirmwareUpdateHostBinding,
|
|
31
|
+
FirmwareUpdateArtifactParams,
|
|
28
32
|
FirmwareUpdateParams,
|
|
29
33
|
FirmwareUpdateBinaryParams,
|
|
30
34
|
FirmwareUpdateV3Params,
|
|
31
35
|
FirmwareUpdateV4Params,
|
|
36
|
+
FirmwareUpdateV4Target,
|
|
32
37
|
} 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';
|
|
33
51
|
export type { AllFirmwareRelease } from './checkAllFirmwareRelease';
|
|
34
52
|
|
|
35
53
|
export type { AllNetworkAddressParams, AllNetworkGetAddressParams } from './allNetworkGetAddress';
|
|
@@ -1,14 +1,53 @@
|
|
|
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';
|
|
4
5
|
|
|
5
6
|
type IUpdateType = 'firmware' | 'ble';
|
|
6
7
|
|
|
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
|
+
|
|
7
31
|
export interface FirmwareUpdateBinaryParams {
|
|
8
32
|
binary: ArrayBuffer;
|
|
9
33
|
updateType: IUpdateType;
|
|
10
34
|
}
|
|
11
35
|
|
|
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
|
+
|
|
12
51
|
export interface FirmwareUpdateParams {
|
|
13
52
|
version?: number[];
|
|
14
53
|
updateType: IUpdateType;
|
|
@@ -37,8 +76,14 @@ export declare function firmwareUpdateV2(
|
|
|
37
76
|
connectId: string | undefined,
|
|
38
77
|
params: Params<FirmwareUpdateBinaryParams & Platform>
|
|
39
78
|
): Response<PROTO.Success>;
|
|
79
|
+
export declare function firmwareUpdateV2(
|
|
80
|
+
connectId: string | undefined,
|
|
81
|
+
params: Params<FirmwareUpdateArtifactParams & Platform>
|
|
82
|
+
): Response<PROTO.Success>;
|
|
40
83
|
|
|
41
84
|
export interface FirmwareUpdateV3Params {
|
|
85
|
+
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
86
|
+
hostBindingGeneration?: number;
|
|
42
87
|
bleVersion?: number[];
|
|
43
88
|
bleBinary?: ArrayBuffer;
|
|
44
89
|
chunkSize?: number;
|
|
@@ -55,6 +100,17 @@ export interface FirmwareUpdateV3Params {
|
|
|
55
100
|
firmwareType?: EFirmwareType;
|
|
56
101
|
|
|
57
102
|
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
|
+
};
|
|
58
114
|
}
|
|
59
115
|
|
|
60
116
|
/**
|
|
@@ -73,10 +129,14 @@ export type FirmwareUpdateV4Target =
|
|
|
73
129
|
| 'se04';
|
|
74
130
|
|
|
75
131
|
export interface FirmwareUpdateV4Params {
|
|
132
|
+
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
133
|
+
hostBindingGeneration?: number;
|
|
76
134
|
platform: IPlatform;
|
|
135
|
+
expectedDeviceId?: string;
|
|
77
136
|
chunkSize?: number;
|
|
78
137
|
firmwareType?: EFirmwareType;
|
|
79
138
|
targetsToUpdate?: FirmwareUpdateV4Target[];
|
|
139
|
+
expectedTargetVersions?: Partial<Record<FirmwareUpdateV4Target, string>>;
|
|
80
140
|
|
|
81
141
|
/** FW_MGMT_TARGET_ROMLOADER = 2; Pro2 cannot install it through firmwareUpdateV4. */
|
|
82
142
|
romloaderBinary?: ArrayBuffer;
|
|
@@ -102,8 +162,24 @@ export interface FirmwareUpdateV4Params {
|
|
|
102
162
|
binary: ArrayBuffer;
|
|
103
163
|
devicePath: string;
|
|
104
164
|
}>;
|
|
165
|
+
artifactReader?: FirmwareArtifactReader;
|
|
166
|
+
componentArtifacts?: Partial<
|
|
167
|
+
Record<Exclude<FirmwareUpdateV4Target, 'resource'>, FirmwareArtifactReference>
|
|
168
|
+
>;
|
|
169
|
+
resourceBundleArtifacts?: Array<{
|
|
170
|
+
name: string;
|
|
171
|
+
artifact: FirmwareArtifactReference;
|
|
172
|
+
}>;
|
|
105
173
|
}
|
|
106
174
|
|
|
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
|
+
|
|
107
183
|
export declare function firmwareUpdateV3(
|
|
108
184
|
connectId: string | undefined,
|
|
109
185
|
params: Params<FirmwareUpdateV3Params>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface FirmwareUpdateCapabilities {
|
|
2
|
+
planSchemaVersion: 2;
|
|
3
|
+
preparedPlanSchemaVersion: 2;
|
|
4
|
+
hostBindingProtocolVersion: 2;
|
|
5
|
+
manifestModes: Array<'external-only' | 'sdk-managed'>;
|
|
6
|
+
supportsArtifactReader: true;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare function getFirmwareUpdateCapabilities(): FirmwareUpdateCapabilities;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FirmwareUpdateV4Target } from './firmwareUpdate';
|
|
2
|
+
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
3
|
+
|
|
4
|
+
export type FirmwareUpdatePlanArtifactRole =
|
|
5
|
+
| 'firmware'
|
|
6
|
+
| 'ble'
|
|
7
|
+
| 'bootloader'
|
|
8
|
+
| 'resource'
|
|
9
|
+
| 'component'
|
|
10
|
+
| 'resourceBundle';
|
|
11
|
+
|
|
12
|
+
export type FirmwareUpdatePlanTarget = 'firmware' | 'ble' | 'bootloader' | FirmwareUpdateV4Target;
|
|
13
|
+
|
|
14
|
+
export interface FirmwareUpdatePlanArtifact {
|
|
15
|
+
artifactId: string;
|
|
16
|
+
role: FirmwareUpdatePlanArtifactRole;
|
|
17
|
+
target: FirmwareUpdatePlanTarget;
|
|
18
|
+
url: string;
|
|
19
|
+
container: 'raw' | 'zip';
|
|
20
|
+
logicalName?: string;
|
|
21
|
+
expectedSize?: number;
|
|
22
|
+
expectedSha256?: string;
|
|
23
|
+
targetVersion?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface FirmwareUpdatePlan {
|
|
27
|
+
schemaVersion: 2;
|
|
28
|
+
planDigest: string;
|
|
29
|
+
executor: 'v2' | 'v3' | 'v4';
|
|
30
|
+
deviceIdentity: string;
|
|
31
|
+
deviceModel: string;
|
|
32
|
+
firmwareType: EFirmwareType;
|
|
33
|
+
platform: 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
|
|
34
|
+
artifacts: FirmwareUpdatePlanArtifact[];
|
|
35
|
+
targetsToUpdate: FirmwareUpdatePlanTarget[];
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { FirmwareArtifactReference } from './firmwareUpdate';
|
|
2
|
+
import type {
|
|
3
|
+
FirmwareUpdatePlan,
|
|
4
|
+
FirmwareUpdatePlanArtifactRole,
|
|
5
|
+
FirmwareUpdatePlanTarget,
|
|
6
|
+
} from './firmwareUpdatePlan';
|
|
7
|
+
|
|
8
|
+
export interface FirmwareUpdatePreparedEntry {
|
|
9
|
+
entryName: string;
|
|
10
|
+
artifact: FirmwareArtifactReference;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface FirmwareUpdatePreparedArtifactInput {
|
|
14
|
+
artifactId: string;
|
|
15
|
+
artifact: FirmwareArtifactReference;
|
|
16
|
+
materializedEntries?: FirmwareUpdatePreparedEntry[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FirmwareUpdatePreparedArtifact {
|
|
20
|
+
artifactId: string;
|
|
21
|
+
role: FirmwareUpdatePlanArtifactRole;
|
|
22
|
+
target: FirmwareUpdatePlanTarget;
|
|
23
|
+
container: 'raw' | 'zip';
|
|
24
|
+
logicalName?: string;
|
|
25
|
+
targetVersion?: string;
|
|
26
|
+
artifact: FirmwareArtifactReference;
|
|
27
|
+
materializedEntries?: FirmwareUpdatePreparedEntry[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface FirmwareUpdatePreparedPlan {
|
|
31
|
+
schemaVersion: 2;
|
|
32
|
+
preparedPlanDigest: string;
|
|
33
|
+
planDigest: string;
|
|
34
|
+
networkPolicy: 'forbid';
|
|
35
|
+
executor: FirmwareUpdatePlan['executor'];
|
|
36
|
+
deviceIdentity: string;
|
|
37
|
+
deviceModel: string;
|
|
38
|
+
firmwareType: FirmwareUpdatePlan['firmwareType'];
|
|
39
|
+
platform: FirmwareUpdatePlan['platform'];
|
|
40
|
+
leaseRef: string;
|
|
41
|
+
artifacts: FirmwareUpdatePreparedArtifact[];
|
|
42
|
+
targetsToUpdate: FirmwareUpdatePlanTarget[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export declare function prepareFirmwareUpdatePlan(input: {
|
|
46
|
+
plan: FirmwareUpdatePlan;
|
|
47
|
+
leaseRef: string;
|
|
48
|
+
artifacts: FirmwareUpdatePreparedArtifactInput[];
|
|
49
|
+
}): FirmwareUpdatePreparedPlan;
|
|
50
|
+
|
|
51
|
+
export declare function validateFirmwareUpdatePreparedPlan(
|
|
52
|
+
value: unknown
|
|
53
|
+
): FirmwareUpdatePreparedPlan;
|
|
@@ -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
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
deviceFactoryInfoGet,
|
|
3
|
-
deviceFactoryInfoSet,
|
|
4
|
-
deviceFirmwareUpdate,
|
|
5
|
-
deviceGetFirmwareUpdateStatus,
|
|
6
2
|
deviceGetOnboardingStatus,
|
|
7
|
-
deviceInfoGet,
|
|
8
3
|
deviceReboot,
|
|
9
|
-
deviceStatusGet,
|
|
10
4
|
deviceUploadWallpaper,
|
|
11
|
-
dirList,
|
|
12
|
-
dirMake,
|
|
13
|
-
dirRemove,
|
|
14
|
-
fileDelete,
|
|
15
|
-
fileRead,
|
|
16
|
-
fileWrite,
|
|
17
|
-
filesystemFormat,
|
|
18
|
-
filesystemPermissionFix,
|
|
19
|
-
pathInfo,
|
|
20
|
-
ping,
|
|
21
|
-
protocolInfoRequest,
|
|
22
5
|
uploadPortfolio,
|
|
23
6
|
} from './protocolV2';
|
|
24
7
|
import type { off, on, removeAllListeners } from './event';
|
|
@@ -46,7 +29,15 @@ import type {
|
|
|
46
29
|
firmwareUpdateV2,
|
|
47
30
|
firmwareUpdateV3,
|
|
48
31
|
firmwareUpdateV4,
|
|
32
|
+
getFirmwareUpdateHostBindingGeneration,
|
|
33
|
+
registerFirmwareUpdateHostBinding,
|
|
34
|
+
unregisterFirmwareUpdateHostBinding,
|
|
49
35
|
} from './firmwareUpdate';
|
|
36
|
+
import type { getFirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
|
|
37
|
+
import type {
|
|
38
|
+
prepareFirmwareUpdatePlan,
|
|
39
|
+
validateFirmwareUpdatePreparedPlan,
|
|
40
|
+
} from './firmwareUpdatePreparedPlan';
|
|
50
41
|
import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
|
|
51
42
|
import type { deviceReset } from './deviceReset';
|
|
52
43
|
import type { deviceRecovery } from './deviceRecovery';
|
|
@@ -236,6 +227,12 @@ export type CoreApi = {
|
|
|
236
227
|
firmwareUpdateV2: typeof firmwareUpdateV2;
|
|
237
228
|
firmwareUpdateV3: typeof firmwareUpdateV3;
|
|
238
229
|
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;
|
|
239
236
|
cipherKeyValue: typeof cipherKeyValue;
|
|
240
237
|
|
|
241
238
|
/**
|
|
@@ -244,24 +241,7 @@ export type CoreApi = {
|
|
|
244
241
|
deviceReboot: typeof deviceReboot;
|
|
245
242
|
deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
|
|
246
243
|
deviceUploadWallpaper: typeof deviceUploadWallpaper;
|
|
247
|
-
deviceInfoGet: typeof deviceInfoGet;
|
|
248
|
-
deviceStatusGet: typeof deviceStatusGet;
|
|
249
|
-
protocolInfoRequest: typeof protocolInfoRequest;
|
|
250
|
-
ping: typeof ping;
|
|
251
|
-
deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
|
|
252
|
-
deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
|
|
253
|
-
deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
|
|
254
|
-
deviceFactoryInfoGet: typeof deviceFactoryInfoGet;
|
|
255
|
-
filesystemPermissionFix: typeof filesystemPermissionFix;
|
|
256
|
-
filesystemFormat: typeof filesystemFormat;
|
|
257
244
|
uploadPortfolio: typeof uploadPortfolio;
|
|
258
|
-
fileRead: typeof fileRead;
|
|
259
|
-
fileWrite: typeof fileWrite;
|
|
260
|
-
fileDelete: typeof fileDelete;
|
|
261
|
-
dirList: typeof dirList;
|
|
262
|
-
dirMake: typeof dirMake;
|
|
263
|
-
dirRemove: typeof dirRemove;
|
|
264
|
-
pathInfo: typeof pathInfo;
|
|
265
245
|
|
|
266
246
|
/**
|
|
267
247
|
* All network function
|
|
@@ -40,6 +40,8 @@ type OpenWalletSessionPayloadBase = {
|
|
|
40
40
|
protocol: 'V1' | 'V2';
|
|
41
41
|
deviceId: string;
|
|
42
42
|
resumed: boolean;
|
|
43
|
+
/** Forwarded only when the firmware response contains a wallet session id. */
|
|
44
|
+
sessionId?: string;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
export type OpenWalletSessionPayload = OpenWalletSessionPayloadBase &
|