Skip to content

Commit 5aeb8e6

Browse files
authored
fix: Fix native decrypt failure & Check wallet type connected with Nostr Provider. (#3868)
* fix: Encrypt error on Native * fix: Check supported wallet types
1 parent c9a5de1 commit 5aeb8e6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/engine/src/vaults/utils/nostr/nostr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ class Nostr {
187187
iv,
188188
);
189189

190-
return `${Buffer.from(encrypted).toString('base64')}?iv=${iv.toString(
191-
'base64',
192-
)}`;
190+
return `${Buffer.from(encrypted).toString('base64')}?iv=${Buffer.from(
191+
iv.buffer,
192+
).toString('base64')}`;
193193
}
194194

195195
async decrypt(pubkey: string, ciphertext: string) {

packages/kit-bg/src/providers/ProviderApiNostr.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
providerApiMethod,
1616
} from '@onekeyhq/shared/src/background/backgroundDecorators';
1717
import { IMPL_LIGHTNING } from '@onekeyhq/shared/src/engine/engineConsts';
18+
import { isHdWallet } from '@onekeyhq/shared/src/engine/engineUtils';
1819
import debugLogger from '@onekeyhq/shared/src/logger/debugLogger';
1920

2021
import ProviderApiBase from './ProviderApiBase';
@@ -64,10 +65,17 @@ class ProviderApiNostr extends ProviderApiBase {
6465
return Promise.resolve();
6566
}
6667

68+
private checkWalletSupport(walletId: string) {
69+
if (!isHdWallet({ walletId })) {
70+
throw web3Errors.rpc.methodNotSupported();
71+
}
72+
}
73+
6774
// Nostr API
6875
@providerApiMethod()
6976
public async getPublicKey(request: IJsBridgeMessagePayload): Promise<string> {
7077
const { walletId } = getActiveWalletAccount();
78+
this.checkWalletSupport(walletId);
7179
const pubkey = await this.backgroundApi.serviceDapp.openModal({
7280
request,
7381
screens: [ModalRoutes.Nostr, NostrModalRoutes.GetPublicKey],
@@ -87,6 +95,7 @@ class ProviderApiNostr extends ProviderApiBase {
8795
request: IJsBridgeMessagePayload,
8896
): Promise<NostrEvent> {
8997
const { walletId } = getActiveWalletAccount();
98+
this.checkWalletSupport(walletId);
9099
const params = (request.data as IJsonRpcRequest)?.params as {
91100
event: NostrEvent;
92101
};
@@ -119,7 +128,7 @@ class ProviderApiNostr extends ProviderApiBase {
119128
@providerApiMethod()
120129
public async encrypt(request: IJsBridgeMessagePayload): Promise<string> {
121130
const { walletId } = getActiveWalletAccount();
122-
console.log(request);
131+
this.checkWalletSupport(walletId);
123132
const params = (request.data as IJsonRpcRequest)?.params as {
124133
pubkey: string;
125134
plaintext: string;
@@ -170,6 +179,7 @@ class ProviderApiNostr extends ProviderApiBase {
170179
@providerApiMethod()
171180
public async decrypt(request: IJsBridgeMessagePayload): Promise<string> {
172181
const { walletId } = getActiveWalletAccount();
182+
this.checkWalletSupport(walletId);
173183
const params = (request.data as IJsonRpcRequest)?.params as {
174184
pubkey: string;
175185
ciphertext: string;
@@ -210,6 +220,7 @@ class ProviderApiNostr extends ProviderApiBase {
210220
@providerApiMethod()
211221
public async signSchnorr(request: IJsBridgeMessagePayload): Promise<string> {
212222
const { walletId } = getActiveWalletAccount();
223+
this.checkWalletSupport(walletId);
213224
const params = (request.data as IJsonRpcRequest)?.params as string;
214225
try {
215226
const signedHash = await this.backgroundApi.serviceDapp.openModal({

0 commit comments

Comments
 (0)