@onekeyfe/hd-core 1.2.0-alpha.56 → 1.2.0-alpha.62
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 -231
- 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__/device-state-contract.test.ts +0 -1
- package/__tests__/device-state-mapper.test.ts +1 -1
- package/__tests__/deviceSettings.test.ts +1 -1
- 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__/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 +35 -201
- package/__tests__/protocol-v2.test.ts +1046 -1388
- package/__tests__/protocolV2FileWrite.test.ts +0 -39
- 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/kaspa/KaspaSignTransaction.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 +3530 -2634
- 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 +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 +975 -584
- package/src/api/GetPassphraseState.ts +1 -7
- package/src/api/OpenWalletSession.ts +17 -70
- package/src/api/SearchDevices.ts +1 -3
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -34
- 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 +7 -27
- package/src/api/index.ts +0 -2
- package/src/api/kaspa/KaspaSignTransaction.ts +12 -1
- 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 +39 -71
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +43 -259
- 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 +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 +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 -286
- 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 -6
- package/src/utils/pro2Nft.ts +0 -142
- package/src/utils/uiProgressThrottle.ts +0 -63
|
@@ -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
|
+
}
|
|
@@ -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;
|
package/src/types/api/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
deviceGetOnboardingStatus,
|
|
3
3
|
deviceReboot,
|
|
4
|
-
deviceUploadNft,
|
|
5
4
|
deviceUploadWallpaper,
|
|
6
5
|
testProtocolV2Ping,
|
|
7
6
|
uploadPortfolio,
|
|
@@ -19,7 +18,6 @@ import type { checkBootloaderRelease } from './checkBootloaderRelease';
|
|
|
19
18
|
import type { checkAllFirmwareRelease } from './checkAllFirmwareRelease';
|
|
20
19
|
import type { checkFirmwareTypeAvailable } from './checkFirmwareTypeAvailable';
|
|
21
20
|
import type { searchDevices } from './searchDevices';
|
|
22
|
-
import type { detectDeviceConnectProtocol } from './detectDeviceConnectProtocol';
|
|
23
21
|
import type { getFeatures } from './getFeatures';
|
|
24
22
|
import type { getDeviceState } from './getDeviceState';
|
|
25
23
|
import type { getOnekeyFeatures } from './getOnekeyFeatures';
|
|
@@ -32,7 +30,15 @@ import type {
|
|
|
32
30
|
firmwareUpdateV2,
|
|
33
31
|
firmwareUpdateV3,
|
|
34
32
|
firmwareUpdateV4,
|
|
33
|
+
getFirmwareUpdateHostBindingGeneration,
|
|
34
|
+
registerFirmwareUpdateHostBinding,
|
|
35
|
+
unregisterFirmwareUpdateHostBinding,
|
|
35
36
|
} from './firmwareUpdate';
|
|
37
|
+
import type { getFirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
|
|
38
|
+
import type {
|
|
39
|
+
prepareFirmwareUpdatePlan,
|
|
40
|
+
validateFirmwareUpdatePreparedPlan,
|
|
41
|
+
} from './firmwareUpdatePreparedPlan';
|
|
36
42
|
import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
|
|
37
43
|
import type { deviceReset } from './deviceReset';
|
|
38
44
|
import type { deviceRecovery } from './deviceRecovery';
|
|
@@ -146,7 +152,6 @@ import type { benfenSignMessage } from './benfenSignMessage';
|
|
|
146
152
|
import type { neoGetAddress } from './neoGetAddress';
|
|
147
153
|
import type { neoSignTransaction } from './neoSignTransaction';
|
|
148
154
|
import type { ConnectSettings } from '../settings';
|
|
149
|
-
import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
150
155
|
|
|
151
156
|
export * from './export';
|
|
152
157
|
export type { DeviceStateScope, GetDeviceStateParams } from './getDeviceState';
|
|
@@ -171,14 +176,6 @@ export type CoreApi = {
|
|
|
171
176
|
removeAllListeners: typeof removeAllListeners;
|
|
172
177
|
dispose: () => void | Promise<void>;
|
|
173
178
|
call: (params: any) => Promise<any>;
|
|
174
|
-
/**
|
|
175
|
-
* Bind a protocol that has already been verified for one transport endpoint.
|
|
176
|
-
* Every later SDK call for the same connectId uses it as a strict expectation.
|
|
177
|
-
*/
|
|
178
|
-
setDeviceConnectProtocol: (
|
|
179
|
-
connectId: string,
|
|
180
|
-
connectProtocol: HardwareConnectProtocol | undefined
|
|
181
|
-
) => void;
|
|
182
179
|
uiResponse: typeof uiResponse;
|
|
183
180
|
cancel: (connectId?: string) => void;
|
|
184
181
|
updateSettings: typeof updateSettings;
|
|
@@ -206,7 +203,6 @@ export type CoreApi = {
|
|
|
206
203
|
* Device function
|
|
207
204
|
*/
|
|
208
205
|
searchDevices: typeof searchDevices;
|
|
209
|
-
detectDeviceConnectProtocol: typeof detectDeviceConnectProtocol;
|
|
210
206
|
promptWebDeviceAccess: typeof promptWebDeviceAccess;
|
|
211
207
|
getFeatures: typeof getFeatures;
|
|
212
208
|
getDeviceState: typeof getDeviceState;
|
|
@@ -239,6 +235,12 @@ export type CoreApi = {
|
|
|
239
235
|
firmwareUpdateV2: typeof firmwareUpdateV2;
|
|
240
236
|
firmwareUpdateV3: typeof firmwareUpdateV3;
|
|
241
237
|
firmwareUpdateV4: typeof firmwareUpdateV4;
|
|
238
|
+
registerFirmwareUpdateHostBinding: typeof registerFirmwareUpdateHostBinding;
|
|
239
|
+
unregisterFirmwareUpdateHostBinding: typeof unregisterFirmwareUpdateHostBinding;
|
|
240
|
+
getFirmwareUpdateHostBindingGeneration: typeof getFirmwareUpdateHostBindingGeneration;
|
|
241
|
+
getFirmwareUpdateCapabilities: typeof getFirmwareUpdateCapabilities;
|
|
242
|
+
prepareFirmwareUpdatePlan: typeof prepareFirmwareUpdatePlan;
|
|
243
|
+
validateFirmwareUpdatePreparedPlan: typeof validateFirmwareUpdatePreparedPlan;
|
|
242
244
|
cipherKeyValue: typeof cipherKeyValue;
|
|
243
245
|
|
|
244
246
|
/**
|
|
@@ -246,7 +248,6 @@ export type CoreApi = {
|
|
|
246
248
|
*/
|
|
247
249
|
deviceReboot: typeof deviceReboot;
|
|
248
250
|
deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
|
|
249
|
-
deviceUploadNft: typeof deviceUploadNft;
|
|
250
251
|
deviceUploadWallpaper: typeof deviceUploadWallpaper;
|
|
251
252
|
uploadPortfolio: typeof uploadPortfolio;
|
|
252
253
|
|
|
@@ -5,10 +5,6 @@ import type {
|
|
|
5
5
|
DeviceUploadWallpaperParams,
|
|
6
6
|
DeviceUploadWallpaperResponse,
|
|
7
7
|
} from '../../api/protocol-v2/DeviceUploadWallpaper';
|
|
8
|
-
import type {
|
|
9
|
-
DeviceUploadNftParams,
|
|
10
|
-
DeviceUploadNftResponse,
|
|
11
|
-
} from '../../api/protocol-v2/DeviceUploadNft';
|
|
12
8
|
|
|
13
9
|
// Re-export implementation parameter types as the single source of truth.
|
|
14
10
|
export type { DeviceRebootParams, RebootTypeInput } from '../../api/protocol-v2/helpers';
|
|
@@ -16,10 +12,6 @@ export type {
|
|
|
16
12
|
DeviceUploadWallpaperParams,
|
|
17
13
|
DeviceUploadWallpaperResponse,
|
|
18
14
|
} from '../../api/protocol-v2/DeviceUploadWallpaper';
|
|
19
|
-
export type {
|
|
20
|
-
DeviceUploadNftParams,
|
|
21
|
-
DeviceUploadNftResponse,
|
|
22
|
-
} from '../../api/protocol-v2/DeviceUploadNft';
|
|
23
15
|
|
|
24
16
|
// ── Shared response shapes (Protocol V2 file system) ────────────────────
|
|
25
17
|
|
|
@@ -60,11 +52,6 @@ export declare function deviceUploadWallpaper(
|
|
|
60
52
|
params: CommonParams & DeviceUploadWallpaperParams
|
|
61
53
|
): Response<DeviceUploadWallpaperResponse>;
|
|
62
54
|
|
|
63
|
-
export declare function deviceUploadNft(
|
|
64
|
-
connectId: string,
|
|
65
|
-
params: CommonParams & DeviceUploadNftParams
|
|
66
|
-
): Response<DeviceUploadNftResponse>;
|
|
67
|
-
|
|
68
55
|
export declare function uploadPortfolio(
|
|
69
56
|
connectId: string,
|
|
70
57
|
params: {
|
package/src/types/device.ts
CHANGED
|
@@ -210,9 +210,7 @@ export type DeviceStateStatus = {
|
|
|
210
210
|
recoveryMode: boolean | null;
|
|
211
211
|
passphraseProtection: boolean | null;
|
|
212
212
|
pinProtection: boolean | null;
|
|
213
|
-
/** `attach_to_pin_enabled`:是否至少存在一个 Attach PIN 绑定。 */
|
|
214
213
|
attachToPinEnabled: boolean | null;
|
|
215
|
-
/** `unlocked_by_attach_to_pin`:本次解锁是否由 Attach PIN 完成。 */
|
|
216
214
|
unlockedAttachPin: boolean | null;
|
|
217
215
|
};
|
|
218
216
|
|
|
@@ -323,7 +321,6 @@ export type NormalizedFeatures = {
|
|
|
323
321
|
sdProtection: boolean | null;
|
|
324
322
|
wipeCodeProtection: boolean | null;
|
|
325
323
|
passphraseAlwaysOnDevice: boolean | null;
|
|
326
|
-
/** `attach_to_pin_enabled`:是否至少存在一个 Attach PIN 绑定。 */
|
|
327
324
|
attachToPinEnabled?: boolean | null;
|
|
328
325
|
safetyChecks: Enum_SafetyCheckLevel | null;
|
|
329
326
|
autoLockDelayMs: number | null;
|
package/src/types/params.ts
CHANGED
|
@@ -61,15 +61,9 @@ export interface CommonParams {
|
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Strictly expected transport protocol. The SDK actively verifies this value and
|
|
64
|
-
* rejects a mismatch.
|
|
64
|
+
* rejects a mismatch. If omitted, a cached protocol only influences probe order.
|
|
65
65
|
*/
|
|
66
66
|
connectProtocol?: HardwareConnectProtocol;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Ignore a previously bound protocol for this call and actively detect the
|
|
70
|
-
* protocol again. Intended for the first verified connection or explicit recovery.
|
|
71
|
-
*/
|
|
72
|
-
forceProtocolDetection?: boolean;
|
|
73
67
|
}
|
|
74
68
|
|
|
75
69
|
export type Params<T> = CommonParams & T & { bundle?: undefined };
|
package/src/types/settings.ts
CHANGED
|
@@ -31,6 +31,8 @@ export type ConnectSettings = {
|
|
|
31
31
|
timestamp: number;
|
|
32
32
|
isFrame?: boolean;
|
|
33
33
|
preRelease?: boolean;
|
|
34
|
+
firmwareManifestMode?: 'sdk-managed' | 'external-only';
|
|
35
|
+
preloadedConfig?: RemoteConfigResponse;
|
|
34
36
|
fetchConfig?: boolean;
|
|
35
37
|
extension?: string;
|
|
36
38
|
configFetcher?: (url: string) => Promise<RemoteConfigResponse | null>;
|
|
@@ -58,55 +60,18 @@ export type IProtocolV2FirmwareComponent = {
|
|
|
58
60
|
fingerprint?: string;
|
|
59
61
|
/** OKPP payload hash, used to detect same-version package changes. */
|
|
60
62
|
payloadHash?: string;
|
|
63
|
+
expectedSize?: number;
|
|
61
64
|
version?: IVersionArray;
|
|
62
65
|
};
|
|
63
66
|
|
|
64
|
-
export type IProtocolV2ResourceType =
|
|
65
|
-
| 'images'
|
|
66
|
-
| 'animation'
|
|
67
|
-
| 'wallpaper'
|
|
68
|
-
| 'translations'
|
|
69
|
-
| 'roobert'
|
|
70
|
-
| 'noto';
|
|
71
|
-
|
|
72
|
-
/** Pro2 RES package descriptor. Hashes identify content without a human-managed version. */
|
|
73
|
-
export type IProtocolV2Resource = {
|
|
74
|
-
type: IProtocolV2ResourceType;
|
|
75
|
-
url: string;
|
|
76
|
-
/** Complete okpkg file size in bytes. */
|
|
77
|
-
size: number;
|
|
78
|
-
/** SHA-256 of the complete okpkg file. */
|
|
79
|
-
fileHash: string;
|
|
80
|
-
/** SHA3-512 header_hash from the signed okpkg header. */
|
|
81
|
-
headerHash: string;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/** Optional Pro2 startup-resource CRATE installed by the bootloader updater. */
|
|
85
|
-
export type IProtocolV2BootResources = {
|
|
86
|
-
required: false;
|
|
87
|
-
target: 'CRATE';
|
|
88
|
-
url: string;
|
|
89
|
-
/** Complete CRATE file size in bytes. */
|
|
90
|
-
size: number;
|
|
91
|
-
/** SHA-256 of the complete CRATE file. */
|
|
92
|
-
fileHash: string;
|
|
93
|
-
/** SHA3-512 payload_hash from the signed CRATE header. */
|
|
94
|
-
payloadHash: string;
|
|
95
|
-
/** SHA3-512 header_hash from the signed CRATE header. */
|
|
96
|
-
headerHash: string;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export type IProtocolV2Resources = {
|
|
100
|
-
stable: IProtocolV2Resource[];
|
|
101
|
-
boot?: IProtocolV2BootResources;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
67
|
/** Pro2 RESC bundle okpkg descriptor for incremental FileWrite synchronization. */
|
|
105
68
|
export type IProtocolV2ResourceBundle = {
|
|
106
69
|
/** Bundle name, such as images, animation, translations, or fonts_roobert. */
|
|
107
70
|
name: string;
|
|
108
71
|
/** Download URL. */
|
|
109
72
|
url: string;
|
|
73
|
+
fingerprint?: string;
|
|
74
|
+
expectedSize?: number;
|
|
110
75
|
/** Device target path, such as vol0:/bundles/images/images.okpkg. */
|
|
111
76
|
devicePath: string;
|
|
112
77
|
/** okpkg payload_version used to skip matching content after FileRead. */
|
|
@@ -128,10 +93,16 @@ export type IFirmwareReleaseInfo = {
|
|
|
128
93
|
firmwareType?: EFirmwareType;
|
|
129
94
|
/** Firmware UI resource */
|
|
130
95
|
resource?: string;
|
|
96
|
+
resourceFingerprint?: string;
|
|
97
|
+
resourceExpectedSize?: number;
|
|
131
98
|
/** Firmware full UI resource */
|
|
132
99
|
fullResource?: string;
|
|
100
|
+
fullResourceFingerprint?: string;
|
|
101
|
+
fullResourceExpectedSize?: number;
|
|
133
102
|
fullResourceRange?: string[];
|
|
134
103
|
bootloaderResource?: string;
|
|
104
|
+
bootloaderFingerprint?: string;
|
|
105
|
+
bootloaderExpectedSize?: number;
|
|
135
106
|
bootloaderVersion?: IVersionArray;
|
|
136
107
|
displayBootloaderVersion?: IVersionArray;
|
|
137
108
|
bootloaderRelatedFirmwareVersion?: IVersionArray;
|
|
@@ -144,6 +115,7 @@ export type IFirmwareReleaseInfo = {
|
|
|
144
115
|
[k in ILocale]: string;
|
|
145
116
|
};
|
|
146
117
|
fingerprint: string;
|
|
118
|
+
expectedSize?: number;
|
|
147
119
|
version: IVersionArray;
|
|
148
120
|
changelog: {
|
|
149
121
|
[k in ILocale]: string;
|
|
@@ -159,6 +131,7 @@ export type IBLEFirmwareReleaseInfo = {
|
|
|
159
131
|
webUpdate: string;
|
|
160
132
|
fingerprint: string;
|
|
161
133
|
fingerprintWeb: string;
|
|
134
|
+
expectedSize?: number;
|
|
162
135
|
version: IVersionArray;
|
|
163
136
|
changelog: {
|
|
164
137
|
[k in ILocale]: string;
|
|
@@ -176,8 +149,6 @@ export type DeviceTypeMap = {
|
|
|
176
149
|
'firmware-v8'?: IFirmwareReleaseInfo[];
|
|
177
150
|
'firmware-btc-v8'?: IFirmwareReleaseInfo[];
|
|
178
151
|
ble: IBLEFirmwareReleaseInfo[];
|
|
179
|
-
/** Independent Pro2 resource release configuration. */
|
|
180
|
-
resources?: IProtocolV2Resources;
|
|
181
152
|
};
|
|
182
153
|
};
|
|
183
154
|
|
|
@@ -37,6 +37,12 @@ export const resolveDeviceSerialNo = (features?: DeviceFeaturesInput): string =>
|
|
|
37
37
|
);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
export const resolveDeviceBootloaderMode = (features?: DeviceFeaturesInput): boolean => {
|
|
41
|
+
if (!features) return false;
|
|
42
|
+
const compatible = asCompatibleFeatures(features);
|
|
43
|
+
return (compatible.bootloaderMode ?? compatible.bootloader_mode) === true;
|
|
44
|
+
};
|
|
45
|
+
|
|
40
46
|
export const resolveDeviceType = (features?: DeviceFeaturesInput): IDeviceType => {
|
|
41
47
|
if (!features || typeof features !== 'object') {
|
|
42
48
|
return EDeviceType.Unknown;
|
|
@@ -106,8 +106,6 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
106
106
|
expectPassphraseState?: string;
|
|
107
107
|
onlyMainPin?: boolean;
|
|
108
108
|
initSession?: boolean;
|
|
109
|
-
deriveCardano?: boolean;
|
|
110
|
-
rejectAttachPinForMainWallet?: boolean;
|
|
111
109
|
}
|
|
112
110
|
) => {
|
|
113
111
|
if (device.isProtocolV2()) {
|
|
@@ -123,8 +121,6 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
123
121
|
initSession: options?.initSession,
|
|
124
122
|
expectedPassphraseState: options?.expectPassphraseState,
|
|
125
123
|
onlyMainPin: options?.onlyMainPin,
|
|
126
|
-
deriveCardano: options?.deriveCardano,
|
|
127
|
-
rejectAttachPinForMainWallet: options?.rejectAttachPinForMainWallet,
|
|
128
124
|
});
|
|
129
125
|
}
|
|
130
126
|
|
|
@@ -189,8 +185,6 @@ export const getPassphraseState = async (
|
|
|
189
185
|
expectPassphraseState?: string;
|
|
190
186
|
onlyMainPin?: boolean;
|
|
191
187
|
initSession?: boolean;
|
|
192
|
-
deriveCardano?: boolean;
|
|
193
|
-
rejectAttachPinForMainWallet?: boolean;
|
|
194
188
|
}
|
|
195
189
|
): Promise<{
|
|
196
190
|
passphraseState: string | undefined;
|
|
@@ -211,8 +205,6 @@ export const getPassphraseState = async (
|
|
|
211
205
|
initSession: options?.initSession,
|
|
212
206
|
expectedPassphraseState: options?.expectPassphraseState,
|
|
213
207
|
onlyMainPin: options?.onlyMainPin,
|
|
214
|
-
deriveCardano: options?.deriveCardano,
|
|
215
|
-
rejectAttachPinForMainWallet: options?.rejectAttachPinForMainWallet,
|
|
216
208
|
});
|
|
217
209
|
}
|
|
218
210
|
|
package/src/utils/homescreen.ts
CHANGED
|
@@ -4,12 +4,6 @@ import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
|
4
4
|
import { getDeviceType } from './deviceInfoUtils';
|
|
5
5
|
import { getDeviceFirmwareVersion } from './deviceVersionUtils';
|
|
6
6
|
import { PRO2_WALLPAPER_HEIGHT, PRO2_WALLPAPER_WIDTH } from './pro2Wallpaper';
|
|
7
|
-
import {
|
|
8
|
-
PRO2_NFT_IMAGE_HEIGHT,
|
|
9
|
-
PRO2_NFT_IMAGE_WIDTH,
|
|
10
|
-
PRO2_NFT_THUMBNAIL_HEIGHT,
|
|
11
|
-
PRO2_NFT_THUMBNAIL_WIDTH,
|
|
12
|
-
} from './pro2Nft';
|
|
13
7
|
|
|
14
8
|
import type { Features, IDeviceType } from '../types';
|
|
15
9
|
|
|
@@ -308,31 +302,6 @@ type SizeConfig = {
|
|
|
308
302
|
radius?: number;
|
|
309
303
|
};
|
|
310
304
|
|
|
311
|
-
export const getNftSize = ({
|
|
312
|
-
deviceType,
|
|
313
|
-
thumbnail,
|
|
314
|
-
}: {
|
|
315
|
-
deviceType: IDeviceType;
|
|
316
|
-
thumbnail?: boolean;
|
|
317
|
-
}): SizeConfig | undefined => {
|
|
318
|
-
const sizes: Partial<Record<IDeviceType, { full: SizeConfig; thumbnail: SizeConfig }>> = {
|
|
319
|
-
touch: {
|
|
320
|
-
full: { width: 480, height: 800 },
|
|
321
|
-
thumbnail: { width: 238, height: 238 },
|
|
322
|
-
},
|
|
323
|
-
pro: {
|
|
324
|
-
full: { width: 480, height: 800 },
|
|
325
|
-
thumbnail: { width: 226, height: 226, radius: 40 },
|
|
326
|
-
},
|
|
327
|
-
pro2: {
|
|
328
|
-
full: { width: PRO2_NFT_IMAGE_WIDTH, height: PRO2_NFT_IMAGE_HEIGHT },
|
|
329
|
-
thumbnail: { width: PRO2_NFT_THUMBNAIL_WIDTH, height: PRO2_NFT_THUMBNAIL_HEIGHT },
|
|
330
|
-
},
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
return sizes[deviceType]?.[thumbnail ? 'thumbnail' : 'full'];
|
|
334
|
-
};
|
|
335
|
-
|
|
336
305
|
export const getHomeScreenSize = ({
|
|
337
306
|
deviceType,
|
|
338
307
|
homeScreenType,
|
|
@@ -343,7 +312,12 @@ export const getHomeScreenSize = ({
|
|
|
343
312
|
thumbnail?: boolean;
|
|
344
313
|
}) => {
|
|
345
314
|
if (deviceType === EDeviceType.Pro2) {
|
|
346
|
-
return thumbnail
|
|
315
|
+
return thumbnail
|
|
316
|
+
? undefined
|
|
317
|
+
: {
|
|
318
|
+
width: PRO2_WALLPAPER_WIDTH,
|
|
319
|
+
height: PRO2_WALLPAPER_HEIGHT,
|
|
320
|
+
};
|
|
347
321
|
}
|
|
348
322
|
|
|
349
323
|
const sizes: Partial<
|
package/src/utils/index.ts
CHANGED
|
@@ -54,12 +54,7 @@ export { getHDPath, getScriptType, getOutputScriptType } from '../api/helpers/pa
|
|
|
54
54
|
|
|
55
55
|
export const isBleConnect = (env: string) => env === 'react-native' || env === 'lowlevel';
|
|
56
56
|
|
|
57
|
-
export {
|
|
58
|
-
getHomeScreenHex,
|
|
59
|
-
getHomeScreenDefaultList,
|
|
60
|
-
getHomeScreenSize,
|
|
61
|
-
getNftSize,
|
|
62
|
-
} from './homescreen';
|
|
57
|
+
export { getHomeScreenHex, getHomeScreenDefaultList, getHomeScreenSize } from './homescreen';
|
|
63
58
|
export { encodePro2Wallpaper, PRO2_WALLPAPER_HEIGHT, PRO2_WALLPAPER_WIDTH } from './pro2Wallpaper';
|
|
64
59
|
export type { Pro2WallpaperColorFormat } from './pro2Wallpaper';
|
|
65
60
|
|
|
@@ -8,8 +8,6 @@ export const PRO2_WALLPAPER_HEIGHT = 1024;
|
|
|
8
8
|
|
|
9
9
|
export type Pro2WallpaperColorFormat = 'RGB565' | 'RGB565A8';
|
|
10
10
|
|
|
11
|
-
export type Pro2ImageAlphaMode = 'preserve' | 'black-background';
|
|
12
|
-
|
|
13
11
|
const COLOR_FORMAT_RGB565 = 0x12;
|
|
14
12
|
const COLOR_FORMAT_RGB565A8 = 0x14;
|
|
15
13
|
|
|
@@ -38,11 +36,10 @@ function align(value: number, boundary: number): number {
|
|
|
38
36
|
return Math.ceil(value / boundary) * boundary;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
export function
|
|
39
|
+
export function encodePro2Wallpaper(options: {
|
|
42
40
|
width: number;
|
|
43
41
|
height: number;
|
|
44
42
|
rgba: Uint8Array | ArrayBuffer;
|
|
45
|
-
alphaMode?: Pro2ImageAlphaMode;
|
|
46
43
|
}): { data: Uint8Array; colorFormat: Pro2WallpaperColorFormat } {
|
|
47
44
|
const { width, height } = options;
|
|
48
45
|
if (!Number.isInteger(width) || width <= 0 || width > 0xffff) {
|
|
@@ -60,14 +57,11 @@ export function encodePro2Image(options: {
|
|
|
60
57
|
);
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
const alphaMode = options.alphaMode ?? 'preserve';
|
|
64
60
|
let hasTransparency = false;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
61
|
+
for (let index = 3; index < rgba.length; index += 4) {
|
|
62
|
+
if (rgba[index] !== 0xff) {
|
|
63
|
+
hasTransparency = true;
|
|
64
|
+
break;
|
|
71
65
|
}
|
|
72
66
|
}
|
|
73
67
|
|
|
@@ -91,22 +85,9 @@ export function encodePro2Image(options: {
|
|
|
91
85
|
for (let x = 0; x < width; x += 1) {
|
|
92
86
|
const sourceOffset = (y * width + x) * 4;
|
|
93
87
|
const thresholdIndex = ((y & 7) << 3) + (x & 7);
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
? Math.round((rgba[sourceOffset] * alpha) / 0xff)
|
|
98
|
-
: rgba[sourceOffset];
|
|
99
|
-
const greenChannel =
|
|
100
|
-
alphaMode === 'black-background'
|
|
101
|
-
? Math.round((rgba[sourceOffset + 1] * alpha) / 0xff)
|
|
102
|
-
: rgba[sourceOffset + 1];
|
|
103
|
-
const blueChannel =
|
|
104
|
-
alphaMode === 'black-background'
|
|
105
|
-
? Math.round((rgba[sourceOffset + 2] * alpha) / 0xff)
|
|
106
|
-
: rgba[sourceOffset + 2];
|
|
107
|
-
const red = Math.min(redChannel + RED_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
108
|
-
const green = Math.min(greenChannel + GREEN_THRESHOLD[thresholdIndex], 0xff) & 0xfc;
|
|
109
|
-
const blue = Math.min(blueChannel + BLUE_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
88
|
+
const red = Math.min(rgba[sourceOffset] + RED_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
89
|
+
const green = Math.min(rgba[sourceOffset + 1] + GREEN_THRESHOLD[thresholdIndex], 0xff) & 0xfc;
|
|
90
|
+
const blue = Math.min(rgba[sourceOffset + 2] + BLUE_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
110
91
|
const rgb565 = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
|
|
111
92
|
const rgbOffset = 12 + y * stride + x * 2;
|
|
112
93
|
data[rgbOffset] = rgb565 & 0xff;
|
|
@@ -120,11 +101,3 @@ export function encodePro2Image(options: {
|
|
|
120
101
|
|
|
121
102
|
return { data, colorFormat };
|
|
122
103
|
}
|
|
123
|
-
|
|
124
|
-
export function encodePro2Wallpaper(options: {
|
|
125
|
-
width: number;
|
|
126
|
-
height: number;
|
|
127
|
-
rgba: Uint8Array | ArrayBuffer;
|
|
128
|
-
}): { data: Uint8Array; colorFormat: Pro2WallpaperColorFormat } {
|
|
129
|
-
return encodePro2Image(options);
|
|
130
|
-
}
|