@onekeyfe/hd-core 1.2.0-alpha.66 → 1.2.0-alpha.67
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 -313
- package/__tests__/DeviceCommands.test.ts +13 -59
- 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__/device-pool-state.test.ts +0 -22
- package/__tests__/device-settings.test.ts +18 -39
- package/__tests__/device-state-contract.test.ts +0 -1
- package/__tests__/device-state-mapper.test.ts +1 -13
- package/__tests__/device-utils.test.ts +1 -48
- package/__tests__/deviceSettings.test.ts +1 -11
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -0
- package/__tests__/firmware-update/device-update-bootloader.test.ts +87 -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 +394 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +231 -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__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +26 -3
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +0 -19
- package/__tests__/open-wallet-session.test.ts +37 -568
- package/__tests__/protocol-v2-unlock-policy.test.ts +37 -300
- package/__tests__/protocol-v2.test.ts +1153 -1458
- package/__tests__/protocolV2FileWrite.test.ts +0 -152
- 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/__tests__/tron-sign-message-init.test.ts +2 -2
- 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 +10 -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 +27 -13
- 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/DeviceSettings.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 +11 -4
- 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 -9
- 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/kaspa/KaspaGetAddress.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
- package/dist/api/polkadot/networks.d.ts +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/solana/SolSignMessage.d.ts +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +2 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +2 -2
- package/dist/api/tron/TronSignTransaction.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 +4 -9
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.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/DeviceConnector.d.ts +1 -2
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.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 +247 -243
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3773 -3054
- 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 +4 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.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 -6
- 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 +5 -3
- 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 -4
- 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 +2 -2
- 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 +21 -38
- 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/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.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 +60 -59
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +298 -126
- package/src/api/FirmwareUpdateV3.ts +265 -63
- package/src/api/FirmwareUpdateV4.ts +1017 -602
- package/src/api/GetPassphraseState.ts +1 -7
- package/src/api/OpenWalletSession.ts +17 -71
- package/src/api/SearchDevices.ts +1 -3
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -36
- package/src/api/device/DeviceSettings.ts +4 -5
- package/src/api/device/DeviceUnlock.ts +3 -8
- package/src/api/device/DeviceUpdateBootloader.ts +125 -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 -27
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +449 -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 +63 -202
- package/src/api/index.ts +0 -2
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +13 -2
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignMessage.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/api/ton/TonGetAddress.ts +1 -1
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/api/ton/TonSignProof.ts +1 -1
- package/src/api/tron/TronSignMessage.ts +2 -2
- package/src/api/tron/TronSignTransaction.ts +1 -1
- package/src/core/deviceEventRegistration.ts +0 -4
- package/src/core/index.ts +111 -213
- package/src/data/messages/messages-protocol-v2.json +0 -25
- package/src/data-manager/DataManager.ts +41 -113
- package/src/data-manager/TransportManager.ts +0 -6
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +49 -274
- package/src/device/DeviceCommands.ts +4 -31
- package/src/device/DeviceConnector.ts +13 -33
- package/src/device/DevicePool.ts +7 -21
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +0 -3
- 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 +7 -10
- package/src/protocols/protocol-v2/firmware.ts +0 -2
- 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 +36 -214
- package/src/topLevelInject.ts +8 -7
- package/src/types/api/checkAllFirmwareRelease.ts +5 -3
- 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 +78 -6
- 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 +3 -15
- package/src/types/params.ts +1 -7
- package/src/types/settings.ts +22 -60
- package/src/utils/deviceFeaturesCompat.ts +6 -5
- package/src/utils/deviceFeaturesUtils.ts +3 -14
- package/src/utils/deviceInfoUtils.ts +0 -2
- package/src/utils/deviceSettings.ts +0 -3
- package/src/utils/homescreen.ts +6 -32
- package/src/utils/index.ts +1 -6
- package/src/utils/pro2Wallpaper.ts +8 -35
- package/__tests__/core-initialization.test.ts +0 -23
- package/__tests__/device-connector-protocol.test.ts +0 -81
- package/__tests__/deviceUploadNft.test.ts +0 -316
- package/__tests__/pro2Nft.test.ts +0 -108
- package/__tests__/protocol-binding.test.ts +0 -89
- package/__tests__/protocol-v2-resources.test.ts +0 -340
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
- package/__tests__/uiProgressThrottle.test.ts +0 -74
- package/__tests__/uiPromiseRegistry.test.ts +0 -115
- 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 -6
- 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 -197
- package/src/core/uiPromiseRegistry.ts +0 -63
- package/src/protocols/protocol-v2/resources.ts +0 -390
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -131
- package/src/types/api/detectDeviceConnectProtocol.ts +0 -6
- package/src/utils/pro2Nft.ts +0 -142
- package/src/utils/uiProgressThrottle.ts +0 -63
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { createDeferred } from '@onekeyfe/hd-shared';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
consumeUiPromise,
|
|
5
|
-
findUiPromiseForResponse,
|
|
6
|
-
rejectUiPromises,
|
|
7
|
-
} from '../src/core/uiPromiseRegistry';
|
|
8
|
-
import { UI_RESPONSE } from '../src/events';
|
|
9
|
-
|
|
10
|
-
import type { UiPromise, UiPromiseResponse } from '../src/events';
|
|
11
|
-
|
|
12
|
-
const createPinPromise = (interactionId: string, deviceId: string) => {
|
|
13
|
-
const promise = createDeferred(UI_RESPONSE.RECEIVE_PIN) as UiPromise<
|
|
14
|
-
typeof UI_RESPONSE.RECEIVE_PIN
|
|
15
|
-
>;
|
|
16
|
-
promise.responseCorrelation = { interactionId, deviceId };
|
|
17
|
-
return promise;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const asRegistry = (promises: UiPromise<typeof UI_RESPONSE.RECEIVE_PIN>[]) =>
|
|
21
|
-
promises as UiPromise<UiPromiseResponse['type']>[];
|
|
22
|
-
|
|
23
|
-
describe('UI response promise correlation', () => {
|
|
24
|
-
test('consumes a rejected UI promise and normalizes its callback error', async () => {
|
|
25
|
-
const pending = createDeferred<string>();
|
|
26
|
-
const onFulfilled = jest.fn();
|
|
27
|
-
const onRejected = jest.fn();
|
|
28
|
-
|
|
29
|
-
consumeUiPromise(pending.promise, onFulfilled, onRejected);
|
|
30
|
-
pending.reject('cancelled' as unknown as Error);
|
|
31
|
-
await Promise.resolve();
|
|
32
|
-
|
|
33
|
-
expect(onFulfilled).not.toHaveBeenCalled();
|
|
34
|
-
expect(onRejected).toHaveBeenCalledWith(expect.any(Error));
|
|
35
|
-
expect(onRejected.mock.calls[0][0].message).toBe('cancelled');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('matches a sensitive response by type, interactionId and deviceId', () => {
|
|
39
|
-
const deviceA = createPinPromise('interaction-a', 'device-a');
|
|
40
|
-
const deviceB = createPinPromise('interaction-b', 'device-b');
|
|
41
|
-
|
|
42
|
-
expect(
|
|
43
|
-
findUiPromiseForResponse(asRegistry([deviceA, deviceB]), {
|
|
44
|
-
type: UI_RESPONSE.RECEIVE_PIN,
|
|
45
|
-
payload: '123',
|
|
46
|
-
interactionId: 'interaction-b',
|
|
47
|
-
deviceId: 'device-b',
|
|
48
|
-
})
|
|
49
|
-
).toBe(deviceB);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('does not match incomplete or incorrect correlation metadata', () => {
|
|
53
|
-
const pending = createPinPromise('interaction-a', 'device-a');
|
|
54
|
-
|
|
55
|
-
expect(
|
|
56
|
-
findUiPromiseForResponse(asRegistry([pending]), {
|
|
57
|
-
type: UI_RESPONSE.RECEIVE_PIN,
|
|
58
|
-
payload: '123',
|
|
59
|
-
interactionId: 'interaction-a',
|
|
60
|
-
})
|
|
61
|
-
).toBeUndefined();
|
|
62
|
-
expect(
|
|
63
|
-
findUiPromiseForResponse(asRegistry([pending]), {
|
|
64
|
-
type: UI_RESPONSE.RECEIVE_PIN,
|
|
65
|
-
payload: '123',
|
|
66
|
-
interactionId: 'interaction-a',
|
|
67
|
-
deviceId: 'device-b',
|
|
68
|
-
})
|
|
69
|
-
).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('keeps legacy responses only when the sensitive candidate is unique', () => {
|
|
73
|
-
const deviceA = createPinPromise('interaction-a', 'device-a');
|
|
74
|
-
const deviceB = createPinPromise('interaction-b', 'device-b');
|
|
75
|
-
const legacyResponse = {
|
|
76
|
-
type: UI_RESPONSE.RECEIVE_PIN,
|
|
77
|
-
payload: '123',
|
|
78
|
-
} as const;
|
|
79
|
-
|
|
80
|
-
expect(findUiPromiseForResponse(asRegistry([deviceA]), legacyResponse)).toBe(deviceA);
|
|
81
|
-
expect(
|
|
82
|
-
findUiPromiseForResponse(asRegistry([deviceA, deviceB]), legacyResponse)
|
|
83
|
-
).toBeUndefined();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('applies the same exact matching to passphrase responses', () => {
|
|
87
|
-
const promise = createDeferred(UI_RESPONSE.RECEIVE_PASSPHRASE) as UiPromise<
|
|
88
|
-
typeof UI_RESPONSE.RECEIVE_PASSPHRASE
|
|
89
|
-
>;
|
|
90
|
-
promise.responseCorrelation = {
|
|
91
|
-
interactionId: 'passphrase-interaction',
|
|
92
|
-
deviceId: 'device-a',
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
expect(
|
|
96
|
-
findUiPromiseForResponse([promise] as UiPromise<UiPromiseResponse['type']>[], {
|
|
97
|
-
type: UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
98
|
-
payload: { value: 'redacted' },
|
|
99
|
-
interactionId: 'passphrase-interaction',
|
|
100
|
-
deviceId: 'device-a',
|
|
101
|
-
})
|
|
102
|
-
).toBe(promise);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('rejects every pending UI promise removed during cleanup', async () => {
|
|
106
|
-
const deviceA = createPinPromise('interaction-a', 'device-a');
|
|
107
|
-
const deviceB = createPinPromise('interaction-b', 'device-b');
|
|
108
|
-
const cancellation = new Error('UI request was cancelled');
|
|
109
|
-
|
|
110
|
-
rejectUiPromises(asRegistry([deviceA, deviceB]), cancellation);
|
|
111
|
-
|
|
112
|
-
await expect(deviceA.promise).rejects.toBe(cancellation);
|
|
113
|
-
await expect(deviceB.promise).rejects.toBe(cancellation);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from './BaseMethod';
|
|
2
|
-
export default class DetectDeviceConnectProtocol extends BaseMethod {
|
|
3
|
-
init(): void;
|
|
4
|
-
getSupportedProtocols(): readonly ["V1", "V2"];
|
|
5
|
-
run(): Promise<"V1" | "V2">;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=DetectDeviceConnectProtocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DetectDeviceConnectProtocol.d.ts","sourceRoot":"","sources":["../../src/api/DetectDeviceConnectProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,UAAU;IACjE,IAAI;IAOJ,qBAAqB;IAIrB,GAAG;CAGJ"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type Pro2NftImage } from '../../utils/pro2Nft';
|
|
2
|
-
import { BaseMethod } from '../BaseMethod';
|
|
3
|
-
export type DeviceUploadNftParams = {
|
|
4
|
-
image: Pro2NftImage;
|
|
5
|
-
thumbnail: Pro2NftImage;
|
|
6
|
-
title: string;
|
|
7
|
-
subtitle: string;
|
|
8
|
-
timestampMs?: number;
|
|
9
|
-
chunkSize?: number;
|
|
10
|
-
paceMs?: number;
|
|
11
|
-
timeoutMs?: number;
|
|
12
|
-
};
|
|
13
|
-
export type DeviceUploadNftResponse = {
|
|
14
|
-
basename: string;
|
|
15
|
-
imagePath: string;
|
|
16
|
-
thumbnailPath: string;
|
|
17
|
-
metadataPath: string;
|
|
18
|
-
totalSize: number;
|
|
19
|
-
nftUpdated: true;
|
|
20
|
-
message?: string;
|
|
21
|
-
};
|
|
22
|
-
export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
|
|
23
|
-
private bundle?;
|
|
24
|
-
getSupportedProtocols(): readonly ["V2"];
|
|
25
|
-
init(): void;
|
|
26
|
-
private assertCapabilities;
|
|
27
|
-
private assertStorageCapacity;
|
|
28
|
-
private updateNft;
|
|
29
|
-
run(): Promise<DeviceUploadNftResponse>;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=DeviceUploadNft.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceUploadNft.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceUploadNft.ts"],"names":[],"mappings":"AAIA,OAAO,EASL,KAAK,YAAY,EAGlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,YAAY,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAOF,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,qBAAqB,CAAC;IAC5E,OAAO,CAAC,MAAM,CAAC,CAAgB;IAE/B,qBAAqB;IAIrB,IAAI;YAkCU,kBAAkB;YAiBlB,qBAAqB;YAwBrB,SAAS;IASjB,GAAG,IAAI,OAAO,CAAC,uBAAuB,CAAC;CA0D9C"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { UiPromise, UiPromiseResponse } from '../events/ui-promise';
|
|
2
|
-
import type { UiResponseEvent } from '../events/ui-response';
|
|
3
|
-
export declare const consumeUiPromise: <T>(promise: Promise<T>, onFulfilled: (value: T) => void, onRejected: (error: Error) => void) => void;
|
|
4
|
-
export declare const rejectUiPromises: (uiPromises: UiPromise<UiPromiseResponse['type']>[], error: Error) => void;
|
|
5
|
-
export declare const findUiPromiseForResponse: (uiPromises: UiPromise<UiPromiseResponse['type']>[], response: UiResponseEvent) => UiPromise<"ui-receive_pin" | "ui-receive_passphrase" | "ui-receive_select-device-in-bootloader-for-web-device" | "ui-receive_select-device-for-switch-firmware-web-device" | "device-disconnect"> | undefined;
|
|
6
|
-
//# sourceMappingURL=uiPromiseRegistry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uiPromiseRegistry.d.ts","sourceRoot":"","sources":["../../src/core/uiPromiseRegistry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,eAAO,MAAM,gBAAgB,sDAEA,IAAI,sBACX,KAAK,KAAK,IAAI,SAKnC,CAAC;AAEF,eAAO,MAAM,gBAAgB,eACf,UAAU,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,SAC3C,KAAK,SAKb,CAAC;AASF,eAAO,MAAM,wBAAwB,eACvB,UAAU,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,YACxC,eAAe,kNA0B1B,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { IProtocolV2Resource, IProtocolV2ResourceFile, IProtocolV2ResourceType, IProtocolV2Resources } from '../../types';
|
|
2
|
-
import type { DeviceCommands } from '../../device/DeviceCommands';
|
|
3
|
-
export declare const PROTOCOL_V2_RESOURCE_TYPES: readonly ["images", "animation", "wallpaper", "translations", "roobert", "noto"];
|
|
4
|
-
export declare const PROTOCOL_V2_RESOURCE_DEVICE_PATHS: Readonly<Record<IProtocolV2ResourceType, string>>;
|
|
5
|
-
export declare const PROTOCOL_V2_RESOURCE_INVENTORY_TIMEOUT_MS: number;
|
|
6
|
-
export type ProtocolV2ResourceInventoryItem = {
|
|
7
|
-
type: IProtocolV2ResourceType;
|
|
8
|
-
size: number;
|
|
9
|
-
headerHash: string;
|
|
10
|
-
};
|
|
11
|
-
export type ProtocolV2ResourceUpdateMode = 'application' | 'bootloader-recovery';
|
|
12
|
-
export type ProtocolV2ResourceUpdatePlan = {
|
|
13
|
-
status: 'valid' | 'outdated' | 'unknown';
|
|
14
|
-
resources: IProtocolV2Resource[];
|
|
15
|
-
};
|
|
16
|
-
export declare function readProtocolV2ResourceInventory({ commands, resources, chunkSize, timeoutMs, }: {
|
|
17
|
-
commands: Pick<DeviceCommands, 'typedCall'>;
|
|
18
|
-
resources: readonly IProtocolV2Resource[];
|
|
19
|
-
chunkSize?: number;
|
|
20
|
-
timeoutMs?: number;
|
|
21
|
-
}): Promise<ProtocolV2ResourceInventoryItem[]>;
|
|
22
|
-
export declare function parseProtocolV2Resources(value: unknown): IProtocolV2Resources | undefined;
|
|
23
|
-
export declare function buildProtocolV2ResourceUpdatePlan({ resources, inventory, mode, forced, }: {
|
|
24
|
-
resources: readonly IProtocolV2Resource[];
|
|
25
|
-
inventory?: readonly ProtocolV2ResourceInventoryItem[];
|
|
26
|
-
mode: ProtocolV2ResourceUpdateMode;
|
|
27
|
-
forced?: boolean;
|
|
28
|
-
}): ProtocolV2ResourceUpdatePlan;
|
|
29
|
-
export declare function isProtocolV2ResourceFileValid(binary: ArrayBuffer, resource: Pick<IProtocolV2ResourceFile, 'size' | 'fileHash'>): boolean;
|
|
30
|
-
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,eAAO,MAAM,0BAA0B,kFAOgB,CAAC;AAExD,eAAO,MAAM,iCAAiC,EAAE,QAAQ,CAAC,MAAM,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAQ7F,CAAC;AAaJ,eAAO,MAAM,yCAAyC,QAAW,CAAC;AAElE,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,uBAAuB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,aAAa,GAAG,qBAAqB,CAAC;AAEjF,MAAM,MAAM,4BAA4B,GAAG;IACzC,MAAM,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,mBAAmB,EAAE,CAAC;CAClC,CAAC;AAwHF,wBAAsB,+BAA+B,CAAC,EACpD,QAAQ,EACR,SAAS,EACT,SAAgD,EAChD,SAAqD,GACtD,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC5C,SAAS,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,+BAA+B,EAAE,CAAC,CAmB7C;AAiGD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAgCzF;AAGD,wBAAgB,iCAAiC,CAAC,EAChD,SAAS,EACT,SAAS,EACT,IAAI,EACJ,MAAc,GACf,EAAE;IACD,SAAS,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAC1C,SAAS,CAAC,EAAE,SAAS,+BAA+B,EAAE,CAAC;IACvD,IAAI,EAAE,4BAA4B,CAAC;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,4BAA4B,CA8B/B;AAOD,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,UAAU,CAAC,GAC3D,OAAO,CAGT"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { BaseMethod } from '../../api/BaseMethod';
|
|
2
|
-
import type { Device } from '../../device/Device';
|
|
3
|
-
import type { ProtocolV2UiInteractionCoordinator } from './uiInteraction';
|
|
4
|
-
export type ProtocolV2UnlockContext = {
|
|
5
|
-
preflightCompleted: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare const createProtocolV2UnlockContext: () => ProtocolV2UnlockContext;
|
|
8
|
-
type RunnableMethod = Pick<BaseMethod, 'run' | 'unlockPolicy' | 'useDevicePassphraseState' | 'protocolV2UiInteraction' | 'protocolV2UiMode' | 'params' | 'payload'> & {
|
|
9
|
-
name?: string;
|
|
10
|
-
protocolV2UnlockContext?: ProtocolV2UnlockContext;
|
|
11
|
-
};
|
|
12
|
-
type UiInteractionCoordinator = Pick<ProtocolV2UiInteractionCoordinator, 'enterMethodInteraction' | 'enterUnlockInteraction'>;
|
|
13
|
-
type RunMethodWithUnlockPolicyOptions<T> = {
|
|
14
|
-
context?: ProtocolV2UnlockContext;
|
|
15
|
-
uiCoordinator?: UiInteractionCoordinator;
|
|
16
|
-
afterStatusBeforeUnlock?: () => void | Promise<void>;
|
|
17
|
-
prepare?: () => Promise<void>;
|
|
18
|
-
run?: () => Promise<T>;
|
|
19
|
-
};
|
|
20
|
-
export declare function runMethodWithUnlockPolicy<T = unknown>(method: RunnableMethod, device: Device, options?: RunMethodWithUnlockPolicyOptions<T>): Promise<T>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=unlockPolicyRunner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unlockPolicyRunner.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/unlockPolicyRunner.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,iBAAiB,CAAC;AAI1E,MAAM,MAAM,uBAAuB,GAAG;IACpC,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,6BAA6B,QAAO,uBAE/C,CAAC;AAEH,KAAK,cAAc,GAAG,IAAI,CACxB,UAAU,EACR,KAAK,GACL,cAAc,GACd,0BAA0B,GAC1B,yBAAyB,GACzB,kBAAkB,GAClB,QAAQ,GACR,SAAS,CACZ,GAAG;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;CACnD,CAAC;AAEF,KAAK,wBAAwB,GAAG,IAAI,CAClC,kCAAkC,EAClC,wBAAwB,GAAG,wBAAwB,CACpD,CAAC;AAEF,KAAK,gCAAgC,CAAC,CAAC,IAAI;IACzC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,aAAa,CAAC,EAAE,wBAAwB,CAAC;IACzC,uBAAuB,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;CACxB,CAAC;AAeF,wBAAsB,yBAAyB,CAAC,CAAC,GAAG,OAAO,EACzD,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,gCAAgC,CAAC,CAAC,CAAM,GAChD,OAAO,CAAC,CAAC,CAAC,CAgEZ"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
2
|
-
import type { Response } from '../params';
|
|
3
|
-
export declare function detectDeviceConnectProtocol(connectId: string): Response<HardwareConnectProtocol>;
|
|
4
|
-
//# sourceMappingURL=detectDeviceConnectProtocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detectDeviceConnectProtocol.d.ts","sourceRoot":"","sources":["../../../src/types/api/detectDeviceConnectProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,OAAO,UAAU,2BAA2B,CACjD,SAAS,EAAE,MAAM,GAChB,QAAQ,CAAC,uBAAuB,CAAC,CAAC"}
|
package/dist/utils/pro2Nft.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export declare const PRO2_NFT_IMAGE_WIDTH = 540;
|
|
2
|
-
export declare const PRO2_NFT_IMAGE_HEIGHT = 540;
|
|
3
|
-
export declare const PRO2_NFT_THUMBNAIL_WIDTH = 263;
|
|
4
|
-
export declare const PRO2_NFT_THUMBNAIL_HEIGHT = 263;
|
|
5
|
-
export declare const PRO2_NFT_DIRECTORY = "vol1:/nft";
|
|
6
|
-
export declare const PRO2_NFT_DEFAULT_CHUNK_SIZE = 2048;
|
|
7
|
-
export declare const PRO2_NFT_DEFAULT_PACE_MS = 0;
|
|
8
|
-
export declare const PRO2_NFT_DEFAULT_TIMEOUT_MS = 15000;
|
|
9
|
-
export declare const PRO2_NFT_MIN_CHUNK_SIZE = 64;
|
|
10
|
-
export declare const PRO2_NFT_MAX_CHUNK_SIZE = 2048;
|
|
11
|
-
export declare const PRO2_NFT_MAX_ITEMS = 10;
|
|
12
|
-
export type Pro2NftImage = {
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
rgba: Uint8Array | ArrayBuffer;
|
|
16
|
-
};
|
|
17
|
-
export type Pro2NftBundle = {
|
|
18
|
-
basename: string;
|
|
19
|
-
image: Uint8Array;
|
|
20
|
-
thumbnail: Uint8Array;
|
|
21
|
-
metadata: Uint8Array;
|
|
22
|
-
};
|
|
23
|
-
export declare function getCompletePro2NftBasenames(childFiles?: string): Set<string>;
|
|
24
|
-
export declare function buildPro2NftBundle(options: {
|
|
25
|
-
image: Pro2NftImage;
|
|
26
|
-
thumbnail: Pro2NftImage;
|
|
27
|
-
title: string;
|
|
28
|
-
subtitle: string;
|
|
29
|
-
timestampMs: number;
|
|
30
|
-
}): Pro2NftBundle;
|
|
31
|
-
//# sourceMappingURL=pro2Nft.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pro2Nft.d.ts","sourceRoot":"","sources":["../../src/utils/pro2Nft.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,MAAM,CAAC;AACzC,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAC7C,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAC9C,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAChD,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAClD,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,UAAU,CAAC;IACtB,QAAQ,EAAE,UAAU,CAAC;CACtB,CAAC;AAiCF,wBAAgB,2BAA2B,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAiB5E;AAsBD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,YAAY,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,aAAa,CAkChB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uiProgressThrottle.d.ts","sourceRoot":"","sources":["../../src/utils/uiProgressThrottle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAiB7C,eAAO,MAAM,6BAA6B,yDAMvB,WAAW,YAqC7B,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from './BaseMethod';
|
|
2
|
-
|
|
3
|
-
export default class DetectDeviceConnectProtocol extends BaseMethod {
|
|
4
|
-
init() {
|
|
5
|
-
this.payload.forceProtocolDetection = true;
|
|
6
|
-
this.useDevicePassphraseState = false;
|
|
7
|
-
this.skipForceUpdateCheck = true;
|
|
8
|
-
this.unlockPolicy = 'none';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
getSupportedProtocols() {
|
|
12
|
-
return ['V1', 'V2'] as const;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
run() {
|
|
16
|
-
return Promise.resolve(this.device.getProtocol());
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode, createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
|
-
|
|
3
|
-
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
4
|
-
import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
|
|
5
|
-
import {
|
|
6
|
-
PRO2_NFT_DEFAULT_CHUNK_SIZE,
|
|
7
|
-
PRO2_NFT_DEFAULT_PACE_MS,
|
|
8
|
-
PRO2_NFT_DEFAULT_TIMEOUT_MS,
|
|
9
|
-
PRO2_NFT_DIRECTORY,
|
|
10
|
-
PRO2_NFT_MAX_CHUNK_SIZE,
|
|
11
|
-
PRO2_NFT_MAX_ITEMS,
|
|
12
|
-
PRO2_NFT_MIN_CHUNK_SIZE,
|
|
13
|
-
type Pro2NftBundle,
|
|
14
|
-
type Pro2NftImage,
|
|
15
|
-
buildPro2NftBundle,
|
|
16
|
-
getCompletePro2NftBasenames,
|
|
17
|
-
} from '../../utils/pro2Nft';
|
|
18
|
-
import { BaseMethod } from '../BaseMethod';
|
|
19
|
-
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
20
|
-
import { writeProtocolV2File } from '../helpers/protocolV2FileWrite';
|
|
21
|
-
|
|
22
|
-
export type DeviceUploadNftParams = {
|
|
23
|
-
image: Pro2NftImage;
|
|
24
|
-
thumbnail: Pro2NftImage;
|
|
25
|
-
title: string;
|
|
26
|
-
subtitle: string;
|
|
27
|
-
timestampMs?: number;
|
|
28
|
-
chunkSize?: number;
|
|
29
|
-
paceMs?: number;
|
|
30
|
-
timeoutMs?: number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type DeviceUploadNftResponse = {
|
|
34
|
-
basename: string;
|
|
35
|
-
imagePath: string;
|
|
36
|
-
thumbnailPath: string;
|
|
37
|
-
metadataPath: string;
|
|
38
|
-
totalSize: number;
|
|
39
|
-
nftUpdated: true;
|
|
40
|
-
message?: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const FILESYSTEM_PATH_INFO_QUERY_MESSAGE_TYPE = 60802;
|
|
44
|
-
const FILESYSTEM_FILE_WRITE_MESSAGE_TYPE = 60805;
|
|
45
|
-
const FILESYSTEM_DIR_LIST_MESSAGE_TYPE = 60808;
|
|
46
|
-
const NFT_UPDATE_MESSAGE_TYPE = 61500;
|
|
47
|
-
|
|
48
|
-
export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
|
|
49
|
-
private bundle?: Pro2NftBundle;
|
|
50
|
-
|
|
51
|
-
getSupportedProtocols() {
|
|
52
|
-
return ['V2'] as const;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
init() {
|
|
56
|
-
const {
|
|
57
|
-
image,
|
|
58
|
-
thumbnail,
|
|
59
|
-
title,
|
|
60
|
-
subtitle,
|
|
61
|
-
timestampMs = Date.now(),
|
|
62
|
-
chunkSize = PRO2_NFT_DEFAULT_CHUNK_SIZE,
|
|
63
|
-
paceMs = PRO2_NFT_DEFAULT_PACE_MS,
|
|
64
|
-
timeoutMs = PRO2_NFT_DEFAULT_TIMEOUT_MS,
|
|
65
|
-
} = this.payload;
|
|
66
|
-
if (
|
|
67
|
-
!Number.isInteger(chunkSize) ||
|
|
68
|
-
chunkSize < PRO2_NFT_MIN_CHUNK_SIZE ||
|
|
69
|
-
chunkSize > PRO2_NFT_MAX_CHUNK_SIZE
|
|
70
|
-
) {
|
|
71
|
-
throw invalidParameter(
|
|
72
|
-
`Parameter [chunkSize] must be an integer between ${PRO2_NFT_MIN_CHUNK_SIZE} and ${PRO2_NFT_MAX_CHUNK_SIZE}.`
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
if (!Number.isInteger(paceMs) || paceMs < 0) {
|
|
76
|
-
throw invalidParameter('Parameter [paceMs] must be a non-negative integer.');
|
|
77
|
-
}
|
|
78
|
-
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
|
|
79
|
-
throw invalidParameter('Parameter [timeoutMs] must be a positive integer.');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.bundle = buildPro2NftBundle({ image, thumbnail, title, subtitle, timestampMs });
|
|
83
|
-
this.params = { image, thumbnail, title, subtitle, timestampMs, chunkSize, paceMs, timeoutMs };
|
|
84
|
-
this.unlockPolicy = 'none';
|
|
85
|
-
this.skipForceUpdateCheck = true;
|
|
86
|
-
this.useDevicePassphraseState = false;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private async assertCapabilities() {
|
|
90
|
-
const protocolInfo = await this.device.ensureProtocolV2RuntimeContext();
|
|
91
|
-
const hasFileWrite = supportsProtocolV2Message(
|
|
92
|
-
protocolInfo,
|
|
93
|
-
FILESYSTEM_FILE_WRITE_MESSAGE_TYPE
|
|
94
|
-
);
|
|
95
|
-
const hasPathInfo = supportsProtocolV2Message(
|
|
96
|
-
protocolInfo,
|
|
97
|
-
FILESYSTEM_PATH_INFO_QUERY_MESSAGE_TYPE
|
|
98
|
-
);
|
|
99
|
-
const hasDirList = supportsProtocolV2Message(protocolInfo, FILESYSTEM_DIR_LIST_MESSAGE_TYPE);
|
|
100
|
-
const hasNftUpdate = supportsProtocolV2Message(protocolInfo, NFT_UPDATE_MESSAGE_TYPE);
|
|
101
|
-
if (!hasFileWrite || !hasPathInfo || !hasDirList || !hasNftUpdate) {
|
|
102
|
-
throw createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private async assertStorageCapacity(basename: string) {
|
|
107
|
-
const { message: pathInfo } = await this.device.commands.typedCall(
|
|
108
|
-
'FilesystemPathInfoQuery',
|
|
109
|
-
'FilesystemPathInfo',
|
|
110
|
-
{ path: PRO2_NFT_DIRECTORY },
|
|
111
|
-
{ timeoutMs: this.params.timeoutMs }
|
|
112
|
-
);
|
|
113
|
-
if (!pathInfo.exist) return;
|
|
114
|
-
|
|
115
|
-
const { message } = await this.device.commands.typedCall(
|
|
116
|
-
'FilesystemDirList',
|
|
117
|
-
'FilesystemDir',
|
|
118
|
-
{ path: PRO2_NFT_DIRECTORY, depth: 1 },
|
|
119
|
-
{ timeoutMs: this.params.timeoutMs }
|
|
120
|
-
);
|
|
121
|
-
const existingBasenames = getCompletePro2NftBasenames(message.child_files);
|
|
122
|
-
if (existingBasenames.size >= PRO2_NFT_MAX_ITEMS && !existingBasenames.has(basename)) {
|
|
123
|
-
throw ERRORS.TypedError(HardwareErrorCode.NftStorageLimitReached, undefined, {
|
|
124
|
-
count: existingBasenames.size,
|
|
125
|
-
limit: PRO2_NFT_MAX_ITEMS,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private async updateNft(basename: string) {
|
|
131
|
-
return this.device.commands.typedCall(
|
|
132
|
-
'NftUpdate',
|
|
133
|
-
'Success',
|
|
134
|
-
{ file_name_no_ext: basename },
|
|
135
|
-
{ timeoutMs: this.params.timeoutMs }
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async run(): Promise<DeviceUploadNftResponse> {
|
|
140
|
-
const { bundle } = this;
|
|
141
|
-
if (!bundle) throw invalidParameter('NFT data has not been initialized.');
|
|
142
|
-
|
|
143
|
-
await this.assertCapabilities();
|
|
144
|
-
this.throwIfAborted();
|
|
145
|
-
await this.assertStorageCapacity(bundle.basename);
|
|
146
|
-
this.throwIfAborted();
|
|
147
|
-
|
|
148
|
-
const files = [
|
|
149
|
-
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.bin`, data: bundle.image },
|
|
150
|
-
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}_m.bin`, data: bundle.thumbnail },
|
|
151
|
-
{ path: `${PRO2_NFT_DIRECTORY}/${bundle.basename}.json`, data: bundle.metadata },
|
|
152
|
-
];
|
|
153
|
-
const totalSize = files.reduce((sum, file) => sum + file.data.byteLength, 0);
|
|
154
|
-
let transferredBeforeFile = 0;
|
|
155
|
-
|
|
156
|
-
for (const file of files) {
|
|
157
|
-
const transferredAtFileStart = transferredBeforeFile;
|
|
158
|
-
await writeProtocolV2File({
|
|
159
|
-
commands: this.device.commands,
|
|
160
|
-
path: file.path,
|
|
161
|
-
data: file.data,
|
|
162
|
-
totalSize: file.data.byteLength,
|
|
163
|
-
chunkSize: this.params.chunkSize,
|
|
164
|
-
timeoutMs: this.params.timeoutMs,
|
|
165
|
-
paceMs: this.params.paceMs,
|
|
166
|
-
overwrite: true,
|
|
167
|
-
append: false,
|
|
168
|
-
throwIfAborted: () => this.throwIfAborted(),
|
|
169
|
-
onProgress: progress => {
|
|
170
|
-
if (typeof this.postMessage !== 'function') return;
|
|
171
|
-
const transferredBytes = transferredAtFileStart + progress.transferredBytes;
|
|
172
|
-
this.postMessage(
|
|
173
|
-
createUiMessage(UI_REQUEST.DEVICE_PROGRESS, {
|
|
174
|
-
...progress,
|
|
175
|
-
progress: Math.floor((transferredBytes / totalSize) * 100),
|
|
176
|
-
transferredBytes,
|
|
177
|
-
totalBytes: totalSize,
|
|
178
|
-
})
|
|
179
|
-
);
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
transferredBeforeFile += file.data.byteLength;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
this.throwIfAborted();
|
|
186
|
-
const response = await this.updateNft(bundle.basename);
|
|
187
|
-
return {
|
|
188
|
-
basename: bundle.basename,
|
|
189
|
-
imagePath: files[0].path,
|
|
190
|
-
thumbnailPath: files[1].path,
|
|
191
|
-
metadataPath: files[2].path,
|
|
192
|
-
totalSize,
|
|
193
|
-
nftUpdated: true,
|
|
194
|
-
message: response.message?.message,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { UI_RESPONSE } from '../events/ui-response';
|
|
2
|
-
|
|
3
|
-
import type { UiPromise, UiPromiseResponse } from '../events/ui-promise';
|
|
4
|
-
import type { UiResponseEvent } from '../events/ui-response';
|
|
5
|
-
|
|
6
|
-
const normalizeUiPromiseError = (error: unknown) =>
|
|
7
|
-
error instanceof Error ? error : new Error(String(error));
|
|
8
|
-
|
|
9
|
-
export const consumeUiPromise = <T>(
|
|
10
|
-
promise: Promise<T>,
|
|
11
|
-
onFulfilled: (value: T) => void,
|
|
12
|
-
onRejected: (error: Error) => void
|
|
13
|
-
) => {
|
|
14
|
-
promise.then(onFulfilled, error => {
|
|
15
|
-
onRejected(normalizeUiPromiseError(error));
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const rejectUiPromises = (
|
|
20
|
-
uiPromises: UiPromise<UiPromiseResponse['type']>[],
|
|
21
|
-
error: Error
|
|
22
|
-
) => {
|
|
23
|
-
for (const uiPromise of uiPromises) {
|
|
24
|
-
uiPromise.reject(error);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const isSensitiveUiResponse = (
|
|
29
|
-
response: UiResponseEvent
|
|
30
|
-
): response is Extract<
|
|
31
|
-
UiResponseEvent,
|
|
32
|
-
{ type: typeof UI_RESPONSE.RECEIVE_PIN | typeof UI_RESPONSE.RECEIVE_PASSPHRASE }
|
|
33
|
-
> => response.type === UI_RESPONSE.RECEIVE_PIN || response.type === UI_RESPONSE.RECEIVE_PASSPHRASE;
|
|
34
|
-
|
|
35
|
-
export const findUiPromiseForResponse = (
|
|
36
|
-
uiPromises: UiPromise<UiPromiseResponse['type']>[],
|
|
37
|
-
response: UiResponseEvent
|
|
38
|
-
) => {
|
|
39
|
-
const candidates = uiPromises.filter(promise => promise.id === response.type);
|
|
40
|
-
if (!isSensitiveUiResponse(response)) {
|
|
41
|
-
return candidates[0];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const hasInteractionId = typeof response.interactionId === 'string';
|
|
45
|
-
const hasDeviceId = typeof response.deviceId === 'string';
|
|
46
|
-
if (hasInteractionId !== hasDeviceId) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (hasInteractionId && hasDeviceId) {
|
|
51
|
-
return candidates.find(promise => {
|
|
52
|
-
const correlation = promise.responseCorrelation;
|
|
53
|
-
return (
|
|
54
|
-
correlation?.interactionId === response.interactionId &&
|
|
55
|
-
correlation?.deviceId === response.deviceId
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Legacy clients do not return correlation metadata. Preserve their single-request
|
|
61
|
-
// behavior, but never guess when multiple sensitive requests are pending.
|
|
62
|
-
return candidates.length === 1 ? candidates[0] : undefined;
|
|
63
|
-
};
|