Skip to content

Commit

Permalink
feat: Add babylon cosmos testnet & Add log for unsupport ethereum met…
Browse files Browse the repository at this point in the history
…hod (#6385)

* feat: bbn testnet

commit 0d6860a
Merge: fea32df 1d8d5fd
Author: Leon <[email protected]>
Date:   Thu Dec 19 15:11:42 2024 +0800

    Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet

commit fea32df
Author: Leon <[email protected]>
Date:   Thu Dec 19 15:11:22 2024 +0800

    feat: optimize cosmos account number

commit da712e4
Merge: b421dda cb571e7
Author: Leon <[email protected]>
Date:   Thu Dec 19 09:38:06 2024 +0800

    Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet

commit b421dda
Merge: 123fd52 ddadbfb
Author: Leon <[email protected]>
Date:   Tue Dec 17 18:10:42 2024 +0800

    Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet

commit 123fd52
Author: Leon <[email protected]>
Date:   Tue Dec 17 15:57:59 2024 +0800

    chore: url

commit 6980a17
Merge: 212a3a1 3ad28f4
Author: Leon <[email protected]>
Date:   Tue Dec 17 08:45:32 2024 +0800

    Merge branch 'x' of github.com:OneKeyHQ/app-monorepo into feat/bbn-devnet

commit 212a3a1
Author: Leon <[email protected]>
Date:   Mon Dec 16 17:16:46 2024 +0800

    feat: bbn devnet

commit 8c40f0c
Author: Leon <[email protected]>
Date:   Mon Dec 16 10:00:31 2024 +0800

    feat: test bbn devnet

* feat: Add log for unsupport method
  • Loading branch information
originalix authored Dec 20, 2024
1 parent 670d037 commit 4d5fb98
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 19 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/chains/btc/CoreChainSoftware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 25 additions & 5 deletions packages/kit-bg/src/providers/ProviderApiCosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
);
Expand Down
33 changes: 22 additions & 11 deletions packages/kit-bg/src/providers/ProviderApiEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.`,
});
Expand Down
12 changes: 10 additions & 2 deletions packages/kit-bg/src/vaults/impls/btc/KeyringHardwareBtcBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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, {
Expand Down
5 changes: 5 additions & 0 deletions packages/kit-bg/src/vaults/impls/cosmos/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ const settings: IVaultSettings = {
curve: 'secp256k1',
nativeTokenAddress: 'utia',
},
'cosmos--bbn-test-5': {
addressPrefix: 'bbn',
curve: 'secp256k1',
nativeTokenAddress: 'ubbn',
},
},

stakingConfig: {
Expand Down
23 changes: 23 additions & 0 deletions packages/shared/src/config/presetNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] => [
Expand Down Expand Up @@ -2769,6 +2790,8 @@ export const getPresetNetworks = memoFn((): IServerNetwork[] => [
akash,
osmosis,
cosmoshub,
bbnTestnet,

// polkadot
polkadot,
astar,
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/logger/scopes/discovery/scenes/dapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 4d5fb98

Please sign in to comment.