@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,173 @@
|
|
|
1
|
+
import { Transport, OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { DataManager } from '../data-manager';
|
|
3
|
+
import TransportManager from '../data-manager/TransportManager';
|
|
4
|
+
import { initLog } from '../utils';
|
|
5
|
+
import { resolveAfter } from '../utils/promiseUtils';
|
|
6
|
+
|
|
7
|
+
export type DeviceDescriptorDiff = {
|
|
8
|
+
didUpdate: boolean;
|
|
9
|
+
connected: DeviceDescriptor[];
|
|
10
|
+
disconnected: DeviceDescriptor[];
|
|
11
|
+
changedSessions: DeviceDescriptor[];
|
|
12
|
+
changedDebugSessions: DeviceDescriptor[];
|
|
13
|
+
acquired: DeviceDescriptor[];
|
|
14
|
+
debugAcquired: DeviceDescriptor[];
|
|
15
|
+
released: DeviceDescriptor[];
|
|
16
|
+
debugReleased: DeviceDescriptor[];
|
|
17
|
+
descriptors: DeviceDescriptor[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const Log = initLog('DeviceConnector');
|
|
21
|
+
|
|
22
|
+
const getDiff = (
|
|
23
|
+
current: DeviceDescriptor[],
|
|
24
|
+
descriptors: DeviceDescriptor[]
|
|
25
|
+
): DeviceDescriptorDiff => {
|
|
26
|
+
const env = DataManager.getSettings('env');
|
|
27
|
+
if (env === 'react-native') {
|
|
28
|
+
return {
|
|
29
|
+
descriptors,
|
|
30
|
+
} as DeviceDescriptorDiff;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
|
|
34
|
+
const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
|
|
35
|
+
const changedSessions = descriptors.filter(d => {
|
|
36
|
+
const currentDescriptor = current.find(x => x.path === d.path);
|
|
37
|
+
if (currentDescriptor) {
|
|
38
|
+
// return currentDescriptor.debug ? (currentDescriptor.debugSession !== d.debugSession) : (currentDescriptor.session !== d.session);
|
|
39
|
+
return currentDescriptor.session !== d.session;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
});
|
|
43
|
+
const acquired = changedSessions.filter(d => typeof d.session === 'string');
|
|
44
|
+
const released = changedSessions.filter(
|
|
45
|
+
d =>
|
|
46
|
+
// const session = descriptor.debug ? descriptor.debugSession : descriptor.session;
|
|
47
|
+
typeof d.session !== 'string'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const changedDebugSessions = descriptors.filter(d => {
|
|
51
|
+
const currentDescriptor = current.find(x => x.path === d.path);
|
|
52
|
+
if (currentDescriptor) {
|
|
53
|
+
return currentDescriptor.debugSession !== d.debugSession;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
});
|
|
57
|
+
const debugAcquired = changedSessions.filter(d => typeof d.debugSession === 'string');
|
|
58
|
+
const debugReleased = changedSessions.filter(d => typeof d.debugSession !== 'string');
|
|
59
|
+
|
|
60
|
+
const didUpdate =
|
|
61
|
+
connected.length + disconnected.length + changedSessions.length + changedDebugSessions.length >
|
|
62
|
+
0;
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
connected,
|
|
66
|
+
disconnected,
|
|
67
|
+
changedSessions,
|
|
68
|
+
acquired,
|
|
69
|
+
released,
|
|
70
|
+
changedDebugSessions,
|
|
71
|
+
debugAcquired,
|
|
72
|
+
debugReleased,
|
|
73
|
+
didUpdate,
|
|
74
|
+
descriptors,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default class DeviceConnector {
|
|
79
|
+
transport: Transport;
|
|
80
|
+
|
|
81
|
+
listenTimestamp = 0;
|
|
82
|
+
|
|
83
|
+
current: DeviceDescriptor[] | null = null;
|
|
84
|
+
|
|
85
|
+
upcoming: DeviceDescriptor[] = [];
|
|
86
|
+
|
|
87
|
+
listening = false;
|
|
88
|
+
|
|
89
|
+
constructor() {
|
|
90
|
+
TransportManager.load();
|
|
91
|
+
this.transport = TransportManager.getTransport();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async enumerate() {
|
|
95
|
+
try {
|
|
96
|
+
this.upcoming = await this.transport.enumerate();
|
|
97
|
+
const diff = this._reportDevicesChange();
|
|
98
|
+
Log.debug('diff result: ', diff);
|
|
99
|
+
return diff;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
throw new Error(error);
|
|
102
|
+
// empty
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async listen() {
|
|
107
|
+
const waitForEvent = this.current !== null;
|
|
108
|
+
const current: DeviceDescriptor[] = this.current || [];
|
|
109
|
+
|
|
110
|
+
this.listening = true;
|
|
111
|
+
|
|
112
|
+
let descriptors: DeviceDescriptor[];
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
Log.debug('Start listening', current);
|
|
116
|
+
this.listenTimestamp = new Date().getTime();
|
|
117
|
+
descriptors = waitForEvent
|
|
118
|
+
? await this.transport.listen(current)
|
|
119
|
+
: await this.transport.enumerate();
|
|
120
|
+
if (!this.listening) return; // do not continue if stop() was called
|
|
121
|
+
|
|
122
|
+
this.upcoming = descriptors;
|
|
123
|
+
Log.debug('Listen result', descriptors);
|
|
124
|
+
this._reportDevicesChange();
|
|
125
|
+
if (this.listening) this.listen(); // handlers might have called stop()
|
|
126
|
+
} catch (error) {
|
|
127
|
+
const time = new Date().getTime() - this.listenTimestamp;
|
|
128
|
+
Log.debug('Listen error', 'timestamp', time, typeof error);
|
|
129
|
+
|
|
130
|
+
if (time > 1100) {
|
|
131
|
+
await resolveAfter(1000, null);
|
|
132
|
+
if (this.listening) this.listen();
|
|
133
|
+
} else {
|
|
134
|
+
Log.warn('Transport error');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
stop() {
|
|
140
|
+
this.listening = false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async acquire(path: string, session?: string | null) {
|
|
144
|
+
console.log('acquire', path, session);
|
|
145
|
+
const env = DataManager.getSettings('env');
|
|
146
|
+
try {
|
|
147
|
+
let res;
|
|
148
|
+
if (env === 'react-native') {
|
|
149
|
+
res = await this.transport.acquire({ uuid: path });
|
|
150
|
+
} else {
|
|
151
|
+
res = await this.transport.acquire({ path, previous: session ?? null });
|
|
152
|
+
}
|
|
153
|
+
return res;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw new Error(error);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async release(session: string, onclose: boolean) {
|
|
160
|
+
try {
|
|
161
|
+
const res = await this.transport.release(session, onclose);
|
|
162
|
+
return res;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw new Error(error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
_reportDevicesChange() {
|
|
169
|
+
const diff = getDiff(this.current || [], this.upcoming);
|
|
170
|
+
this.current = this.upcoming;
|
|
171
|
+
return diff;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import DeviceConnector from './DeviceConnector';
|
|
3
|
+
import { Device } from './Device';
|
|
4
|
+
import { getDeviceUUID } from '../utils/deviceFeaturesUtils';
|
|
5
|
+
|
|
6
|
+
export class DeviceList extends EventEmitter {
|
|
7
|
+
devices: Record<string, Device> = {};
|
|
8
|
+
|
|
9
|
+
connector?: DeviceConnector;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 获取已连接的设备列表
|
|
13
|
+
* @returns {OneKeyDeviceInfo[]}
|
|
14
|
+
*/
|
|
15
|
+
async getDeviceLists() {
|
|
16
|
+
const deviceDiff = await this.connector?.enumerate();
|
|
17
|
+
const descriptorList = deviceDiff?.descriptors ?? [];
|
|
18
|
+
|
|
19
|
+
this.devices = {};
|
|
20
|
+
const deviceList = [];
|
|
21
|
+
console.log('get device list');
|
|
22
|
+
for await (const descriptor of descriptorList) {
|
|
23
|
+
const device = Device.fromDescriptor(descriptor);
|
|
24
|
+
device.deviceConnector = this.connector;
|
|
25
|
+
await device.connect();
|
|
26
|
+
await device.initialize();
|
|
27
|
+
await device.release();
|
|
28
|
+
|
|
29
|
+
// clean session after release
|
|
30
|
+
deviceList.push(device);
|
|
31
|
+
if (device.features) {
|
|
32
|
+
const uuid = getDeviceUUID(device.features);
|
|
33
|
+
this.devices[uuid] = device;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return deviceList;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
allDevices(): Device[] {
|
|
41
|
+
return Object.keys(this.devices).map(key => this.devices[key]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getDevice(connectId: string) {
|
|
45
|
+
return this.devices[connectId];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { serializeError } from '../constants/errors';
|
|
2
|
+
import { IFRAME } from './iframe';
|
|
3
|
+
import { CommonParams, CoreApi } from '../types';
|
|
4
|
+
|
|
5
|
+
type UnwrappedResponse<T> = T extends Promise<infer R>
|
|
6
|
+
? R extends { success: true; payload: infer P }
|
|
7
|
+
? P
|
|
8
|
+
: never
|
|
9
|
+
: void;
|
|
10
|
+
|
|
11
|
+
type OverloadedMethod<T, E extends Record<string, string>> = T extends {
|
|
12
|
+
(params: infer P1): infer R1;
|
|
13
|
+
(params: infer P2): infer R2;
|
|
14
|
+
}
|
|
15
|
+
? ((params: P1 & E) => R1) | ((params: P2 & E) => R2) // - method IS overloaded, result depends on params (example: getAddress)
|
|
16
|
+
: T extends (...args: infer P) => infer R
|
|
17
|
+
? (params: E & P[0]) => R // - method in NOT overloaded, one set of params and one set of result (example: signTransaction)
|
|
18
|
+
: never;
|
|
19
|
+
|
|
20
|
+
type UnwrappedMethod<T, M extends Record<string, string>> = T extends () => infer R
|
|
21
|
+
? (params: M & CommonParams) => R // - method doesn't have params (example: dispose, disableWebUSB)
|
|
22
|
+
: OverloadedMethod<T, M>;
|
|
23
|
+
|
|
24
|
+
type IsMethodCallable<T> = T extends (...args: any[]) => infer R
|
|
25
|
+
? R extends Promise<{ success: boolean }>
|
|
26
|
+
? R
|
|
27
|
+
: never
|
|
28
|
+
: never;
|
|
29
|
+
|
|
30
|
+
type CallApi = {
|
|
31
|
+
[K in keyof CoreApi]: IsMethodCallable<CoreApi[K]> extends never
|
|
32
|
+
? never
|
|
33
|
+
: UnwrappedMethod<CoreApi[K], { method: K }>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type CallMethodUnion = CallApi[keyof CallApi];
|
|
37
|
+
export type CallMethodPayload = Parameters<CallMethodUnion>[0];
|
|
38
|
+
export type CallMethodResponse<M extends keyof CallApi> = UnwrappedResponse<ReturnType<CallApi[M]>>;
|
|
39
|
+
export type CallMethodAnyResponse = ReturnType<CallMethodUnion>;
|
|
40
|
+
|
|
41
|
+
export type CallMethod = (params: CallMethodPayload) => Promise<any>;
|
|
42
|
+
|
|
43
|
+
export interface IFrameCallMessage {
|
|
44
|
+
event: typeof IFRAME.CALL;
|
|
45
|
+
type: typeof IFRAME.CALL;
|
|
46
|
+
payload: CallMethodPayload;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const RESPONSE_EVENT = 'RESPONSE_EVENT';
|
|
50
|
+
|
|
51
|
+
export interface MethodResponseMessage {
|
|
52
|
+
event: typeof RESPONSE_EVENT;
|
|
53
|
+
type: typeof RESPONSE_EVENT;
|
|
54
|
+
id: number;
|
|
55
|
+
success: boolean;
|
|
56
|
+
payload: any;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const createResponseMessage = (
|
|
60
|
+
id: number,
|
|
61
|
+
success: boolean,
|
|
62
|
+
payload: any
|
|
63
|
+
): MethodResponseMessage => ({
|
|
64
|
+
event: RESPONSE_EVENT,
|
|
65
|
+
type: RESPONSE_EVENT,
|
|
66
|
+
id,
|
|
67
|
+
success,
|
|
68
|
+
|
|
69
|
+
payload: success ? payload : serializeError(payload),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export type CallMethodKeys = keyof CoreApi;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Unsuccessful } from '../types/params';
|
|
2
|
+
import { IFrameCallMessage } from './call';
|
|
3
|
+
import { IFrameEventMessage } from './iframe';
|
|
4
|
+
import { UiEventMessage } from './ui-request';
|
|
5
|
+
import { UiResponseMessage } from './ui-response';
|
|
6
|
+
|
|
7
|
+
export const CORE_EVENT = 'CORE_EVENT';
|
|
8
|
+
|
|
9
|
+
export type CoreMessage = {
|
|
10
|
+
id?: string;
|
|
11
|
+
success?: true | false;
|
|
12
|
+
} & (IFrameEventMessage | IFrameCallMessage | UiResponseMessage | UiEventMessage);
|
|
13
|
+
|
|
14
|
+
export type PostMessageEvent = MessageEvent<any>;
|
|
15
|
+
|
|
16
|
+
export const parseMessage = (messageData: any): CoreMessage => {
|
|
17
|
+
const { data } = messageData;
|
|
18
|
+
const message: CoreMessage = {
|
|
19
|
+
event: data.event,
|
|
20
|
+
type: data.type,
|
|
21
|
+
payload: data.payload,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (typeof messageData.id === 'number') {
|
|
25
|
+
message.id = messageData.id;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof message.success === 'boolean') {
|
|
29
|
+
message.success = data.success;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return message;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const createErrorMessage = (error: Error & { code?: string }): Unsuccessful => ({
|
|
36
|
+
success: false,
|
|
37
|
+
payload: {
|
|
38
|
+
error: error.message,
|
|
39
|
+
code: error.code,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PROTO } from '../constants';
|
|
2
|
+
|
|
3
|
+
export const DEVICE = {
|
|
4
|
+
// device list events
|
|
5
|
+
CONNECT: 'device-connect',
|
|
6
|
+
CONNECT_UNACQUIRED: 'device-connect_unacquired',
|
|
7
|
+
DISCONNECT: 'device-disconnect',
|
|
8
|
+
CHANGED: 'device-changed',
|
|
9
|
+
ACQUIRE: 'device-acquire',
|
|
10
|
+
RELEASE: 'device-release',
|
|
11
|
+
ACQUIRED: 'device-acquired',
|
|
12
|
+
RELEASED: 'device-released',
|
|
13
|
+
USED_ELSEWHERE: 'device-used_elsewhere',
|
|
14
|
+
UNREADABLE: 'unreadable-device',
|
|
15
|
+
|
|
16
|
+
LOADING: 'device-loading',
|
|
17
|
+
|
|
18
|
+
// onekey-transport events in protobuf format
|
|
19
|
+
BUTTON: 'button',
|
|
20
|
+
PIN: 'pin',
|
|
21
|
+
PASSPHRASE: 'passphrase',
|
|
22
|
+
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
23
|
+
WORD: 'word',
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'code'> {
|
|
27
|
+
code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ConnectSettings } from '../types';
|
|
2
|
+
import { UI_EVENT } from './ui-request';
|
|
3
|
+
import { MessageFactoryFn } from './utils';
|
|
4
|
+
|
|
5
|
+
export const IFRAME = {
|
|
6
|
+
INIT: 'iframe-init',
|
|
7
|
+
INIT_BRIDGE: 'iframe-init-bridge',
|
|
8
|
+
CALL: 'iframe-call',
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export interface IFrameInit {
|
|
12
|
+
type: typeof IFRAME.INIT;
|
|
13
|
+
payload: {
|
|
14
|
+
settings: ConnectSettings;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IFrameBridge {
|
|
19
|
+
type: typeof IFRAME.INIT_BRIDGE;
|
|
20
|
+
payload: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type IFrameEvent = IFrameInit | IFrameBridge;
|
|
24
|
+
export type IFrameEventMessage = IFrameEvent & { event: typeof UI_EVENT };
|
|
25
|
+
|
|
26
|
+
export const createIFrameMessage: MessageFactoryFn<typeof UI_EVENT, IFrameEvent> = (
|
|
27
|
+
type,
|
|
28
|
+
payload
|
|
29
|
+
) =>
|
|
30
|
+
({
|
|
31
|
+
event: UI_EVENT,
|
|
32
|
+
type,
|
|
33
|
+
payload,
|
|
34
|
+
} as any);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DEVICE } from './device';
|
|
2
|
+
import type { Device } from '../device/Device';
|
|
3
|
+
import type { UiResponseEvent } from './ui-response';
|
|
4
|
+
import type { Deferred } from '../utils/deferred';
|
|
5
|
+
|
|
6
|
+
export type UiPromiseResponse =
|
|
7
|
+
| UiResponseEvent
|
|
8
|
+
| { type: typeof DEVICE.DISCONNECT; payload?: undefined };
|
|
9
|
+
|
|
10
|
+
export type UiPromise<T extends UiPromiseResponse['type']> = Deferred<
|
|
11
|
+
Extract<UiPromiseResponse, { type: T }>,
|
|
12
|
+
T,
|
|
13
|
+
Device
|
|
14
|
+
>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PROTO } from '../constants';
|
|
2
|
+
import type { Device } from '../types';
|
|
3
|
+
import type { MessageFactoryFn } from './utils';
|
|
4
|
+
|
|
5
|
+
export const UI_EVENT = 'UI_EVENT';
|
|
6
|
+
|
|
7
|
+
export const UI_REQUEST = {
|
|
8
|
+
REQUEST_PIN: 'ui-request_pin',
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export type UiRequestDeviceAction = {
|
|
12
|
+
type: typeof UI_REQUEST.REQUEST_PIN;
|
|
13
|
+
payload: {
|
|
14
|
+
device: Device;
|
|
15
|
+
type?: PROTO.PinMatrixRequestType;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type UiEvent = UiRequestDeviceAction;
|
|
20
|
+
|
|
21
|
+
export type UiEventMessage = UiEvent & { event: typeof UI_EVENT };
|
|
22
|
+
|
|
23
|
+
export const createUiMessage: MessageFactoryFn<typeof UI_EVENT, UiEvent> = (type, payload) =>
|
|
24
|
+
({
|
|
25
|
+
event: UI_EVENT,
|
|
26
|
+
type,
|
|
27
|
+
payload,
|
|
28
|
+
} as any);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UI_EVENT } from './ui-request';
|
|
2
|
+
import type { MessageFactoryFn } from './utils';
|
|
3
|
+
|
|
4
|
+
export const UI_RESPONSE = {
|
|
5
|
+
RECEIVE_PIN: 'ui-receive_pin',
|
|
6
|
+
} as const;
|
|
7
|
+
|
|
8
|
+
export interface UiResponsePin {
|
|
9
|
+
type: typeof UI_RESPONSE.RECEIVE_PIN;
|
|
10
|
+
payload: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type UiResponseEvent = UiResponsePin;
|
|
14
|
+
|
|
15
|
+
export type UiResponseMessage = UiResponseEvent & { event: typeof UI_EVENT };
|
|
16
|
+
|
|
17
|
+
export const createUiResponse: MessageFactoryFn<typeof UI_EVENT, UiResponseEvent> = (
|
|
18
|
+
type,
|
|
19
|
+
payload
|
|
20
|
+
) =>
|
|
21
|
+
({
|
|
22
|
+
event: UI_EVENT,
|
|
23
|
+
type,
|
|
24
|
+
payload,
|
|
25
|
+
} as any);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
2
|
+
k: infer I
|
|
3
|
+
) => void
|
|
4
|
+
? I
|
|
5
|
+
: never;
|
|
6
|
+
|
|
7
|
+
export type MessageFactoryFn<Group, Event> = UnionToIntersection<
|
|
8
|
+
Event extends { type: string }
|
|
9
|
+
? Event extends { payload: any }
|
|
10
|
+
? (
|
|
11
|
+
type: Event['type'],
|
|
12
|
+
payload: Event['payload']
|
|
13
|
+
) => { event: Group; type: Event['type']; payload: Event['payload'] }
|
|
14
|
+
: (
|
|
15
|
+
type: Event['type'],
|
|
16
|
+
payload?: undefined
|
|
17
|
+
) => { event: Group; type: Event['type']; payload: undefined }
|
|
18
|
+
: never
|
|
19
|
+
>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { inject, InjectApi } from './inject';
|
|
2
|
+
import { CoreApi } from './types/api';
|
|
3
|
+
|
|
4
|
+
export { default as Core, init as initCore } from './core';
|
|
5
|
+
|
|
6
|
+
export * from './constants';
|
|
7
|
+
export * from './utils';
|
|
8
|
+
export * from './data-manager';
|
|
9
|
+
export * from './events';
|
|
10
|
+
export * from './types';
|
|
11
|
+
|
|
12
|
+
const HardwareSdk = ({
|
|
13
|
+
init,
|
|
14
|
+
call,
|
|
15
|
+
dispose,
|
|
16
|
+
eventEmitter,
|
|
17
|
+
uiResponse,
|
|
18
|
+
cancel,
|
|
19
|
+
}: InjectApi): CoreApi =>
|
|
20
|
+
inject({
|
|
21
|
+
init,
|
|
22
|
+
call,
|
|
23
|
+
dispose,
|
|
24
|
+
eventEmitter,
|
|
25
|
+
uiResponse,
|
|
26
|
+
cancel,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export default HardwareSdk;
|
package/src/inject.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { CallMethod } from './events';
|
|
3
|
+
import { CoreApi } from './types/api';
|
|
4
|
+
|
|
5
|
+
export interface InjectApi {
|
|
6
|
+
call: CallMethod;
|
|
7
|
+
eventEmitter: EventEmitter;
|
|
8
|
+
init: CoreApi['init'];
|
|
9
|
+
dispose: CoreApi['dispose'];
|
|
10
|
+
uiResponse: CoreApi['uiResponse'];
|
|
11
|
+
cancel: CoreApi['cancel'];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const inject = ({
|
|
15
|
+
call,
|
|
16
|
+
cancel,
|
|
17
|
+
dispose,
|
|
18
|
+
eventEmitter,
|
|
19
|
+
init,
|
|
20
|
+
uiResponse,
|
|
21
|
+
}: InjectApi): CoreApi => {
|
|
22
|
+
const api: CoreApi = {
|
|
23
|
+
on: <T extends string, P extends (...args: any[]) => any>(type: T, fn: P) => {
|
|
24
|
+
eventEmitter.on(type, fn);
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
off: (type, fn) => {
|
|
28
|
+
eventEmitter.removeListener(type, fn);
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
removeAllListeners: type => {
|
|
32
|
+
eventEmitter.removeAllListeners(type);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
init,
|
|
36
|
+
|
|
37
|
+
call,
|
|
38
|
+
|
|
39
|
+
dispose,
|
|
40
|
+
|
|
41
|
+
uiResponse,
|
|
42
|
+
|
|
43
|
+
cancel,
|
|
44
|
+
/**
|
|
45
|
+
* 搜索设备
|
|
46
|
+
*/
|
|
47
|
+
searchDevices: () => call({ method: 'searchDevices' }),
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 获取设备信息
|
|
51
|
+
*/
|
|
52
|
+
getFeatures: connectId => call({ connectId, method: 'getFeatures' }),
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 检查固件版本
|
|
56
|
+
*/
|
|
57
|
+
checkFirmwareRelease: connectId => call({ connectId, method: 'checkFirmwareRelease' }),
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 检查蓝牙固件版本
|
|
61
|
+
*/
|
|
62
|
+
checkBLEFirmwareRelease: connectId => call({ connectId, method: 'checkBLEFirmwareRelease' }),
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 检查 bridge 版本
|
|
66
|
+
*/
|
|
67
|
+
checkTransportRelease: () => call({ method: 'checkTransportRelease' }),
|
|
68
|
+
|
|
69
|
+
deviceBackup: connectId => call({ connectId, method: 'deviceBackup' }),
|
|
70
|
+
deviceChangePin: (connectId, params) =>
|
|
71
|
+
call({ ...params, connectId, method: 'deviceChangePin' }),
|
|
72
|
+
deviceFlags: (connectId, params) => call({ ...params, connectId, method: 'deviceFlags' }),
|
|
73
|
+
deviceRebootToBootloader: connectId => call({ connectId, method: 'deviceRebootToBootloader' }),
|
|
74
|
+
deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
|
|
75
|
+
deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
|
|
76
|
+
deviceSettings: connectId => call({ connectId, method: 'deviceSettings' }),
|
|
77
|
+
deviceUpdateReboot: connectId => call({ connectId, method: 'deviceUpdateReboot' }),
|
|
78
|
+
deviceWipe: connectId => call({ connectId, method: 'deviceWipe' }),
|
|
79
|
+
|
|
80
|
+
evmGetAddress: (connectId, params) => call({ ...params, connectId, method: 'evmGetAddress' }),
|
|
81
|
+
evmGetPublicKey: (connectId, params) =>
|
|
82
|
+
call({ ...params, connectId, method: 'evmGetPublicKey' }),
|
|
83
|
+
evmSignMessage: (connectId, params) => call({ ...params, connectId, method: 'evmSignMessage' }),
|
|
84
|
+
evmSignMessageEIP712: (connectId, params) =>
|
|
85
|
+
call({ ...params, connectId, method: 'evmSignMessageEIP712' }),
|
|
86
|
+
evmSignTransaction: (connectId, params) =>
|
|
87
|
+
call({ ...params, connectId, method: 'evmSignTransaction' }),
|
|
88
|
+
evmSignTypedData: (connectId, params) =>
|
|
89
|
+
call({ ...params, connectId, method: 'evmSignTypedData' }),
|
|
90
|
+
evmVerifyMessage: (connectId, params) =>
|
|
91
|
+
call({ ...params, connectId, method: 'evmVerifyMessage' }),
|
|
92
|
+
|
|
93
|
+
btcGetAddress: (connectId, params) => call({ ...params, connectId, method: 'btcGetAddress' }),
|
|
94
|
+
btcGetPublicKey: (connectId, params) =>
|
|
95
|
+
call({ ...params, connectId, method: 'btcGetPublicKey' }),
|
|
96
|
+
btcSignMessage: (connectId, params) => call({ ...params, connectId, method: 'btcSignMessage' }),
|
|
97
|
+
btcSignTransaction: (connectId, params) =>
|
|
98
|
+
call({ ...params, connectId, method: 'btcSignTransaction' }),
|
|
99
|
+
btcVerifyMessage: (connectId, params) =>
|
|
100
|
+
call({ ...params, connectId, method: 'btcVerifyMessage' }),
|
|
101
|
+
};
|
|
102
|
+
return api;
|
|
103
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
InputScriptType,
|
|
4
|
+
MultisigRedeemScriptType,
|
|
5
|
+
} from '@onekeyfe/hd-transport/src/types/messages';
|
|
6
|
+
import type { CommonParams, Response } from '../params';
|
|
7
|
+
|
|
8
|
+
export type BTCGetAddressParams = {
|
|
9
|
+
path: string | number[];
|
|
10
|
+
coin?: string;
|
|
11
|
+
showOnOneKey?: boolean;
|
|
12
|
+
multisig?: MultisigRedeemScriptType;
|
|
13
|
+
scriptType?: InputScriptType;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export declare function btcGetAddress(
|
|
17
|
+
connectId: string,
|
|
18
|
+
params: CommonParams & BTCGetAddressParams
|
|
19
|
+
): Response<Address>;
|
|
20
|
+
|
|
21
|
+
export declare function btcGetAddress(
|
|
22
|
+
connectId: string,
|
|
23
|
+
params: CommonParams & { bundle?: BTCGetAddressParams[] }
|
|
24
|
+
): Response<Array<Address>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InputScriptType, PublicKey } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import type { CommonParams, Response } from '../params';
|
|
3
|
+
|
|
4
|
+
export type BTCGetPublicKeyParams = {
|
|
5
|
+
path: string | number[];
|
|
6
|
+
coin?: string;
|
|
7
|
+
showOnOneKey?: boolean;
|
|
8
|
+
scriptType?: InputScriptType;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export declare function btcGetPublicKey(
|
|
12
|
+
connectId: string,
|
|
13
|
+
params: CommonParams & BTCGetPublicKeyParams
|
|
14
|
+
): Response<PublicKey>;
|
|
15
|
+
|
|
16
|
+
export declare function btcGetPublicKey(
|
|
17
|
+
connectId: string,
|
|
18
|
+
params: CommonParams & { bundle?: BTCGetPublicKeyParams[] }
|
|
19
|
+
): Response<Array<PublicKey>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MessageSignature } from '@onekeyfe/hd-transport/src/types/messages';
|
|
2
|
+
import type { CommonParams, Response } from '../params';
|
|
3
|
+
|
|
4
|
+
export type BTCSignMessageParams = {
|
|
5
|
+
path: string | number[];
|
|
6
|
+
messageHex: string;
|
|
7
|
+
coin?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export declare function btcSignMessage(
|
|
11
|
+
connectId: string,
|
|
12
|
+
params: CommonParams & BTCSignMessageParams
|
|
13
|
+
): Response<MessageSignature>;
|