Skip to content

Commit

Permalink
fix: 1s sign type data (#297)
Browse files Browse the repository at this point in the history
* fix: 1s sign type data

* chore: update version
  • Loading branch information
ByteZhang1024 authored Dec 25, 2023
1 parent 1a376d1 commit 9b1787a
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 59 deletions.
10 changes: 5 additions & 5 deletions packages/connect-examples/expo-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-example",
"version": "0.3.35",
"version": "0.3.36",
"scripts": {
"start": "expo start --dev-client",
"android": "expo run:android",
Expand All @@ -11,10 +11,10 @@
"dependencies": {
"@expo/webpack-config": "^18.1.3",
"@noble/hashes": "^1.3.2",
"@onekeyfe/hd-ble-sdk": "^0.3.35",
"@onekeyfe/hd-common-connect-sdk": "^0.3.35",
"@onekeyfe/hd-core": "^0.3.35",
"@onekeyfe/hd-web-sdk": "^0.3.35",
"@onekeyfe/hd-ble-sdk": "^0.3.36",
"@onekeyfe/hd-common-connect-sdk": "^0.3.36",
"@onekeyfe/hd-core": "^0.3.36",
"@onekeyfe/hd-web-sdk": "^0.3.36",
"@onekeyfe/react-native-ble-plx": "3.0.0",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-picker/picker": "2.4.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const getHardwareSDKInstance = memoizee(
console.log(HardwareSDK);

if (Platform.OS === 'web') {
settings.connectSrc = 'https://jssdk.onekey.so/0.3.34/';
settings.connectSrc = 'https://jssdk.onekey.so/0.3.36/';
// settings.connectSrc = 'https://localhost:8087/';
settings.env = 'web';
settings.preRelease = false;
// HardwareLowLevelSDK = await importLowLevelSDK();
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-core",
"version": "0.3.35",
"version": "0.3.36",
"description": "> TODO: description",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -25,8 +25,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.35",
"@onekeyfe/hd-transport": "^0.3.35",
"@onekeyfe/hd-shared": "^0.3.36",
"@onekeyfe/hd-transport": "^0.3.36",
"axios": "^0.27.2",
"bignumber.js": "^9.0.2",
"bytebuffer": "^5.0.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/api/CheckBootloaderRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from './firmware/updateBootloader';
import { DataManager } from '../data-manager';
import { getDeviceType } from '../utils';
import { DeviceModelToTypes } from '../types';

export default class CheckBootloaderRelease extends BaseMethod {
init() {
Expand All @@ -22,7 +23,8 @@ export default class CheckBootloaderRelease extends BaseMethod {
const { features } = this.device;
const deviceType = getDeviceType(features);
let shouldUpdate = false;
if (deviceType === 'classic' || deviceType === 'mini') {
// classic mini classic1s
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
shouldUpdate = !!checkNeedUpdateBootForClassicAndMini(
features,
this.payload.willUpdateFirmwareVersion
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/api/CheckBridgeRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BaseMethod } from './BaseMethod';
import { UI_REQUEST } from '../constants/ui-request';
import { getDeviceType } from '../utils';
import { getDeviceFirmwareVersion } from '../utils/deviceFeaturesUtils';
import { DeviceModelToTypes } from '../types';

const BridgeVersion = '2.2.0';
const TouchNeedUpdateVersion = '4.3.0';
Expand Down Expand Up @@ -45,7 +46,8 @@ export default class CheckBridgeRelease extends BaseMethod {
shouldUpdate = true;
}
}
if (deviceType === 'classic' || deviceType === 'mini') {
// classic mini classic1s
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
if (
semver.gte(willUpdateFirmwareVersion, ClassicAndMiniNeedUpdateVersion) &&
isOldVersionBridge
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/api/FirmwareUpdateV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import { getBinary, getInfo, getSysResourceBinary } from './firmware/getBinary';
import { updateResources, uploadFirmware } from './firmware/uploadFirmware';
import { getDeviceType, getDeviceUUID, wait, getLogger, LoggerNames } from '../utils';
import { createUiMessage } from '../events/ui-request';
import type { KnownDevice, Features } from '../types';
import { DeviceModelToTypes } from '../types';
import { DataManager } from '../data-manager';
import { getDeviceFirmwareVersion } from '../utils/deviceFeaturesUtils';

import type { KnownDevice, Features } from '../types';

type Params = {
binary?: ArrayBuffer;
version?: number[];
Expand Down Expand Up @@ -235,7 +237,7 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
this.checkDeviceToBootloader(this.payload.connectId);

// force clean classic device cache so that the device can initialize again
if (deviceType === 'classic') {
if (DeviceModelToTypes.model_classic.includes(deviceType)) {
DevicePool.clearDeviceCache(uuid);
}
delete DevicePool.devicesCache[''];
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/api/device/DeviceVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { formatAnyHex } from '../helpers/hexUtils';
import { BaseMethod } from '../BaseMethod';
import { validateParams } from '../helpers/paramsValidator';
import { getDeviceType } from '../../utils';
import { DeviceModelToTypes } from '../../types';
import type { DeviceVerifySignature } from '../../types';

export default class DeviceVerify extends BaseMethod<BixinVerifyDeviceRequest> {
Expand All @@ -26,7 +27,7 @@ export default class DeviceVerify extends BaseMethod<BixinVerifyDeviceRequest> {
const deviceType = getDeviceType(this.device.features);
let response: DeviceVerifySignature | undefined;

if (deviceType === 'classic') {
if (DeviceModelToTypes.model_classic.includes(deviceType)) {
const res = await this.device.commands.typedCall(
'BixinVerifyDeviceRequest',
'BixinVerifyDeviceAck',
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/api/evm/EVMSignTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { BaseMethod } from '../BaseMethod';
import { validateParams } from '../helpers/paramsValidator';
import { formatAnyHex } from '../helpers/hexUtils';
import { getDeviceFirmwareVersion, getDeviceType } from '../../utils/deviceFeaturesUtils';
import type { EthereumSignTypedDataMessage, EthereumSignTypedDataTypes } from '../../types';
import {
DeviceModelToTypes,
type EthereumSignTypedDataMessage,
type EthereumSignTypedDataTypes,
} from '../../types';
import TransportManager from '../../data-manager/TransportManager';
import { signTypedHash as signTypedHashLegacyV1 } from './legacyV1/signTypedHash';
import { signTypedHash } from './latest/signTypedHash';
Expand Down Expand Up @@ -348,7 +352,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>

supportSignTyped() {
const deviceType = getDeviceType(this.device.features);
if (deviceType === 'classic' || deviceType === 'mini') {
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
const supportSignTypedVersion = '2.2.0';

Expand All @@ -372,7 +376,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>

// For Classic、Mini device we use EthereumSignTypedData
const deviceType = getDeviceType(this.device.features);
if (deviceType === 'classic' || deviceType === 'mini') {
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
validateParams(this.params, [
{ name: 'domainHash', type: 'hexString', required: true },
{ name: 'messageHash', type: 'hexString', required: true },
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/api/firmware/updateBootloader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ByteBuffer from 'bytebuffer';
import semver from 'semver';
import { Features } from '../../types';
import { DeviceModelToTypes, Features } from '../../types';
import { getDeviceType } from '../../utils';
import {
getDeviceBootloaderVersion,
Expand Down Expand Up @@ -32,7 +32,7 @@ export function checkNeedUpdateBootForClassicAndMini(
willUpdateFirmware: string
) {
const deviceType = getDeviceType(features);
if (deviceType !== 'classic' && deviceType !== 'mini') return false;
if (!DeviceModelToTypes.model_mini.includes(deviceType)) return false;
if (!willUpdateFirmware) return false;
const currentVersion = getDeviceFirmwareVersion(features).join('.');
const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/data-manager/DataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
IVersionArray,
RemoteConfigResponse,
} from '../types';
import { DeviceModelToTypes } from '../types';
import { findLatestRelease, getReleaseChangelog, getReleaseStatus } from '../utils/release';

export type FirmwareField = 'firmware' | 'firmware-v2' | 'firmware-v4';
Expand Down Expand Up @@ -69,7 +70,7 @@ export default class DataManager {
return 'none';
}

if (deviceType === 'classic' && features.bootloader_mode) {
if (DeviceModelToTypes.model_classic.includes(deviceType) && features.bootloader_mode) {
return 'unknown';
}

Expand Down Expand Up @@ -153,7 +154,7 @@ export default class DataManager {
static getBootloaderRelatedFirmwareVersion = (features: Features): IVersionArray | undefined => {
const deviceType = getDeviceType(features);

if (!(deviceType === 'classic' || deviceType === 'mini')) return undefined;
if (!DeviceModelToTypes.model_mini.includes(deviceType)) return undefined;
const firmwareUpdateField = getFirmwareUpdateField({
features,
updateType: 'firmware',
Expand All @@ -172,7 +173,7 @@ export default class DataManager {

if (
features.firmware_present === false ||
(deviceType === 'classic' && features.bootloader_mode)
(DeviceModelToTypes.model_classic.includes(deviceType) && features.bootloader_mode)
) {
return [];
}
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/types/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,22 @@ export type Features = PROTO.Features;

export type IDeviceType = 'classic' | 'classic1s' | 'mini' | 'touch' | 'pro';

// model_mini: 'classic' | 'mini'
// model_touch: 'touch' | 'pro'
export type IDeviceModel = 'model_mini' | 'model_touch';
/**
* model_classic: 'classic' | 'classic1s'
* model_mini: 'classic' | 'mini'
* model_touch: 'touch' | 'pro'
*/
export type IDeviceModel = 'model_classic' | 'model_mini' | 'model_touch';

export const DeviceModelToTypes: { [deviceModel in IDeviceModel]: IDeviceType[] } = {
model_mini: ['classic', 'classic1s', 'mini'],
model_touch: ['touch', 'pro'],
model_classic: ['classic', 'classic1s'],
};

export const DeviceTypeToModels: { [deviceType in IDeviceType]: IDeviceModel[] } = {
classic: ['model_mini'],
classic1s: ['model_mini'],
classic: ['model_classic', 'model_mini'],
classic1s: ['model_classic', 'model_mini'],
mini: ['model_mini'],
touch: ['model_touch'],
pro: ['model_touch'],
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/utils/deviceFeaturesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
IVersionArray,
SupportFeatureType,
} from '../types';
import { DeviceTypeToModels } from '../types';
import { DeviceModelToTypes, DeviceTypeToModels } from '../types';
import DataManager, { FirmwareField, MessageVersion } from '../data-manager/DataManager';
import { PROTOBUF_MESSAGE_CONFIG } from '../data-manager/MessagesConfig';
import { Device } from '../device/Device';
Expand Down Expand Up @@ -68,6 +68,7 @@ export const getDeviceTypeByBleName = (name?: string): IDeviceType | null => {
return 'classic';
};

// @deprecated
export const getDeviceTypeByDeviceId = (deviceId?: string): IDeviceType => {
if (!deviceId) {
return 'classic';
Expand Down Expand Up @@ -253,7 +254,7 @@ export const supportModifyHomescreen = (features?: Features): SupportFeatureType
const currentVersion = getDeviceFirmwareVersion(features).join('.');

const deviceType = getDeviceType(features);
if (deviceType === 'classic' || deviceType === 'mini') {
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
return { support: true };
}

Expand All @@ -278,7 +279,7 @@ export const getFirmwareUpdateField = ({
return 'ble';
}

if (deviceType === 'classic' || deviceType === 'mini') {
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
return 'firmware-v4';
}

Expand Down
8 changes: 4 additions & 4 deletions packages/hd-ble-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-ble-sdk",
"version": "0.3.35",
"version": "0.3.36",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,8 +20,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "^0.3.35",
"@onekeyfe/hd-shared": "^0.3.35",
"@onekeyfe/hd-transport-react-native": "^0.3.35"
"@onekeyfe/hd-core": "^0.3.36",
"@onekeyfe/hd-shared": "^0.3.36",
"@onekeyfe/hd-transport-react-native": "^0.3.36"
}
}
12 changes: 6 additions & 6 deletions packages/hd-common-connect-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-common-connect-sdk",
"version": "0.3.35",
"version": "0.3.36",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "ISC",
Expand All @@ -20,10 +20,10 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-core": "^0.3.35",
"@onekeyfe/hd-shared": "^0.3.35",
"@onekeyfe/hd-transport-http": "^0.3.35",
"@onekeyfe/hd-transport-lowlevel": "^0.3.35",
"@onekeyfe/hd-transport-webusb": "^0.3.35"
"@onekeyfe/hd-core": "^0.3.36",
"@onekeyfe/hd-shared": "^0.3.36",
"@onekeyfe/hd-transport-http": "^0.3.36",
"@onekeyfe/hd-transport-lowlevel": "^0.3.36",
"@onekeyfe/hd-transport-webusb": "^0.3.36"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-http",
"version": "0.3.35",
"version": "0.3.36",
"description": "hardware http transport",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
Expand All @@ -24,8 +24,8 @@
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.35",
"@onekeyfe/hd-transport": "^0.3.35",
"@onekeyfe/hd-shared": "^0.3.36",
"@onekeyfe/hd-transport": "^0.3.36",
"axios": "^0.27.2"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-lowlevel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-lowlevel",
"version": "0.3.35",
"version": "0.3.36",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -19,7 +19,7 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.35",
"@onekeyfe/hd-transport": "^0.3.35"
"@onekeyfe/hd-shared": "^0.3.36",
"@onekeyfe/hd-transport": "^0.3.36"
}
}
6 changes: 3 additions & 3 deletions packages/hd-transport-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-react-native",
"version": "0.3.35",
"version": "0.3.36",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -19,8 +19,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.35",
"@onekeyfe/hd-transport": "^0.3.35",
"@onekeyfe/hd-shared": "^0.3.36",
"@onekeyfe/hd-transport": "^0.3.36",
"@onekeyfe/react-native-ble-plx": "3.0.0",
"react-native-ble-manager": "^8.1.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hd-transport-webusb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/hd-transport-webusb",
"version": "0.3.35",
"version": "0.3.36",
"author": "OneKey",
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
"license": "MIT",
Expand All @@ -20,8 +20,8 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@onekeyfe/hd-shared": "^0.3.35",
"@onekeyfe/hd-transport": "^0.3.35"
"@onekeyfe/hd-shared": "^0.3.36",
"@onekeyfe/hd-transport": "^0.3.36"
},
"devDependencies": {
"@types/w3c-web-usb": "^1.0.6"
Expand Down
Loading

0 comments on commit 9b1787a

Please sign in to comment.