From d1ad72f08fcd4d7a1f7a09e30f94f9a7c45d42ee Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Sun, 21 Jul 2024 23:00:01 +0800 Subject: [PATCH 1/3] feat: support all network --- .../expo-example/src/data/allnetwork.ts | 294 +++++++++++++++ .../src/views/ApiPayloadScreen.tsx | 4 + .../api/allnetwork/AllNetworkGetAddress.ts | 349 ++++++++++++++++++ packages/core/src/api/index.ts | 2 + packages/core/src/core/index.ts | 17 +- packages/core/src/inject.ts | 3 + .../src/types/api/allNetworkGetAddress.ts | 78 ++++ packages/core/src/types/api/export.ts | 2 + packages/core/src/types/api/index.ts | 7 + submodules/firmware | 2 +- 10 files changed, 756 insertions(+), 2 deletions(-) create mode 100644 packages/connect-examples/expo-example/src/data/allnetwork.ts create mode 100644 packages/core/src/api/allnetwork/AllNetworkGetAddress.ts create mode 100644 packages/core/src/types/api/allNetworkGetAddress.ts diff --git a/packages/connect-examples/expo-example/src/data/allnetwork.ts b/packages/connect-examples/expo-example/src/data/allnetwork.ts new file mode 100644 index 000000000..4bad3d523 --- /dev/null +++ b/packages/connect-examples/expo-example/src/data/allnetwork.ts @@ -0,0 +1,294 @@ +import { type PlaygroundProps } from '../components/Playground'; + +const api: PlaygroundProps[] = [ + { + method: 'allNetworkGetAddress', + description: 'Get address', + presupposes: [ + { + title: 'Batch Get Address', + value: { + bundle: [ + { + network: 'btc', + path: "m/44'/0'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'tbtc', + path: "m/44'/1'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'ltc', + path: "m/44'/2'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'bch', + path: "m/44'/145'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'neurai', + path: "m/44'/1900'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'doge', + path: "m/44'/3'/0'/0/0", + showOnOneKey: false, + }, + + { + network: 'btc', + chainName: 'bitcoin', + path: "m/44'/0'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'testnet', + path: "m/44'/1'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'litecoin', + path: "m/44'/2'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'bcash', + path: "m/44'/145'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'neurai', + path: "m/44'/1900'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'dogecoin', + path: "m/44'/3'/0'/0/0", + showOnOneKey: false, + }, + + { + network: 'evm', + path: "m/44'/60'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'evm', + path: "m/44'/60'/0'/0/0", + chainName: '20', + showOnOneKey: false, + }, + + { + network: 'algo', + path: "m/44'/283'/0'/0'/0'", + showOnOneKey: false, + }, + { + network: 'aptos', + path: "m/44'/637'/0'/0'/0'", + showOnOneKey: false, + }, + { + network: 'ada', + path: "m/1852'/1815'/0'", + showOnOneKey: false, + }, + { + network: 'cfx', + path: "m/44'/503'/0'/0/0", + chainName: '1029', + showOnOneKey: false, + }, + { + network: 'cfx', + path: "m/44'/503'/0'/0/0", + chainName: '1', + showOnOneKey: false, + }, + { + network: 'cosmos', + path: "m/44'/118'/0'/0/0", + prefix: 'cosmos', + showOnOneKey: false, + }, + { + network: 'cosmos', + path: "m/44'/118'/0'/0/0", + prefix: 'osmosis', + showOnOneKey: false, + }, + { + network: 'dynex', + path: "m/44'/29538'/0'/0'/0'", + showOnOneKey: false, + }, + { + network: 'fil', + path: "m/44'/461'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'kaspa', + path: "m/44'/111111'/0'/0/0", + prefix: 'kaspa', + showOnOneKey: false, + }, + { + network: 'near', + path: "m/44'/397'/0'", + showOnOneKey: false, + }, + { + network: 'nexa', + path: "m/44'/29223'/0'/0/0", + prefix: 'nexa', + showOnOneKey: false, + }, + { + network: 'nervos', + path: "m/44'/309'/0'/0/0", + chainName: 'ckb', + showOnOneKey: false, + }, + { + network: 'dot', + path: "m/44'/354'/0'/0'/0'", + prefix: '0', + chainName: 'polkadot', + showOnOneKey: false, + }, + { + network: 'xrp', + path: "m/44'/144'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'sol', + path: "m/44'/501'/0'/0'", + showOnOneKey: false, + }, + { + network: 'stc', + path: "m/44'/101010'/0'/0'/0'", + showOnOneKey: false, + }, + { + network: 'sui', + path: "m/44'/784'/0'/0'/0'", + showOnOneKey: false, + }, + { + network: 'tron', + path: "m/44'/195'/0'/0/0", + showOnOneKey: false, + }, + ], + }, + }, + { + title: 'Batch ADA Get Address', + value: { + bundle: [ + { + network: 'ada', + path: "m/1852'/1815'/0'", + showOnOneKey: false, + }, + { + network: 'dynex', + path: "m/44'/29538'/0'/0'/0'", + showOnOneKey: false, + }, + ], + }, + }, + { + title: 'Batch Bitcoin Get Address', + value: { + bundle: [ + { + network: 'btc', + path: "m/44'/0'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'tbtc', + path: "m/44'/1'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'ltc', + path: "m/44'/2'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'bch', + path: "m/44'/145'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'neurai', + path: "m/44'/1900'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'doge', + path: "m/44'/3'/0'/0/0", + showOnOneKey: false, + }, + + { + network: 'btc', + chainName: 'bitcoin', + path: "m/44'/0'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'testnet', + path: "m/44'/1'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'litecoin', + path: "m/44'/2'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'bcash', + path: "m/44'/145'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'neurai', + path: "m/44'/1900'/0'/0/0", + showOnOneKey: false, + }, + { + network: 'btc', + chainName: 'dogecoin', + path: "m/44'/3'/0'/0/0", + showOnOneKey: false, + }, + ], + }, + }, + ], + }, +]; + +export default api; diff --git a/packages/connect-examples/expo-example/src/views/ApiPayloadScreen.tsx b/packages/connect-examples/expo-example/src/views/ApiPayloadScreen.tsx index f1cf61140..8b17bf917 100644 --- a/packages/connect-examples/expo-example/src/views/ApiPayloadScreen.tsx +++ b/packages/connect-examples/expo-example/src/views/ApiPayloadScreen.tsx @@ -25,6 +25,10 @@ const playgroundConfig = [ title: 'Device API', data: require('../data/device').default, }, + { + title: 'AllNetwork API', + data: require('../data/allnetwork').default, + }, { title: 'Bitcoin API', data: require('../data/bitcoin').default, diff --git a/packages/core/src/api/allnetwork/AllNetworkGetAddress.ts b/packages/core/src/api/allnetwork/AllNetworkGetAddress.ts new file mode 100644 index 000000000..66f3d32a7 --- /dev/null +++ b/packages/core/src/api/allnetwork/AllNetworkGetAddress.ts @@ -0,0 +1,349 @@ +import semver from 'semver'; +import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared'; +import { UI_REQUEST } from '../../constants/ui-request'; +import { serializedPath } from '../helpers/pathUtils'; +import { BaseMethod } from '../BaseMethod'; +import { validateParams } from '../helpers/paramsValidator'; +import { CoreApi } from '../../types'; + +import type { + AllNetworkAddress, + AllNetworkAddressParams, + INetwork, +} from '../../types/api/allNetworkGetAddress'; +import { findMethod } from '../utils'; +import { IFRAME } from '../../events'; +import { getDeviceFirmwareVersion, getMethodVersionRange } from '../../utils'; +import { Device } from '../../device/Device'; +import { PROTO } from '../../constants'; + +const Mainnet = 'mainnet'; + +type NetworkConfig = { + methodName: keyof CoreApi; + getParams?: (baseParams: AllNetworkAddressParams, chainName?: string) => any; +}; + +type INetworkReal = Exclude; + +type NetworkConfigMap = { + [K in INetworkReal]: NetworkConfig; +}; + +const networkAliases: { + [key: string]: { name: INetworkReal; coin: string }; +} = { + tbtc: { name: 'btc', coin: 'Testnet' }, + bch: { name: 'btc', coin: 'Bcash' }, + doge: { name: 'btc', coin: 'Dogecoin' }, + ltc: { name: 'btc', coin: 'Litecoin' }, + neurai: { name: 'btc', coin: 'Neurai' }, +}; + +const networkConfigMap: NetworkConfigMap = { + btc: { + methodName: 'btcGetAddress', + getParams: (baseParams: AllNetworkAddressParams, chainName?: string) => ({ + coin: chainName, + ...baseParams, + }), + }, + evm: { + methodName: 'evmGetAddress', + getParams: (baseParams: AllNetworkAddressParams, chainName?: string) => { + const { path, showOnOneKey } = baseParams; + let chainId; + if (chainName) { + chainId = parseInt(chainName); + } + return { + chainId, + path, + showOnOneKey, + }; + }, + }, + sol: { + methodName: 'solGetAddress', + }, + algo: { + methodName: 'algoGetAddress', + }, + near: { + methodName: 'nearGetAddress', + }, + stc: { + methodName: 'starcoinGetAddress', + }, + cfx: { + methodName: 'confluxGetAddress', + getParams: (baseParams: AllNetworkAddressParams, chainName?: string) => { + const { path, showOnOneKey } = baseParams; + return { + chainId: parseInt(chainName ?? '1029'), + path, + showOnOneKey, + }; + }, + }, + tron: { + methodName: 'tronGetAddress', + }, + aptos: { + methodName: 'aptosGetAddress', + }, + xrp: { + methodName: 'xrpGetAddress', + }, + cosmos: { + methodName: 'cosmosGetAddress', + getParams: (baseParams: AllNetworkAddressParams) => { + const { path, prefix, showOnOneKey } = baseParams; + return { + hrp: prefix, + path, + showOnOneKey, + }; + }, + }, + ada: { + methodName: 'cardanoGetAddress', + getParams: (baseParams: AllNetworkAddressParams, chainName?: string) => { + const { path, showOnOneKey } = baseParams; + + const addressPath = + typeof path === 'string' ? `${path}/0/0` : serializedPath([...path, 0, 0]); + const stakingPath = + typeof path === 'string' ? `${path}/2/0` : serializedPath([...path, 2, 0]); + + let networkId = 1; + if (chainName) { + networkId = chainName === Mainnet ? 1 : 0; + } + + return { + addressParameters: { + addressType: PROTO.CardanoAddressType.BASE, + path: addressPath, + stakingPath, + }, + protocolMagic: 764824073, + networkId, + derivationType: PROTO.CardanoDerivationType.ICARUS, + showOnOneKey, + address: '', + isCheck: false, + }; + }, + }, + sui: { + methodName: 'suiGetAddress', + }, + fil: { + methodName: 'filecoinGetAddress', + getParams: (baseParams: AllNetworkAddressParams, chainName?: string) => { + const { path, showOnOneKey } = baseParams; + let isTestnet = false; + if (chainName) { + isTestnet = chainName !== Mainnet; + } + return { + isTestnet, + path, + showOnOneKey, + }; + }, + }, + dot: { + methodName: 'polkadotGetAddress', + getParams: (baseParams: AllNetworkAddressParams, chainName?: string) => { + const { path, prefix, showOnOneKey } = baseParams; + if (!prefix || !chainName) { + throw new Error('Invalid params'); + } + return { + prefix: parseInt(prefix), + network: chainName, + path, + showOnOneKey, + }; + }, + }, + kaspa: { + methodName: 'kaspaGetAddress', + getParams: (baseParams: AllNetworkAddressParams) => { + const { path, prefix, showOnOneKey } = baseParams; + return { + scheme: 'schnorr', + prefix, + path, + showOnOneKey, + }; + }, + }, + nexa: { + methodName: 'nexaGetAddress', + getParams: (baseParams: AllNetworkAddressParams) => { + const { path, prefix, showOnOneKey } = baseParams; + return { + scheme: 'Schnorr', + prefix, + path, + showOnOneKey, + }; + }, + }, + dynex: { + methodName: 'dnxGetAddress', + }, + nervos: { + methodName: 'nervosGetAddress', + getParams: (baseParams: AllNetworkAddressParams, chainName?: string) => { + const { path, showOnOneKey } = baseParams; + return { + network: chainName, + path, + showOnOneKey, + }; + }, + }, +}; + +export default class AllNetworkGetAddress extends BaseMethod< + { + address_n: number[]; + show_display: boolean; + network: string; + chain_name?: string; + }[] +> { + init() { + this.checkDeviceId = true; + this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE]; + + // check payload + validateParams(this.payload, [{ name: 'bundle', type: 'array' }]); + + // check bundle + console.log('=====>>>>>> this.payload.bundle', this.payload.bundle); + + this.payload.bundle.forEach((batch: AllNetworkAddressParams) => { + validateParams(batch, [ + { name: 'path', required: true }, + { name: 'network', type: 'string', required: true }, + { name: 'chainName', type: 'string' }, + { name: 'showOnOneKey', type: 'boolean' }, + ]); + }); + } + + generateMethodName({ + network, + payload, + }: { + network: INetwork; + payload: AllNetworkAddressParams; + }): { + methodName: keyof CoreApi; + params: Parameters[0]; + } { + const { name: networkName, coin } = networkAliases[network] || { + name: network, + coin: payload?.chainName, + }; + const config = networkConfigMap[networkName]; + if (!config) { + throw new Error(`Unsupported network: ${network}`); + } + + return { + methodName: config.methodName, + params: config?.getParams?.(payload, coin) ?? payload, + }; + } + + async run() { + const responses: AllNetworkAddress[] = []; + for (let i = 0; i < this.payload.bundle.length; i++) { + const param = this.payload.bundle[i]; + const { methodName, params } = this.generateMethodName({ + network: param.network as INetwork, + payload: param, + }); + + const method: BaseMethod = findMethod({ + event: IFRAME.CALL, + type: IFRAME.CALL, + payload: { + connectId: this.payload.connectId, + deviceId: this.payload.deviceId, + method: methodName, + ...params, + }, + }); + + method.connector = this.connector; + method.postMessage = this.postMessage; + method.init(); + method.setDevice?.(this.device); + + const baseParams = { + network: param.network, + path: typeof param.path === 'string' ? param.path : serializedPath(param.path), + chainName: param.chainName, + prefix: param.prefix, + }; + + let result: AllNetworkAddress; + try { + const response = await method.run(); + result = { + ...baseParams, + success: true, + error: response.error, + payload: response, + }; + } catch (e: any) { + const errorMessage = + e instanceof Error ? handleHardwareError(e, this.device, method) : 'Unknown error'; + + result = { + ...baseParams, + success: false, + error: errorMessage, + }; + } + + responses.push(result); + this.postPreviousAddressMessage(result); + } + + return Promise.resolve(responses); + } +} + +function handleHardwareError(e: any, device: Device, method: BaseMethod) { + let message = e?.message || ''; + + if (message.includes('Failure_UnexpectedMessage')) { + const versionRange = getMethodVersionRange( + device.features, + type => method.getVersionRange()[type] + ); + const currentVersion = getDeviceFirmwareVersion(device.features).join('.'); + + if ( + versionRange && + semver.valid(versionRange.min) && + semver.lt(currentVersion, versionRange.min) + ) { + message = ERRORS.TypedError( + HardwareErrorCode.CallMethodNeedUpgradeFirmware, + `Device firmware version is too low, please update to ${versionRange.min}`, + { current: currentVersion, require: versionRange.min } + ).message; + } + } + + return message; +} diff --git a/packages/core/src/api/index.ts b/packages/core/src/api/index.ts index b50ecfcb1..8d00f5f1a 100644 --- a/packages/core/src/api/index.ts +++ b/packages/core/src/api/index.ts @@ -39,6 +39,8 @@ export { default as requestWebUsbDevice } from './RequestWebUsbDevice'; export { default as cipherKeyValue } from './CipherKeyValue'; +export { default as allNetworkGetAddress } from './allnetwork/AllNetworkGetAddress'; + export { default as btcGetAddress } from './btc/BTCGetAddress'; export { default as btcGetPublicKey } from './btc/BTCGetPublicKey'; export { default as btcSignMessage } from './btc/BTCSignMessage'; diff --git a/packages/core/src/core/index.ts b/packages/core/src/core/index.ts index 5898fb791..3fa75f446 100644 --- a/packages/core/src/core/index.ts +++ b/packages/core/src/core/index.ts @@ -44,11 +44,25 @@ import DeviceConnector from '../device/DeviceConnector'; const Log = getLogger(LoggerNames.Core); +function hasDeriveCardano(method: BaseMethod): boolean { + if ( + method.name.startsWith('allNetworkGetAddress') && + method.payload && + method.payload.bundle && + // @ts-expect-error + method.payload.bundle.some(net => net && net.network === 'ada') + ) { + return true; + } + + return method.name.startsWith('cardano') || method.payload?.deriveCardano; +} + const parseInitOptions = (method?: BaseMethod): InitOptions => ({ initSession: method?.payload.initSession, passphraseState: method?.payload.passphraseState, deviceId: method?.payload.deviceId, - deriveCardano: method?.name.startsWith('cardano') || method?.payload?.deriveCardano, + deriveCardano: method && hasDeriveCardano(method), }); let _core: Core; @@ -283,6 +297,7 @@ export const callAPI = async (message: CoreMessage) => { } try { + console.log('=====>>>>>>Call API - Inner Running method', method.payload); const response: object = await method.run(); Log.debug('Call API - Inner Method Run: '); messageResponse = createResponseMessage(method.responseID, true, response); diff --git a/packages/core/src/inject.ts b/packages/core/src/inject.ts index e7dd1cc4d..8560f0a67 100644 --- a/packages/core/src/inject.ts +++ b/packages/core/src/inject.ts @@ -143,6 +143,9 @@ export const createCoreApi = ( call({ ...params, connectId, method: 'getNextU2FCounter' }), setU2FCounter: (connectId, params) => call({ ...params, connectId, method: 'setU2FCounter' }), + allNetworkGetAddress: (connectId, deviceId, params) => + call({ ...params, connectId, deviceId, method: 'allNetworkGetAddress' }), + evmGetAddress: (connectId, deviceId, params) => call({ ...params, connectId, deviceId, method: 'evmGetAddress' }), evmGetPublicKey: (connectId, deviceId, params) => diff --git a/packages/core/src/types/api/allNetworkGetAddress.ts b/packages/core/src/types/api/allNetworkGetAddress.ts new file mode 100644 index 000000000..65c4a2280 --- /dev/null +++ b/packages/core/src/types/api/allNetworkGetAddress.ts @@ -0,0 +1,78 @@ +import type { CommonParams, Response } from '../params'; +import type { CardanoAddressParameters } from './cardano'; + +export type INetwork = + | 'evm' + // BTC forks + | 'btc' + | 'tbtc' + | 'doge' + | 'neurai' + | 'ltc' + | 'bch' + // Other + | 'sol' + | 'algo' + | 'near' + | 'stc' + | 'cfx' + | 'tron' + | 'aptos' + | 'xrp' + | 'cosmos' + | 'ada' + | 'sui' + | 'fil' + | 'dot' + | 'kaspa' + | 'nexa' + | 'dynex' + | 'nervos'; + +type CommonResponseParams = { + path: string; + network: INetwork; + chainName?: string; + prefix?: string; +}; + +export type AllNetworkAddressParams = { + path: string | number[]; + network: INetwork; + chainName?: string; + prefix?: string; + showOnOneKey?: boolean; +}; + +type AllNetworkAddressPayload = + | { + address: string; + publicKey?: string; + } + | { + // Cardano + addressParameters: CardanoAddressParameters; + protocolMagic: number; + networkId: number; + serializedPath: string; + serializedStakingPath: string; + address: string; + xpub?: string; + stakeAddress?: string; + }; + +export type AllNetworkAddress = CommonResponseParams & { + success: boolean; + error?: string; + payload?: AllNetworkAddressPayload; +}; + +export type AllNetworkGetAddressParams = { + bundle: AllNetworkAddressParams[]; +}; + +export declare function allNetworkGetAddress( + connectId: string, + deviceId: string, + params: CommonParams & AllNetworkGetAddressParams +): Response; diff --git a/packages/core/src/types/api/export.ts b/packages/core/src/types/api/export.ts index 2a8d54824..5639db85d 100644 --- a/packages/core/src/types/api/export.ts +++ b/packages/core/src/types/api/export.ts @@ -23,6 +23,8 @@ export type { DeviceSupportFeatures } from './deviceSupportFeatures'; export type { DeviceUploadResourceParams } from './deviceUploadResource'; export type { FirmwareUpdateParams, FirmwareUpdateBinaryParams } from './firmwareUpdate'; +export type { AllNetworkAddressParams, AllNetworkGetAddressParams } from './allNetworkGetAddress'; + export type { EVMAddress, EVMGetAddressParams } from './evmGetAddress'; export type { EVMPublicKey, EVMGetPublicKeyParams } from './evmGetPublicKey'; export type { EVMSignMessageParams } from './evmSignMessage'; diff --git a/packages/core/src/types/api/index.ts b/packages/core/src/types/api/index.ts index 4e68ecd21..8d276ab81 100644 --- a/packages/core/src/types/api/index.ts +++ b/packages/core/src/types/api/index.ts @@ -43,6 +43,8 @@ import { setU2FCounter } from './setU2FCounter'; import { cipherKeyValue } from './cipherKeyValue'; +import { allNetworkGetAddress } from './allNetworkGetAddress'; + import { evmGetAddress } from './evmGetAddress'; import { evmGetPublicKey } from './evmGetPublicKey'; import { evmSignMessage } from './evmSignMessage'; @@ -205,6 +207,11 @@ export type CoreApi = { cipherKeyValue: typeof cipherKeyValue; + /** + * All network function + */ + allNetworkGetAddress: typeof allNetworkGetAddress; + /** * EVM function */ diff --git a/submodules/firmware b/submodules/firmware index f24cf00ab..22f8c2252 160000 --- a/submodules/firmware +++ b/submodules/firmware @@ -1 +1 @@ -Subproject commit f24cf00abb3ca7c522ff5fab674fa10ac3052059 +Subproject commit 22f8c2252c92cea9a25241257680bb2b5af55ab9 From 32e86921b2d257bcc14927ecd7f4f28b9f61dd57 Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Fri, 23 Aug 2024 11:03:54 +0800 Subject: [PATCH 2/3] feat: print EmmcFileWrite error --- packages/core/src/api/firmware/uploadFirmware.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/api/firmware/uploadFirmware.ts b/packages/core/src/api/firmware/uploadFirmware.ts index 4a5779c80..1223e27aa 100644 --- a/packages/core/src/api/firmware/uploadFirmware.ts +++ b/packages/core/src/api/firmware/uploadFirmware.ts @@ -3,7 +3,13 @@ import { blake2s } from '@noble/hashes/blake2s'; import JSZip from 'jszip'; import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared'; import { Success } from '@onekeyfe/hd-transport'; -import { wait, getDeviceBootloaderVersion, getDeviceType } from '../../utils'; +import { + wait, + getDeviceBootloaderVersion, + getDeviceType, + LoggerNames, + getLogger, +} from '../../utils'; import { DEVICE, CoreMessage, createUiMessage, UI_REQUEST } from '../../events'; import { PROTO } from '../../constants'; import type { Device } from '../../device/Device'; @@ -16,6 +22,8 @@ import { DevicePool } from '../../device/DevicePool'; const NEW_BOOT_UPRATE_FIRMWARE_VERSION = '2.4.5'; const SESSION_ERROR = 'session not found'; +const Log = getLogger(LoggerNames.Core); + const postConfirmationMessage = (device: Device) => { // only if firmware is already installed. fresh device does not require button confirmation if (device.features?.firmware_present) { @@ -235,7 +243,7 @@ const emmcFileWriteWithRetry = async ( const result = await writeFunc(); return result; } catch (error) { - console.error(`emmcWrite error: `, error); + Log.error(`emmcWrite error: `, error); retryCount--; if (retryCount === 0) { throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'emmc file write firmware error'); From f31e120face0f0edf7e705cc27f9fc91cc13b03b Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Fri, 23 Aug 2024 11:05:06 +0800 Subject: [PATCH 3/3] chore: release version 1.0.10-alpha.2 --- .../connect-examples/electron-example/package.json | 2 +- packages/connect-examples/expo-example/package.json | 10 +++++----- .../expo-example/src/constants/connect.ts | 2 +- packages/core/package.json | 6 +++--- packages/hd-ble-sdk/package.json | 8 ++++---- packages/hd-common-connect-sdk/package.json | 12 ++++++------ packages/hd-transport-http/package.json | 6 +++--- packages/hd-transport-lowlevel/package.json | 6 +++--- packages/hd-transport-react-native/package.json | 6 +++--- packages/hd-transport-webusb/package.json | 6 +++--- packages/hd-transport/package.json | 2 +- packages/hd-web-sdk/package.json | 10 +++++----- packages/shared/package.json | 2 +- 13 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/connect-examples/electron-example/package.json b/packages/connect-examples/electron-example/package.json index f5093c577..6e43f432c 100644 --- a/packages/connect-examples/electron-example/package.json +++ b/packages/connect-examples/electron-example/package.json @@ -2,7 +2,7 @@ "name": "hardware-example", "productName": "HardwareExample", "executableName": "onekey-hardware-example", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "author": "OneKey", "description": "End-to-end encrypted workspaces for teams", "main": "dist/index.js", diff --git a/packages/connect-examples/expo-example/package.json b/packages/connect-examples/expo-example/package.json index b4856accb..bcf83e118 100644 --- a/packages/connect-examples/expo-example/package.json +++ b/packages/connect-examples/expo-example/package.json @@ -1,6 +1,6 @@ { "name": "expo-example", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "scripts": { "start": "yarn expo start --dev-client", "android": "yarn expo run:android", @@ -15,10 +15,10 @@ "@noble/ed25519": "^2.1.0", "@noble/hashes": "^1.3.3", "@noble/secp256k1": "^1.7.1", - "@onekeyfe/hd-ble-sdk": "^1.0.10-alpha.1", - "@onekeyfe/hd-common-connect-sdk": "^1.0.10-alpha.1", - "@onekeyfe/hd-core": "^1.0.10-alpha.1", - "@onekeyfe/hd-web-sdk": "^1.0.10-alpha.1", + "@onekeyfe/hd-ble-sdk": "^1.0.10-alpha.2", + "@onekeyfe/hd-common-connect-sdk": "^1.0.10-alpha.2", + "@onekeyfe/hd-core": "^1.0.10-alpha.2", + "@onekeyfe/hd-web-sdk": "^1.0.10-alpha.2", "@onekeyfe/react-native-ble-plx": "3.0.0", "@react-native-async-storage/async-storage": "1.21.0", "@react-native-picker/picker": "2.6.1", diff --git a/packages/connect-examples/expo-example/src/constants/connect.ts b/packages/connect-examples/expo-example/src/constants/connect.ts index 702e77431..43cf94c0d 100644 --- a/packages/connect-examples/expo-example/src/constants/connect.ts +++ b/packages/connect-examples/expo-example/src/constants/connect.ts @@ -1,2 +1,2 @@ -export const CONNECT_SRC = 'https://jssdk.onekey.so/1.0.10-alpha.1/'; +export const CONNECT_SRC = 'https://jssdk.onekey.so/1.0.10-alpha.2/'; // export const CONNECT_SRC = 'https://localhost:8087/'; diff --git a/packages/core/package.json b/packages/core/package.json index e0af6fd71..461f29e5f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-core", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "description": "> TODO: description", "author": "OneKey", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", @@ -25,8 +25,8 @@ "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues" }, "dependencies": { - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport": "^1.0.10-alpha.1", + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport": "^1.0.10-alpha.2", "axios": "^0.27.2", "bignumber.js": "^9.0.2", "bytebuffer": "^5.0.1", diff --git a/packages/hd-ble-sdk/package.json b/packages/hd-ble-sdk/package.json index 1011976b7..52fa0db80 100644 --- a/packages/hd-ble-sdk/package.json +++ b/packages/hd-ble-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-ble-sdk", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "author": "OneKey", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", "license": "ISC", @@ -20,8 +20,8 @@ "lint:fix": "eslint . --fix" }, "dependencies": { - "@onekeyfe/hd-core": "^1.0.10-alpha.1", - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport-react-native": "^1.0.10-alpha.1" + "@onekeyfe/hd-core": "^1.0.10-alpha.2", + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport-react-native": "^1.0.10-alpha.2" } } diff --git a/packages/hd-common-connect-sdk/package.json b/packages/hd-common-connect-sdk/package.json index d5eda4c07..a495120aa 100644 --- a/packages/hd-common-connect-sdk/package.json +++ b/packages/hd-common-connect-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-common-connect-sdk", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "author": "OneKey", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", "license": "ISC", @@ -20,10 +20,10 @@ "lint:fix": "eslint . --fix" }, "dependencies": { - "@onekeyfe/hd-core": "^1.0.10-alpha.1", - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport-http": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport-lowlevel": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport-webusb": "^1.0.10-alpha.1" + "@onekeyfe/hd-core": "^1.0.10-alpha.2", + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport-http": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport-lowlevel": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport-webusb": "^1.0.10-alpha.2" } } diff --git a/packages/hd-transport-http/package.json b/packages/hd-transport-http/package.json index e88f01a2a..86dcbb024 100644 --- a/packages/hd-transport-http/package.json +++ b/packages/hd-transport-http/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-transport-http", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "description": "hardware http transport", "author": "OneKey", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", @@ -24,8 +24,8 @@ "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues" }, "dependencies": { - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport": "^1.0.10-alpha.1", + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport": "^1.0.10-alpha.2", "axios": "^0.27.2" } } diff --git a/packages/hd-transport-lowlevel/package.json b/packages/hd-transport-lowlevel/package.json index aed96f643..49fc09e7a 100644 --- a/packages/hd-transport-lowlevel/package.json +++ b/packages/hd-transport-lowlevel/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-transport-lowlevel", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", "license": "MIT", "main": "dist/index.js", @@ -19,7 +19,7 @@ "lint:fix": "eslint . --fix" }, "dependencies": { - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport": "^1.0.10-alpha.1" + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport": "^1.0.10-alpha.2" } } diff --git a/packages/hd-transport-react-native/package.json b/packages/hd-transport-react-native/package.json index 0ba1199f2..355636af0 100644 --- a/packages/hd-transport-react-native/package.json +++ b/packages/hd-transport-react-native/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-transport-react-native", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", "license": "MIT", "main": "dist/index.js", @@ -19,8 +19,8 @@ "lint:fix": "eslint . --fix" }, "dependencies": { - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport": "^1.0.10-alpha.1", + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport": "^1.0.10-alpha.2", "@onekeyfe/react-native-ble-plx": "3.0.1", "react-native-ble-manager": "^8.1.0" } diff --git a/packages/hd-transport-webusb/package.json b/packages/hd-transport-webusb/package.json index b418c961b..49aa006f3 100644 --- a/packages/hd-transport-webusb/package.json +++ b/packages/hd-transport-webusb/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-transport-webusb", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "author": "OneKey", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", "license": "MIT", @@ -20,8 +20,8 @@ "lint:fix": "eslint . --fix" }, "dependencies": { - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport": "^1.0.10-alpha.1" + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport": "^1.0.10-alpha.2" }, "devDependencies": { "@types/w3c-web-usb": "^1.0.6" diff --git a/packages/hd-transport/package.json b/packages/hd-transport/package.json index 415468d89..17e8399ec 100644 --- a/packages/hd-transport/package.json +++ b/packages/hd-transport/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-transport", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "description": "> TODO: description", "author": "OneKey", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", diff --git a/packages/hd-web-sdk/package.json b/packages/hd-web-sdk/package.json index 6c1fe7a60..62b84e3d0 100644 --- a/packages/hd-web-sdk/package.json +++ b/packages/hd-web-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-web-sdk", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "author": "OneKey", "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme", "license": "ISC", @@ -21,10 +21,10 @@ }, "dependencies": { "@onekeyfe/cross-inpage-provider-core": "^0.0.17", - "@onekeyfe/hd-core": "^1.0.10-alpha.1", - "@onekeyfe/hd-shared": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport-http": "^1.0.10-alpha.1", - "@onekeyfe/hd-transport-webusb": "^1.0.10-alpha.1" + "@onekeyfe/hd-core": "^1.0.10-alpha.2", + "@onekeyfe/hd-shared": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport-http": "^1.0.10-alpha.2", + "@onekeyfe/hd-transport-webusb": "^1.0.10-alpha.2" }, "devDependencies": { "@babel/plugin-proposal-optional-chaining": "^7.17.12", diff --git a/packages/shared/package.json b/packages/shared/package.json index e52634062..f8728a4f0 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@onekeyfe/hd-shared", - "version": "1.0.10-alpha.1", + "version": "1.0.10-alpha.2", "description": "Hardware SDK's shared tool library", "keywords": [ "Hardware-SDK",