@onekeyfe/hd-core 0.0.1
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/.eslintrc +6 -0
- package/README.md +3 -0
- package/dist/api/BTCGetAddress.d.ts +8 -0
- package/dist/api/BTCGetAddress.d.ts.map +1 -0
- package/dist/api/BTCGetPublicKey.d.ts +8 -0
- package/dist/api/BTCGetPublicKey.d.ts.map +1 -0
- package/dist/api/BTCSignMessage.d.ts +10 -0
- package/dist/api/BTCSignMessage.d.ts.map +1 -0
- package/dist/api/BTCSignTransaction.d.ts +17 -0
- package/dist/api/BTCSignTransaction.d.ts.map +1 -0
- package/dist/api/BTCVerifyMessage.d.ts +9 -0
- package/dist/api/BTCVerifyMessage.d.ts.map +1 -0
- package/dist/api/BaseMethod.d.ts +24 -0
- package/dist/api/BaseMethod.d.ts.map +1 -0
- package/dist/api/CheckBLEFirmwareRelease.d.ts +6 -0
- package/dist/api/CheckBLEFirmwareRelease.d.ts.map +1 -0
- package/dist/api/CheckFirmwareRelease.d.ts +6 -0
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -0
- package/dist/api/CheckTransportRelease.d.ts +6 -0
- package/dist/api/CheckTransportRelease.d.ts.map +1 -0
- package/dist/api/DeviceBackup.d.ts +9 -0
- package/dist/api/DeviceBackup.d.ts.map +1 -0
- package/dist/api/DeviceChangePin.d.ts +9 -0
- package/dist/api/DeviceChangePin.d.ts.map +1 -0
- package/dist/api/DeviceFlags.d.ts +9 -0
- package/dist/api/DeviceFlags.d.ts.map +1 -0
- package/dist/api/DeviceRebootToBootloader.d.ts +9 -0
- package/dist/api/DeviceRebootToBootloader.d.ts.map +1 -0
- package/dist/api/DeviceRecovery.d.ts +9 -0
- package/dist/api/DeviceRecovery.d.ts.map +1 -0
- package/dist/api/DeviceReset.d.ts +9 -0
- package/dist/api/DeviceReset.d.ts.map +1 -0
- package/dist/api/DeviceSettings.d.ts +9 -0
- package/dist/api/DeviceSettings.d.ts.map +1 -0
- package/dist/api/DeviceUpdateReboot.d.ts +9 -0
- package/dist/api/DeviceUpdateReboot.d.ts.map +1 -0
- package/dist/api/DeviceWipe.d.ts +9 -0
- package/dist/api/DeviceWipe.d.ts.map +1 -0
- package/dist/api/EVMGetAddress.d.ts +8 -0
- package/dist/api/EVMGetAddress.d.ts.map +1 -0
- package/dist/api/EVMGetPublicKey.d.ts +8 -0
- package/dist/api/EVMGetPublicKey.d.ts.map +1 -0
- package/dist/api/EVMSignMessage.d.ts +10 -0
- package/dist/api/EVMSignMessage.d.ts.map +1 -0
- package/dist/api/EVMSignMessageEIP712.d.ts +10 -0
- package/dist/api/EVMSignMessageEIP712.d.ts.map +1 -0
- package/dist/api/EVMSignTransaction.d.ts +20 -0
- package/dist/api/EVMSignTransaction.d.ts.map +1 -0
- package/dist/api/EVMSignTypedData.d.ts +18 -0
- package/dist/api/EVMSignTypedData.d.ts.map +1 -0
- package/dist/api/EVMVerifyMessage.d.ts +9 -0
- package/dist/api/EVMVerifyMessage.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +51 -0
- package/dist/api/GetFeatures.d.ts.map +1 -0
- package/dist/api/SearchDevices.d.ts +16 -0
- package/dist/api/SearchDevices.d.ts.map +1 -0
- package/dist/api/helpers/bigNumberUtils.d.ts +4 -0
- package/dist/api/helpers/bigNumberUtils.d.ts.map +1 -0
- package/dist/api/helpers/btc/signtx.d.ts +5 -0
- package/dist/api/helpers/btc/signtx.d.ts.map +1 -0
- package/dist/api/helpers/btc/signtxLegacy.d.ts +5 -0
- package/dist/api/helpers/btc/signtxLegacy.d.ts.map +1 -0
- package/dist/api/helpers/btcParamsUtils.d.ts +11 -0
- package/dist/api/helpers/btcParamsUtils.d.ts.map +1 -0
- package/dist/api/helpers/hexUtils.d.ts +7 -0
- package/dist/api/helpers/hexUtils.d.ts.map +1 -0
- package/dist/api/helpers/paramsValidator.d.ts +8 -0
- package/dist/api/helpers/paramsValidator.d.ts.map +1 -0
- package/dist/api/helpers/pathUtils.d.ts +12 -0
- package/dist/api/helpers/pathUtils.d.ts.map +1 -0
- package/dist/api/helpers/stringUtils.d.ts +2 -0
- package/dist/api/helpers/stringUtils.d.ts.map +1 -0
- package/dist/api/helpers/typeNameUtils.d.ts +9 -0
- package/dist/api/helpers/typeNameUtils.d.ts.map +1 -0
- package/dist/api/index.d.ts +27 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/utils.d.ts +5 -0
- package/dist/api/utils.d.ts.map +1 -0
- package/dist/constants/errors.d.ts +25 -0
- package/dist/constants/errors.d.ts.map +1 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/ui-request.d.ts +13 -0
- package/dist/constants/ui-request.d.ts.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/data/version.d.ts +3 -0
- package/dist/data/version.d.ts.map +1 -0
- package/dist/data-manager/CoinManager.d.ts +13 -0
- package/dist/data-manager/CoinManager.d.ts.map +1 -0
- package/dist/data-manager/DataManager.d.ts +17 -0
- package/dist/data-manager/DataManager.d.ts.map +1 -0
- package/dist/data-manager/TransportManager.d.ts +15 -0
- package/dist/data-manager/TransportManager.d.ts.map +1 -0
- package/dist/data-manager/connectSettings.d.ts +9 -0
- package/dist/data-manager/connectSettings.d.ts.map +1 -0
- package/dist/data-manager/index.d.ts +3 -0
- package/dist/data-manager/index.d.ts.map +1 -0
- package/dist/device/Device.d.ts +64 -0
- package/dist/device/Device.d.ts.map +1 -0
- package/dist/device/DeviceCommands.d.ts +35 -0
- package/dist/device/DeviceCommands.d.ts.map +1 -0
- package/dist/device/DeviceConnector.d.ts +28 -0
- package/dist/device/DeviceConnector.d.ts.map +1 -0
- package/dist/device/DeviceList.d.ts +12 -0
- package/dist/device/DeviceList.d.ts.map +1 -0
- package/dist/events/call.d.ts +41 -0
- package/dist/events/call.d.ts.map +1 -0
- package/dist/events/core.d.ts +16 -0
- package/dist/events/core.d.ts.map +1 -0
- package/dist/events/device.d.ts +23 -0
- package/dist/events/device.d.ts.map +1 -0
- package/dist/events/iframe.d.ts +24 -0
- package/dist/events/iframe.d.ts.map +1 -0
- package/dist/events/index.d.ts +8 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/ui-promise.d.ts +12 -0
- package/dist/events/ui-promise.d.ts.map +1 -0
- package/dist/events/ui-request.d.ts +20 -0
- package/dist/events/ui-request.d.ts.map +1 -0
- package/dist/events/ui-response.d.ts +15 -0
- package/dist/events/ui-response.d.ts.map +1 -0
- package/dist/events/utils.d.ts +15 -0
- package/dist/events/utils.d.ts.map +1 -0
- package/dist/index.d.ts +823 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12396 -0
- package/dist/inject.d.ts +14 -0
- package/dist/inject.d.ts.map +1 -0
- package/dist/types/api/btcGetAddress.d.ts +14 -0
- package/dist/types/api/btcGetAddress.d.ts.map +1 -0
- package/dist/types/api/btcGetPublicKey.d.ts +13 -0
- package/dist/types/api/btcGetPublicKey.d.ts.map +1 -0
- package/dist/types/api/btcSignMessage.d.ts +9 -0
- package/dist/types/api/btcSignMessage.d.ts.map +1 -0
- package/dist/types/api/btcSignTransaction.d.ts +74 -0
- package/dist/types/api/btcSignTransaction.d.ts.map +1 -0
- package/dist/types/api/btcVerifyMessage.d.ts +10 -0
- package/dist/types/api/btcVerifyMessage.d.ts.map +1 -0
- package/dist/types/api/checkBLEFirmwareRelease.d.ts +4 -0
- package/dist/types/api/checkBLEFirmwareRelease.d.ts.map +1 -0
- package/dist/types/api/checkFirmwareRelease.d.ts +4 -0
- package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -0
- package/dist/types/api/checkTransportRelease.d.ts +4 -0
- package/dist/types/api/checkTransportRelease.d.ts.map +1 -0
- package/dist/types/api/deviceBackup.d.ts +4 -0
- package/dist/types/api/deviceBackup.d.ts.map +1 -0
- package/dist/types/api/deviceChangePin.d.ts +7 -0
- package/dist/types/api/deviceChangePin.d.ts.map +1 -0
- package/dist/types/api/deviceFlags.d.ts +7 -0
- package/dist/types/api/deviceFlags.d.ts.map +1 -0
- package/dist/types/api/deviceRebootToBootloader.d.ts +4 -0
- package/dist/types/api/deviceRebootToBootloader.d.ts.map +1 -0
- package/dist/types/api/deviceRecovery.d.ts +15 -0
- package/dist/types/api/deviceRecovery.d.ts.map +1 -0
- package/dist/types/api/deviceReset.d.ts +16 -0
- package/dist/types/api/deviceReset.d.ts.map +1 -0
- package/dist/types/api/deviceSettings.d.ts +16 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -0
- package/dist/types/api/deviceUpdateReboot.d.ts +4 -0
- package/dist/types/api/deviceUpdateReboot.d.ts.map +1 -0
- package/dist/types/api/deviceWipe.d.ts +4 -0
- package/dist/types/api/deviceWipe.d.ts.map +1 -0
- package/dist/types/api/event.d.ts +4 -0
- package/dist/types/api/event.d.ts.map +1 -0
- package/dist/types/api/evmGetAddress.d.ts +11 -0
- package/dist/types/api/evmGetAddress.d.ts.map +1 -0
- package/dist/types/api/evmGetPublicKey.d.ts +11 -0
- package/dist/types/api/evmGetPublicKey.d.ts.map +1 -0
- package/dist/types/api/evmSignMessage.d.ts +8 -0
- package/dist/types/api/evmSignMessage.d.ts.map +1 -0
- package/dist/types/api/evmSignMessageEIP712.d.ts +9 -0
- package/dist/types/api/evmSignMessageEIP712.d.ts.map +1 -0
- package/dist/types/api/evmSignTransaction.d.ts +36 -0
- package/dist/types/api/evmSignTransaction.d.ts.map +1 -0
- package/dist/types/api/evmSignTypedData.d.ts +33 -0
- package/dist/types/api/evmSignTypedData.d.ts.map +1 -0
- package/dist/types/api/evmVerifyMessage.d.ts +9 -0
- package/dist/types/api/evmVerifyMessage.d.ts.map +1 -0
- package/dist/types/api/getFeatures.d.ts +4 -0
- package/dist/types/api/getFeatures.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +66 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/init.d.ts +3 -0
- package/dist/types/api/init.d.ts.map +1 -0
- package/dist/types/api/searchDevices.d.ts +4 -0
- package/dist/types/api/searchDevices.d.ts.map +1 -0
- package/dist/types/api/uiResponse.d.ts +3 -0
- package/dist/types/api/uiResponse.d.ts.map +1 -0
- package/dist/types/device.d.ts +29 -0
- package/dist/types/device.d.ts.map +1 -0
- package/dist/types/firmware.d.ts +37 -0
- package/dist/types/firmware.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/params.d.ts +16 -0
- package/dist/types/params.d.ts.map +1 -0
- package/dist/types/settings.d.ts +65 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/dist/utils/assets.d.ts +3 -0
- package/dist/utils/assets.d.ts.map +1 -0
- package/dist/utils/deferred.d.ts +9 -0
- package/dist/utils/deferred.d.ts.map +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts +52 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -0
- package/dist/utils/findDefectiveBatchDevice.d.ts +3 -0
- package/dist/utils/findDefectiveBatchDevice.d.ts.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/networkUtils.d.ts +2 -0
- package/dist/utils/networkUtils.d.ts.map +1 -0
- package/dist/utils/promiseUtils.d.ts +2 -0
- package/dist/utils/promiseUtils.d.ts.map +1 -0
- package/dist/utils/versionUtils.d.ts +6 -0
- package/dist/utils/versionUtils.d.ts.map +1 -0
- package/package.json +39 -0
- package/src/api/BTCGetAddress.ts +71 -0
- package/src/api/BTCGetPublicKey.ts +70 -0
- package/src/api/BTCSignMessage.ts +40 -0
- package/src/api/BTCSignTransaction.ts +141 -0
- package/src/api/BTCVerifyMessage.ts +40 -0
- package/src/api/BaseMethod.ts +71 -0
- package/src/api/CheckBLEFirmwareRelease.ts +18 -0
- package/src/api/CheckFirmwareRelease.ts +15 -0
- package/src/api/CheckTransportRelease.ts +19 -0
- package/src/api/DeviceBackup.ts +12 -0
- package/src/api/DeviceChangePin.ts +22 -0
- package/src/api/DeviceFlags.ts +23 -0
- package/src/api/DeviceRebootToBootloader.ts +13 -0
- package/src/api/DeviceRecovery.ts +41 -0
- package/src/api/DeviceReset.ts +43 -0
- package/src/api/DeviceSettings.ts +45 -0
- package/src/api/DeviceUpdateReboot.ts +13 -0
- package/src/api/DeviceWipe.ts +12 -0
- package/src/api/EVMGetAddress.ts +54 -0
- package/src/api/EVMGetPublicKey.ts +58 -0
- package/src/api/EVMSignMessage.ts +40 -0
- package/src/api/EVMSignMessageEIP712.ts +40 -0
- package/src/api/EVMSignTransaction.ts +195 -0
- package/src/api/EVMSignTypedData.ts +212 -0
- package/src/api/EVMVerifyMessage.ts +33 -0
- package/src/api/GetFeatures.ts +12 -0
- package/src/api/SearchDevices.ts +40 -0
- package/src/api/helpers/bigNumberUtils.ts +58 -0
- package/src/api/helpers/btc/signtx.ts +232 -0
- package/src/api/helpers/btc/signtxLegacy.ts +205 -0
- package/src/api/helpers/btcParamsUtils.ts +57 -0
- package/src/api/helpers/hexUtils.ts +50 -0
- package/src/api/helpers/paramsValidator.ts +95 -0
- package/src/api/helpers/pathUtils.ts +111 -0
- package/src/api/helpers/stringUtils.ts +8 -0
- package/src/api/helpers/typeNameUtils.ts +132 -0
- package/src/api/index.ts +26 -0
- package/src/api/utils.ts +18 -0
- package/src/constants/errors.ts +47 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/ui-request.ts +12 -0
- package/src/core/index.ts +305 -0
- package/src/data/coins/bitcoin.json +42 -0
- package/src/data/messages/messages.json +8658 -0
- package/src/data/version.ts +3 -0
- package/src/data-manager/CoinManager.ts +31 -0
- package/src/data-manager/DataManager.ts +148 -0
- package/src/data-manager/TransportManager.ts +87 -0
- package/src/data-manager/connectSettings.ts +109 -0
- package/src/data-manager/index.ts +2 -0
- package/src/device/Device.ts +411 -0
- package/src/device/DeviceCommands.ts +207 -0
- package/src/device/DeviceConnector.ts +173 -0
- package/src/device/DeviceList.ts +47 -0
- package/src/events/call.ts +72 -0
- package/src/events/core.ts +41 -0
- package/src/events/device.ts +28 -0
- package/src/events/iframe.ts +34 -0
- package/src/events/index.ts +7 -0
- package/src/events/ui-promise.ts +14 -0
- package/src/events/ui-request.ts +28 -0
- package/src/events/ui-response.ts +25 -0
- package/src/events/utils.ts +19 -0
- package/src/index.ts +29 -0
- package/src/inject.ts +103 -0
- package/src/types/api/btcGetAddress.ts +24 -0
- package/src/types/api/btcGetPublicKey.ts +19 -0
- package/src/types/api/btcSignMessage.ts +13 -0
- package/src/types/api/btcSignTransaction.ts +98 -0
- package/src/types/api/btcVerifyMessage.ts +14 -0
- package/src/types/api/checkBLEFirmwareRelease.ts +6 -0
- package/src/types/api/checkFirmwareRelease.ts +4 -0
- package/src/types/api/checkTransportRelease.ts +4 -0
- package/src/types/api/deviceBackup.ts +4 -0
- package/src/types/api/deviceChangePin.ts +11 -0
- package/src/types/api/deviceFlags.ts +11 -0
- package/src/types/api/deviceRebootToBootloader.ts +4 -0
- package/src/types/api/deviceRecovery.ts +19 -0
- package/src/types/api/deviceReset.ts +20 -0
- package/src/types/api/deviceSettings.ts +17 -0
- package/src/types/api/deviceUpdateReboot.ts +4 -0
- package/src/types/api/deviceWipe.ts +4 -0
- package/src/types/api/event.ts +8 -0
- package/src/types/api/evmGetAddress.ts +17 -0
- package/src/types/api/evmGetPublicKey.ts +17 -0
- package/src/types/api/evmSignMessage.ts +12 -0
- package/src/types/api/evmSignMessageEIP712.ts +13 -0
- package/src/types/api/evmSignTransaction.ts +43 -0
- package/src/types/api/evmSignTypedData.ts +40 -0
- package/src/types/api/evmVerifyMessage.ts +13 -0
- package/src/types/api/getFeatures.ts +4 -0
- package/src/types/api/index.ts +80 -0
- package/src/types/api/init.ts +3 -0
- package/src/types/api/searchDevices.ts +4 -0
- package/src/types/api/uiResponse.ts +3 -0
- package/src/types/device.ts +71 -0
- package/src/types/firmware.ts +40 -0
- package/src/types/global.d.ts +3 -0
- package/src/types/index.ts +5 -0
- package/src/types/params.ts +15 -0
- package/src/types/settings.ts +77 -0
- package/src/utils/assets.ts +5 -0
- package/src/utils/deferred.ts +35 -0
- package/src/utils/deviceFeaturesUtils.ts +49 -0
- package/src/utils/findDefectiveBatchDevice.ts +10 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/logger.ts +113 -0
- package/src/utils/networkUtils.ts +18 -0
- package/src/utils/promiseUtils.ts +4 -0
- package/src/utils/versionUtils.ts +120 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { TxInputType, TxOutputType } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
|
|
3
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
4
|
+
import { getOutputScriptType, isSegwitPath, validatePath } from './helpers/pathUtils';
|
|
5
|
+
import { BaseMethod } from './BaseMethod';
|
|
6
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
7
|
+
import {
|
|
8
|
+
AccountAddresses,
|
|
9
|
+
BTCSignTransactionParams,
|
|
10
|
+
RefTransaction,
|
|
11
|
+
TransactionOptions,
|
|
12
|
+
} from '../types/api/btcSignTransaction';
|
|
13
|
+
import { ERRORS } from '../constants';
|
|
14
|
+
import signtx from './helpers/btc/signtx';
|
|
15
|
+
import signtxLegacy from './helpers/btc/signtxLegacy';
|
|
16
|
+
import { getCoinInfo } from './helpers/btcParamsUtils';
|
|
17
|
+
|
|
18
|
+
type Params = {
|
|
19
|
+
inputs: TxInputType[];
|
|
20
|
+
outputs: TxOutputType[];
|
|
21
|
+
refTxs: RefTransaction[];
|
|
22
|
+
addresses?: AccountAddresses;
|
|
23
|
+
options: TransactionOptions;
|
|
24
|
+
coinName: string;
|
|
25
|
+
};
|
|
26
|
+
export default class BTCSignTransaction extends BaseMethod<Params> {
|
|
27
|
+
init() {
|
|
28
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
29
|
+
|
|
30
|
+
validateParams(this.payload, [
|
|
31
|
+
{ name: 'coin', type: 'string', required: true },
|
|
32
|
+
{ name: 'inputs', type: 'array', required: true },
|
|
33
|
+
{ name: 'outputs', type: 'array', required: true },
|
|
34
|
+
{ name: 'refTxs', type: 'array', required: true, allowEmpty: true },
|
|
35
|
+
{ name: 'locktime', type: 'number' },
|
|
36
|
+
{ name: 'version', type: 'number' },
|
|
37
|
+
{ name: 'expiry', type: 'number' },
|
|
38
|
+
{ name: 'overwintered', type: 'boolean' },
|
|
39
|
+
{ name: 'versionGroupId', type: 'number' },
|
|
40
|
+
{ name: 'branchId', type: 'number' },
|
|
41
|
+
{ name: 'timestamp', type: 'number' },
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
this.payload.refTxs.forEach((tx: RefTransaction) => {
|
|
45
|
+
validateParams(tx, [
|
|
46
|
+
{ name: 'hash', type: 'hexString', required: true },
|
|
47
|
+
{ name: 'inputs', type: 'array', required: true },
|
|
48
|
+
{ name: 'bin_outputs', type: 'array', required: !Array.isArray(tx.outputs) },
|
|
49
|
+
{ name: 'outputs', type: 'array' },
|
|
50
|
+
{ name: 'version', type: 'number', required: true },
|
|
51
|
+
{ name: 'lock_time', type: 'number', required: true },
|
|
52
|
+
{ name: 'extra_data', type: 'string' },
|
|
53
|
+
{ name: 'timestamp', type: 'number' },
|
|
54
|
+
{ name: 'version_group_id', type: 'number' },
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
this.payload.inputs.forEach((input: any) => {
|
|
59
|
+
validatePath(input.address_n);
|
|
60
|
+
const useAmount = isSegwitPath(input.address_n);
|
|
61
|
+
validateParams(input, [
|
|
62
|
+
{ name: 'prev_hash', type: 'hexString', required: true },
|
|
63
|
+
{ name: 'prev_index', type: 'number', required: true },
|
|
64
|
+
{ name: 'script_type', type: 'string' },
|
|
65
|
+
{ name: 'amount', type: 'string', required: useAmount },
|
|
66
|
+
{ name: 'sequence', type: 'number' },
|
|
67
|
+
{ name: 'multisig', type: 'object' },
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
this.payload.outputs.forEach((output: any) => {
|
|
72
|
+
validateParams(output, [
|
|
73
|
+
{ name: 'address_n', type: 'array' },
|
|
74
|
+
{ name: 'address', type: 'string' },
|
|
75
|
+
{ name: 'amount', type: 'string' },
|
|
76
|
+
{ name: 'op_return_data', type: 'string' },
|
|
77
|
+
{ name: 'multisig', type: 'object' },
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
if (
|
|
81
|
+
Object.prototype.hasOwnProperty.call(output, 'address_n') &&
|
|
82
|
+
Object.prototype.hasOwnProperty.call(output, 'address')
|
|
83
|
+
) {
|
|
84
|
+
throw ERRORS.TypedError(
|
|
85
|
+
'Method_InvalidParameter',
|
|
86
|
+
'Cannot use address and address_n in one output'
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (output.address_n) {
|
|
91
|
+
const scriptType = getOutputScriptType(output.address_n);
|
|
92
|
+
if (output.script_type !== scriptType)
|
|
93
|
+
throw ERRORS.TypedError(
|
|
94
|
+
'Method_InvalidParameter',
|
|
95
|
+
`Output change script_type should be set to ${scriptType}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const { inputs, outputs, refTxs, account, coin } = this.payload as BTCSignTransactionParams;
|
|
101
|
+
|
|
102
|
+
const coinName = getCoinInfo(undefined, coin).name;
|
|
103
|
+
|
|
104
|
+
this.params = {
|
|
105
|
+
inputs,
|
|
106
|
+
outputs,
|
|
107
|
+
refTxs,
|
|
108
|
+
addresses: account ? account.addresses : undefined,
|
|
109
|
+
options: {
|
|
110
|
+
lock_time: this.payload.locktime,
|
|
111
|
+
timestamp: this.payload.timestamp,
|
|
112
|
+
version: this.payload.version,
|
|
113
|
+
expiry: this.payload.expiry,
|
|
114
|
+
overwintered: this.payload.overwintered,
|
|
115
|
+
version_group_id: this.payload.versionGroupId,
|
|
116
|
+
branch_id: this.payload.branchId,
|
|
117
|
+
},
|
|
118
|
+
coinName,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async run() {
|
|
123
|
+
const { device, params } = this;
|
|
124
|
+
|
|
125
|
+
const useLegacySignProcess = device.unavailableCapabilities.replaceTransaction;
|
|
126
|
+
|
|
127
|
+
const { refTxs } = params;
|
|
128
|
+
|
|
129
|
+
const signTxMethod = !useLegacySignProcess ? signtx : signtxLegacy;
|
|
130
|
+
const response = await signTxMethod(
|
|
131
|
+
device.commands.typedCall.bind(device.commands),
|
|
132
|
+
params.inputs,
|
|
133
|
+
params.outputs,
|
|
134
|
+
refTxs,
|
|
135
|
+
params.options,
|
|
136
|
+
params.coinName
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return response;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { VerifyMessage } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
|
|
4
|
+
import { BaseMethod } from './BaseMethod';
|
|
5
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
6
|
+
import { formatAnyHex } from './helpers/hexUtils';
|
|
7
|
+
import { getCoinInfo } from './helpers/btcParamsUtils';
|
|
8
|
+
|
|
9
|
+
export default class BTCVerifyMessage extends BaseMethod<VerifyMessage> {
|
|
10
|
+
init() {
|
|
11
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
12
|
+
|
|
13
|
+
validateParams(this.payload, [
|
|
14
|
+
{ name: 'address', type: 'string', required: true },
|
|
15
|
+
{ name: 'messageHex', type: 'hexString', required: true },
|
|
16
|
+
{ name: 'signature', type: 'hexString', required: true },
|
|
17
|
+
{ name: 'coin', type: 'string', required: true },
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const { coin } = this.payload;
|
|
21
|
+
const { address, messageHex, signature } = formatAnyHex(this.payload);
|
|
22
|
+
|
|
23
|
+
const coinName = getCoinInfo(undefined, coin).name;
|
|
24
|
+
|
|
25
|
+
this.params = {
|
|
26
|
+
address,
|
|
27
|
+
message: messageHex,
|
|
28
|
+
signature,
|
|
29
|
+
coin_name: coinName,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async run() {
|
|
34
|
+
const res = await this.device.commands.typedCall('VerifyMessage', 'Success', {
|
|
35
|
+
...this.params,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return Promise.resolve(res.message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
2
|
+
import { Device } from '../device/Device';
|
|
3
|
+
import DeviceConnector from '../device/DeviceConnector';
|
|
4
|
+
|
|
5
|
+
export abstract class BaseMethod<Params = undefined> {
|
|
6
|
+
responseID: number;
|
|
7
|
+
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
device: Device;
|
|
10
|
+
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
params: Params;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* USB: onekey_serial or serial_no
|
|
16
|
+
* iOS: uuid
|
|
17
|
+
* Android: MAC address
|
|
18
|
+
*/
|
|
19
|
+
connectId?: string;
|
|
20
|
+
|
|
21
|
+
deviceState?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* method name
|
|
25
|
+
*/
|
|
26
|
+
name: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 请求携带参数
|
|
30
|
+
*/
|
|
31
|
+
payload: Record<string, any>;
|
|
32
|
+
|
|
33
|
+
connector?: DeviceConnector;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 是否需要使用设备
|
|
37
|
+
*/
|
|
38
|
+
useDevice: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 许可的设备模式
|
|
42
|
+
*/
|
|
43
|
+
allowDeviceMode: string[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 依赖的设备模式
|
|
47
|
+
*/
|
|
48
|
+
requireDeviceMode: string[];
|
|
49
|
+
|
|
50
|
+
constructor(message: { id?: number; payload: any }) {
|
|
51
|
+
const { payload } = message;
|
|
52
|
+
this.name = payload.method;
|
|
53
|
+
this.payload = payload;
|
|
54
|
+
this.responseID = message.id || 0;
|
|
55
|
+
this.connectId = payload.connectId || '';
|
|
56
|
+
this.useDevice = true;
|
|
57
|
+
this.allowDeviceMode = [UI_REQUEST.INITIALIZE];
|
|
58
|
+
this.requireDeviceMode = [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
abstract init(): void;
|
|
62
|
+
|
|
63
|
+
abstract run(): Promise<any>;
|
|
64
|
+
|
|
65
|
+
setDevice(device: Device) {
|
|
66
|
+
this.device = device;
|
|
67
|
+
this.connectId = device.originalDescriptor.path;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
dispose() {}
|
|
71
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
|
|
3
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
4
|
+
import { DataManager } from '../data-manager';
|
|
5
|
+
|
|
6
|
+
export default class CheckBLEFirmwareRelease extends BaseMethod {
|
|
7
|
+
init() {
|
|
8
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
run() {
|
|
12
|
+
if (this.device.features) {
|
|
13
|
+
const firmwareStatus = DataManager.getBLEFirmwareStatus(this.device.features);
|
|
14
|
+
return Promise.resolve(firmwareStatus);
|
|
15
|
+
}
|
|
16
|
+
return Promise.resolve(null);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
|
|
3
|
+
import { DataManager } from '../data-manager';
|
|
4
|
+
|
|
5
|
+
export default class CheckFirmwareRelease extends BaseMethod {
|
|
6
|
+
init() {}
|
|
7
|
+
|
|
8
|
+
run() {
|
|
9
|
+
if (this.device.features) {
|
|
10
|
+
const firmwareStatus = DataManager.getFirmwareStatus(this.device.features);
|
|
11
|
+
return Promise.resolve(firmwareStatus);
|
|
12
|
+
}
|
|
13
|
+
return Promise.resolve(null);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataManager } from '../data-manager';
|
|
2
|
+
import TransportManager from '../data-manager/TransportManager';
|
|
3
|
+
|
|
4
|
+
import { BaseMethod } from './BaseMethod';
|
|
5
|
+
|
|
6
|
+
export default class CheckTransportRelease extends BaseMethod {
|
|
7
|
+
init() {
|
|
8
|
+
this.useDevice = false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async run() {
|
|
12
|
+
const transport = TransportManager.getTransport();
|
|
13
|
+
const localVersion = await transport.init();
|
|
14
|
+
|
|
15
|
+
const response = DataManager.getTransportStatus(localVersion);
|
|
16
|
+
|
|
17
|
+
return Promise.resolve(response);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BackupDevice } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
|
|
4
|
+
export default class DeviceBackup extends BaseMethod<BackupDevice> {
|
|
5
|
+
init() {}
|
|
6
|
+
|
|
7
|
+
async run() {
|
|
8
|
+
const res = await this.device.commands.typedCall('BackupDevice', 'Success');
|
|
9
|
+
|
|
10
|
+
return Promise.resolve(res.message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ChangePin } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
4
|
+
|
|
5
|
+
export default class DeviceChangePin extends BaseMethod<ChangePin> {
|
|
6
|
+
init() {
|
|
7
|
+
// check payload
|
|
8
|
+
validateParams(this.payload, [{ name: 'remove', type: 'boolean' }]);
|
|
9
|
+
|
|
10
|
+
this.params = {
|
|
11
|
+
remove: this.payload.remove,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async run() {
|
|
16
|
+
const res = await this.device.commands.typedCall('ChangePin', 'Success', {
|
|
17
|
+
...this.params,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return Promise.resolve(res.message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ApplyFlags } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
4
|
+
|
|
5
|
+
export default class DeviceFlags extends BaseMethod<ApplyFlags> {
|
|
6
|
+
init() {
|
|
7
|
+
// check payload
|
|
8
|
+
validateParams(this.payload, [{ name: 'flags', type: 'number' }]);
|
|
9
|
+
|
|
10
|
+
// init params
|
|
11
|
+
this.params = {
|
|
12
|
+
flags: this.payload.flags,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async run() {
|
|
17
|
+
const res = await this.device.commands.typedCall('ApplyFlags', 'Success', {
|
|
18
|
+
...this.params,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return Promise.resolve(res.message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RebootToBootloader } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
|
|
4
|
+
// Reboot BootLoader
|
|
5
|
+
export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloader> {
|
|
6
|
+
init() {}
|
|
7
|
+
|
|
8
|
+
async run() {
|
|
9
|
+
const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
|
|
10
|
+
|
|
11
|
+
return Promise.resolve(res.message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RecoveryDevice } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
4
|
+
|
|
5
|
+
export default class DeviceRecovery extends BaseMethod<RecoveryDevice> {
|
|
6
|
+
init() {
|
|
7
|
+
// check payload
|
|
8
|
+
validateParams(this.payload, [
|
|
9
|
+
{ name: 'wordCount', type: 'number' },
|
|
10
|
+
{ name: 'passphraseProtection', type: 'boolean' },
|
|
11
|
+
{ name: 'pinProtection', type: 'boolean' },
|
|
12
|
+
{ name: 'language', type: 'string' },
|
|
13
|
+
{ name: 'label', type: 'string' },
|
|
14
|
+
{ name: 'enforceWordlist', type: 'boolean' },
|
|
15
|
+
{ name: 'type', type: 'object' },
|
|
16
|
+
{ name: 'u2fCounter', type: 'number' },
|
|
17
|
+
{ name: 'dryRun', type: 'boolean' },
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
// init params
|
|
21
|
+
this.params = {
|
|
22
|
+
word_count: this.payload.wordCount,
|
|
23
|
+
passphrase_protection: this.payload.passphraseProtection,
|
|
24
|
+
pin_protection: this.payload.pinProtection,
|
|
25
|
+
language: this.payload.language,
|
|
26
|
+
label: this.payload.label,
|
|
27
|
+
enforce_wordlist: this.payload.enforceWordlist,
|
|
28
|
+
type: this.payload.type,
|
|
29
|
+
u2f_counter: this.payload.u2fCounter || Math.floor(Date.now() / 1000),
|
|
30
|
+
dry_run: this.payload.dryRun,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async run() {
|
|
35
|
+
const res = await this.device.commands.typedCall('RecoveryDevice', 'Success', {
|
|
36
|
+
...this.params,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return Promise.resolve(res.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ResetDevice } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
4
|
+
|
|
5
|
+
export default class DeviceReset extends BaseMethod<ResetDevice> {
|
|
6
|
+
init() {
|
|
7
|
+
// check payload
|
|
8
|
+
validateParams(this.payload, [
|
|
9
|
+
{ name: 'displayRandom', type: 'boolean' },
|
|
10
|
+
{ name: 'strength', type: 'number' },
|
|
11
|
+
{ name: 'passphraseProtection', type: 'boolean' },
|
|
12
|
+
{ name: 'pinProtection', type: 'boolean' },
|
|
13
|
+
{ name: 'language', type: 'string' },
|
|
14
|
+
{ name: 'label', type: 'string' },
|
|
15
|
+
{ name: 'u2fCounter', type: 'number' },
|
|
16
|
+
{ name: 'skipBackup', type: 'boolean' },
|
|
17
|
+
{ name: 'noBackup', type: 'boolean' },
|
|
18
|
+
{ name: 'backupType' },
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
// init params
|
|
22
|
+
this.params = {
|
|
23
|
+
display_random: this.payload.displayRandom,
|
|
24
|
+
strength: this.payload.strength || 256,
|
|
25
|
+
passphrase_protection: this.payload.passphraseProtection,
|
|
26
|
+
pin_protection: this.payload.pinProtection,
|
|
27
|
+
language: this.payload.language,
|
|
28
|
+
label: this.payload.label,
|
|
29
|
+
u2f_counter: this.payload.u2fCounter || Math.floor(Date.now() / 1000),
|
|
30
|
+
skip_backup: this.payload.skipBackup,
|
|
31
|
+
no_backup: this.payload.noBackup,
|
|
32
|
+
backup_type: this.payload.backupType,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async run() {
|
|
37
|
+
const res = await this.device.commands.typedCall('ResetDevice', 'Success', {
|
|
38
|
+
...this.params,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return Promise.resolve(res.message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ApplySettings } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
4
|
+
|
|
5
|
+
export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
6
|
+
init() {
|
|
7
|
+
// check payload
|
|
8
|
+
validateParams(this.payload, [
|
|
9
|
+
{ name: 'language', type: 'string' },
|
|
10
|
+
{ name: 'label', type: 'string' },
|
|
11
|
+
{ name: 'usePassphrase', type: 'boolean' },
|
|
12
|
+
{ name: 'homescreen', type: 'string' },
|
|
13
|
+
{ name: 'passphraseSource', type: 'number' },
|
|
14
|
+
{ name: 'autoLockDelayMs', type: 'number' },
|
|
15
|
+
{ name: 'displayRotation', type: 'number' },
|
|
16
|
+
{ name: 'passphraseAlwaysOnDevice', type: 'boolean' },
|
|
17
|
+
{ name: 'safetyChecks', type: 'object' },
|
|
18
|
+
{ name: 'experimentalFeatures', type: 'boolean' },
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
console.log('DeviceSettings payload', this.payload);
|
|
22
|
+
|
|
23
|
+
// init params
|
|
24
|
+
this.params = {
|
|
25
|
+
language: this.payload.language,
|
|
26
|
+
label: this.payload.label,
|
|
27
|
+
use_passphrase: this.payload.usePassphrase,
|
|
28
|
+
homescreen: this.payload.homescreen,
|
|
29
|
+
_passphrase_source: this.payload.passphraseSource,
|
|
30
|
+
auto_lock_delay_ms: this.payload.autoLockDelayMs,
|
|
31
|
+
display_rotation: this.payload.displayRotation,
|
|
32
|
+
passphrase_always_on_device: this.payload.passphraseAlwaysOnDevice,
|
|
33
|
+
safety_checks: this.payload.safetyChecks,
|
|
34
|
+
experimental_features: this.payload.experimentalFeatures,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async run() {
|
|
39
|
+
const res = await this.device.commands.typedCall('ApplySettings', 'Success', {
|
|
40
|
+
...this.params,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return Promise.resolve(res.message);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BixinReboot } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
|
|
4
|
+
// Upload hint Reboot BootLoader
|
|
5
|
+
export default class DeviceUpdateReboot extends BaseMethod<BixinReboot> {
|
|
6
|
+
init() {}
|
|
7
|
+
|
|
8
|
+
async run() {
|
|
9
|
+
const res = await this.device.commands.typedCall('BixinReboot', 'Success');
|
|
10
|
+
|
|
11
|
+
return Promise.resolve(res.message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WipeDevice } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { BaseMethod } from './BaseMethod';
|
|
3
|
+
|
|
4
|
+
export default class DeviceWipe extends BaseMethod<WipeDevice> {
|
|
5
|
+
init() {}
|
|
6
|
+
|
|
7
|
+
async run() {
|
|
8
|
+
const res = await this.device.commands.typedCall('WipeDevice', 'Success');
|
|
9
|
+
|
|
10
|
+
return Promise.resolve(res.message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { EthereumAddress, EthereumGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
import { validatePath } from './helpers/pathUtils';
|
|
4
|
+
import { BaseMethod } from './BaseMethod';
|
|
5
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
6
|
+
import { EVMGetAddressParams } from '../types/api/evmGetAddress';
|
|
7
|
+
|
|
8
|
+
export default class EvmGetAddress extends BaseMethod<EthereumGetAddress[]> {
|
|
9
|
+
hasBundle = false;
|
|
10
|
+
|
|
11
|
+
init() {
|
|
12
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
13
|
+
|
|
14
|
+
this.hasBundle = !!this.payload?.bundle;
|
|
15
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
16
|
+
|
|
17
|
+
// check payload
|
|
18
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
19
|
+
|
|
20
|
+
// init params
|
|
21
|
+
this.params = [];
|
|
22
|
+
payload.bundle.forEach((batch: EVMGetAddressParams) => {
|
|
23
|
+
const addressN = validatePath(batch.path, 3);
|
|
24
|
+
|
|
25
|
+
validateParams(batch, [
|
|
26
|
+
{ name: 'path', required: true },
|
|
27
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const showOnOneKey = batch.showOnOneKey ?? true;
|
|
31
|
+
|
|
32
|
+
this.params.push({
|
|
33
|
+
address_n: addressN,
|
|
34
|
+
show_display: showOnOneKey,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async run() {
|
|
40
|
+
const responses: EthereumAddress[] = [];
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
43
|
+
const param = this.params[i];
|
|
44
|
+
|
|
45
|
+
const res = await this.device.commands.typedCall('EthereumGetAddress', 'EthereumAddress', {
|
|
46
|
+
...param,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
responses.push(res.message);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { EthereumGetPublicKey, EthereumPublicKey } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import { UI_REQUEST } from '../constants/ui-request';
|
|
3
|
+
import { validatePath } from './helpers/pathUtils';
|
|
4
|
+
import { BaseMethod } from './BaseMethod';
|
|
5
|
+
import { validateParams } from './helpers/paramsValidator';
|
|
6
|
+
import { EVMGetPublicKeyParams } from '../types/api/evmGetPublicKey';
|
|
7
|
+
|
|
8
|
+
export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKey[]> {
|
|
9
|
+
hasBundle = false;
|
|
10
|
+
|
|
11
|
+
init() {
|
|
12
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
13
|
+
|
|
14
|
+
this.hasBundle = !!this.payload?.bundle;
|
|
15
|
+
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
16
|
+
|
|
17
|
+
// check payload
|
|
18
|
+
validateParams(payload, [{ name: 'bundle', type: 'array' }]);
|
|
19
|
+
|
|
20
|
+
// init params
|
|
21
|
+
this.params = [];
|
|
22
|
+
payload.bundle.forEach((batch: EVMGetPublicKeyParams) => {
|
|
23
|
+
const addressN = validatePath(batch.path, 3);
|
|
24
|
+
|
|
25
|
+
validateParams(batch, [
|
|
26
|
+
{ name: 'path', required: true },
|
|
27
|
+
{ name: 'showOnOneKey', type: 'boolean' },
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const showOnOneKey = batch.showOnOneKey ?? true;
|
|
31
|
+
|
|
32
|
+
this.params.push({
|
|
33
|
+
address_n: addressN,
|
|
34
|
+
show_display: showOnOneKey,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async run() {
|
|
40
|
+
const responses: EthereumPublicKey[] = [];
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < this.params.length; i++) {
|
|
43
|
+
const param = this.params[i];
|
|
44
|
+
|
|
45
|
+
const res = await this.device.commands.typedCall(
|
|
46
|
+
'EthereumGetPublicKey',
|
|
47
|
+
'EthereumPublicKey',
|
|
48
|
+
{
|
|
49
|
+
...param,
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
responses.push(res.message);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
57
|
+
}
|
|
58
|
+
}
|