From 5aeb8e6c49e4ee4a70e984943ae81596eb48dba9 Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 27 Nov 2023 21:09:51 +0800 Subject: [PATCH] fix: Fix native decrypt failure & Check wallet type connected with Nostr Provider. (#3868) * fix: Encrypt error on Native * fix: Check supported wallet types --- packages/engine/src/vaults/utils/nostr/nostr.ts | 6 +++--- packages/kit-bg/src/providers/ProviderApiNostr.ts | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/engine/src/vaults/utils/nostr/nostr.ts b/packages/engine/src/vaults/utils/nostr/nostr.ts index aef3230b933..37981642422 100644 --- a/packages/engine/src/vaults/utils/nostr/nostr.ts +++ b/packages/engine/src/vaults/utils/nostr/nostr.ts @@ -187,9 +187,9 @@ class Nostr { iv, ); - return `${Buffer.from(encrypted).toString('base64')}?iv=${iv.toString( - 'base64', - )}`; + return `${Buffer.from(encrypted).toString('base64')}?iv=${Buffer.from( + iv.buffer, + ).toString('base64')}`; } async decrypt(pubkey: string, ciphertext: string) { diff --git a/packages/kit-bg/src/providers/ProviderApiNostr.ts b/packages/kit-bg/src/providers/ProviderApiNostr.ts index 58404a53fe3..e3e06b5338f 100644 --- a/packages/kit-bg/src/providers/ProviderApiNostr.ts +++ b/packages/kit-bg/src/providers/ProviderApiNostr.ts @@ -15,6 +15,7 @@ import { providerApiMethod, } from '@onekeyhq/shared/src/background/backgroundDecorators'; import { IMPL_LIGHTNING } from '@onekeyhq/shared/src/engine/engineConsts'; +import { isHdWallet } from '@onekeyhq/shared/src/engine/engineUtils'; import debugLogger from '@onekeyhq/shared/src/logger/debugLogger'; import ProviderApiBase from './ProviderApiBase'; @@ -64,10 +65,17 @@ class ProviderApiNostr extends ProviderApiBase { return Promise.resolve(); } + private checkWalletSupport(walletId: string) { + if (!isHdWallet({ walletId })) { + throw web3Errors.rpc.methodNotSupported(); + } + } + // Nostr API @providerApiMethod() public async getPublicKey(request: IJsBridgeMessagePayload): Promise { const { walletId } = getActiveWalletAccount(); + this.checkWalletSupport(walletId); const pubkey = await this.backgroundApi.serviceDapp.openModal({ request, screens: [ModalRoutes.Nostr, NostrModalRoutes.GetPublicKey], @@ -87,6 +95,7 @@ class ProviderApiNostr extends ProviderApiBase { request: IJsBridgeMessagePayload, ): Promise { const { walletId } = getActiveWalletAccount(); + this.checkWalletSupport(walletId); const params = (request.data as IJsonRpcRequest)?.params as { event: NostrEvent; }; @@ -119,7 +128,7 @@ class ProviderApiNostr extends ProviderApiBase { @providerApiMethod() public async encrypt(request: IJsBridgeMessagePayload): Promise { const { walletId } = getActiveWalletAccount(); - console.log(request); + this.checkWalletSupport(walletId); const params = (request.data as IJsonRpcRequest)?.params as { pubkey: string; plaintext: string; @@ -170,6 +179,7 @@ class ProviderApiNostr extends ProviderApiBase { @providerApiMethod() public async decrypt(request: IJsBridgeMessagePayload): Promise { const { walletId } = getActiveWalletAccount(); + this.checkWalletSupport(walletId); const params = (request.data as IJsonRpcRequest)?.params as { pubkey: string; ciphertext: string; @@ -210,6 +220,7 @@ class ProviderApiNostr extends ProviderApiBase { @providerApiMethod() public async signSchnorr(request: IJsBridgeMessagePayload): Promise { const { walletId } = getActiveWalletAccount(); + this.checkWalletSupport(walletId); const params = (request.data as IJsonRpcRequest)?.params as string; try { const signedHash = await this.backgroundApi.serviceDapp.openModal({