@onekeyfe/hd-core 1.2.0-alpha.10 → 1.2.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/DeviceCommands.test.ts +25 -0
- package/__tests__/RequestQueue.test.ts +34 -0
- package/__tests__/pro2Wallpaper.test.ts +50 -0
- package/__tests__/protocol-v2.test.ts +426 -60
- package/dist/api/BaseMethod.d.ts +4 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +0 -4
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +1 -6
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +18 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +1 -4
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +16 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +12 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +26 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -0
- package/dist/core/RequestQueue.d.ts +2 -0
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- 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/events/call.d.ts +7 -0
- package/dist/events/call.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -2
- package/dist/events/core.d.ts.map +1 -1
- package/dist/events/iframe.d.ts +1 -0
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/index.d.ts +76 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +694 -253
- package/dist/inject.d.ts +3 -2
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts +2 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +9 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +2 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts +2 -10
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +8 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +19 -4
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -2
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- 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 +12 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +18 -0
- package/src/api/FileWrite.ts +9 -1
- package/src/api/FirmwareUpdateV4.ts +21 -91
- package/src/api/GetPassphraseState.ts +9 -18
- package/src/api/UploadPortfolio.ts +37 -0
- package/src/api/index.ts +5 -0
- package/src/api/protocol-v2/DeviceSessionGet.ts +3 -14
- package/src/api/protocol-v2/DeviceSettingsGet.ts +16 -0
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +59 -0
- package/src/api/protocol-v2/DeviceSettingsSet.ts +39 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +160 -0
- package/src/core/RequestQueue.ts +19 -0
- package/src/core/index.ts +10 -1
- package/src/data/messages/messages-protocol-v2.json +92 -8
- package/src/device/Device.ts +17 -3
- package/src/device/DeviceCommands.ts +9 -3
- package/src/events/call.ts +6 -0
- package/src/events/core.ts +2 -0
- package/src/events/iframe.ts +1 -0
- package/src/index.ts +4 -0
- package/src/inject.ts +13 -0
- package/src/lowLevelInject.ts +3 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +46 -0
- package/src/protocols/protocol-v2/walletSession.ts +14 -5
- package/src/topLevelInject.ts +2 -0
- package/src/types/api/firmwareUpdate.ts +12 -0
- package/src/types/api/getPassphraseState.ts +2 -11
- package/src/types/api/index.ts +12 -1
- package/src/types/api/protocolV2.ts +46 -3
- package/src/utils/deviceFeaturesUtils.ts +3 -8
- package/src/utils/index.ts +6 -0
- package/src/utils/pro2Wallpaper.ts +111 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
export const PRO2_WALLPAPER_WIDTH = 604;
|
|
4
|
+
export const PRO2_WALLPAPER_HEIGHT = 1024;
|
|
5
|
+
|
|
6
|
+
export type Pro2WallpaperColorFormat = 'RGB565' | 'RGB565A8';
|
|
7
|
+
|
|
8
|
+
const COLOR_FORMAT_RGB565 = 0x12;
|
|
9
|
+
const COLOR_FORMAT_RGB565A8 = 0x14;
|
|
10
|
+
|
|
11
|
+
const RED_THRESHOLD = [
|
|
12
|
+
1, 7, 3, 5, 0, 8, 2, 6, 7, 1, 5, 3, 8, 0, 6, 2, 3, 5, 0, 8, 2, 6, 1, 7, 5, 3, 8,
|
|
13
|
+
0, 6, 2, 7, 1, 0, 8, 2, 6, 1, 7, 3, 5, 8, 0, 6, 2, 7, 1, 5, 3, 2, 6, 1, 7, 3, 5, 0,
|
|
14
|
+
8, 6, 2, 7, 1, 5, 3, 8, 0,
|
|
15
|
+
];
|
|
16
|
+
const GREEN_THRESHOLD = [
|
|
17
|
+
1, 3, 2, 2, 3, 1, 2, 2, 2, 2, 0, 4, 2, 2, 4, 0, 3, 1, 2, 2, 1, 3, 2, 2, 2, 2, 4,
|
|
18
|
+
0, 2, 2, 0, 4, 1, 3, 2, 2, 3, 1, 2, 2, 2, 2, 0, 4, 2, 2, 4, 0, 3, 1, 2, 2, 1, 3, 2,
|
|
19
|
+
2, 2, 2, 4, 0, 2, 2, 0, 4,
|
|
20
|
+
];
|
|
21
|
+
const BLUE_THRESHOLD = [
|
|
22
|
+
5, 3, 8, 0, 6, 2, 7, 1, 3, 5, 0, 8, 2, 6, 1, 7, 8, 0, 6, 2, 7, 1, 5, 3, 0, 8, 2,
|
|
23
|
+
6, 1, 7, 3, 5, 6, 2, 7, 1, 5, 3, 8, 0, 2, 6, 1, 7, 3, 5, 0, 8, 7, 1, 5, 3, 8, 0, 6,
|
|
24
|
+
2, 1, 7, 3, 5, 0, 8, 2, 6,
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
function invalidParameter(message: string): Error {
|
|
28
|
+
return ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, message);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function asBytes(rgba: Uint8Array | ArrayBuffer): Uint8Array {
|
|
32
|
+
return rgba instanceof Uint8Array ? rgba : new Uint8Array(rgba);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function align(value: number, boundary: number): number {
|
|
36
|
+
return Math.ceil(value / boundary) * boundary;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function encodePro2Wallpaper(options: {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
rgba: Uint8Array | ArrayBuffer;
|
|
43
|
+
}): { data: Uint8Array; colorFormat: Pro2WallpaperColorFormat } {
|
|
44
|
+
const { width, height } = options;
|
|
45
|
+
if (!Number.isInteger(width) || width <= 0 || width > 0xffff) {
|
|
46
|
+
throw invalidParameter('Wallpaper width must be an integer between 1 and 65535.');
|
|
47
|
+
}
|
|
48
|
+
if (!Number.isInteger(height) || height <= 0 || height > 0xffff) {
|
|
49
|
+
throw invalidParameter('Wallpaper height must be an integer between 1 and 65535.');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const rgba = asBytes(options.rgba);
|
|
53
|
+
const expectedLength = width * height * 4;
|
|
54
|
+
if (rgba.byteLength !== expectedLength) {
|
|
55
|
+
throw invalidParameter(
|
|
56
|
+
`Wallpaper RGBA data length must be ${expectedLength} bytes, received ${rgba.byteLength}.`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let hasTransparency = false;
|
|
61
|
+
for (let index = 3; index < rgba.length; index += 4) {
|
|
62
|
+
if (rgba[index] !== 0xff) {
|
|
63
|
+
hasTransparency = true;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const colorFormat: Pro2WallpaperColorFormat = hasTransparency ? 'RGB565A8' : 'RGB565';
|
|
69
|
+
const stride = align(width * 2, 4);
|
|
70
|
+
const alphaStride = stride / 2;
|
|
71
|
+
const rgbSize = stride * height;
|
|
72
|
+
const alphaSize = hasTransparency ? alphaStride * height : 0;
|
|
73
|
+
const data = new Uint8Array(12 + rgbSize + alphaSize);
|
|
74
|
+
const view = new DataView(data.buffer);
|
|
75
|
+
|
|
76
|
+
data[0] = 0x19;
|
|
77
|
+
data[1] = hasTransparency ? COLOR_FORMAT_RGB565A8 : COLOR_FORMAT_RGB565;
|
|
78
|
+
view.setUint16(2, 0, true);
|
|
79
|
+
view.setUint16(4, width, true);
|
|
80
|
+
view.setUint16(6, height, true);
|
|
81
|
+
view.setUint16(8, stride, true);
|
|
82
|
+
view.setUint16(10, 0, true);
|
|
83
|
+
|
|
84
|
+
for (let y = 0; y < height; y += 1) {
|
|
85
|
+
for (let x = 0; x < width; x += 1) {
|
|
86
|
+
const sourceOffset = (y * width + x) * 4;
|
|
87
|
+
const thresholdIndex = ((y & 7) << 3) + (x & 7);
|
|
88
|
+
let red = Math.min(rgba[sourceOffset] + RED_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
89
|
+
let green =
|
|
90
|
+
Math.min(rgba[sourceOffset + 1] + GREEN_THRESHOLD[thresholdIndex], 0xff) & 0xfc;
|
|
91
|
+
let blue =
|
|
92
|
+
Math.min(rgba[sourceOffset + 2] + BLUE_THRESHOLD[thresholdIndex], 0xff) & 0xf8;
|
|
93
|
+
if (!hasTransparency) {
|
|
94
|
+
const alpha = rgba[sourceOffset + 3];
|
|
95
|
+
red = (red * alpha) >> 8;
|
|
96
|
+
green = (green * alpha) >> 8;
|
|
97
|
+
blue = (blue * alpha) >> 8;
|
|
98
|
+
}
|
|
99
|
+
const rgb565 = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
|
|
100
|
+
const rgbOffset = 12 + y * stride + x * 2;
|
|
101
|
+
data[rgbOffset] = rgb565 & 0xff;
|
|
102
|
+
data[rgbOffset + 1] = rgb565 >> 8;
|
|
103
|
+
|
|
104
|
+
if (hasTransparency) {
|
|
105
|
+
data[12 + rgbSize + y * alphaStride + x] = rgba[sourceOffset + 3];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { data, colorFormat };
|
|
111
|
+
}
|