@onekeyfe/hd-core 1.2.0-alpha.53 → 1.2.0-alpha.54
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__/AllNetworkGetAddressBase.tracing.test.ts +0 -78
- package/__tests__/DeviceCommands.test.ts +0 -45
- package/__tests__/DeviceEventRegistration.test.ts +0 -6
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +3 -198
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-initialize-timeout.test.ts +56 -0
- package/__tests__/device-lifecycle-events.test.ts +3 -105
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -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-preparation-error.test.ts +27 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +294 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -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 +59 -31
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +12 -132
- package/__tests__/homescreen.test.ts +1 -41
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +0 -19
- package/__tests__/open-wallet-session.test.ts +33 -446
- package/__tests__/protocol-v2-unlock-policy.test.ts +35 -201
- package/__tests__/protocol-v2.test.ts +1034 -1378
- package/__tests__/protocolV2UiInteraction.test.ts +0 -63
- package/__tests__/public-pro2-api-boundary.test.ts +0 -1
- package/__tests__/search-devices.test.ts +3 -12
- package/dist/api/BaseMethod.d.ts +1 -3
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +1 -2
- package/dist/api/CheckAllFirmwareRelease.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 +25 -11
- 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/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -2
- 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/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/FirmwarePreparationError.d.ts +3 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +9 -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 +25 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +32 -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/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- 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 +0 -2
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +0 -2
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +2 -4
- 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 +6 -29
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/events/device.d.ts +0 -4
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +2 -4
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +2 -31
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +2 -10
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +231 -214
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3497 -2559
- package/dist/inject.d.ts +1 -6
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +4 -7
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +1 -5
- 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 +4 -2
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -5
- 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 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +70 -2
- 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 +28 -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/index.d.ts +10 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +0 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +0 -1
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -22
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +1 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -4
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +0 -4
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts +0 -10
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +10 -8
- package/src/api/CheckAllFirmwareRelease.ts +57 -54
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +316 -126
- package/src/api/FirmwareUpdateV3.ts +265 -63
- package/src/api/FirmwareUpdateV4.ts +965 -566
- package/src/api/GetPassphraseState.ts +1 -7
- package/src/api/OpenWalletSession.ts +17 -54
- package/src/api/SearchDevices.ts +1 -3
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -32
- package/src/api/device/DeviceUnlock.ts +3 -8
- package/src/api/device/DeviceUpdateBootloader.ts +122 -6
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwarePreparationError.ts +12 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -16
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +415 -0
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +144 -39
- package/src/api/helpers/protocolV2FileWrite.ts +4 -11
- package/src/api/index.ts +0 -2
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
- package/src/api/protocol-v2/helpers.ts +0 -1
- package/src/core/deviceEventRegistration.ts +0 -4
- package/src/core/index.ts +83 -167
- package/src/data/messages/messages-protocol-v2.json +0 -25
- package/src/data-manager/DataManager.ts +38 -67
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +42 -258
- package/src/device/DeviceCommands.ts +1 -7
- package/src/device/DevicePool.ts +2 -7
- package/src/events/device.ts +0 -4
- package/src/events/logBlockEvent.ts +0 -1
- package/src/events/ui-promise.ts +2 -4
- package/src/events/ui-request.ts +2 -36
- package/src/events/ui-response.ts +2 -12
- package/src/index.ts +5 -0
- package/src/inject.ts +24 -60
- package/src/lowLevelInject.ts +8 -7
- package/src/protocols/protocol-v2/features.ts +3 -10
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +6 -46
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
- package/src/protocols/protocol-v2/walletSession.ts +30 -180
- package/src/topLevelInject.ts +8 -7
- package/src/types/api/checkAllFirmwareRelease.ts +4 -2
- package/src/types/api/deviceUnlock.ts +1 -12
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -1
- package/src/types/api/firmwareUpdate.ts +76 -3
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +38 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/index.ts +14 -13
- package/src/types/api/protocolV2.ts +0 -13
- package/src/types/device.ts +0 -3
- package/src/types/params.ts +1 -7
- package/src/types/settings.ts +13 -42
- package/src/utils/deviceFeaturesCompat.ts +6 -0
- package/src/utils/deviceFeaturesUtils.ts +0 -8
- package/src/utils/homescreen.ts +6 -32
- package/src/utils/index.ts +1 -6
- package/src/utils/pro2Wallpaper.ts +8 -35
- package/__tests__/deviceUploadNft.test.ts +0 -293
- package/__tests__/pro2Nft.test.ts +0 -108
- package/__tests__/protocol-binding.test.ts +0 -89
- package/__tests__/protocol-v2-resources.test.ts +0 -284
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
- package/__tests__/uiProgressThrottle.test.ts +0 -74
- package/__tests__/uiPromiseRegistry.test.ts +0 -86
- package/dist/api/DetectDeviceConnectProtocol.d.ts +0 -7
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -31
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
- package/dist/core/uiPromiseRegistry.d.ts +0 -4
- package/dist/core/uiPromiseRegistry.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/resources.d.ts +0 -30
- package/dist/protocols/protocol-v2/resources.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +0 -4
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/utils/pro2Nft.d.ts +0 -31
- package/dist/utils/pro2Nft.d.ts.map +0 -1
- package/dist/utils/uiProgressThrottle.d.ts +0 -3
- package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
- package/src/api/DetectDeviceConnectProtocol.ts +0 -18
- package/src/api/protocol-v2/DeviceUploadNft.ts +0 -189
- package/src/core/uiPromiseRegistry.ts +0 -41
- package/src/protocols/protocol-v2/resources.ts +0 -359
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -118
- package/src/types/api/detectDeviceConnectProtocol.ts +0 -7
- package/src/utils/pro2Nft.ts +0 -142
- package/src/utils/uiProgressThrottle.ts +0 -63
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceSessionPinType
|
|
2
|
+
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
3
3
|
|
|
4
4
|
import { DEVICE } from '../../events';
|
|
5
5
|
import { assertCompleteDeviceSession } from './deviceSession';
|
|
@@ -38,74 +38,32 @@ export async function refreshProtocolV2DeviceStatus(device: Device) {
|
|
|
38
38
|
return device.updateProtocolV2Status(status);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export async function ensureProtocolV2WalletSessionUnlocked(device: Device) {
|
|
42
|
-
if (!device.isProtocolV2() || device.isBootloader?.() || device.isRomloader?.()) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
await refreshProtocolV2DeviceStatus(device);
|
|
47
|
-
if (device.state?.status.unlocked !== false) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
await device.unlockDevice(DeviceSessionPinType.Main, {
|
|
52
|
-
source: 'unlock-coordinator',
|
|
53
|
-
reason: 'device-locked',
|
|
54
|
-
deviceOnly: true,
|
|
55
|
-
});
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
41
|
const negotiateEventlessWalletSession = async (device: Device) => {
|
|
60
|
-
await device.
|
|
42
|
+
await device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
|
|
43
|
+
eventless_wallet_session: true,
|
|
44
|
+
});
|
|
61
45
|
};
|
|
62
46
|
|
|
63
47
|
const getDeviceSession = async (device: Device, request: DeviceSessionGet) =>
|
|
64
48
|
device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
|
|
65
49
|
|
|
66
|
-
const buildDeviceSessionGetRequest = ({
|
|
67
|
-
sessionId,
|
|
68
|
-
expectedPassphraseState,
|
|
69
|
-
deriveCardano,
|
|
70
|
-
}: {
|
|
71
|
-
sessionId?: string;
|
|
72
|
-
expectedPassphraseState?: string;
|
|
73
|
-
deriveCardano?: boolean;
|
|
74
|
-
} = {}): DeviceSessionGet => ({
|
|
75
|
-
...(sessionId ? { session_id: sessionId } : {}),
|
|
76
|
-
...(expectedPassphraseState ? { btc_test_address: expectedPassphraseState } : {}),
|
|
77
|
-
seed_domains:
|
|
78
|
-
deriveCardano === undefined
|
|
79
|
-
? []
|
|
80
|
-
: [
|
|
81
|
-
DeviceSessionSeedDomain.SeedDomain_Standard,
|
|
82
|
-
...(deriveCardano ? [DeviceSessionSeedDomain.SeedDomain_Cardano] : []),
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
|
|
86
50
|
const askDevicePassphrase = async (device: Device, requestPayload: DeviceSessionAskPassphrase) => {
|
|
87
51
|
await device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', requestPayload);
|
|
88
52
|
await refreshProtocolV2DeviceStatus(device);
|
|
89
53
|
};
|
|
90
54
|
|
|
91
|
-
const selectDeviceSession = async (
|
|
92
|
-
device: Device,
|
|
93
|
-
expectedPassphraseState?: string,
|
|
94
|
-
deriveCardano?: boolean
|
|
95
|
-
) => {
|
|
55
|
+
const selectDeviceSession = async (device: Device, expectedPassphraseState?: string) => {
|
|
96
56
|
const existsAttachPinUser = device.features?.attachToPinEnabled === true;
|
|
97
57
|
const metadata = {
|
|
98
58
|
source: 'wallet-session-coordinator' as const,
|
|
99
59
|
reason: expectedPassphraseState ? ('session-recovery' as const) : ('open-wallet' as const),
|
|
100
60
|
...(expectedPassphraseState ? { expectedPassphraseState } : {}),
|
|
101
61
|
};
|
|
102
|
-
const passphraseInteraction = device.createProtocolV2UiPhaseMetadata?.('passphrase', 'start');
|
|
103
62
|
const response = await device.commands.promptPassphrase(
|
|
104
63
|
{
|
|
105
64
|
existsAttachPinUser,
|
|
106
65
|
deviceOnly: false,
|
|
107
66
|
...metadata,
|
|
108
|
-
...(passphraseInteraction ? { interaction: passphraseInteraction } : {}),
|
|
109
67
|
},
|
|
110
68
|
{ cancelDeviceOnReject: false }
|
|
111
69
|
);
|
|
@@ -144,16 +102,9 @@ const selectDeviceSession = async (
|
|
|
144
102
|
'Attach PIN wallet selection is unavailable on this device.'
|
|
145
103
|
);
|
|
146
104
|
}
|
|
147
|
-
|
|
148
|
-
device.
|
|
149
|
-
|
|
150
|
-
...(attachPinInteraction ? { interaction: attachPinInteraction } : {}),
|
|
151
|
-
});
|
|
152
|
-
await device.unlockDevice(DeviceSessionPinType.AttachToPin, {
|
|
153
|
-
emitUiEvent: false,
|
|
154
|
-
interaction: attachPinInteraction,
|
|
155
|
-
});
|
|
156
|
-
return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
|
|
105
|
+
device.emit(DEVICE.ATTACH_PIN_ON_DEVICE, device, metadata);
|
|
106
|
+
await device.unlockDevice(DeviceSessionPinType.AttachToPin);
|
|
107
|
+
return getDeviceSession(device, {});
|
|
157
108
|
}
|
|
158
109
|
|
|
159
110
|
if (hasHostPassphrase) {
|
|
@@ -161,19 +112,12 @@ const selectDeviceSession = async (
|
|
|
161
112
|
passphrase: hostPassphrase,
|
|
162
113
|
on_device: false,
|
|
163
114
|
});
|
|
164
|
-
return getDeviceSession(device,
|
|
115
|
+
return getDeviceSession(device, {});
|
|
165
116
|
}
|
|
166
117
|
|
|
167
|
-
|
|
168
|
-
'passphrase-on-device',
|
|
169
|
-
'start'
|
|
170
|
-
);
|
|
171
|
-
device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, {
|
|
172
|
-
...metadata,
|
|
173
|
-
...(passphraseOnDeviceInteraction ? { interaction: passphraseOnDeviceInteraction } : {}),
|
|
174
|
-
});
|
|
118
|
+
device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
|
|
175
119
|
await askDevicePassphrase(device, { on_device: true });
|
|
176
|
-
return getDeviceSession(device,
|
|
120
|
+
return getDeviceSession(device, {});
|
|
177
121
|
};
|
|
178
122
|
|
|
179
123
|
export async function getProtocolV2WalletSession(
|
|
@@ -184,11 +128,7 @@ export async function getProtocolV2WalletSession(
|
|
|
184
128
|
initSession?: boolean;
|
|
185
129
|
expectedPassphraseState?: string;
|
|
186
130
|
onlyMainPin?: boolean;
|
|
187
|
-
/** 业务安全校验遇到 Attach PIN 上下文时直接拒绝,不主动切换钱包。 */
|
|
188
|
-
rejectAttachPinForMainWallet?: boolean;
|
|
189
|
-
selectMainWalletBeforeRestore?: boolean;
|
|
190
131
|
resumeOnly?: boolean;
|
|
191
|
-
deriveCardano?: boolean;
|
|
192
132
|
}
|
|
193
133
|
) {
|
|
194
134
|
const forceWalletSelection =
|
|
@@ -221,80 +161,17 @@ export async function getProtocolV2WalletSession(
|
|
|
221
161
|
: undefined;
|
|
222
162
|
let response;
|
|
223
163
|
let resumed = false;
|
|
224
|
-
let mainPinSelected =
|
|
225
|
-
options?.onlyMainPin === true &&
|
|
226
|
-
device.features?.unlocked === true &&
|
|
227
|
-
device.features?.unlockedAttachPin === false;
|
|
228
|
-
|
|
229
|
-
const clearCurrentWalletSession = () => {
|
|
230
|
-
if (options?.onlyMainPin) {
|
|
231
|
-
device.clearStandardInternalState?.();
|
|
232
|
-
} else {
|
|
233
|
-
device.clearInternalState();
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const rejectMismatchedAttachPinWallet = async () => {
|
|
238
|
-
const features = await refreshProtocolV2DeviceStatus(device);
|
|
239
|
-
if (features.unlockedAttachPin !== true) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
try {
|
|
244
|
-
await device.lockDevice();
|
|
245
|
-
} catch {
|
|
246
|
-
// Reject the mismatched Attach PIN wallet even when older firmware cannot lock.
|
|
247
|
-
}
|
|
248
|
-
if (options?.rejectAttachPinForMainWallet) {
|
|
249
|
-
device.clearStandardInternalState?.();
|
|
250
|
-
device.clearInternalState();
|
|
251
|
-
} else {
|
|
252
|
-
clearCurrentWalletSession();
|
|
253
|
-
}
|
|
254
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
if (options?.onlyMainPin && options.rejectAttachPinForMainWallet) {
|
|
258
|
-
await rejectMismatchedAttachPinWallet();
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const selectMainPin = async (force = false) => {
|
|
262
|
-
if (force || !mainPinSelected) {
|
|
263
|
-
await device.unlockDevice(DeviceSessionPinType.Main, {
|
|
264
|
-
source: 'wallet-session-coordinator',
|
|
265
|
-
reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet',
|
|
266
|
-
deviceOnly: true,
|
|
267
|
-
});
|
|
268
|
-
mainPinSelected = true;
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const selectStandardWallet = async () => {
|
|
273
|
-
// Main PIN authenticates the device; an empty host passphrase selects the standard derivation.
|
|
274
|
-
await selectMainPin();
|
|
275
|
-
if (device.features?.passphraseProtection === true) {
|
|
276
|
-
await askDevicePassphrase(device, {
|
|
277
|
-
passphrase: '',
|
|
278
|
-
on_device: false,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
164
|
|
|
283
165
|
if (options?.onlyMainPin) {
|
|
284
166
|
expectedPassphraseState = cachedStandardSession?.passphraseState;
|
|
285
167
|
if (cachedStandardSession) {
|
|
286
168
|
try {
|
|
287
|
-
if (
|
|
288
|
-
await
|
|
169
|
+
if (device.features?.unlockedAttachPin === true) {
|
|
170
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
289
171
|
}
|
|
290
|
-
response = await getDeviceSession(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
sessionId: cachedStandardSession.sessionId,
|
|
294
|
-
expectedPassphraseState,
|
|
295
|
-
deriveCardano: options?.deriveCardano,
|
|
296
|
-
})
|
|
297
|
-
);
|
|
172
|
+
response = await getDeviceSession(device, {
|
|
173
|
+
session_id: cachedStandardSession.sessionId,
|
|
174
|
+
});
|
|
298
175
|
resumed = true;
|
|
299
176
|
} catch (error) {
|
|
300
177
|
device.clearStandardInternalState?.();
|
|
@@ -306,22 +183,12 @@ export async function getProtocolV2WalletSession(
|
|
|
306
183
|
}
|
|
307
184
|
|
|
308
185
|
if (!response) {
|
|
309
|
-
await
|
|
310
|
-
response = await getDeviceSession(
|
|
311
|
-
device,
|
|
312
|
-
buildDeviceSessionGetRequest({ deriveCardano: options?.deriveCardano })
|
|
313
|
-
);
|
|
186
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
187
|
+
response = await getDeviceSession(device, {});
|
|
314
188
|
}
|
|
315
189
|
} else if (cachedSessionId && expectedPassphraseState) {
|
|
316
190
|
try {
|
|
317
|
-
response = await getDeviceSession(
|
|
318
|
-
device,
|
|
319
|
-
buildDeviceSessionGetRequest({
|
|
320
|
-
sessionId: cachedSessionId,
|
|
321
|
-
expectedPassphraseState,
|
|
322
|
-
deriveCardano: options?.deriveCardano,
|
|
323
|
-
})
|
|
324
|
-
);
|
|
191
|
+
response = await getDeviceSession(device, { session_id: cachedSessionId });
|
|
325
192
|
resumed = true;
|
|
326
193
|
} catch (error) {
|
|
327
194
|
device.clearInternalState();
|
|
@@ -330,20 +197,6 @@ export async function getProtocolV2WalletSession(
|
|
|
330
197
|
}
|
|
331
198
|
resumed = false;
|
|
332
199
|
}
|
|
333
|
-
} else if (expectedPassphraseState) {
|
|
334
|
-
try {
|
|
335
|
-
response = await getDeviceSession(
|
|
336
|
-
device,
|
|
337
|
-
buildDeviceSessionGetRequest({
|
|
338
|
-
expectedPassphraseState,
|
|
339
|
-
deriveCardano: options?.deriveCardano,
|
|
340
|
-
})
|
|
341
|
-
);
|
|
342
|
-
} catch (error) {
|
|
343
|
-
if (options?.resumeOnly || !isWalletSessionInvalidError(error)) {
|
|
344
|
-
throw error;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
200
|
}
|
|
348
201
|
|
|
349
202
|
if (!response) {
|
|
@@ -351,7 +204,7 @@ export async function getProtocolV2WalletSession(
|
|
|
351
204
|
device.clearInternalState();
|
|
352
205
|
throw ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid);
|
|
353
206
|
}
|
|
354
|
-
response = await selectDeviceSession(device, expectedPassphraseState
|
|
207
|
+
response = await selectDeviceSession(device, expectedPassphraseState);
|
|
355
208
|
}
|
|
356
209
|
|
|
357
210
|
let { message } = response;
|
|
@@ -367,21 +220,17 @@ export async function getProtocolV2WalletSession(
|
|
|
367
220
|
}
|
|
368
221
|
if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
|
|
369
222
|
resumed = false;
|
|
370
|
-
await rejectMismatchedAttachPinWallet();
|
|
371
223
|
if (options?.resumeOnly) {
|
|
372
224
|
device.clearInternalState();
|
|
373
225
|
throw ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid);
|
|
374
226
|
}
|
|
375
227
|
if (options?.onlyMainPin) {
|
|
376
228
|
device.clearStandardInternalState?.();
|
|
377
|
-
await
|
|
378
|
-
response = await getDeviceSession(
|
|
379
|
-
device,
|
|
380
|
-
buildDeviceSessionGetRequest({ deriveCardano: options?.deriveCardano })
|
|
381
|
-
);
|
|
229
|
+
await device.unlockDevice(DeviceSessionPinType.Main);
|
|
230
|
+
response = await getDeviceSession(device, {});
|
|
382
231
|
} else {
|
|
383
232
|
device.clearInternalState();
|
|
384
|
-
response = await selectDeviceSession(device, expectedPassphraseState
|
|
233
|
+
response = await selectDeviceSession(device, expectedPassphraseState);
|
|
385
234
|
}
|
|
386
235
|
message = response.message;
|
|
387
236
|
try {
|
|
@@ -395,8 +244,11 @@ export async function getProtocolV2WalletSession(
|
|
|
395
244
|
throw error;
|
|
396
245
|
}
|
|
397
246
|
if (expectedPassphraseState !== message.btc_test_address) {
|
|
398
|
-
|
|
399
|
-
|
|
247
|
+
if (options?.onlyMainPin) {
|
|
248
|
+
device.clearStandardInternalState?.();
|
|
249
|
+
} else {
|
|
250
|
+
device.clearInternalState();
|
|
251
|
+
}
|
|
400
252
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
401
253
|
}
|
|
402
254
|
}
|
|
@@ -417,19 +269,17 @@ export async function getProtocolV2WalletSession(
|
|
|
417
269
|
return {
|
|
418
270
|
passphraseState: message.btc_test_address,
|
|
419
271
|
newSession: message.session_id,
|
|
420
|
-
unlockedAttachPin:
|
|
272
|
+
unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
|
|
421
273
|
resumed,
|
|
422
274
|
};
|
|
423
275
|
}
|
|
424
276
|
|
|
425
277
|
export async function restoreProtocolV2WalletSession(
|
|
426
278
|
device: Device,
|
|
427
|
-
expectedPassphraseState: string
|
|
428
|
-
deriveCardano?: boolean
|
|
279
|
+
expectedPassphraseState: string
|
|
429
280
|
) {
|
|
430
281
|
return getProtocolV2WalletSession(device, {
|
|
431
282
|
expectedPassphraseState,
|
|
432
283
|
resumeOnly: true,
|
|
433
|
-
deriveCardano,
|
|
434
284
|
});
|
|
435
285
|
}
|
package/src/topLevelInject.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
|
|
3
|
-
import { createCoreApi
|
|
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';
|
|
@@ -19,7 +20,6 @@ export const topLevelInject = () => {
|
|
|
19
20
|
if (!lowLevelApi) return Promise.resolve(undefined);
|
|
20
21
|
return lowLevelApi.call(params);
|
|
21
22
|
};
|
|
22
|
-
const protocolAwareCall = createProtocolAwareCall(call);
|
|
23
23
|
const api: CoreApi = {
|
|
24
24
|
on: <T extends string, P extends (...args: any[]) => any>(type: T, fn: P) => {
|
|
25
25
|
eventEmitter.on(type, fn);
|
|
@@ -38,18 +38,19 @@ export const topLevelInject = () => {
|
|
|
38
38
|
return lowLevelApi?.init(settings) ?? Promise.resolve(false);
|
|
39
39
|
},
|
|
40
40
|
|
|
41
|
-
call
|
|
41
|
+
call,
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
...createCoreApi(protocolAwareCall.call),
|
|
43
|
+
...createCoreApi(call),
|
|
46
44
|
|
|
47
45
|
removeAllListeners: type => {
|
|
48
46
|
eventEmitter.removeAllListeners(type);
|
|
49
47
|
lowLevelApi?.removeAllListeners(type);
|
|
50
48
|
},
|
|
51
49
|
|
|
52
|
-
dispose: () =>
|
|
50
|
+
dispose: async () => {
|
|
51
|
+
unregisterFirmwareUpdateHostBinding();
|
|
52
|
+
await lowLevelApi?.dispose();
|
|
53
|
+
},
|
|
53
54
|
|
|
54
55
|
uiResponse: response => lowLevelApi?.uiResponse(response),
|
|
55
56
|
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
IProtocolV2FirmwareComponentTarget,
|
|
13
13
|
} from '../settings';
|
|
14
14
|
import type { FirmwareUpdateV4Target } from './firmwareUpdate';
|
|
15
|
+
import type { FirmwareUpdatePlan, FirmwareUpdatePlanForceTarget } from './firmwareUpdatePlan';
|
|
15
16
|
|
|
16
17
|
export type FirmwareRelease = {
|
|
17
18
|
shouldUpdate?: boolean;
|
|
@@ -59,17 +60,18 @@ export type AllFirmwareRelease = {
|
|
|
59
60
|
status?: ProtocolV2FirmwareReleaseStatus;
|
|
60
61
|
hasUpgrade?: boolean;
|
|
61
62
|
required?: boolean;
|
|
62
|
-
resourceStatus?: 'valid' | 'outdated' | 'unknown';
|
|
63
63
|
currentVersions?: DeviceStateVersions;
|
|
64
64
|
components?: ProtocolV2FirmwareComponentRelease[];
|
|
65
65
|
targetsToUpdate?: FirmwareUpdateV4Target[];
|
|
66
66
|
release?: IFirmwareReleaseInfo;
|
|
67
|
+
firmwareUpdatePlan?: FirmwareUpdatePlan;
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
export type CheckAllFirmwareReleaseParams = {
|
|
70
71
|
checkBridgeRelease?: boolean;
|
|
71
|
-
checkFirmwareHash?: boolean;
|
|
72
72
|
firmwareType?: EFirmwareType;
|
|
73
|
+
platform?: 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
|
|
74
|
+
forceUpdateTargets?: FirmwareUpdatePlanForceTarget[];
|
|
73
75
|
};
|
|
74
76
|
|
|
75
77
|
export declare function checkAllFirmwareRelease(
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import type { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
1
|
import type { Features } from '../device';
|
|
3
2
|
import type { CommonParams, Response } from '../params';
|
|
4
3
|
|
|
5
|
-
export
|
|
6
|
-
/**
|
|
7
|
-
* 限定本次解锁允许使用的 PIN 类型。省略时保持兼容行为,仅允许主 PIN。
|
|
8
|
-
*/
|
|
9
|
-
pinType?: DeviceSessionPinType;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export declare function deviceUnlock(
|
|
13
|
-
connectId: string,
|
|
14
|
-
params?: CommonParams & DeviceUnlockParams
|
|
15
|
-
): Response<Features>;
|
|
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
|
@@ -14,7 +14,6 @@ export type {
|
|
|
14
14
|
export type { CipheredKeyValue, CipheredKeyValueParams } from './cipherKeyValue';
|
|
15
15
|
|
|
16
16
|
export type { DeviceChangePinParams } from './deviceChangePin';
|
|
17
|
-
export type { DeviceUnlockParams } from './deviceUnlock';
|
|
18
17
|
export type { DeviceFlagsParams } from './deviceFlags';
|
|
19
18
|
export type { DeviceRecoveryParams } from './deviceRecovery';
|
|
20
19
|
export type { DeviceResetParams } from './deviceReset';
|
|
@@ -26,12 +25,30 @@ export type {
|
|
|
26
25
|
DeviceUploadResourceResponse,
|
|
27
26
|
} from './deviceUploadResource';
|
|
28
27
|
export type {
|
|
28
|
+
FirmwareArtifactReader,
|
|
29
|
+
FirmwareArtifactReference,
|
|
30
|
+
FirmwareUpdateHostBinding,
|
|
31
|
+
FirmwareUpdateArtifactParams,
|
|
29
32
|
FirmwareUpdateParams,
|
|
30
33
|
FirmwareUpdateBinaryParams,
|
|
31
34
|
FirmwareUpdateV3Params,
|
|
32
35
|
FirmwareUpdateV4Params,
|
|
33
36
|
FirmwareUpdateV4Target,
|
|
34
37
|
} from './firmwareUpdate';
|
|
38
|
+
export type {
|
|
39
|
+
FirmwareUpdatePlan,
|
|
40
|
+
FirmwareUpdatePlanArtifact,
|
|
41
|
+
FirmwareUpdatePlanArtifactRole,
|
|
42
|
+
FirmwareUpdatePlanForceTarget,
|
|
43
|
+
FirmwareUpdatePlanTarget,
|
|
44
|
+
} from './firmwareUpdatePlan';
|
|
45
|
+
export type {
|
|
46
|
+
FirmwareUpdatePreparedArtifact,
|
|
47
|
+
FirmwareUpdatePreparedArtifactInput,
|
|
48
|
+
FirmwareUpdatePreparedEntry,
|
|
49
|
+
FirmwareUpdatePreparedPlan,
|
|
50
|
+
} from './firmwareUpdatePreparedPlan';
|
|
51
|
+
export type { FirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
|
|
35
52
|
export type { AllFirmwareRelease } from './checkAllFirmwareRelease';
|
|
36
53
|
export type {
|
|
37
54
|
ProtocolV2FirmwareComponentRelease,
|
|
@@ -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
|
/**
|
|
@@ -63,7 +119,6 @@ export interface FirmwareUpdateV3Params {
|
|
|
63
119
|
*/
|
|
64
120
|
export type FirmwareUpdateV4Target =
|
|
65
121
|
| 'boot'
|
|
66
|
-
| 'boot_resources'
|
|
67
122
|
| 'app_v1'
|
|
68
123
|
| 'app_v2'
|
|
69
124
|
| 'coprocessor'
|
|
@@ -74,17 +129,19 @@ export type FirmwareUpdateV4Target =
|
|
|
74
129
|
| 'se04';
|
|
75
130
|
|
|
76
131
|
export interface FirmwareUpdateV4Params {
|
|
132
|
+
preparedPlan?: FirmwareUpdatePreparedPlan;
|
|
133
|
+
hostBindingGeneration?: number;
|
|
77
134
|
platform: IPlatform;
|
|
135
|
+
expectedDeviceId?: string;
|
|
78
136
|
chunkSize?: number;
|
|
79
137
|
firmwareType?: EFirmwareType;
|
|
80
138
|
targetsToUpdate?: FirmwareUpdateV4Target[];
|
|
139
|
+
expectedTargetVersions?: Partial<Record<FirmwareUpdateV4Target, string>>;
|
|
81
140
|
|
|
82
141
|
/** FW_MGMT_TARGET_ROMLOADER = 2; Pro2 cannot install it through firmwareUpdateV4. */
|
|
83
142
|
romloaderBinary?: ArrayBuffer;
|
|
84
143
|
/** FW_MGMT_TARGET_BOOTLOADER = 3 */
|
|
85
144
|
bootloaderBinary?: ArrayBuffer;
|
|
86
|
-
/** FW_MGMT_TARGET_CRATE = 1; optional Pro2 startup resources. */
|
|
87
|
-
bootResourcesBinary?: ArrayBuffer;
|
|
88
145
|
/** FW_MGMT_TARGET_APPLICATION_P1 = 4 */
|
|
89
146
|
applicationP1Binary?: ArrayBuffer;
|
|
90
147
|
/** FW_MGMT_TARGET_APPLICATION_P2 = 5 */
|
|
@@ -105,8 +162,24 @@ export interface FirmwareUpdateV4Params {
|
|
|
105
162
|
binary: ArrayBuffer;
|
|
106
163
|
devicePath: string;
|
|
107
164
|
}>;
|
|
165
|
+
artifactReader?: FirmwareArtifactReader;
|
|
166
|
+
componentArtifacts?: Partial<
|
|
167
|
+
Record<Exclude<FirmwareUpdateV4Target, 'resource'>, FirmwareArtifactReference>
|
|
168
|
+
>;
|
|
169
|
+
resourceBundleArtifacts?: Array<{
|
|
170
|
+
name: string;
|
|
171
|
+
artifact: FirmwareArtifactReference;
|
|
172
|
+
}>;
|
|
108
173
|
}
|
|
109
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
|
+
|
|
110
183
|
export declare function firmwareUpdateV3(
|
|
111
184
|
connectId: string | undefined,
|
|
112
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,38 @@
|
|
|
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 type FirmwareUpdatePlanForceTarget = 'firmware' | 'ble' | 'bootloader' | 'resource';
|
|
15
|
+
|
|
16
|
+
export interface FirmwareUpdatePlanArtifact {
|
|
17
|
+
artifactId: string;
|
|
18
|
+
role: FirmwareUpdatePlanArtifactRole;
|
|
19
|
+
target: FirmwareUpdatePlanTarget;
|
|
20
|
+
url: string;
|
|
21
|
+
container: 'raw' | 'zip';
|
|
22
|
+
logicalName?: string;
|
|
23
|
+
expectedSize?: number;
|
|
24
|
+
expectedSha256?: string;
|
|
25
|
+
targetVersion?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface FirmwareUpdatePlan {
|
|
29
|
+
schemaVersion: 2;
|
|
30
|
+
planDigest: string;
|
|
31
|
+
executor: 'v2' | 'v3' | 'v4';
|
|
32
|
+
deviceIdentity: string;
|
|
33
|
+
deviceModel: string;
|
|
34
|
+
firmwareType: EFirmwareType;
|
|
35
|
+
platform: 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
|
|
36
|
+
artifacts: FirmwareUpdatePlanArtifact[];
|
|
37
|
+
targetsToUpdate: FirmwareUpdatePlanTarget[];
|
|
38
|
+
}
|