From 4d5fb984b940570b41c6ee9318b4d8487aa6d696 Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 20 Dec 2024 16:47:46 +0800 Subject: [PATCH] feat: Add babylon cosmos testnet & Add log for unsupport ethereum method (#6385) * feat: bbn testnet commit 0d6860a5e7e3329d4c15f5afe36b72b107cfd442 Merge: fea32dfa60 1d8d5fdb17 Author: Leon Date: Thu Dec 19 15:11:42 2024 +0800 Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet commit fea32dfa601f7fc74246940a9e2167584aba881e Author: Leon Date: Thu Dec 19 15:11:22 2024 +0800 feat: optimize cosmos account number commit da712e40a956f84a3349c54106a3eb08eb7d4a37 Merge: b421dda0e8 cb571e764a Author: Leon Date: Thu Dec 19 09:38:06 2024 +0800 Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet commit b421dda0e858a03043eb1ecd28a3112eaaaa36e0 Merge: 123fd526f5 ddadbfb971 Author: Leon Date: Tue Dec 17 18:10:42 2024 +0800 Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet commit 123fd526f5b4eaf61df9b601472ad74e73a76578 Author: Leon Date: Tue Dec 17 15:57:59 2024 +0800 chore: url commit 6980a17067ea53a75a7b21bda8aca6050f902100 Merge: 212a3a1db8 3ad28f4959 Author: Leon Date: Tue Dec 17 08:45:32 2024 +0800 Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet commit 212a3a1db8c3e3d47040d27ba9c8ef5e511b1d06 Author: Leon Date: Mon Dec 16 17:16:46 2024 +0800 feat: bbn devnet commit 8c40f0c2d5f15395381cc6b1a04385f8849393df Author: Leon Date: Mon Dec 16 10:00:31 2024 +0800 feat: test bbn devnet * feat: Add log for unsupport method --- .../core/src/chains/btc/CoreChainSoftware.ts | 6 +++- .../kit-bg/src/providers/ProviderApiCosmos.ts | 30 ++++++++++++++--- .../src/providers/ProviderApiEthereum.ts | 33 ++++++++++++------- .../impls/btc/KeyringHardwareBtcBase.ts | 12 +++++-- .../src/vaults/impls/cosmos/settings.ts | 5 +++ packages/shared/src/config/presetNetworks.ts | 23 +++++++++++++ .../logger/scopes/discovery/scenes/dapp.ts | 5 +++ 7 files changed, 95 insertions(+), 19 deletions(-) diff --git a/packages/core/src/chains/btc/CoreChainSoftware.ts b/packages/core/src/chains/btc/CoreChainSoftware.ts index caa622e4014..1cfa6cfe05d 100644 --- a/packages/core/src/chains/btc/CoreChainSoftware.ts +++ b/packages/core/src/chains/btc/CoreChainSoftware.ts @@ -564,7 +564,11 @@ export default class CoreChainSoftwareBtc extends CoreChainApiBase { !addressInfo.encoding || (addressInfo.encoding && !supportedTypes.includes(addressInfo.encoding)) ) { - throw new AddressNotSupportSignMethodError(); + throw new AddressNotSupportSignMethodError({ + info: { + type: 'Native Segwit, Taproot', + }, + }); } const outputScript = BitcoinJsAddress.toOutputScript( diff --git a/packages/kit-bg/src/providers/ProviderApiCosmos.ts b/packages/kit-bg/src/providers/ProviderApiCosmos.ts index 77e37a29b50..895091f944a 100644 --- a/packages/kit-bg/src/providers/ProviderApiCosmos.ts +++ b/packages/kit-bg/src/providers/ProviderApiCosmos.ts @@ -3,6 +3,7 @@ import { bytesToHex, hexToBytes } from '@noble/hashes/utils'; import { web3Errors } from '@onekeyfe/cross-inpage-provider-errors'; import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types'; import { Semaphore } from 'async-mutex'; +import BigNumber from 'bignumber.js'; import { PubKey } from 'cosmjs-types/cosmos/crypto/ed25519/keys'; import { AuthInfo, TxBody } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; @@ -360,13 +361,32 @@ class ProviderApiCosmos extends ProviderApiBase { const account = await this._getAccount(request, networkId); - const encodeTx = params.signDoc; + const encodedTx = params.signDoc; + const accountNumberBN = new BigNumber(encodedTx.accountNumber || '0'); + if ( + !encodedTx.accountNumber || + accountNumberBN.isZero() || + accountNumberBN.isNaN() + ) { + const accountInfo = + await this.backgroundApi.serviceAccountProfile.fetchAccountDetails({ + networkId, + accountId: account.account.id, + withNonce: true, + }); + + if (!accountInfo) { + throw new Error('Invalid account'); + } + + encodedTx.accountNumber = `${accountInfo.accountNumber ?? 0}`; + } const txWrapper = TransactionWrapper.fromDirectSignDocHex( { - bodyBytes: encodeTx.bodyBytes ?? '', - authInfoBytes: encodeTx.authInfoBytes ?? '', - chainId: encodeTx.chainId ?? '', - accountNumber: encodeTx.accountNumber ?? '', + bodyBytes: encodedTx.bodyBytes ?? '', + authInfoBytes: encodedTx.authInfoBytes ?? '', + chainId: encodedTx.chainId ?? '', + accountNumber: encodedTx.accountNumber ?? '', }, undefined, ); diff --git a/packages/kit-bg/src/providers/ProviderApiEthereum.ts b/packages/kit-bg/src/providers/ProviderApiEthereum.ts index dcbaa41fddd..2d0e3160773 100644 --- a/packages/kit-bg/src/providers/ProviderApiEthereum.ts +++ b/packages/kit-bg/src/providers/ProviderApiEthereum.ts @@ -166,6 +166,7 @@ class ProviderApiEthereum extends ProviderApiBase { const { method, params } = rpcRequest; if (!EVM_SAFE_RPC_METHODS.includes(method)) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @@ -373,12 +374,14 @@ class ProviderApiEthereum extends ProviderApiBase { } @providerApiMethod() - eth_subscribe() { + eth_subscribe(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - eth_unsubscribe() { + eth_unsubscribe(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @@ -494,42 +497,50 @@ class ProviderApiEthereum extends ProviderApiBase { } @providerApiMethod() - async metamask_logWeb3ShimUsage() { + async metamask_logWeb3ShimUsage(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - async wallet_registerOnboarding() { + async wallet_registerOnboarding(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - async wallet_scanQRCode() { + async wallet_scanQRCode(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - async wallet_getCapabilities() { + async wallet_getCapabilities(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - async wallet_sendCalls() { + async wallet_sendCalls(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - async wallet_getCallsStatus() { + async wallet_getCallsStatus(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - async wallet_showCallsStatus() { + async wallet_showCallsStatus(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @providerApiMethod() - async wallet_getSnaps() { + async wallet_getSnaps(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequestNotSupport({ request }); throw web3Errors.rpc.methodNotSupported(); } @@ -754,7 +765,7 @@ class ProviderApiEthereum extends ProviderApiBase { // eslint-disable-next-line @typescript-eslint/no-unsafe-call if (this._switchEthereumChainMemo._has(request, params)) { throw web3Errors.rpc.resourceUnavailable({ - message: `Request of type 'wallet_addEthereumChain' already pending for origin ${ + message: `Request of type 'wallet_switchEthereumChain' already pending for origin ${ request?.origin || '' }. Please wait.`, }); diff --git a/packages/kit-bg/src/vaults/impls/btc/KeyringHardwareBtcBase.ts b/packages/kit-bg/src/vaults/impls/btc/KeyringHardwareBtcBase.ts index 06f4fafdec4..44812acdee4 100644 --- a/packages/kit-bg/src/vaults/impls/btc/KeyringHardwareBtcBase.ts +++ b/packages/kit-bg/src/vaults/impls/btc/KeyringHardwareBtcBase.ts @@ -200,7 +200,11 @@ export abstract class KeyringHardwareBtcBase extends KeyringHardwareBase { const dbAccount = (await this.vault.getAccount()) as IDBUtxoAccount; if (!isTaprootPath(dbAccount.path)) { - throw new AddressNotSupportSignMethodError(); + throw new AddressNotSupportSignMethodError({ + info: { + type: 'Taproot', + }, + }); } const network = await this.getNetwork(); @@ -327,7 +331,11 @@ export abstract class KeyringHardwareBtcBase extends KeyringHardwareBase { const dAppSignType = (type as 'ecdsa' | 'bip322-simple') || undefined; if (dAppSignType && !isTaprootPath(dbAccount.path)) { - throw new AddressNotSupportSignMethodError(); + throw new AddressNotSupportSignMethodError({ + info: { + type: 'Taproot', + }, + }); } const response = await sdk.btcSignMessage(connectId, deviceId, { diff --git a/packages/kit-bg/src/vaults/impls/cosmos/settings.ts b/packages/kit-bg/src/vaults/impls/cosmos/settings.ts index d0da9e64901..7bf912b0260 100644 --- a/packages/kit-bg/src/vaults/impls/cosmos/settings.ts +++ b/packages/kit-bg/src/vaults/impls/cosmos/settings.ts @@ -115,6 +115,11 @@ const settings: IVaultSettings = { curve: 'secp256k1', nativeTokenAddress: 'utia', }, + 'cosmos--bbn-test-5': { + addressPrefix: 'bbn', + curve: 'secp256k1', + nativeTokenAddress: 'ubbn', + }, }, stakingConfig: { diff --git a/packages/shared/src/config/presetNetworks.ts b/packages/shared/src/config/presetNetworks.ts index 5ce78d85892..75f8a17a41c 100644 --- a/packages/shared/src/config/presetNetworks.ts +++ b/packages/shared/src/config/presetNetworks.ts @@ -2664,6 +2664,27 @@ export const presetNetworksMap = { benfen, }; +const bbnTestnet: IServerNetwork = { + 'chainId': 'bbn-test-5', + 'code': 'ubbn', + 'decimals': 6, + 'id': 'cosmos--bbn-test-5', + 'impl': 'cosmos', + 'isTestnet': true, + 'logoURI': 'https://uni.onekey-asset.com/static/logo/babylon.png', + 'name': 'Babylon Testnet', + 'shortcode': 'bbn', + 'shortname': 'BBN', + 'symbol': 'BBN', + 'feeMeta': { + 'code': 'ubbn', + 'decimals': 6, + 'symbol': 'UBBN', + }, + 'defaultEnabled': false, + 'status': ENetworkStatus.LISTED, +}; + // top 20 tvl evm networks export const getDefaultEnabledEVMNetworksInAllNetworks = memoFn( (): IServerNetwork[] => [ @@ -2769,6 +2790,8 @@ export const getPresetNetworks = memoFn((): IServerNetwork[] => [ akash, osmosis, cosmoshub, + bbnTestnet, + // polkadot polkadot, astar, diff --git a/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts b/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts index 5750023df45..c3d05cc040c 100644 --- a/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts +++ b/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts @@ -54,6 +54,11 @@ export class DappScene extends BaseScene { return params; } + @LogToLocal({ level: 'info' }) + public dappRequestNotSupport(params: { request: IJsBridgeMessagePayload }) { + return params; + } + @LogToServer() @LogToLocal() public disconnect(params: {