@onekeyfe/hd-core 1.1.27-alpha.30 → 1.1.27-alpha.32
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__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/protocol-v2.test.ts +503 -37
- package/dist/api/DirList.d.ts.map +1 -1
- package/dist/api/DirMake.d.ts.map +1 -1
- package/dist/api/DirRemove.d.ts.map +1 -1
- package/dist/api/FileDelete.d.ts.map +1 -1
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +6 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/PathInfo.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
- package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
- package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/helpers/filesystemValidation.d.ts +7 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
- package/dist/api/index.d.ts +5 -5
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +19 -19
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -3
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/MessagesConfig.d.ts +2 -2
- package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +3 -3
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.d.ts +37 -27
- package/dist/index.js +385 -236
- package/dist/protocols/protocol-v2/features.d.ts +2 -1
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +7 -7
- package/dist/types/api/getPassphraseState.d.ts +10 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +7 -6
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +16 -16
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +5 -3
- package/dist/utils/deviceFeaturesUtils.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/DirList.ts +6 -2
- package/src/api/DirMake.ts +2 -1
- package/src/api/DirRemove.ts +2 -1
- package/src/api/FileDelete.ts +2 -1
- package/src/api/FileRead.ts +12 -5
- package/src/api/FileWrite.ts +19 -7
- package/src/api/FirmwareUpdateV4.ts +13 -13
- package/src/api/GetPassphraseState.ts +18 -2
- package/src/api/PathInfo.ts +2 -1
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +15 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
- package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
- package/src/api/device/DeviceRebootToBootloader.ts +4 -4
- package/src/api/dynex/DnxGetAddress.ts +7 -0
- package/src/api/dynex/DnxSignTransaction.ts +7 -0
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +1 -1
- package/src/api/evm/EVMSignMessage.ts +1 -1
- package/src/api/evm/EVMSignTransaction.ts +1 -1
- package/src/api/evm/EVMSignTypedData.ts +6 -6
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/helpers/batchGetPublickeys.ts +4 -2
- package/src/api/helpers/filesystemValidation.ts +51 -0
- package/src/api/index.ts +5 -5
- package/src/api/protocol-v2/{DevFirmwareUpdate.ts → DeviceFirmwareUpdate.ts} +5 -4
- package/src/api/protocol-v2/{DevGetDeviceInfo.ts → DeviceGetDeviceInfo.ts} +3 -3
- package/src/api/protocol-v2/{DevGetFirmwareUpdateStatus.ts → DeviceGetFirmwareUpdateStatus.ts} +3 -3
- package/src/api/protocol-v2/{DevGetOnboardingStatus.ts → DeviceGetOnboardingStatus.ts} +3 -3
- package/src/api/protocol-v2/{DevReboot.ts → DeviceReboot.ts} +3 -3
- package/src/api/protocol-v2/helpers.ts +68 -45
- package/src/api/tron/TronSignMessage.ts +1 -1
- package/src/api/xrp/XrpSignTransaction.ts +1 -1
- package/src/core/index.ts +13 -1
- package/src/data/messages/{messages-pro2.json → messages-protocol-v2.json} +67 -63
- package/src/data-manager/DataManager.ts +9 -8
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +13 -13
- package/src/device/Device.ts +7 -3
- package/src/inject.ts +9 -9
- package/src/protocols/protocol-v2/features.ts +39 -41
- package/src/protocols/protocol-v2/firmware.ts +16 -16
- package/src/types/api/getPassphraseState.ts +15 -2
- package/src/types/api/index.ts +11 -10
- package/src/types/api/protocolV2.ts +27 -27
- package/src/utils/deviceFeaturesUtils.ts +53 -19
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts +0 -7
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts +0 -7
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
1
|
+
import { EDeviceType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
4
4
|
import { getPassphraseStateWithRefreshDeviceInfo } from '../utils/deviceFeaturesUtils';
|
|
5
|
+
import { getDeviceType } from '../utils/deviceInfoUtils';
|
|
5
6
|
import { BaseMethod } from './BaseMethod';
|
|
6
7
|
|
|
7
8
|
export default class GetPassphraseState extends BaseMethod {
|
|
@@ -14,9 +15,24 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
14
15
|
if (!this.device.features)
|
|
15
16
|
return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
|
|
16
17
|
|
|
17
|
-
const { passphraseState } =
|
|
18
|
+
const { passphraseState, newSession, unlockedAttachPin } =
|
|
19
|
+
await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
20
|
+
expectPassphraseState: this.payload.passphraseState,
|
|
21
|
+
onlyMainPin: this.payload.useEmptyPassphrase,
|
|
22
|
+
allowCreateAttachPin: this.payload.allowCreateAttachPin,
|
|
23
|
+
});
|
|
18
24
|
|
|
19
25
|
const { features } = this.device;
|
|
26
|
+
const isPro2 = getDeviceType(features) === EDeviceType.Pro2;
|
|
27
|
+
|
|
28
|
+
if (isPro2) {
|
|
29
|
+
return Promise.resolve({
|
|
30
|
+
passphrase_state: passphraseState,
|
|
31
|
+
session_id: newSession ?? features?.session_id ?? undefined,
|
|
32
|
+
unlocked_attach_pin: unlockedAttachPin,
|
|
33
|
+
passphrase_protection: features?.passphrase_protection ?? null,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
20
36
|
|
|
21
37
|
// refresh device info
|
|
22
38
|
if (features && features.passphrase_protection === true) {
|
package/src/api/PathInfo.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
import { validateNonEmptyString } from './helpers/filesystemValidation';
|
|
2
3
|
|
|
3
4
|
export type PathInfoParams = {
|
|
4
5
|
path: string;
|
|
@@ -8,7 +9,7 @@ export default class PathInfo extends BaseMethod<PathInfoParams> {
|
|
|
8
9
|
init() {
|
|
9
10
|
this.skipForceUpdateCheck = true;
|
|
10
11
|
this.useDevicePassphraseState = false;
|
|
11
|
-
this.params = { path: this.payload.path };
|
|
12
|
+
this.params = { path: validateNonEmptyString(this.payload.path, 'path') };
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
async run() {
|
|
@@ -492,9 +492,20 @@ 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
|
+
);
|
|
495
499
|
|
|
496
500
|
if (e instanceof HardwareError && e.errorCode !== HardwareErrorCode.RuntimeError) {
|
|
497
501
|
const { errorCode } = e;
|
|
502
|
+
if (
|
|
503
|
+
skipMethodSupportCheck &&
|
|
504
|
+
(errorCode === HardwareErrorCode.CallMethodNeedUpgradeFirmware ||
|
|
505
|
+
errorCode === HardwareErrorCode.DeviceNotSupportMethod)
|
|
506
|
+
) {
|
|
507
|
+
return undefined;
|
|
508
|
+
}
|
|
498
509
|
if (errorCode === HardwareErrorCode.CallMethodNeedUpgradeFirmware) {
|
|
499
510
|
error = e;
|
|
500
511
|
} else if (errorCode === HardwareErrorCode.DeviceNotSupportMethod) {
|
|
@@ -504,6 +515,10 @@ function handleSkippableHardwareError(
|
|
|
504
515
|
e.message?.includes('Failure_UnexpectedMessage') ||
|
|
505
516
|
e.message?.includes('Failure_UnknownMessage')
|
|
506
517
|
) {
|
|
518
|
+
if (skipMethodSupportCheck) {
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
|
|
507
522
|
const versionRange = getMethodVersionRange(
|
|
508
523
|
device.features,
|
|
509
524
|
type => method.getVersionRange()[type]
|
|
@@ -34,7 +34,7 @@ export default class ConfluxSignTransaction extends BaseMethod {
|
|
|
34
34
|
|
|
35
35
|
// check if transaction is valid
|
|
36
36
|
const schema: SchemaParam[] = [
|
|
37
|
-
{ name: 'to', type: '
|
|
37
|
+
{ name: 'to', type: 'string', required: true },
|
|
38
38
|
{ name: 'value', type: 'hexString', required: true },
|
|
39
39
|
{ name: 'gasLimit', type: 'hexString', required: true },
|
|
40
40
|
{ name: 'gasPrice', type: 'hexString', required: true },
|
|
@@ -47,7 +47,10 @@ export default class ConfluxSignTransaction extends BaseMethod {
|
|
|
47
47
|
|
|
48
48
|
validateParams(tx, schema);
|
|
49
49
|
|
|
50
|
-
this.formattedTx =
|
|
50
|
+
this.formattedTx = {
|
|
51
|
+
...formatAnyHex(tx),
|
|
52
|
+
to: tx.to,
|
|
53
|
+
};
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
processTxRequest = async (request: ConfluxTxRequest, data: string): Promise<ConfluxSignedTx> => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -23,10 +23,10 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
|
-
// Protocol V2 uses
|
|
26
|
+
// Protocol V2 uses DeviceReboot with reboot_type enum.
|
|
27
27
|
if (this.device.originalDescriptor?.protocolType === 'V2') {
|
|
28
|
-
const res = await this.device.commands.typedCall('
|
|
29
|
-
reboot_type:
|
|
28
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
|
+
reboot_type: DeviceRebootType.Boardloader,
|
|
30
30
|
});
|
|
31
31
|
return Promise.resolve(res.message);
|
|
32
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -23,10 +23,10 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
|
-
// Protocol V2 uses
|
|
26
|
+
// Protocol V2 uses DeviceReboot with reboot_type enum.
|
|
27
27
|
if (this.device.originalDescriptor?.protocolType === 'V2') {
|
|
28
|
-
const res = await this.device.commands.typedCall('
|
|
29
|
-
reboot_type:
|
|
28
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
|
+
reboot_type: DeviceRebootType.Bootloader,
|
|
30
30
|
});
|
|
31
31
|
return Promise.resolve(res.message);
|
|
32
32
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
1
3
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
2
4
|
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
3
5
|
import { BaseMethod } from '../BaseMethod';
|
|
4
6
|
import { validateParams, validateResult } from '../helpers/paramsValidator';
|
|
7
|
+
import { getFirmwareType } from '../../utils';
|
|
5
8
|
|
|
6
9
|
import type { DnxGetAddress as HardwareDnxGetAddress } from '@onekeyfe/hd-transport';
|
|
7
10
|
import type { DnxAddress, DnxGetAddressParams } from '../../types';
|
|
@@ -47,6 +50,10 @@ export default class DnxGetAddress extends BaseMethod<HardwareDnxGetAddress[]> {
|
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
async run() {
|
|
53
|
+
if (this.device.originalDescriptor?.protocolType === 'V2') {
|
|
54
|
+
throw createDeviceNotSupportMethodError(this.name, getFirmwareType(this.device.features));
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
const responses: DnxAddress[] = [];
|
|
51
58
|
|
|
52
59
|
for (let i = 0; i < this.params.length; i++) {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
1
3
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
2
4
|
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
3
5
|
import { BaseMethod } from '../BaseMethod';
|
|
4
6
|
import { validateParams } from '../helpers/paramsValidator';
|
|
5
7
|
import { stripHexPrefix } from '../helpers/hexUtils';
|
|
8
|
+
import { getFirmwareType } from '../../utils';
|
|
6
9
|
|
|
7
10
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
8
11
|
import type { DnxSignature } from '../../types';
|
|
@@ -115,6 +118,10 @@ export default class DnxSignTransaction extends BaseMethod<DnxSignTx> {
|
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
async run() {
|
|
121
|
+
if (this.device.originalDescriptor?.protocolType === 'V2') {
|
|
122
|
+
throw createDeviceNotSupportMethodError(this.name, getFirmwareType(this.device.features));
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
119
126
|
|
|
120
127
|
const res = await this.device.commands.typedCall('DnxSignTx', 'DnxInputRequest', {
|
|
@@ -44,7 +44,7 @@ export default class EvmGetAddress extends BaseMethod<EthereumGetAddressOneKey[]
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async getEvmAddress(param: EthereumGetAddressOneKey) {
|
|
47
|
-
if (TransportManager.
|
|
47
|
+
if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
|
|
48
48
|
return getAddressLegacyV1({
|
|
49
49
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
50
50
|
param,
|
|
@@ -57,7 +57,7 @@ export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneK
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
getEvmPublicKey(param: EthereumGetPublicKey) {
|
|
60
|
-
if (TransportManager.
|
|
60
|
+
if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
|
|
61
61
|
return getPublicKeyLegacyV1({
|
|
62
62
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
63
63
|
param,
|
|
@@ -34,7 +34,7 @@ export default class EVMSignMessage extends BaseMethod<EthereumSignMessageOneKey
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
async run() {
|
|
37
|
-
if (TransportManager.
|
|
37
|
+
if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
|
|
38
38
|
return signMessageLegacyV1({
|
|
39
39
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
40
40
|
params: this.params,
|
|
@@ -120,7 +120,7 @@ export default class EVMSignTransaction extends BaseMethod {
|
|
|
120
120
|
|
|
121
121
|
if (formattedTx == null) throw ERRORS.TypedError('Runtime', 'formattedTx is not set');
|
|
122
122
|
|
|
123
|
-
if (TransportManager.
|
|
123
|
+
if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
|
|
124
124
|
return signTransactionLegacyV1({
|
|
125
125
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
126
126
|
addressN,
|
|
@@ -260,8 +260,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
260
260
|
|
|
261
261
|
let supportTrezor = false;
|
|
262
262
|
let response: MessageResponse<MessageKey>;
|
|
263
|
-
switch (TransportManager.
|
|
264
|
-
case '
|
|
263
|
+
switch (TransportManager.getProtocolV1MessageSchema()) {
|
|
264
|
+
case 'v1LegacySchema':
|
|
265
265
|
supportTrezor = true;
|
|
266
266
|
response = await signTypedDataLegacyV1({
|
|
267
267
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
@@ -272,7 +272,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
272
272
|
});
|
|
273
273
|
break;
|
|
274
274
|
|
|
275
|
-
case '
|
|
275
|
+
case 'v1CurrentSchema':
|
|
276
276
|
default:
|
|
277
277
|
supportTrezor = false;
|
|
278
278
|
response = await signTypedData({
|
|
@@ -308,8 +308,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
308
308
|
}) {
|
|
309
309
|
if (!domainHash) throw ERRORS.TypedError('Runtime', 'domainHash is required');
|
|
310
310
|
|
|
311
|
-
switch (TransportManager.
|
|
312
|
-
case '
|
|
311
|
+
switch (TransportManager.getProtocolV1MessageSchema()) {
|
|
312
|
+
case 'v1LegacySchema':
|
|
313
313
|
return signTypedHashLegacyV1({
|
|
314
314
|
typedCall,
|
|
315
315
|
addressN,
|
|
@@ -319,7 +319,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
319
319
|
device: this.device,
|
|
320
320
|
});
|
|
321
321
|
|
|
322
|
-
case '
|
|
322
|
+
case 'v1CurrentSchema':
|
|
323
323
|
default:
|
|
324
324
|
return signTypedHash({
|
|
325
325
|
typedCall,
|
|
@@ -31,7 +31,7 @@ export default class EVMSignMessage extends BaseMethod<EthereumVerifyMessageOneK
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async run() {
|
|
34
|
-
if (TransportManager.
|
|
34
|
+
if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
|
|
35
35
|
return verifyMessageLegacyV1({
|
|
36
36
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
37
37
|
params: this.params,
|
|
@@ -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 } from '../../utils';
|
|
10
|
+
import { getDeviceType, getFirmwareType, shouldSkipMethodSupportCheck } from '../../utils';
|
|
11
11
|
import { DeviceModelToTypes } from '../../types';
|
|
12
12
|
|
|
13
13
|
import type { EcdsaPublicKeys, Path } from '@onekeyfe/hd-transport';
|
|
@@ -28,7 +28,9 @@ export async function batchGetPublickeys(
|
|
|
28
28
|
throw TypedError(HardwareErrorCode.ForbiddenKeyPath, 'Path length must be greater than 3');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const supportsBatchPublicKey =
|
|
31
|
+
const supportsBatchPublicKey =
|
|
32
|
+
shouldSkipMethodSupportCheck(device.features, device.originalDescriptor?.protocolType) ||
|
|
33
|
+
supportBatchPublicKey(device.features, options);
|
|
32
34
|
if (!supportsBatchPublicKey) {
|
|
33
35
|
throw createDeviceNotSupportMethodError('BatchGetPublickeys', getFirmwareType(device.features));
|
|
34
36
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
export const invalidParameter = (message: string) =>
|
|
4
|
+
ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, message);
|
|
5
|
+
|
|
6
|
+
export function validateNonEmptyString(value: unknown, name: string): string {
|
|
7
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
8
|
+
throw invalidParameter(`Parameter [${name}] is required and must be a non-empty string.`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function validateNonNegativeInteger(
|
|
14
|
+
value: unknown,
|
|
15
|
+
name: string,
|
|
16
|
+
defaultValue?: number
|
|
17
|
+
): number {
|
|
18
|
+
if (value === undefined || value === null) {
|
|
19
|
+
if (defaultValue !== undefined) return defaultValue;
|
|
20
|
+
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const numeric = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;
|
|
24
|
+
if (typeof numeric !== 'number' || !Number.isSafeInteger(numeric) || numeric < 0) {
|
|
25
|
+
throw invalidParameter(`Parameter [${name}] must be a non-negative integer.`);
|
|
26
|
+
}
|
|
27
|
+
return numeric;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function validateOptionalNonNegativeInteger(
|
|
31
|
+
value: unknown,
|
|
32
|
+
name: string
|
|
33
|
+
): number | undefined {
|
|
34
|
+
if (value === undefined || value === null) return undefined;
|
|
35
|
+
return validateNonNegativeInteger(value, name);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function validateOptionalPercentage(value: unknown, name: string): number | undefined {
|
|
39
|
+
const numeric = validateOptionalNonNegativeInteger(value, name);
|
|
40
|
+
if (numeric === undefined) return undefined;
|
|
41
|
+
if (numeric > 100) {
|
|
42
|
+
throw invalidParameter(`Parameter [${name}] must be between 0 and 100.`);
|
|
43
|
+
}
|
|
44
|
+
return numeric;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function validateRequiredData(value: unknown, name: string): void {
|
|
48
|
+
if (value === undefined || value === null) {
|
|
49
|
+
throw invalidParameter(`Missing required parameter: ${name}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/api/index.ts
CHANGED
|
@@ -43,11 +43,11 @@ export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
|
|
|
43
43
|
// File system & device control API (Protocol V2 only)
|
|
44
44
|
export { default as getProtoVersion } from './protocol-v2/GetProtoVersion';
|
|
45
45
|
export { default as ping } from './protocol-v2/Ping';
|
|
46
|
-
export { default as
|
|
47
|
-
export { default as
|
|
48
|
-
export { default as
|
|
49
|
-
export { default as
|
|
50
|
-
export { default as
|
|
46
|
+
export { default as deviceReboot } from './protocol-v2/DeviceReboot';
|
|
47
|
+
export { default as deviceGetDeviceInfo } from './protocol-v2/DeviceGetDeviceInfo';
|
|
48
|
+
export { default as deviceGetOnboardingStatus } from './protocol-v2/DeviceGetOnboardingStatus';
|
|
49
|
+
export { default as deviceFirmwareUpdate } from './protocol-v2/DeviceFirmwareUpdate';
|
|
50
|
+
export { default as deviceGetFirmwareUpdateStatus } from './protocol-v2/DeviceGetFirmwareUpdateStatus';
|
|
51
51
|
export { default as factoryDeviceInfoSettings } from './protocol-v2/FactoryDeviceInfoSettings';
|
|
52
52
|
export { default as factoryGetDeviceInfo } from './protocol-v2/FactoryGetDeviceInfo';
|
|
53
53
|
export { default as filesystemFixPermission } from './protocol-v2/FilesystemFixPermission';
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
normalizeFirmwareTargets,
|
|
6
6
|
} from './helpers';
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { DeviceFirmwareUpdateParams } from './helpers';
|
|
9
9
|
|
|
10
|
-
export default class
|
|
10
|
+
export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdateParams> {
|
|
11
11
|
init() {
|
|
12
12
|
this.skipForceUpdateCheck = true;
|
|
13
13
|
this.useDevicePassphraseState = false;
|
|
@@ -20,11 +20,12 @@ export default class DevFirmwareUpdate extends BaseMethod<DevFirmwareUpdateParam
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async run() {
|
|
23
|
+
const targets = normalizeFirmwareTargets(this.params);
|
|
23
24
|
const res = await this.device.commands.typedCall(
|
|
24
|
-
'
|
|
25
|
+
'DeviceFirmwareUpdate',
|
|
25
26
|
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
26
27
|
{
|
|
27
|
-
targets
|
|
28
|
+
targets,
|
|
28
29
|
},
|
|
29
30
|
PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS
|
|
30
31
|
);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
import { buildTargets, buildTypes } from './helpers';
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { DeviceGetDeviceInfoParams } from './helpers';
|
|
5
5
|
|
|
6
|
-
export default class
|
|
6
|
+
export default class DeviceGetDeviceInfo extends BaseMethod<DeviceGetDeviceInfoParams> {
|
|
7
7
|
init() {
|
|
8
8
|
this.skipForceUpdateCheck = true;
|
|
9
9
|
this.useDevicePassphraseState = false;
|
|
@@ -26,7 +26,7 @@ export default class DevGetDeviceInfo extends BaseMethod<DevGetDeviceInfoParams>
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async run() {
|
|
29
|
-
const res = await this.device.commands.typedCall('
|
|
29
|
+
const res = await this.device.commands.typedCall('DeviceGetDeviceInfo', 'DeviceInfo', {
|
|
30
30
|
targets: buildTargets(this.params),
|
|
31
31
|
types: buildTypes(this.params),
|
|
32
32
|
});
|
package/src/api/protocol-v2/{DevGetFirmwareUpdateStatus.ts → DeviceGetFirmwareUpdateStatus.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
|
|
3
|
-
export default class
|
|
3
|
+
export default class DeviceGetFirmwareUpdateStatus extends BaseMethod {
|
|
4
4
|
init() {
|
|
5
5
|
this.skipForceUpdateCheck = true;
|
|
6
6
|
this.useDevicePassphraseState = false;
|
|
@@ -9,8 +9,8 @@ export default class DevGetFirmwareUpdateStatus extends BaseMethod {
|
|
|
9
9
|
|
|
10
10
|
async run() {
|
|
11
11
|
const res = await this.device.commands.typedCall(
|
|
12
|
-
'
|
|
13
|
-
'
|
|
12
|
+
'DeviceGetFirmwareUpdateStatus',
|
|
13
|
+
'DeviceFirmwareUpdateStatus',
|
|
14
14
|
{}
|
|
15
15
|
);
|
|
16
16
|
return Promise.resolve(res.message);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
|
|
3
|
-
export default class
|
|
3
|
+
export default class DeviceGetOnboardingStatus extends BaseMethod {
|
|
4
4
|
init() {
|
|
5
5
|
this.skipForceUpdateCheck = true;
|
|
6
6
|
this.useDevicePassphraseState = false;
|
|
@@ -9,8 +9,8 @@ export default class DevGetOnboardingStatus extends BaseMethod {
|
|
|
9
9
|
|
|
10
10
|
async run() {
|
|
11
11
|
const res = await this.device.commands.typedCall(
|
|
12
|
-
'
|
|
13
|
-
'
|
|
12
|
+
'DeviceGetOnboardingStatus',
|
|
13
|
+
'DeviceOnboardingStatus',
|
|
14
14
|
{}
|
|
15
15
|
);
|
|
16
16
|
return Promise.resolve(res.message);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
import { normalizeRebootType } from './helpers';
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { DeviceRebootParams } from './helpers';
|
|
5
5
|
|
|
6
|
-
export default class
|
|
6
|
+
export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
|
|
7
7
|
init() {
|
|
8
8
|
this.skipForceUpdateCheck = true;
|
|
9
9
|
this.useDevicePassphraseState = false;
|
|
@@ -14,7 +14,7 @@ export default class DevReboot extends BaseMethod<DevRebootParams> {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async run() {
|
|
17
|
-
const res = await this.device.commands.typedCall('
|
|
17
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
18
18
|
reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
|
|
19
19
|
});
|
|
20
20
|
return Promise.resolve(res.message);
|