@onekeyfe/hd-core 1.2.0-alpha.105 → 1.2.0-alpha.107
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 +2 -10
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +0 -2
- package/__tests__/device-lifecycle-events.test.ts +2 -113
- package/__tests__/device-pool-state.test.ts +0 -29
- package/__tests__/deviceUploadNft.test.ts +4 -33
- package/__tests__/get-device-state.test.ts +13 -52
- package/__tests__/protocol-v2.test.ts +18 -330
- package/__tests__/refresh-device-state.test.ts +1 -4
- package/__tests__/search-devices.test.ts +38 -34
- package/dist/api/FirmwareUpdateV4.d.ts +0 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceState.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/firmware/protocolV2Release.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -10
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/index.d.ts +16 -18
- package/dist/index.js +99 -277
- package/dist/protocols/protocol-v2/features.d.ts +0 -8
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +2 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/types/api/getDeviceState.d.ts +0 -1
- package/dist/types/api/getDeviceState.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -1
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/pro2Nft.d.ts +0 -7
- package/dist/utils/pro2Nft.d.ts.map +1 -1
- package/package.json +4 -6
- package/src/api/FirmwareUpdateV4.ts +24 -72
- package/src/api/GetDeviceState.ts +0 -1
- package/src/api/SearchDevices.ts +2 -4
- package/src/api/UploadPortfolio.ts +2 -9
- package/src/api/firmware/protocolV2Release.ts +0 -1
- package/src/api/protocol-v2/DeviceUploadNft.ts +8 -56
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +18 -37
- package/src/api/ton/TonSignMessage.ts +3 -5
- package/src/core/index.ts +0 -4
- package/src/device/Device.ts +31 -90
- package/src/device/DevicePool.ts +5 -17
- package/src/protocols/protocol-v2/features.ts +0 -10
- package/src/protocols/protocol-v2/index.ts +0 -2
- package/src/types/api/getDeviceState.ts +0 -2
- package/src/types/api/protocolV2.ts +1 -1
- package/src/types/device.ts +2 -1
- package/src/utils/pro2Nft.ts +8 -31
- package/__tests__/base64Data.test.ts +0 -70
- package/__tests__/protocol-v2-legacy-recovery.test.ts +0 -29
- package/__tests__/resourceBase64Boundary.test.ts +0 -48
- package/__tests__/ton-sign-message.test.ts +0 -84
- package/dist/api/helpers/base64Data.d.ts +0 -16
- package/dist/api/helpers/base64Data.d.ts.map +0 -1
- package/dist/core/protocolV2LegacyRecovery.d.ts +0 -5
- package/dist/core/protocolV2LegacyRecovery.d.ts.map +0 -1
- package/src/api/helpers/base64Data.ts +0 -85
- package/src/core/protocolV2LegacyRecovery.ts +0 -12
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { BaseMethod } from '../api/BaseMethod';
|
|
2
|
-
type CoreMethodDescriptor = Pick<BaseMethod, 'name' | 'payload'>;
|
|
3
|
-
export declare const isLegacyProtocolV2FirmwareRecoveryMethod: (method?: CoreMethodDescriptor) => boolean;
|
|
4
|
-
export {};
|
|
5
|
-
//# sourceMappingURL=protocolV2LegacyRecovery.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocolV2LegacyRecovery.d.ts","sourceRoot":"","sources":["../../src/core/protocolV2LegacyRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,KAAK,oBAAoB,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAMjE,eAAO,MAAM,wCAAwC,YAAa,oBAAoB,KAAG,OAGb,CAAC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
import { decode as decodeJpeg } from 'jpeg-js';
|
|
3
|
-
|
|
4
|
-
import { invalidParameter } from './filesystemValidation';
|
|
5
|
-
|
|
6
|
-
const BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
7
|
-
const JPEG_CONTAINER_OVERHEAD_BYTES = 64 * 1024;
|
|
8
|
-
const JPEG_MAX_MEMORY_USAGE_IN_MB = 32;
|
|
9
|
-
const JPEG_MAX_RESOLUTION_IN_MP = 1;
|
|
10
|
-
|
|
11
|
-
export function decodeCanonicalBase64({
|
|
12
|
-
value,
|
|
13
|
-
parameterName,
|
|
14
|
-
maxBytes,
|
|
15
|
-
}: {
|
|
16
|
-
value: unknown;
|
|
17
|
-
parameterName: string;
|
|
18
|
-
maxBytes: number;
|
|
19
|
-
}): Uint8Array {
|
|
20
|
-
if (typeof value !== 'string' || value.length === 0) {
|
|
21
|
-
throw invalidParameter(`Parameter [${parameterName}] must be a non-empty Base64 string.`);
|
|
22
|
-
}
|
|
23
|
-
if (value.length > Math.ceil(maxBytes / 3) * 4) {
|
|
24
|
-
throw invalidParameter(`Parameter [${parameterName}] exceeds the maximum supported size.`);
|
|
25
|
-
}
|
|
26
|
-
if (value.length % 4 !== 0 || !BASE64_PATTERN.test(value)) {
|
|
27
|
-
throw invalidParameter(`Parameter [${parameterName}] must use canonical Base64 encoding.`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const decoded = Buffer.from(value, 'base64');
|
|
31
|
-
if (decoded.byteLength === 0 || decoded.byteLength > maxBytes) {
|
|
32
|
-
throw invalidParameter(`Parameter [${parameterName}] exceeds the maximum supported size.`);
|
|
33
|
-
}
|
|
34
|
-
if (decoded.toString('base64') !== value) {
|
|
35
|
-
throw invalidParameter(`Parameter [${parameterName}] must use canonical Base64 encoding.`);
|
|
36
|
-
}
|
|
37
|
-
return Uint8Array.from(decoded);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function decodeJpegBase64ToRgba({
|
|
41
|
-
jpegBase64,
|
|
42
|
-
parameterName,
|
|
43
|
-
expectedWidth,
|
|
44
|
-
expectedHeight,
|
|
45
|
-
}: {
|
|
46
|
-
jpegBase64: unknown;
|
|
47
|
-
parameterName: string;
|
|
48
|
-
expectedWidth: number;
|
|
49
|
-
expectedHeight: number;
|
|
50
|
-
}): { width: number; height: number; data: Uint8Array } {
|
|
51
|
-
const jpegBytes = decodeCanonicalBase64({
|
|
52
|
-
value: jpegBase64,
|
|
53
|
-
parameterName,
|
|
54
|
-
maxBytes: expectedWidth * expectedHeight * 8 + JPEG_CONTAINER_OVERHEAD_BYTES,
|
|
55
|
-
});
|
|
56
|
-
if (jpegBytes[0] !== 0xff || jpegBytes[1] !== 0xd8) {
|
|
57
|
-
throw invalidParameter(`Parameter [${parameterName}] must contain a JPEG image.`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let decoded: { width: number; height: number; data: Uint8Array };
|
|
61
|
-
try {
|
|
62
|
-
decoded = decodeJpeg(jpegBytes, {
|
|
63
|
-
useTArray: true,
|
|
64
|
-
formatAsRGBA: true,
|
|
65
|
-
tolerantDecoding: false,
|
|
66
|
-
maxResolutionInMP: JPEG_MAX_RESOLUTION_IN_MP,
|
|
67
|
-
maxMemoryUsageInMB: JPEG_MAX_MEMORY_USAGE_IN_MB,
|
|
68
|
-
});
|
|
69
|
-
} catch {
|
|
70
|
-
throw invalidParameter(`Parameter [${parameterName}] must contain a valid JPEG image.`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (decoded.width !== expectedWidth || decoded.height !== expectedHeight) {
|
|
74
|
-
throw invalidParameter(
|
|
75
|
-
`Parameter [${parameterName}] must contain a ${expectedWidth}x${expectedHeight} JPEG image.`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
const expectedLength = expectedWidth * expectedHeight * 4;
|
|
79
|
-
if (decoded.data.byteLength !== expectedLength) {
|
|
80
|
-
throw invalidParameter(
|
|
81
|
-
`Decoded parameter [${parameterName}] must contain ${expectedLength} RGBA bytes.`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return decoded;
|
|
85
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BaseMethod } from '../api/BaseMethod';
|
|
2
|
-
|
|
3
|
-
type CoreMethodDescriptor = Pick<BaseMethod, 'name' | 'payload'>;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* TEMPORARY COMPATIBILITY: Legacy ProtocolInfo is accepted only by the
|
|
7
|
-
* firmware recovery entry points used before and during Protocol V2 updates.
|
|
8
|
-
*/
|
|
9
|
-
export const isLegacyProtocolV2FirmwareRecoveryMethod = (method?: CoreMethodDescriptor): boolean =>
|
|
10
|
-
method?.name === 'firmwareUpdateV4' ||
|
|
11
|
-
method?.name === 'checkAllFirmwareRelease' ||
|
|
12
|
-
(method?.name === 'getDeviceState' && method.payload.scope === 'firmware');
|