Skip to content

Commit

Permalink
fix: Fix native decrypt failure & Check wallet type connected with No…
Browse files Browse the repository at this point in the history
…str Provider. (#3868)

* fix: Encrypt error on Native

* fix: Check supported wallet types
  • Loading branch information
originalix authored Nov 27, 2023
1 parent c9a5de1 commit 5aeb8e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/engine/src/vaults/utils/nostr/nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion packages/kit-bg/src/providers/ProviderApiNostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string> {
const { walletId } = getActiveWalletAccount();
this.checkWalletSupport(walletId);
const pubkey = await this.backgroundApi.serviceDapp.openModal({
request,
screens: [ModalRoutes.Nostr, NostrModalRoutes.GetPublicKey],
Expand All @@ -87,6 +95,7 @@ class ProviderApiNostr extends ProviderApiBase {
request: IJsBridgeMessagePayload,
): Promise<NostrEvent> {
const { walletId } = getActiveWalletAccount();
this.checkWalletSupport(walletId);
const params = (request.data as IJsonRpcRequest)?.params as {
event: NostrEvent;
};
Expand Down Expand Up @@ -119,7 +128,7 @@ class ProviderApiNostr extends ProviderApiBase {
@providerApiMethod()
public async encrypt(request: IJsBridgeMessagePayload): Promise<string> {
const { walletId } = getActiveWalletAccount();
console.log(request);
this.checkWalletSupport(walletId);
const params = (request.data as IJsonRpcRequest)?.params as {
pubkey: string;
plaintext: string;
Expand Down Expand Up @@ -170,6 +179,7 @@ class ProviderApiNostr extends ProviderApiBase {
@providerApiMethod()
public async decrypt(request: IJsBridgeMessagePayload): Promise<string> {
const { walletId } = getActiveWalletAccount();
this.checkWalletSupport(walletId);
const params = (request.data as IJsonRpcRequest)?.params as {
pubkey: string;
ciphertext: string;
Expand Down Expand Up @@ -210,6 +220,7 @@ class ProviderApiNostr extends ProviderApiBase {
@providerApiMethod()
public async signSchnorr(request: IJsBridgeMessagePayload): Promise<string> {
const { walletId } = getActiveWalletAccount();
this.checkWalletSupport(walletId);
const params = (request.data as IJsonRpcRequest)?.params as string;
try {
const signedHash = await this.backgroundApi.serviceDapp.openModal({
Expand Down

0 comments on commit 5aeb8e6

Please sign in to comment.