@onekeyfe/hd-core 1.1.27-alpha.32 → 1.1.27-alpha.34
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__/protocol-v2.test.ts +140 -45
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/GetDeviceInfo.d.ts +9 -0
- package/dist/api/GetDeviceInfo.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/alephium/AlephiumGetAddress.d.ts +2 -6
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts +2 -5
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetAddress.d.ts +2 -9
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +1 -11
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +1 -15
- package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
- package/dist/api/btc/BTCSignTransaction.d.ts +1 -11
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
- package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts +2 -8
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
- package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/helpers/deviceInfo.d.ts +15 -0
- package/dist/api/helpers/deviceInfo.d.ts.map +1 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/neo/NeoGetAddress.d.ts +2 -8
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts +2 -9
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +10 -0
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +1 -0
- package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarGetAddress.d.ts +2 -1
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +2 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +2 -2
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/index.d.ts +94 -4
- package/dist/index.js +404 -58
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +20 -3
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +84 -0
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +5 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +4 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +5 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +1 -1
- package/dist/utils/deviceInfoUtils.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/package.json +4 -4
- package/src/api/BaseMethod.ts +5 -10
- package/src/api/GetDeviceInfo.ts +153 -0
- package/src/api/alephium/AlephiumGetAddress.ts +6 -2
- package/src/api/alephium/AlephiumSignMessage.ts +6 -1
- package/src/api/alephium/AlephiumSignTransaction.ts +6 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +13 -20
- package/src/api/benfen/BenfenGetAddress.ts +6 -2
- package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
- package/src/api/benfen/BenfenSignMessage.ts +6 -1
- package/src/api/benfen/BenfenSignTransaction.ts +6 -1
- package/src/api/btc/helpers/versionLimit.ts +7 -1
- package/src/api/evm/EVMSignMessageEIP712.ts +14 -1
- package/src/api/helpers/batchGetPublickeys.ts +2 -4
- package/src/api/helpers/deviceInfo.ts +205 -0
- package/src/api/index.ts +2 -0
- package/src/api/neo/NeoGetAddress.ts +6 -1
- package/src/api/neo/NeoSignTransaction.ts +6 -1
- package/src/api/nervos/NervosGetAddress.ts +6 -2
- package/src/api/nervos/NervosSignTransaction.ts +6 -2
- package/src/api/nexa/NexaGetAddress.ts +6 -2
- package/src/api/nexa/NexaSignTransaction.ts +6 -2
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +17 -1
- package/src/api/protocol-v2/FilesystemDiskControl.ts +34 -0
- package/src/api/scdo/ScdoGetAddress.ts +6 -2
- package/src/api/scdo/ScdoSignMessage.ts +6 -1
- package/src/api/scdo/ScdoSignTransaction.ts +6 -2
- package/src/api/stellar/StellarGetAddress.ts +10 -1
- package/src/api/stellar/StellarSignTransaction.ts +14 -1
- package/src/api/sui/SuiSignTransaction.ts +12 -9
- package/src/core/index.ts +7 -7
- package/src/data/messages/messages-protocol-v2.json +10 -0
- package/src/inject.ts +3 -0
- package/src/protocols/protocol-v2/features.ts +35 -21
- package/src/types/api/getDeviceInfo.ts +97 -0
- package/src/types/api/index.ts +16 -0
- package/src/types/api/protocolV2.ts +5 -0
- package/src/types/device.ts +30 -1
- package/src/utils/deviceFeaturesUtils.ts +9 -2
- package/src/utils/deviceInfoUtils.ts +5 -7
- package/src/utils/index.ts +1 -1
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
getDeviceFirmwareVersion,
|
|
17
17
|
getFirmwareType,
|
|
18
18
|
getMethodVersionRange,
|
|
19
|
-
|
|
19
|
+
isMethodVersionRangeUnsupported,
|
|
20
20
|
} from '../../utils';
|
|
21
21
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
22
22
|
import { onDeviceButtonHandler } from '../../core';
|
|
@@ -460,16 +460,16 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
460
460
|
* @param method BaseMethod
|
|
461
461
|
*/
|
|
462
462
|
function preCheckDeviceSupport(device: Device, method: BaseMethod) {
|
|
463
|
-
if (shouldSkipMethodSupportCheck(device.features, device.originalDescriptor?.protocolType)) {
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
463
|
const versionRange = getMethodVersionRange(
|
|
468
464
|
device.features,
|
|
469
465
|
type => method.getVersionRange()[type]
|
|
470
466
|
);
|
|
471
467
|
const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
|
|
472
468
|
|
|
469
|
+
if (isMethodVersionRangeUnsupported(versionRange)) {
|
|
470
|
+
throw ERRORS.createDeviceNotSupportMethodError(method.name, getFirmwareType(device.features));
|
|
471
|
+
}
|
|
472
|
+
|
|
473
473
|
if (
|
|
474
474
|
versionRange &&
|
|
475
475
|
semver.valid(versionRange.min) &&
|
|
@@ -492,20 +492,9 @@ function handleSkippableHardwareError(
|
|
|
492
492
|
method: BaseMethod
|
|
493
493
|
): HardwareError | undefined {
|
|
494
494
|
let error: HardwareError | undefined;
|
|
495
|
-
const skipMethodSupportCheck = shouldSkipMethodSupportCheck(
|
|
496
|
-
device.features,
|
|
497
|
-
device.originalDescriptor?.protocolType
|
|
498
|
-
);
|
|
499
495
|
|
|
500
496
|
if (e instanceof HardwareError && e.errorCode !== HardwareErrorCode.RuntimeError) {
|
|
501
497
|
const { errorCode } = e;
|
|
502
|
-
if (
|
|
503
|
-
skipMethodSupportCheck &&
|
|
504
|
-
(errorCode === HardwareErrorCode.CallMethodNeedUpgradeFirmware ||
|
|
505
|
-
errorCode === HardwareErrorCode.DeviceNotSupportMethod)
|
|
506
|
-
) {
|
|
507
|
-
return undefined;
|
|
508
|
-
}
|
|
509
498
|
if (errorCode === HardwareErrorCode.CallMethodNeedUpgradeFirmware) {
|
|
510
499
|
error = e;
|
|
511
500
|
} else if (errorCode === HardwareErrorCode.DeviceNotSupportMethod) {
|
|
@@ -515,16 +504,20 @@ function handleSkippableHardwareError(
|
|
|
515
504
|
e.message?.includes('Failure_UnexpectedMessage') ||
|
|
516
505
|
e.message?.includes('Failure_UnknownMessage')
|
|
517
506
|
) {
|
|
518
|
-
if (skipMethodSupportCheck) {
|
|
519
|
-
return undefined;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
507
|
const versionRange = getMethodVersionRange(
|
|
523
508
|
device.features,
|
|
524
509
|
type => method.getVersionRange()[type]
|
|
525
510
|
);
|
|
526
511
|
const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
|
|
527
512
|
|
|
513
|
+
if (isMethodVersionRangeUnsupported(versionRange)) {
|
|
514
|
+
error = ERRORS.createDeviceNotSupportMethodError(
|
|
515
|
+
method.name,
|
|
516
|
+
getFirmwareType(device.features)
|
|
517
|
+
);
|
|
518
|
+
return error;
|
|
519
|
+
}
|
|
520
|
+
|
|
528
521
|
if (
|
|
529
522
|
versionRange &&
|
|
530
523
|
semver.valid(versionRange.min) &&
|
|
@@ -6,7 +6,7 @@ import { hex2BfcAddress, publicKeyToAddress } from './normalize';
|
|
|
6
6
|
import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
|
|
7
7
|
import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
|
|
8
8
|
|
|
9
|
-
import type { BenfenAddress, BenfenGetAddressParams } from '../../types';
|
|
9
|
+
import type { BenfenAddress, BenfenGetAddressParams, DeviceFirmwareRange } from '../../types';
|
|
10
10
|
import type { BenfenGetAddress as HardwareBenfenGetAddress } from '@onekeyfe/hd-transport';
|
|
11
11
|
|
|
12
12
|
export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddress[]> {
|
|
@@ -47,8 +47,12 @@ export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddres
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
getVersionRange() {
|
|
50
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
51
51
|
return {
|
|
52
|
+
pro2: {
|
|
53
|
+
min: '0.0.0',
|
|
54
|
+
unsupported: true,
|
|
55
|
+
},
|
|
52
56
|
pro: {
|
|
53
57
|
min: '4.12.0',
|
|
54
58
|
},
|
|
@@ -4,7 +4,7 @@ import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
|
4
4
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
5
5
|
import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
|
|
6
6
|
|
|
7
|
-
import type { BenfenGetPublicKeyParams, BenfenPublicKey } from '../../types';
|
|
7
|
+
import type { BenfenGetPublicKeyParams, BenfenPublicKey, DeviceFirmwareRange } from '../../types';
|
|
8
8
|
|
|
9
9
|
export default class BenfenGetPublicKey extends BaseMethod<any> {
|
|
10
10
|
hasBundle = false;
|
|
@@ -38,8 +38,12 @@ export default class BenfenGetPublicKey extends BaseMethod<any> {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
getVersionRange() {
|
|
41
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
42
42
|
return {
|
|
43
|
+
pro2: {
|
|
44
|
+
min: '0.0.0',
|
|
45
|
+
unsupported: true,
|
|
46
|
+
},
|
|
43
47
|
pro: {
|
|
44
48
|
min: '4.12.0',
|
|
45
49
|
},
|
|
@@ -5,6 +5,7 @@ import { validateParams } from '../helpers/paramsValidator';
|
|
|
5
5
|
import { stripHexPrefix } from '../helpers/hexUtils';
|
|
6
6
|
|
|
7
7
|
import type { BenfenSignMessage as HardwareBenfenSignMessage } from '@onekeyfe/hd-transport';
|
|
8
|
+
import type { DeviceFirmwareRange } from '../../types';
|
|
8
9
|
|
|
9
10
|
export default class BenfenSignMessage extends BaseMethod<HardwareBenfenSignMessage> {
|
|
10
11
|
init() {
|
|
@@ -25,8 +26,12 @@ export default class BenfenSignMessage extends BaseMethod<HardwareBenfenSignMess
|
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
getVersionRange() {
|
|
29
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
29
30
|
return {
|
|
31
|
+
pro2: {
|
|
32
|
+
min: '0.0.0',
|
|
33
|
+
unsupported: true,
|
|
34
|
+
},
|
|
30
35
|
pro: {
|
|
31
36
|
min: '4.12.0',
|
|
32
37
|
},
|
|
@@ -8,6 +8,7 @@ import { formatAnyHex } from '../helpers/hexUtils';
|
|
|
8
8
|
|
|
9
9
|
import type { BenfenSignTx, BenfenSignedTx, MessageType, TypedCall } from '@onekeyfe/hd-transport';
|
|
10
10
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
11
|
+
import type { DeviceFirmwareRange } from '../../types';
|
|
11
12
|
|
|
12
13
|
export default class BenfenSignTransaction extends BaseMethod<BenfenSignTx> {
|
|
13
14
|
init() {
|
|
@@ -32,8 +33,12 @@ export default class BenfenSignTransaction extends BaseMethod<BenfenSignTx> {
|
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
getVersionRange() {
|
|
36
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
36
37
|
return {
|
|
38
|
+
pro2: {
|
|
39
|
+
min: '0.0.0',
|
|
40
|
+
unsupported: true,
|
|
41
|
+
},
|
|
37
42
|
pro: {
|
|
38
43
|
min: '4.12.0',
|
|
39
44
|
},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DeviceFirmwareRange } from '../../../types';
|
|
2
|
+
|
|
1
3
|
function isCoinNameInList(coinName: string, coinNames: (string | undefined)[]) {
|
|
2
4
|
for (let i = 0; i < coinNames.length; i++) {
|
|
3
5
|
const coin_name = coinNames[i];
|
|
@@ -8,9 +10,13 @@ function isCoinNameInList(coinName: string, coinNames: (string | undefined)[]) {
|
|
|
8
10
|
return false;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
export function getBitcoinForkVersionRange(params: (string | undefined)[]) {
|
|
13
|
+
export function getBitcoinForkVersionRange(params: (string | undefined)[]): DeviceFirmwareRange {
|
|
12
14
|
if (isCoinNameInList('Neurai', params)) {
|
|
13
15
|
return {
|
|
16
|
+
pro2: {
|
|
17
|
+
min: '0.0.0',
|
|
18
|
+
unsupported: true,
|
|
19
|
+
},
|
|
14
20
|
model_mini: {
|
|
15
21
|
min: '3.7.0',
|
|
16
22
|
},
|
|
@@ -5,6 +5,7 @@ import { validateParams } from '../helpers/paramsValidator';
|
|
|
5
5
|
import { formatAnyHex } from '../helpers/hexUtils';
|
|
6
6
|
|
|
7
7
|
import type { EthereumSignMessageEIP712 } from '@onekeyfe/hd-transport';
|
|
8
|
+
import type { DeviceFirmwareRange } from '../../types';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @deprecated Use EVMSignTypedData instead.
|
|
@@ -31,8 +32,12 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EthereumSignMessage
|
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
getVersionRange() {
|
|
35
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
35
36
|
return {
|
|
37
|
+
pro2: {
|
|
38
|
+
min: '0.0.0',
|
|
39
|
+
unsupported: true,
|
|
40
|
+
},
|
|
36
41
|
model_mini: {
|
|
37
42
|
min: '2.1.9',
|
|
38
43
|
},
|
|
@@ -43,6 +48,14 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EthereumSignMessage
|
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
async run() {
|
|
51
|
+
this.checkFeatureVersionLimit(
|
|
52
|
+
() => true,
|
|
53
|
+
() => this.getVersionRange(),
|
|
54
|
+
{
|
|
55
|
+
strictCheckDeviceSupport: true,
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
|
|
46
59
|
const res = await this.device.commands.typedCall(
|
|
47
60
|
'EthereumSignMessageEIP712',
|
|
48
61
|
'EthereumMessageSignature',
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
|
|
8
8
|
import { isEqualBip44CoinType } from './pathUtils';
|
|
9
9
|
import { splitArray } from '../../utils/arrayUtils';
|
|
10
|
-
import { getDeviceType, getFirmwareType
|
|
10
|
+
import { getDeviceType, getFirmwareType } from '../../utils';
|
|
11
11
|
import { DeviceModelToTypes } from '../../types';
|
|
12
12
|
|
|
13
13
|
import type { EcdsaPublicKeys, Path } from '@onekeyfe/hd-transport';
|
|
@@ -28,9 +28,7 @@ export async function batchGetPublickeys(
|
|
|
28
28
|
throw TypedError(HardwareErrorCode.ForbiddenKeyPath, 'Path length must be greater than 3');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const supportsBatchPublicKey =
|
|
32
|
-
shouldSkipMethodSupportCheck(device.features, device.originalDescriptor?.protocolType) ||
|
|
33
|
-
supportBatchPublicKey(device.features, options);
|
|
31
|
+
const supportsBatchPublicKey = supportBatchPublicKey(device.features, options);
|
|
34
32
|
if (!supportsBatchPublicKey) {
|
|
35
33
|
throw createDeviceNotSupportMethodError('BatchGetPublickeys', getFirmwareType(device.features));
|
|
36
34
|
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDeviceBLEFirmwareVersion,
|
|
3
|
+
getDeviceBleName,
|
|
4
|
+
getDeviceBoardloaderVersion,
|
|
5
|
+
getDeviceBootloaderVersion,
|
|
6
|
+
getDeviceFirmwareVersion,
|
|
7
|
+
getDeviceLabel,
|
|
8
|
+
getDeviceType,
|
|
9
|
+
getDeviceUUID,
|
|
10
|
+
getFirmwareType,
|
|
11
|
+
} from '../../utils';
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
DeviceInfoProtocol,
|
|
15
|
+
DeviceInfoSource,
|
|
16
|
+
DeviceInfoStatus,
|
|
17
|
+
GetDeviceInfoParams,
|
|
18
|
+
UnifiedDeviceInfo,
|
|
19
|
+
UnifiedDeviceInfoRaw,
|
|
20
|
+
UnifiedDeviceInfoVerify,
|
|
21
|
+
UnifiedDeviceInfoVersions,
|
|
22
|
+
} from '../../types/api/getDeviceInfo';
|
|
23
|
+
import type { Features, OnekeyFeatures } from '../../types';
|
|
24
|
+
import type { ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
|
|
25
|
+
|
|
26
|
+
type BuildDeviceInfoParams = {
|
|
27
|
+
protocol: DeviceInfoProtocol;
|
|
28
|
+
features?: Features;
|
|
29
|
+
onekeyFeatures?: OnekeyFeatures;
|
|
30
|
+
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
31
|
+
sources: DeviceInfoSource[];
|
|
32
|
+
scope?: GetDeviceInfoParams['scope'];
|
|
33
|
+
includeRaw?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const isMeaningfulVersion = (version?: string | null) => Boolean(version && version !== '0.0.0');
|
|
37
|
+
|
|
38
|
+
const versionArrayToString = (version?: Array<number | string | null> | null) => {
|
|
39
|
+
if (!version || version.length === 0) return null;
|
|
40
|
+
const value = version.join('.');
|
|
41
|
+
return isMeaningfulVersion(value) ? value : null;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const firstVersion = (...versions: Array<string | null | undefined>) =>
|
|
45
|
+
versions.find(isMeaningfulVersion) ?? null;
|
|
46
|
+
|
|
47
|
+
const safeGetDeviceUUID = (features?: Features) => (features ? getDeviceUUID(features) : '');
|
|
48
|
+
|
|
49
|
+
const shouldIncludeVerify = (scope?: GetDeviceInfoParams['scope']) =>
|
|
50
|
+
scope === 'verify' || scope === 'full';
|
|
51
|
+
|
|
52
|
+
const getDeviceMode = (features?: Features): DeviceInfoStatus['mode'] => {
|
|
53
|
+
if (!features) return 'unknown';
|
|
54
|
+
if (features.bootloader_mode === true) return 'bootloader';
|
|
55
|
+
if (features.initialized === false) return 'notInitialized';
|
|
56
|
+
if (features.initialized === true) return 'normal';
|
|
57
|
+
return 'unknown';
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const normalizeVersions = (
|
|
61
|
+
features?: Features,
|
|
62
|
+
onekeyFeatures?: OnekeyFeatures
|
|
63
|
+
): UnifiedDeviceInfoVersions => ({
|
|
64
|
+
firmware: firstVersion(
|
|
65
|
+
onekeyFeatures?.onekey_firmware_version,
|
|
66
|
+
versionArrayToString(getDeviceFirmwareVersion(features))
|
|
67
|
+
),
|
|
68
|
+
bootloader: firstVersion(
|
|
69
|
+
onekeyFeatures?.onekey_boot_version,
|
|
70
|
+
versionArrayToString(getDeviceBootloaderVersion(features))
|
|
71
|
+
),
|
|
72
|
+
board: firstVersion(
|
|
73
|
+
onekeyFeatures?.onekey_board_version,
|
|
74
|
+
versionArrayToString(features ? getDeviceBoardloaderVersion(features) : undefined)
|
|
75
|
+
),
|
|
76
|
+
ble: firstVersion(
|
|
77
|
+
onekeyFeatures?.onekey_ble_version,
|
|
78
|
+
features?.onekey_ble_version,
|
|
79
|
+
features?.ble_ver,
|
|
80
|
+
versionArrayToString(features ? getDeviceBLEFirmwareVersion(features) : undefined)
|
|
81
|
+
),
|
|
82
|
+
se01: firstVersion(onekeyFeatures?.onekey_se01_version, features?.onekey_se01_version),
|
|
83
|
+
se02: firstVersion(onekeyFeatures?.onekey_se02_version, features?.onekey_se02_version),
|
|
84
|
+
se03: firstVersion(onekeyFeatures?.onekey_se03_version, features?.onekey_se03_version),
|
|
85
|
+
se04: firstVersion(onekeyFeatures?.onekey_se04_version, features?.onekey_se04_version),
|
|
86
|
+
se01Boot: firstVersion(
|
|
87
|
+
onekeyFeatures?.onekey_se01_boot_version,
|
|
88
|
+
features?.onekey_se01_boot_version
|
|
89
|
+
),
|
|
90
|
+
se02Boot: firstVersion(
|
|
91
|
+
onekeyFeatures?.onekey_se02_boot_version,
|
|
92
|
+
features?.onekey_se02_boot_version
|
|
93
|
+
),
|
|
94
|
+
se03Boot: firstVersion(
|
|
95
|
+
onekeyFeatures?.onekey_se03_boot_version,
|
|
96
|
+
features?.onekey_se03_boot_version
|
|
97
|
+
),
|
|
98
|
+
se04Boot: firstVersion(
|
|
99
|
+
onekeyFeatures?.onekey_se04_boot_version,
|
|
100
|
+
features?.onekey_se04_boot_version
|
|
101
|
+
),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const normalizeStatus = (protocol: DeviceInfoProtocol, features?: Features): DeviceInfoStatus => ({
|
|
105
|
+
mode: getDeviceMode(features),
|
|
106
|
+
initialized: features?.initialized ?? null,
|
|
107
|
+
bootloaderMode: features?.bootloader_mode ?? null,
|
|
108
|
+
unlocked: protocol === 'V2' ? null : features?.unlocked ?? null,
|
|
109
|
+
passphraseProtection: features?.passphrase_protection ?? null,
|
|
110
|
+
backupRequired: features?.needs_backup ?? null,
|
|
111
|
+
language: features?.language ?? null,
|
|
112
|
+
bleEnabled: (features as { ble_enable?: boolean } | undefined)?.ble_enable ?? null,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const normalizeVerify = (
|
|
116
|
+
features?: Features,
|
|
117
|
+
onekeyFeatures?: OnekeyFeatures
|
|
118
|
+
): UnifiedDeviceInfoVerify => {
|
|
119
|
+
const featureRecord = features as Record<string, string | undefined> | undefined;
|
|
120
|
+
return {
|
|
121
|
+
firmwareBuildId: onekeyFeatures?.onekey_firmware_build_id ?? features?.onekey_firmware_build_id,
|
|
122
|
+
firmwareHash: onekeyFeatures?.onekey_firmware_hash ?? features?.onekey_firmware_hash,
|
|
123
|
+
bootloaderBuildId: onekeyFeatures?.onekey_boot_build_id ?? features?.onekey_boot_build_id,
|
|
124
|
+
bootloaderHash: onekeyFeatures?.onekey_boot_hash ?? features?.onekey_boot_hash,
|
|
125
|
+
boardBuildId: onekeyFeatures?.onekey_board_build_id ?? featureRecord?.onekey_board_build_id,
|
|
126
|
+
boardHash: onekeyFeatures?.onekey_board_hash ?? features?.onekey_board_hash,
|
|
127
|
+
bleBuildId: onekeyFeatures?.onekey_ble_build_id ?? features?.onekey_ble_build_id,
|
|
128
|
+
bleHash: onekeyFeatures?.onekey_ble_hash ?? features?.onekey_ble_hash,
|
|
129
|
+
se01BuildId: onekeyFeatures?.onekey_se01_build_id ?? features?.onekey_se01_build_id,
|
|
130
|
+
se01Hash: onekeyFeatures?.onekey_se01_hash ?? featureRecord?.onekey_se01_hash,
|
|
131
|
+
se02BuildId: onekeyFeatures?.onekey_se02_build_id ?? featureRecord?.onekey_se02_build_id,
|
|
132
|
+
se02Hash: onekeyFeatures?.onekey_se02_hash ?? featureRecord?.onekey_se02_hash,
|
|
133
|
+
se03BuildId: onekeyFeatures?.onekey_se03_build_id ?? featureRecord?.onekey_se03_build_id,
|
|
134
|
+
se03Hash: onekeyFeatures?.onekey_se03_hash ?? featureRecord?.onekey_se03_hash,
|
|
135
|
+
se04BuildId: onekeyFeatures?.onekey_se04_build_id ?? featureRecord?.onekey_se04_build_id,
|
|
136
|
+
se04Hash: onekeyFeatures?.onekey_se04_hash ?? featureRecord?.onekey_se04_hash,
|
|
137
|
+
se01BootBuildId:
|
|
138
|
+
onekeyFeatures?.onekey_se01_boot_build_id ?? features?.onekey_se01_boot_build_id,
|
|
139
|
+
se01BootHash: onekeyFeatures?.onekey_se01_boot_hash ?? features?.onekey_se01_boot_hash,
|
|
140
|
+
se02BootBuildId:
|
|
141
|
+
onekeyFeatures?.onekey_se02_boot_build_id ?? features?.onekey_se02_boot_build_id,
|
|
142
|
+
se02BootHash: onekeyFeatures?.onekey_se02_boot_hash ?? features?.onekey_se02_boot_hash,
|
|
143
|
+
se03BootBuildId:
|
|
144
|
+
onekeyFeatures?.onekey_se03_boot_build_id ?? features?.onekey_se03_boot_build_id,
|
|
145
|
+
se03BootHash: onekeyFeatures?.onekey_se03_boot_hash ?? features?.onekey_se03_boot_hash,
|
|
146
|
+
se04BootBuildId:
|
|
147
|
+
onekeyFeatures?.onekey_se04_boot_build_id ?? features?.onekey_se04_boot_build_id,
|
|
148
|
+
se04BootHash: onekeyFeatures?.onekey_se04_boot_hash ?? features?.onekey_se04_boot_hash,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const normalizeRaw = ({
|
|
153
|
+
features,
|
|
154
|
+
onekeyFeatures,
|
|
155
|
+
protocolV2DeviceInfo,
|
|
156
|
+
}: Pick<
|
|
157
|
+
BuildDeviceInfoParams,
|
|
158
|
+
'features' | 'onekeyFeatures' | 'protocolV2DeviceInfo'
|
|
159
|
+
>): UnifiedDeviceInfoRaw => ({
|
|
160
|
+
...(features ? { features } : {}),
|
|
161
|
+
...(onekeyFeatures ? { onekeyFeatures } : {}),
|
|
162
|
+
...(protocolV2DeviceInfo ? { protocolV2DeviceInfo } : {}),
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export function buildUnifiedDeviceInfo({
|
|
166
|
+
protocol,
|
|
167
|
+
features,
|
|
168
|
+
onekeyFeatures,
|
|
169
|
+
protocolV2DeviceInfo,
|
|
170
|
+
sources,
|
|
171
|
+
scope = 'basic',
|
|
172
|
+
includeRaw = false,
|
|
173
|
+
}: BuildDeviceInfoParams): UnifiedDeviceInfo {
|
|
174
|
+
const mergedFeatures = {
|
|
175
|
+
...(features ?? {}),
|
|
176
|
+
...(onekeyFeatures ?? {}),
|
|
177
|
+
} as Features;
|
|
178
|
+
const hasFeatures = Boolean(features || onekeyFeatures);
|
|
179
|
+
const sourceFeatures = hasFeatures ? mergedFeatures : undefined;
|
|
180
|
+
const deviceType = getDeviceType(sourceFeatures);
|
|
181
|
+
const verify = normalizeVerify(sourceFeatures, onekeyFeatures);
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
protocol,
|
|
185
|
+
sources,
|
|
186
|
+
deviceType,
|
|
187
|
+
firmwareType: getFirmwareType(sourceFeatures),
|
|
188
|
+
deviceId: sourceFeatures?.device_id || safeGetDeviceUUID(sourceFeatures),
|
|
189
|
+
serialNo: safeGetDeviceUUID(sourceFeatures),
|
|
190
|
+
label: getDeviceLabel(sourceFeatures),
|
|
191
|
+
bleName: getDeviceBleName(sourceFeatures),
|
|
192
|
+
status: normalizeStatus(protocol, sourceFeatures),
|
|
193
|
+
versions: normalizeVersions(sourceFeatures, onekeyFeatures),
|
|
194
|
+
...(shouldIncludeVerify(scope) ? { verify } : {}),
|
|
195
|
+
...(includeRaw
|
|
196
|
+
? {
|
|
197
|
+
raw: normalizeRaw({
|
|
198
|
+
features,
|
|
199
|
+
onekeyFeatures,
|
|
200
|
+
protocolV2DeviceInfo,
|
|
201
|
+
}),
|
|
202
|
+
}
|
|
203
|
+
: {}),
|
|
204
|
+
};
|
|
205
|
+
}
|
package/src/api/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { default as testInitializeDeviceDuration } from './test/TestInitializeDe
|
|
|
2
2
|
|
|
3
3
|
export { default as searchDevices } from './SearchDevices';
|
|
4
4
|
export { default as getFeatures } from './GetFeatures';
|
|
5
|
+
export { default as getDeviceInfo } from './GetDeviceInfo';
|
|
5
6
|
export { default as getOnekeyFeatures } from './GetOnekeyFeatures';
|
|
6
7
|
export { default as getPassphraseState } from './GetPassphraseState';
|
|
7
8
|
export { default as getLogs } from './GetLogs';
|
|
@@ -52,6 +53,7 @@ export { default as factoryDeviceInfoSettings } from './protocol-v2/FactoryDevic
|
|
|
52
53
|
export { default as factoryGetDeviceInfo } from './protocol-v2/FactoryGetDeviceInfo';
|
|
53
54
|
export { default as filesystemFixPermission } from './protocol-v2/FilesystemFixPermission';
|
|
54
55
|
export { default as filesystemFormat } from './protocol-v2/FilesystemFormat';
|
|
56
|
+
export { default as filesystemDiskControl } from './protocol-v2/FilesystemDiskControl';
|
|
55
57
|
export { default as fileRead } from './FileRead';
|
|
56
58
|
export { default as fileWrite } from './FileWrite';
|
|
57
59
|
export { default as fileDelete } from './FileDelete';
|
|
@@ -5,6 +5,7 @@ import { UI_REQUEST } from '../../constants/ui-request';
|
|
|
5
5
|
|
|
6
6
|
import type { NeoGetAddress as HardwareNeoGetAddress } from '@onekeyfe/hd-transport';
|
|
7
7
|
import type { NeoAddress, NeoGetAddressParams } from '../../types/api/neoGetAddress';
|
|
8
|
+
import type { DeviceFirmwareRange } from '../../types';
|
|
8
9
|
|
|
9
10
|
export default class NeoGetAddress extends BaseMethod<HardwareNeoGetAddress[]> {
|
|
10
11
|
hasBundle = false;
|
|
@@ -37,8 +38,12 @@ export default class NeoGetAddress extends BaseMethod<HardwareNeoGetAddress[]> {
|
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
getVersionRange() {
|
|
41
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
41
42
|
return {
|
|
43
|
+
pro2: {
|
|
44
|
+
min: '0.0.0',
|
|
45
|
+
unsupported: true,
|
|
46
|
+
},
|
|
42
47
|
pro: {
|
|
43
48
|
min: '4.12.0',
|
|
44
49
|
},
|
|
@@ -5,6 +5,7 @@ import { validateParams } from '../helpers/paramsValidator';
|
|
|
5
5
|
import { formatAnyHex } from '../helpers/hexUtils';
|
|
6
6
|
|
|
7
7
|
import type { NeoSignTx } from '@onekeyfe/hd-transport';
|
|
8
|
+
import type { DeviceFirmwareRange } from '../../types';
|
|
8
9
|
|
|
9
10
|
export default class NeoSignTransaction extends BaseMethod<NeoSignTx> {
|
|
10
11
|
init() {
|
|
@@ -28,8 +29,12 @@ export default class NeoSignTransaction extends BaseMethod<NeoSignTx> {
|
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
getVersionRange() {
|
|
32
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
32
33
|
return {
|
|
34
|
+
pro2: {
|
|
35
|
+
min: '0.0.0',
|
|
36
|
+
unsupported: true,
|
|
37
|
+
},
|
|
33
38
|
pro: {
|
|
34
39
|
min: '4.12.0',
|
|
35
40
|
},
|
|
@@ -4,7 +4,7 @@ import { BaseMethod } from '../BaseMethod';
|
|
|
4
4
|
import { validateParams, validateResult } from '../helpers/paramsValidator';
|
|
5
5
|
|
|
6
6
|
import type { NervosGetAddress as HardwareNervosGetAddress } from '@onekeyfe/hd-transport';
|
|
7
|
-
import type { NervosAddress, NervosGetAddressParams } from '../../types';
|
|
7
|
+
import type { DeviceFirmwareRange, NervosAddress, NervosGetAddressParams } from '../../types';
|
|
8
8
|
|
|
9
9
|
export default class NervosGetAddress extends BaseMethod<HardwareNervosGetAddress[]> {
|
|
10
10
|
hasBundle = false;
|
|
@@ -40,8 +40,12 @@ export default class NervosGetAddress extends BaseMethod<HardwareNervosGetAddres
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
getVersionRange() {
|
|
43
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
44
44
|
return {
|
|
45
|
+
pro2: {
|
|
46
|
+
min: '0.0.0',
|
|
47
|
+
unsupported: true,
|
|
48
|
+
},
|
|
45
49
|
model_mini: {
|
|
46
50
|
min: '3.7.0',
|
|
47
51
|
},
|
|
@@ -5,7 +5,7 @@ import { BaseMethod } from '../BaseMethod';
|
|
|
5
5
|
import { validateParams } from '../helpers/paramsValidator';
|
|
6
6
|
import { formatAnyHex } from '../helpers/hexUtils';
|
|
7
7
|
|
|
8
|
-
import type { NervosSignTransactionParams, NervosSignedTx } from '../../types';
|
|
8
|
+
import type { DeviceFirmwareRange, NervosSignTransactionParams, NervosSignedTx } from '../../types';
|
|
9
9
|
import type { NervosSignTx as HardwareNervosSignTx, TypedCall } from '@onekeyfe/hd-transport';
|
|
10
10
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
11
11
|
|
|
@@ -40,8 +40,12 @@ export default class NervosSignTransaction extends BaseMethod<NervosSignTx> {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
getVersionRange() {
|
|
43
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
44
44
|
return {
|
|
45
|
+
pro2: {
|
|
46
|
+
min: '0.0.0',
|
|
47
|
+
unsupported: true,
|
|
48
|
+
},
|
|
45
49
|
model_mini: {
|
|
46
50
|
min: '3.7.0',
|
|
47
51
|
},
|
|
@@ -4,7 +4,7 @@ import { BaseMethod } from '../BaseMethod';
|
|
|
4
4
|
import { validateParams, validateResult } from '../helpers/paramsValidator';
|
|
5
5
|
|
|
6
6
|
import type { NexaGetAddress as HardwareNexaGetAddress } from '@onekeyfe/hd-transport';
|
|
7
|
-
import type { NexaGetAddressParams } from '../../types';
|
|
7
|
+
import type { DeviceFirmwareRange, NexaGetAddressParams } from '../../types';
|
|
8
8
|
|
|
9
9
|
export default class NexaGetAddress extends BaseMethod<HardwareNexaGetAddress[]> {
|
|
10
10
|
hasBundle = false;
|
|
@@ -43,8 +43,12 @@ export default class NexaGetAddress extends BaseMethod<HardwareNexaGetAddress[]>
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
getVersionRange() {
|
|
46
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
47
47
|
return {
|
|
48
|
+
pro2: {
|
|
49
|
+
min: '0.0.0',
|
|
50
|
+
unsupported: true,
|
|
51
|
+
},
|
|
48
52
|
model_mini: {
|
|
49
53
|
min: '3.2.0',
|
|
50
54
|
},
|
|
@@ -6,7 +6,7 @@ import { validateParams } from '../helpers/paramsValidator';
|
|
|
6
6
|
|
|
7
7
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
8
8
|
import type { TypedCall } from '@onekeyfe/hd-transport';
|
|
9
|
-
import type { NexaSignTransactionParams, NexaSignature } from '../../types';
|
|
9
|
+
import type { DeviceFirmwareRange, NexaSignTransactionParams, NexaSignature } from '../../types';
|
|
10
10
|
|
|
11
11
|
export default class NexaSignTransaction extends BaseMethod<NexaSignTransactionParams> {
|
|
12
12
|
hasBundle = false;
|
|
@@ -25,8 +25,12 @@ export default class NexaSignTransaction extends BaseMethod<NexaSignTransactionP
|
|
|
25
25
|
this.params = payload;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
getVersionRange() {
|
|
28
|
+
getVersionRange(): DeviceFirmwareRange {
|
|
29
29
|
return {
|
|
30
|
+
pro2: {
|
|
31
|
+
min: '0.0.0',
|
|
32
|
+
unsupported: true,
|
|
33
|
+
},
|
|
30
34
|
model_mini: {
|
|
31
35
|
min: '3.2.0',
|
|
32
36
|
},
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
5
5
|
normalizeFirmwareTargets,
|
|
6
6
|
} from './helpers';
|
|
7
|
+
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
8
|
+
import type { KnownDevice } from '../../types';
|
|
7
9
|
|
|
8
10
|
import type { DeviceFirmwareUpdateParams } from './helpers';
|
|
9
11
|
|
|
@@ -27,7 +29,21 @@ export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdat
|
|
|
27
29
|
{
|
|
28
30
|
targets,
|
|
29
31
|
},
|
|
30
|
-
|
|
32
|
+
{
|
|
33
|
+
...PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS,
|
|
34
|
+
onIntermediateResponse: response => {
|
|
35
|
+
if (response.type !== 'DeviceFirmwareInstallProgress') return;
|
|
36
|
+
const progress = Number(response.message?.progress);
|
|
37
|
+
if (!Number.isFinite(progress)) return;
|
|
38
|
+
this.postMessage(
|
|
39
|
+
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
40
|
+
device: this.device.toMessageObject() as KnownDevice,
|
|
41
|
+
progress: Math.min(Math.max(progress, 0), 100),
|
|
42
|
+
progressType: 'installingFirmware',
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
}
|
|
31
47
|
);
|
|
32
48
|
return Promise.resolve(res.message);
|
|
33
49
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import {
|
|
3
|
+
validateNonNegativeInteger,
|
|
4
|
+
validateOptionalNonNegativeInteger,
|
|
5
|
+
} from '../helpers/filesystemValidation';
|
|
6
|
+
|
|
7
|
+
export type FilesystemDiskControlParams = {
|
|
8
|
+
enable?: number | string;
|
|
9
|
+
timeoutMs?: number | string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default class FilesystemDiskControl extends BaseMethod<FilesystemDiskControlParams> {
|
|
13
|
+
init() {
|
|
14
|
+
this.skipForceUpdateCheck = true;
|
|
15
|
+
this.useDevicePassphraseState = false;
|
|
16
|
+
this.params = {
|
|
17
|
+
enable: validateNonNegativeInteger(this.payload.enable, 'enable', 0),
|
|
18
|
+
timeoutMs: validateOptionalNonNegativeInteger(this.payload.timeoutMs, 'timeoutMs'),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async run() {
|
|
23
|
+
const timeoutMs = Number(this.params.timeoutMs);
|
|
24
|
+
const res = await this.device.commands.typedCall(
|
|
25
|
+
'FilesystemDiskControl',
|
|
26
|
+
'Success',
|
|
27
|
+
{
|
|
28
|
+
enable: Number(this.params.enable ?? 0),
|
|
29
|
+
},
|
|
30
|
+
Number.isFinite(timeoutMs) && timeoutMs > 0 ? { timeoutMs } : undefined
|
|
31
|
+
);
|
|
32
|
+
return Promise.resolve(res.message);
|
|
33
|
+
}
|
|
34
|
+
}
|