Skip to content

Commit fb0244c

Browse files
Feat/bitcoin only (#613)
* feat: support bitcoinlony * fix: checkAllFirmwareRelease return features * chore: add log * feat: upload file header * chore: release 1.1.19-patch.2 * chore: organize log
1 parent fee35af commit fb0244c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1387
-475
lines changed

.eslintrc

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,38 @@
4444
"import/no-extraneous-dependencies": "off",
4545
"class-methods-use-this": "off",
4646
"@typescript-eslint/restrict-template-expressions": "off",
47-
"import/no-cycle": "off"
47+
"import/no-cycle": "off",
48+
"@typescript-eslint/consistent-type-imports": [
49+
"warn",
50+
{
51+
"disallowTypeAnnotations": false
52+
}
53+
],
54+
"sort-imports": [
55+
"warn",
56+
{
57+
"ignoreMemberSort": false,
58+
"ignoreDeclarationSort": true,
59+
}
60+
],
61+
"import/order": [
62+
"warn",
63+
{
64+
"groups": [
65+
[
66+
"builtin",
67+
"external"
68+
],
69+
[
70+
"internal",
71+
"parent",
72+
"sibling",
73+
"index"
74+
],
75+
"type"
76+
],
77+
"newlines-between": "always"
78+
}
79+
]
4880
}
4981
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_modules
66
*.sublime-project
77
*.sublime-workspace
88
.vscode/**/*
9+
.vscode
910
!.vscode/launch.json
1011
!.vscode/tasks.json
1112
!.vscode/settings.json

packages/connect-examples/electron-example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "hardware-example",
33
"productName": "HardwareExample",
44
"executableName": "onekey-hardware-example",
5-
"version": "1.1.18",
5+
"version": "1.1.19-alpha.2",
66
"author": "OneKey",
77
"description": "End-to-end encrypted workspaces for teams",
88
"main": "dist/index.js",
@@ -22,7 +22,7 @@
2222
"ts:check": "yarn tsc --noEmit"
2323
},
2424
"dependencies": {
25-
"@onekeyfe/hd-transport-electron": "1.1.18",
25+
"@onekeyfe/hd-transport-electron": "1.1.19-alpha.2",
2626
"@stoprocent/noble": "2.3.4",
2727
"debug": "4.3.4",
2828
"electron-is-dev": "^3.0.1",

packages/connect-examples/expo-example/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "expo-example",
3-
"version": "1.1.18",
3+
"version": "1.1.19-alpha.2",
44
"scripts": {
55
"start": "cross-env CONNECT_SRC=https://localhost:8087/ yarn expo start --dev-client",
66
"android": "yarn expo run:android",
@@ -19,10 +19,10 @@
1919
"@noble/ed25519": "^2.1.0",
2020
"@noble/hashes": "^1.3.3",
2121
"@noble/secp256k1": "^1.7.1",
22-
"@onekeyfe/hd-ble-sdk": "1.1.18",
23-
"@onekeyfe/hd-common-connect-sdk": "1.1.18",
24-
"@onekeyfe/hd-core": "1.1.18",
25-
"@onekeyfe/hd-web-sdk": "1.1.18",
22+
"@onekeyfe/hd-ble-sdk": "1.1.19-alpha.2",
23+
"@onekeyfe/hd-common-connect-sdk": "1.1.19-alpha.2",
24+
"@onekeyfe/hd-core": "1.1.19-alpha.2",
25+
"@onekeyfe/hd-web-sdk": "1.1.19-alpha.2",
2626
"@onekeyfe/react-native-ble-utils": "^0.1.3",
2727
"@polkadot/util-crypto": "13.1.1",
2828
"@react-native-async-storage/async-storage": "1.21.0",

packages/connect-examples/expo-example/src/components/HandleSDKEvents.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useCallback, useContext, useState } from 'react';
22
import {
3-
CoreMessage,
43
DEVICE,
54
FIRMWARE_EVENT,
65
LOG_EVENT,
@@ -9,13 +8,16 @@ import {
98
UI_RESPONSE,
109
supportInputPinOnSoftware,
1110
} from '@onekeyfe/hd-core';
12-
1311
import { useFocusEffect } from '@react-navigation/native';
1412
import { View } from 'tamagui';
13+
1514
import HardwareSDKContext from '../provider/HardwareSDKContext';
1615
import { ReceivePin } from './ReceivePin';
1716
import { WebUsbAuthorize } from './WebUsbAuthorize';
18-
import { BluetoothPermission, BluetoothErrorType } from './BluetoothPermission';
17+
import { BluetoothPermission } from './BluetoothPermission';
18+
19+
import type { BluetoothErrorType } from './BluetoothPermission';
20+
import type { CoreMessage } from '@onekeyfe/hd-core';
1921

2022
// Type declaration for desktopApi matches the one in BluetoothPermission
2123
declare global {
@@ -207,6 +209,15 @@ export default function HandleSDKEvents() {
207209
}, [HardwareLowLevelSDK, SDK, onInputPinOnDeviceCallback])
208210
);
209211

212+
const onTestUnexpectedMessage = useCallback(() => {
213+
SDK?.btcGetAddress('', '', {
214+
path: "m/44'/0'/0'/0/0",
215+
showOnOneKey: false,
216+
useEmptyPassphrase: true,
217+
passphraseState: undefined,
218+
});
219+
}, [SDK]);
220+
210221
return (
211222
<View>
212223
<ReceivePin
@@ -215,6 +226,7 @@ export default function HandleSDKEvents() {
215226
onConfirm={val => onConfirmPin(val)}
216227
onSwitchDevice={onInputPinOnDeviceCallback}
217228
onCancel={onPinCancelCallback}
229+
onTestUnexpectedMessage={onTestUnexpectedMessage}
218230
/>
219231
<WebUsbAuthorize
220232
open={showWebUsbAuthorize}

packages/connect-examples/expo-example/src/components/ReceivePin.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, { useMemo, useCallback, memo } from 'react';
1+
import React, { memo, useCallback, useMemo } from 'react';
22
import { useIntl } from 'react-intl';
33
import { Dialog, Stack, Text, Unspaced, XStack, YStack } from 'tamagui';
44
import { Delete, X } from '@tamagui/lucide-icons';
55
import { StyleSheet } from 'react-native';
66
import { atom, getDefaultStore, useAtomValue, useSetAtom } from 'jotai';
7+
78
import { Button } from './ui/Button';
89
import { useMedia } from '../provider/MediaProvider';
910

@@ -256,10 +257,19 @@ type IReceivePinProps = {
256257
onConfirm: (value: string) => void;
257258
onSwitchDevice: () => void;
258259
onCancel: () => void;
260+
onTestUnexpectedMessage: () => void;
259261
};
260262

261263
export const ReceivePin = memo<IReceivePinProps>(
262-
({ open, payload, onOpenChange, onConfirm, onSwitchDevice, onCancel }: IReceivePinProps) => {
264+
({
265+
open,
266+
payload,
267+
onOpenChange,
268+
onConfirm,
269+
onSwitchDevice,
270+
onCancel,
271+
onTestUnexpectedMessage,
272+
}: IReceivePinProps) => {
263273
const intl = useIntl();
264274
const media = useMedia();
265275
const setPinAction = useSetAtom(pinActionsAtom);
@@ -312,6 +322,7 @@ export const ReceivePin = memo<IReceivePinProps>(
312322
{payload && <Text>payload: {JSON.stringify(payload)}</Text>}
313323
<PinInputArea />
314324
<PinActions onConfirm={onConfirm} onSwitchDevice={onSwitchDevice} />
325+
<Button onPress={onTestUnexpectedMessage}>Test UnexpectedMessage</Button>
315326
</YStack>
316327

317328
<CloseButton onCancel={handleCancel} />

packages/connect-examples/expo-example/src/data/device.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ const api: PlaygroundProps[] = [
165165
checkBridgeRelease: true,
166166
},
167167
},
168+
{
169+
title: 'checkAllFirmwareRelease Bitcoin Only',
170+
value: {
171+
checkBridgeRelease: true,
172+
firmwareType: 'bitcoinonly',
173+
},
174+
},
168175
],
169176
},
170177
{

packages/connect-examples/expo-playground/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "onekey-hardware-playground",
3-
"version": "1.1.18",
3+
"version": "1.1.19-alpha.2",
44
"private": true,
55
"sideEffects": [
66
"app/utils/shim.js",
@@ -17,9 +17,9 @@
1717
},
1818
"dependencies": {
1919
"@noble/hashes": "^1.8.0",
20-
"@onekeyfe/hd-common-connect-sdk": "1.1.18",
21-
"@onekeyfe/hd-core": "1.1.18",
22-
"@onekeyfe/hd-shared": "1.1.18",
20+
"@onekeyfe/hd-common-connect-sdk": "1.1.19-alpha.2",
21+
"@onekeyfe/hd-core": "1.1.19-alpha.2",
22+
"@onekeyfe/hd-shared": "1.1.19-alpha.2",
2323
"@radix-ui/react-checkbox": "^1.3.2",
2424
"@radix-ui/react-dialog": "^1.1.14",
2525
"@radix-ui/react-dropdown-menu": "^2.1.15",

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-core",
3-
"version": "1.1.18",
3+
"version": "1.1.19-alpha.2",
44
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
55
"author": "OneKey",
66
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
2525
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
2626
},
2727
"dependencies": {
28-
"@onekeyfe/hd-shared": "1.1.18",
29-
"@onekeyfe/hd-transport": "1.1.18",
28+
"@onekeyfe/hd-shared": "1.1.19-alpha.2",
29+
"@onekeyfe/hd-transport": "1.1.19-alpha.2",
3030
"axios": "1.12.2",
3131
"bignumber.js": "^9.0.2",
3232
"bytebuffer": "^5.0.1",

packages/core/src/api/BaseMethod.ts

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import semver from 'semver';
22
import {
3-
createNeedUpgradeFirmwareHardwareError,
43
ERRORS,
54
HardwareErrorCode,
5+
createNeedUpgradeFirmwareHardwareError,
66
} from '@onekeyfe/hd-shared';
7+
78
import { supportInputPinOnSoftware, supportModifyHomescreen } from '../utils/deviceFeaturesUtils';
89
import { createDeviceMessage } from '../events/device';
910
import { UI_REQUEST } from '../constants/ui-request';
10-
import { Device } from '../device/Device';
11-
import DeviceConnector from '../device/DeviceConnector';
12-
import { DeviceFirmwareRange, KnownDevice } from '../types';
13-
import { CoreMessage, createFirmwareMessage, createUiMessage, DEVICE, FIRMWARE } from '../events';
11+
import { DEVICE, FIRMWARE, createFirmwareMessage, createUiMessage } from '../events';
1412
import { getBleFirmwareReleaseInfo, getFirmwareReleaseInfo } from './firmware/releaseHelper';
15-
import { getDeviceFirmwareVersion, getLogger, getMethodVersionRange, LoggerNames } from '../utils';
13+
import {
14+
LoggerNames,
15+
getDeviceFirmwareVersion,
16+
getFirmwareType,
17+
getLogger,
18+
getMethodVersionRange,
19+
} from '../utils';
20+
21+
import type { Device } from '../device/Device';
22+
import type DeviceConnector from '../device/DeviceConnector';
23+
import type { DeviceFirmwareRange, KnownDevice } from '../types';
24+
import type { CoreMessage } from '../events';
25+
import { generateInstanceId, RequestContext } from '../utils/tracing';
1626
import type { CoreContext } from '../core';
1727

1828
const Log = getLogger(LoggerNames.Method);
@@ -45,6 +55,12 @@ export abstract class BaseMethod<Params = undefined> {
4555
*/
4656
name: string;
4757

58+
instanceId!: string;
59+
60+
sdkInstanceId?: string;
61+
62+
requestContext?: RequestContext;
63+
4864
/**
4965
* 请求携带参数
5066
*/
@@ -121,14 +137,45 @@ export abstract class BaseMethod<Params = undefined> {
121137
return {};
122138
}
123139

140+
setContext(context: CoreContext) {
141+
this.sdkInstanceId = context.sdkInstanceId;
142+
this.instanceId = generateInstanceId('Method', this.sdkInstanceId);
143+
Log.debug(
144+
`[BaseMethod] Created: ${this.instanceId}, method: ${this.name}, SDK: ${this.sdkInstanceId}`
145+
);
146+
}
147+
124148
setDevice(device: Device) {
125149
this.device = device;
126-
// this.connectId = device.originalDescriptor.path;
150+
151+
if (!device.sdkInstanceId && this.sdkInstanceId) {
152+
device.sdkInstanceId = this.sdkInstanceId;
153+
device.instanceId = generateInstanceId('Device', this.sdkInstanceId);
154+
}
155+
156+
if (this.requestContext) {
157+
this.requestContext.deviceInstanceId = device.instanceId;
158+
this.requestContext.commandsInstanceId = device.commands?.instanceId;
159+
this.requestContext.sdkInstanceId = this.sdkInstanceId;
160+
}
161+
162+
if (device.commands && this.sdkInstanceId) {
163+
device.commands.instanceId = generateInstanceId('DeviceCommands', this.sdkInstanceId);
164+
}
165+
166+
if (device.commands) {
167+
device.commands.currentResponseID = this.responseID;
168+
}
169+
170+
Log.debug(
171+
`[${this.instanceId}] setDevice: ${device.instanceId}, commands: ${device.commands?.instanceId}`
172+
);
127173
}
128174

129175
checkFirmwareRelease() {
130176
if (!this.device || !this.device.features) return;
131-
const releaseInfo = getFirmwareReleaseInfo(this.device.features);
177+
const firmwareType = getFirmwareType(this.device.features);
178+
const releaseInfo = getFirmwareReleaseInfo(this.device.features, firmwareType);
132179
this.postMessage(
133180
createFirmwareMessage(FIRMWARE.RELEASE_INFO, {
134181
...releaseInfo,

0 commit comments

Comments
 (0)