From 7e654ab99413715477b808065f4ed972cacecc07 Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 21 Aug 2024 17:14:54 +0800 Subject: [PATCH] chore: Add logs for dApp (#5603) * chore: Add logs for dApp * feat: Add logs --- packages/kit-bg/src/providers/ProviderApiAlgo.ts | 4 +++- .../kit-bg/src/providers/ProviderApiAptos.ts | 11 +++++++++++ packages/kit-bg/src/providers/ProviderApiBtc.ts | 10 +++++++++- .../kit-bg/src/providers/ProviderApiCardano.ts | 5 +++++ .../kit-bg/src/providers/ProviderApiConflux.ts | 8 ++++++-- .../kit-bg/src/providers/ProviderApiCosmos.ts | 7 +++++++ .../kit-bg/src/providers/ProviderApiEthereum.ts | 12 ++++++++++++ packages/kit-bg/src/providers/ProviderApiNear.ts | 2 ++ .../kit-bg/src/providers/ProviderApiNostr.ts | 5 +++++ .../kit-bg/src/providers/ProviderApiPolkadot.ts | 3 +++ .../kit-bg/src/providers/ProviderApiSolana.ts | 6 ++++++ packages/kit-bg/src/providers/ProviderApiSui.ts | 6 ++++++ packages/kit-bg/src/providers/ProviderApiTron.ts | 3 +++ .../kit-bg/src/providers/ProviderApiWebln.ts | 7 +++++++ packages/kit-bg/src/services/ServiceDApp.ts | 6 ++++++ .../src/logger/scopes/discovery/scenes/dapp.ts | 16 ++++++++++++++++ 16 files changed, 107 insertions(+), 4 deletions(-) diff --git a/packages/kit-bg/src/providers/ProviderApiAlgo.ts b/packages/kit-bg/src/providers/ProviderApiAlgo.ts index e513beeaa26..8f9db7eae29 100644 --- a/packages/kit-bg/src/providers/ProviderApiAlgo.ts +++ b/packages/kit-bg/src/providers/ProviderApiAlgo.ts @@ -7,6 +7,7 @@ import { providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; import { SEPERATOR } from '@onekeyhq/shared/src/engine/engineConsts'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import ProviderApiBase from './ProviderApiBase'; @@ -82,7 +83,7 @@ class ProviderApiAlgo extends ProviderApiBase { @providerApiMethod() public async connect(request: IJsBridgeMessagePayload) { - console.log('algo connect', request); + defaultLogger.discovery.dapp.dappRequest({ request }); const accounts = await this.accounts(request); if (accounts && accounts.length > 0) { @@ -98,6 +99,7 @@ class ProviderApiAlgo extends ProviderApiBase { request: IJsBridgeMessagePayload, walletTransactions: Array<{ txn: string; signers: [] }>, ): Promise<(string | null)[]> { + defaultLogger.discovery.dapp.dappRequest({ request }); const txsToSign: string[] = []; for (let i = 0; i < walletTransactions.length; i += 1) { // transaction with signers means that this transaction is not meant to be signed diff --git a/packages/kit-bg/src/providers/ProviderApiAptos.ts b/packages/kit-bg/src/providers/ProviderApiAptos.ts index 6c6dd01b82d..14e39485c7b 100644 --- a/packages/kit-bg/src/providers/ProviderApiAptos.ts +++ b/packages/kit-bg/src/providers/ProviderApiAptos.ts @@ -13,6 +13,7 @@ import { permissionRequired, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import bufferUtils from '@onekeyhq/shared/src/utils/bufferUtils'; import hexUtils from '@onekeyhq/shared/src/utils/hexUtils'; import { EMessageTypesAptos } from '@onekeyhq/shared/types/message'; @@ -108,6 +109,7 @@ class ProviderApiAptos extends ProviderApiBase { @providerApiMethod() public async connect(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); const accountsInfo = await this.backgroundApi.serviceDApp.dAppGetConnectedAccountsInfo( request, @@ -177,6 +179,7 @@ class ProviderApiAptos extends ProviderApiBase { request: IJsBridgeMessagePayload, params: IEncodedTxAptos, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const encodeTx = params; const accounts = await this.getAccountsInfo(request); @@ -260,6 +263,7 @@ class ProviderApiAptos extends ProviderApiBase { request: IJsBridgeMessagePayload, params: string, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const { account, accountInfo } = await this._getAccount(request); const vault = await this.getAptosVault(request); @@ -287,6 +291,7 @@ class ProviderApiAptos extends ProviderApiBase { request: IJsBridgeMessagePayload, params: string, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { account, accountInfo } = await this._getAccount(request); const vault = await this.getAptosVault(request); @@ -317,6 +322,7 @@ class ProviderApiAptos extends ProviderApiBase { request: IJsBridgeMessagePayload, params: IEncodedTxAptos, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { account, accountInfo } = await this._getAccount(request); const result = await this.backgroundApi.serviceDApp.openSignAndSendTransactionModal({ @@ -336,6 +342,7 @@ class ProviderApiAptos extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISignMessagePayload, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); // @ts-expect-error const isPetra = request.data?.aptosProviderType === 'petra'; @@ -377,6 +384,7 @@ class ProviderApiAptos extends ProviderApiBase { type_args: any[]; }, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const encodeTx: IEncodedTxAptos = { type: 'entry_function_payload', function: params.func, @@ -443,6 +451,7 @@ class ProviderApiAptos extends ProviderApiBase { property_types?: Array; }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { account, accountInfo } = await this._getAccount(request); const encodeTx = generateTransferCreateNft( account.address, @@ -511,6 +520,7 @@ class ProviderApiAptos extends ProviderApiBase { }; }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const vault = await this.getAptosVault(request); const rawTx = await vault.client.generateTransaction( params.sender, @@ -527,6 +537,7 @@ class ProviderApiAptos extends ProviderApiBase { request: IJsBridgeMessagePayload, params: Uint8Array | string, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { account, accountInfo } = await this._getAccount(request); const bcsTxn: Uint8Array = decodeBytesTransaction(params); const encodedTx = { diff --git a/packages/kit-bg/src/providers/ProviderApiBtc.ts b/packages/kit-bg/src/providers/ProviderApiBtc.ts index 73d30da96a5..8e1952ef09a 100644 --- a/packages/kit-bg/src/providers/ProviderApiBtc.ts +++ b/packages/kit-bg/src/providers/ProviderApiBtc.ts @@ -17,6 +17,7 @@ import { providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; import { getNetworkIdsMap } from '@onekeyhq/shared/src/config/networkIds'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import accountUtils from '@onekeyhq/shared/src/utils/accountUtils'; import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils'; import networkUtils from '@onekeyhq/shared/src/utils/networkUtils'; @@ -99,6 +100,7 @@ class ProviderApiBtc extends ProviderApiBase { @providerApiMethod() public async requestAccounts(request: IJsBridgeMessagePayload) { return this.semaphore.runExclusive(async () => { + defaultLogger.discovery.dapp.dappRequest({ request }); const accounts = await this.getAccounts(request); if (accounts && accounts.length) { return accounts; @@ -155,7 +157,7 @@ class ProviderApiBtc extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISwitchNetworkParams, ) { - console.log('ProviderApiBtc.switchNetwork'); + defaultLogger.discovery.dapp.dappRequest({ request }); const accountsInfo = await this.backgroundApi.serviceDApp.dAppGetConnectedAccountsInfo( request, @@ -223,6 +225,7 @@ class ProviderApiBtc extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISendBitcoinParams, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { toAddress, satoshis, feeRate } = params; const accountsInfo = await this.getAccountsInfo(request); const { accountInfo: { accountId, networkId, address } = {} } = @@ -279,6 +282,7 @@ class ProviderApiBtc extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISignMessageParams, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { message, type } = params; const accountsInfo = await this.getAccountsInfo(request); const { accountInfo: { accountId, networkId } = {} } = accountsInfo[0]; @@ -317,6 +321,7 @@ class ProviderApiBtc extends ProviderApiBase { @providerApiMethod() public async pushTx(request: IJsBridgeMessagePayload, params: IPushTxParams) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { rawTx } = params; const accountsInfo = await this.getAccountsInfo(request); const { accountInfo: { accountId, networkId, address } = {} } = @@ -352,6 +357,7 @@ class ProviderApiBtc extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISignPsbtParams, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const accountsInfo = await this.getAccountsInfo(request); const { accountInfo: { accountId, networkId } = {} } = accountsInfo[0]; @@ -393,6 +399,7 @@ class ProviderApiBtc extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISignPsbtsParams, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const accountsInfo = await this.getAccountsInfo(request); const { accountInfo: { accountId, networkId } = {} } = accountsInfo[0]; @@ -530,6 +537,7 @@ class ProviderApiBtc extends ProviderApiBase { request: IJsBridgeMessagePayload, params: IPushPsbtParams, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const accountsInfo = await this.getAccountsInfo(request); const { accountInfo: { accountId, networkId, address } = {} } = accountsInfo[0]; diff --git a/packages/kit-bg/src/providers/ProviderApiCardano.ts b/packages/kit-bg/src/providers/ProviderApiCardano.ts index 981438ea66d..f023b7477c0 100644 --- a/packages/kit-bg/src/providers/ProviderApiCardano.ts +++ b/packages/kit-bg/src/providers/ProviderApiCardano.ts @@ -8,6 +8,7 @@ import { backgroundClass, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { EMessageTypesCommon } from '@onekeyhq/shared/types/message'; import { vaultFactory } from '../vaults/factory'; @@ -84,6 +85,7 @@ class ProviderApiCardano extends ProviderApiBase { @providerApiMethod() async connect(request: IJsBridgeMessagePayload) { return this.semaphore.runExclusive(async () => { + defaultLogger.discovery.dapp.dappRequest({ request }); const connectedAddress = await this.cardano_accounts(request); if (connectedAddress) { return connectedAddress; @@ -173,6 +175,7 @@ class ProviderApiCardano extends ProviderApiBase { @providerApiMethod() async signTx(request: IJsBridgeMessagePayload, params: { tx: string }) { + defaultLogger.discovery.dapp.dappRequest({ request }); const vault = await this.getAdaVault(request); if (!vault) { throw new Error('Not connected to any account.'); @@ -200,6 +203,7 @@ class ProviderApiCardano extends ProviderApiBase { payload: string; }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); if (typeof params.payload !== 'string') { throw web3Errors.rpc.invalidInput(); } @@ -226,6 +230,7 @@ class ProviderApiCardano extends ProviderApiBase { @providerApiMethod() async submitTx(request: IJsBridgeMessagePayload, params: string) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId, address } = {} } = ( await this.getAccountsInfo(request) )[0]; diff --git a/packages/kit-bg/src/providers/ProviderApiConflux.ts b/packages/kit-bg/src/providers/ProviderApiConflux.ts index 385f0ca697d..68a909cad81 100644 --- a/packages/kit-bg/src/providers/ProviderApiConflux.ts +++ b/packages/kit-bg/src/providers/ProviderApiConflux.ts @@ -11,6 +11,7 @@ import { permissionRequired, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils'; import { toBigIntHex } from '@onekeyhq/shared/src/utils/numberUtils'; import { EMessageTypesEth } from '@onekeyhq/shared/types/message'; @@ -189,7 +190,7 @@ class ProviderApiConflux extends ProviderApiBase { @providerApiMethod() async cfx_requestAccounts(request: IJsBridgeMessagePayload) { - console.log('ProviderApiConflux.cfx_requestAccounts', request); + defaultLogger.discovery.dapp.dappRequest({ request }); const accounts = await this.cfx_accounts(request); if (accounts && accounts.length) { @@ -205,7 +206,7 @@ class ProviderApiConflux extends ProviderApiBase { request: IJsBridgeMessagePayload, transaction: IEncodedTxCfx, ) { - console.log('cfx_sendTransaction', request, transaction); + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this.getAccountsInfo(request) @@ -232,6 +233,7 @@ class ProviderApiConflux extends ProviderApiBase { @providerApiMethod() cfx_signTypedData_v4(request: IJsBridgeMessagePayload, ...messages: any[]) { + defaultLogger.discovery.dapp.dappRequest({ request }); return this._showSignMessageModal(request, { type: EMessageTypesEth.TYPED_DATA_V4, message: messages[1], @@ -246,6 +248,7 @@ class ProviderApiConflux extends ProviderApiBase { @providerApiMethod() async personal_sign(request: IJsBridgeMessagePayload, ...messages: any[]) { + defaultLogger.discovery.dapp.dappRequest({ request }); const message = messages[0]; return this._showSignMessageModal(request, { @@ -257,6 +260,7 @@ class ProviderApiConflux extends ProviderApiBase { @providerApiMethod() cfx_sign(request: IJsBridgeMessagePayload, ...messages: any[]) { + defaultLogger.discovery.dapp.dappRequest({ request }); return this._showSignMessageModal(request, { type: EMessageTypesEth.ETH_SIGN, message: messages[1], diff --git a/packages/kit-bg/src/providers/ProviderApiCosmos.ts b/packages/kit-bg/src/providers/ProviderApiCosmos.ts index 82d59ff2e5a..33e1828a205 100644 --- a/packages/kit-bg/src/providers/ProviderApiCosmos.ts +++ b/packages/kit-bg/src/providers/ProviderApiCosmos.ts @@ -17,6 +17,7 @@ import { permissionRequired, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import accountUtils from '@onekeyhq/shared/src/utils/accountUtils'; import networkUtils from '@onekeyhq/shared/src/utils/networkUtils'; import timerUtils from '@onekeyhq/shared/src/utils/timerUtils'; @@ -239,6 +240,7 @@ class ProviderApiCosmos extends ProviderApiBase { signOptions?: any; }, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const txWrapper = TransactionWrapper.fromAminoSignDoc( params.signDoc, undefined, @@ -309,6 +311,7 @@ class ProviderApiCosmos extends ProviderApiBase { signOptions?: any; }, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const networkId = this.convertCosmosChainId(params.signDoc.chainId); if (!networkId) throw new Error('Invalid chainId'); @@ -383,6 +386,7 @@ class ProviderApiCosmos extends ProviderApiBase { mode: string; }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const networkId = this.convertCosmosChainId(params.chainId); if (!networkId) throw new Error('Invalid chainId'); @@ -411,6 +415,7 @@ class ProviderApiCosmos extends ProviderApiBase { }, ) { return this.signMessageSemaphore.runExclusive(async () => { + defaultLogger.discovery.dapp.dappRequest({ request }); const paramsData = { data: params.data, signer: params.signer, @@ -452,6 +457,7 @@ class ProviderApiCosmos extends ProviderApiBase { data: string; }, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const txInfo = await this.signArbitraryMessage(request, params); const [signerInfo] = txInfo.authInfo.signerInfos; @@ -487,6 +493,7 @@ class ProviderApiCosmos extends ProviderApiBase { }; }, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const txInfo = await this.signArbitraryMessage(request, params); const [signerInfo] = txInfo.authInfo.signerInfos; diff --git a/packages/kit-bg/src/providers/ProviderApiEthereum.ts b/packages/kit-bg/src/providers/ProviderApiEthereum.ts index 4fe6332b6dd..3a43722cec0 100644 --- a/packages/kit-bg/src/providers/ProviderApiEthereum.ts +++ b/packages/kit-bg/src/providers/ProviderApiEthereum.ts @@ -14,6 +14,7 @@ import { providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; import { IMPL_EVM } from '@onekeyhq/shared/src/engine/engineConsts'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { check } from '@onekeyhq/shared/src/utils/assertUtils'; import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils'; import hexUtils from '@onekeyhq/shared/src/utils/hexUtils'; @@ -154,6 +155,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, permissions: Record, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); await this.backgroundApi.serviceDApp.openConnectionModal(request); const accounts = await this.eth_accounts(request); const result = Object.keys(permissions).map((permissionName) => { @@ -251,6 +253,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, transaction: IEncodedTxEvm, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -302,6 +305,7 @@ class ProviderApiEthereum extends ProviderApiBase { @providerApiMethod() async eth_sign(request: IJsBridgeMessagePayload, ...messages: any[]) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -320,6 +324,7 @@ class ProviderApiEthereum extends ProviderApiBase { // Provider API @providerApiMethod() async personal_sign(request: IJsBridgeMessagePayload, ...messages: any[]) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId, address: accountAddress } = {}, } = (await this.getAccountsInfo(request))[0]; @@ -350,6 +355,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, ...messages: string[] ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const [message, signature] = messages; if ( typeof message === 'string' && @@ -389,6 +395,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, ...messages: any[] ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -441,6 +448,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, ...messages: any[] ) { + defaultLogger.discovery.dapp.dappRequest({ request }); console.log('eth_signTypedData_v1', messages, request); return this.eth_signTypedData(request, ...messages); } @@ -450,6 +458,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, ...messages: any[] ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -471,6 +480,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, ...messages: any[] ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -492,6 +502,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISwitchEthereumChainParameter, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); // @ts-ignore // eslint-disable-next-line @typescript-eslint/no-unsafe-call if (this._switchEthereumChainMemo._has(request, params)) { @@ -525,6 +536,7 @@ class ProviderApiEthereum extends ProviderApiBase { request: IJsBridgeMessagePayload, params: Record, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); if (get(params, 'eth_accounts', null) && request.origin) { await this.backgroundApi.serviceDApp.disconnectWebsite({ origin: request.origin, diff --git a/packages/kit-bg/src/providers/ProviderApiNear.ts b/packages/kit-bg/src/providers/ProviderApiNear.ts index 7c5fc0a7400..b777d823223 100644 --- a/packages/kit-bg/src/providers/ProviderApiNear.ts +++ b/packages/kit-bg/src/providers/ProviderApiNear.ts @@ -7,6 +7,7 @@ import { permissionRequired, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { getPublicKey } from '../vaults/impls/near/utils'; @@ -164,6 +165,7 @@ class ProviderApiNear extends ProviderApiBase { send: boolean; }, ): Promise<{ transactionHashes: string[] }> { + defaultLogger.discovery.dapp.dappRequest({ request }); const { transactions } = params; const transactionHashes: string[] = []; diff --git a/packages/kit-bg/src/providers/ProviderApiNostr.ts b/packages/kit-bg/src/providers/ProviderApiNostr.ts index 2ba6abc72d0..f7eb6a8c7e8 100644 --- a/packages/kit-bg/src/providers/ProviderApiNostr.ts +++ b/packages/kit-bg/src/providers/ProviderApiNostr.ts @@ -10,6 +10,7 @@ import { backgroundClass, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { EDAppConnectionModal, EModalRoutes, @@ -114,6 +115,7 @@ class ProviderApiNostr extends ProviderApiBase { public async signEvent( request: IJsBridgeMessagePayload, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const params = (request.data as IJsonRpcRequest)?.params as { event: INostrEvent; }; @@ -171,6 +173,7 @@ class ProviderApiNostr extends ProviderApiBase { @providerApiMethod() public async encrypt(request: IJsBridgeMessagePayload): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId, walletId } = {} } = ( await this._getAccountsInfo(request) )[0]; @@ -232,6 +235,7 @@ class ProviderApiNostr extends ProviderApiBase { @providerApiMethod() public async decrypt(request: IJsBridgeMessagePayload): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const result = await this.decryptMutex.runExclusive(() => this.decryptRequest(request), ); @@ -292,6 +296,7 @@ class ProviderApiNostr extends ProviderApiBase { @providerApiMethod() public async signSchnorr(request: IJsBridgeMessagePayload): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId, walletId } = {} } = ( await this._getAccountsInfo(request) )[0]; diff --git a/packages/kit-bg/src/providers/ProviderApiPolkadot.ts b/packages/kit-bg/src/providers/ProviderApiPolkadot.ts index 516b4c74d51..e50033a0528 100644 --- a/packages/kit-bg/src/providers/ProviderApiPolkadot.ts +++ b/packages/kit-bg/src/providers/ProviderApiPolkadot.ts @@ -12,6 +12,7 @@ import { providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; import { NotImplemented } from '@onekeyhq/shared/src/errors'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { EMessageTypesCommon } from '@onekeyhq/shared/types/message'; import settings from '../vaults/impls/dot/settings'; @@ -230,6 +231,7 @@ class ProviderApiPolkadot extends ProviderApiBase { request: IJsBridgeMessagePayload, params: SignerPayloadJSON, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const { account, accountInfo } = await this.findAccount( request, params.address, @@ -261,6 +263,7 @@ class ProviderApiPolkadot extends ProviderApiBase { request: IJsBridgeMessagePayload, params: SignerPayloadRaw, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { account, accountInfo } = await this.findAccount( request, params.address, diff --git a/packages/kit-bg/src/providers/ProviderApiSolana.ts b/packages/kit-bg/src/providers/ProviderApiSolana.ts index 893b7c2f83c..ba8b6ce8fd8 100644 --- a/packages/kit-bg/src/providers/ProviderApiSolana.ts +++ b/packages/kit-bg/src/providers/ProviderApiSolana.ts @@ -9,6 +9,7 @@ import { backgroundClass, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { EMessageTypesCommon } from '@onekeyhq/shared/types/message'; import ProviderApiBase from './ProviderApiBase'; @@ -106,6 +107,7 @@ class ProviderApiSolana extends ProviderApiBase { request: IJsBridgeMessagePayload, params: { message: string }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -131,6 +133,7 @@ class ProviderApiSolana extends ProviderApiBase { request: IJsBridgeMessagePayload, params: { message: string[] }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { message: txsToBeSigned } = params; if ( @@ -156,6 +159,7 @@ class ProviderApiSolana extends ProviderApiBase { request: IJsBridgeMessagePayload, params: { message: string; options?: ISolanaSendOptions }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { message } = params; if (!isString(message)) { @@ -189,6 +193,7 @@ class ProviderApiSolana extends ProviderApiBase { display?: 'hex' | 'utf8'; }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { message, display = 'utf8' } = params; const { accountInfo: { accountId, networkId, address } = {} } = ( @@ -221,6 +226,7 @@ class ProviderApiSolana extends ProviderApiBase { request: IJsBridgeMessagePayload, params?: { onlyIfTrusted: boolean }, ) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { onlyIfTrusted = false } = params || {}; let publicKey = (await this._getConnectedAccountsPublicKey(request))[0]; diff --git a/packages/kit-bg/src/providers/ProviderApiSui.ts b/packages/kit-bg/src/providers/ProviderApiSui.ts index 341c60a66af..c43c36b509f 100644 --- a/packages/kit-bg/src/providers/ProviderApiSui.ts +++ b/packages/kit-bg/src/providers/ProviderApiSui.ts @@ -8,6 +8,7 @@ import { backgroundClass, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import bufferUtils from '@onekeyhq/shared/src/utils/bufferUtils'; import { EMessageTypesCommon } from '@onekeyhq/shared/types/message'; import type { @@ -90,6 +91,7 @@ class ProviderApiSui extends ProviderApiBase { @providerApiMethod() async requestPermissions(request: IJsBridgeMessagePayload): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const account = await this.sui_accounts(request); if (account) { return true; @@ -142,6 +144,7 @@ class ProviderApiSui extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISignAndExecuteTransactionBlockInput, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId, address } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -174,6 +177,7 @@ class ProviderApiSui extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISignTransactionBlockInput, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId, address } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -204,6 +208,7 @@ class ProviderApiSui extends ProviderApiBase { request: IJsBridgeMessagePayload, params: ISignMessageInput, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId, address } = {} } = ( await this.getAccountsInfo(request) )[0]; @@ -233,6 +238,7 @@ class ProviderApiSui extends ProviderApiBase { bytes: string; signature: string; }> { + defaultLogger.discovery.dapp.dappRequest({ request }); const result = await this.signMessage(request, params); return { bytes: result.messageBytes, diff --git a/packages/kit-bg/src/providers/ProviderApiTron.ts b/packages/kit-bg/src/providers/ProviderApiTron.ts index 151db73f76d..6cec97cbaeb 100644 --- a/packages/kit-bg/src/providers/ProviderApiTron.ts +++ b/packages/kit-bg/src/providers/ProviderApiTron.ts @@ -9,6 +9,7 @@ import { permissionRequired, providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import hexUtils from '@onekeyhq/shared/src/utils/hexUtils'; import ProviderApiBase from './ProviderApiBase'; @@ -166,6 +167,7 @@ class ProviderApiTron extends ProviderApiBase { @providerApiMethod() async tron_requestAccounts(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); console.log('ProviderTron.tron_requestAccounts', request); const accounts = await this.tron_accounts(request); if (accounts && accounts.length) { @@ -181,6 +183,7 @@ class ProviderApiTron extends ProviderApiBase { request: IJsBridgeMessagePayload, transaction: any, ): Promise { + defaultLogger.discovery.dapp.dappRequest({ request }); console.log('tron_signTransaction', request, transaction); const { accountInfo: { networkId, accountId } = {} } = ( diff --git a/packages/kit-bg/src/providers/ProviderApiWebln.ts b/packages/kit-bg/src/providers/ProviderApiWebln.ts index e9158fe7161..ea83e5c668d 100644 --- a/packages/kit-bg/src/providers/ProviderApiWebln.ts +++ b/packages/kit-bg/src/providers/ProviderApiWebln.ts @@ -7,6 +7,7 @@ import { providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; import { NotImplemented } from '@onekeyhq/shared/src/errors'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import { EDAppConnectionModal, EModalRoutes, @@ -74,6 +75,7 @@ class ProviderApiWebln extends ProviderApiBase { // WEBLN API @providerApiMethod() public async enable(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); try { const accountsInfo = await this._getAccountsInfo(request); if (accountsInfo.length > 0) { @@ -110,6 +112,7 @@ class ProviderApiWebln extends ProviderApiBase { @providerApiMethod() public async makeInvoice(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this._getAccountsInfo(request) )[0]; @@ -139,6 +142,7 @@ class ProviderApiWebln extends ProviderApiBase { @providerApiMethod() public async sendPayment(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this._getAccountsInfo(request) )[0]; @@ -170,6 +174,7 @@ class ProviderApiWebln extends ProviderApiBase { @providerApiMethod() public async signMessage(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this._getAccountsInfo(request) )[0]; @@ -200,6 +205,7 @@ class ProviderApiWebln extends ProviderApiBase { @providerApiMethod() public async verifyMessage(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this._getAccountsInfo(request) )[0]; @@ -228,6 +234,7 @@ class ProviderApiWebln extends ProviderApiBase { @providerApiMethod() public async lnurl(request: IJsBridgeMessagePayload) { + defaultLogger.discovery.dapp.dappRequest({ request }); const { accountInfo: { accountId, networkId } = {} } = ( await this._getAccountsInfo(request) )[0]; diff --git a/packages/kit-bg/src/services/ServiceDApp.ts b/packages/kit-bg/src/services/ServiceDApp.ts index 5e408b2b55b..edafef05c9b 100644 --- a/packages/kit-bg/src/services/ServiceDApp.ts +++ b/packages/kit-bg/src/services/ServiceDApp.ts @@ -17,6 +17,7 @@ import { EAppEventBusNames, appEventBus, } from '@onekeyhq/shared/src/eventBus/appEventBus'; +import { defaultLogger } from '@onekeyhq/shared/src/logger/logger'; import platformEnv from '@onekeyhq/shared/src/platformEnv'; import { parseRPCResponse } from '@onekeyhq/shared/src/request/utils'; import { @@ -121,6 +122,11 @@ class ServiceDApp extends ServiceBase { params?: any; fullScreen?: boolean; }) { + defaultLogger.discovery.dapp.dappOpenModal({ + request, + screens, + params, + }); // Try to open an existing window anyway in the extension this.tryOpenExistingExtensionWindow(); diff --git a/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts b/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts index f94c959bdfd..fa629c32678 100644 --- a/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts +++ b/packages/shared/src/logger/scopes/discovery/scenes/dapp.ts @@ -1,6 +1,8 @@ import { BaseScene } from '../../../base/baseScene'; import { LogToLocal, LogToServer } from '../../../decorators'; +import type { IJsBridgeMessagePayload } from '@onekeyfe/cross-inpage-provider-types'; + export enum EEnterMethod { banner = 'banner', dashboard = 'dashboard', @@ -36,4 +38,18 @@ export class DappScene extends BaseScene { }) { return params; } + + @LogToLocal({ level: 'info' }) + public dappOpenModal(params: { + request: IJsBridgeMessagePayload; + screens: any[]; + params?: any; + }) { + return params; + } + + @LogToLocal({ level: 'info' }) + public dappRequest(params: { request: IJsBridgeMessagePayload }) { + return params; + } }