Skip to content

Commit

Permalink
permissions (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-zhang-sv authored Aug 28, 2024
1 parent e98c9e2 commit 4531713
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/wallet-sdk/src/sign/scw/SCWSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
exportKeyToHexString,
importKeyFromHexString,
} from ':util/cipher';
import { fetchRPCRequest } from ':util/provider';

jest.mock(':util/provider');

jest.mock('./SCWKeyManager');
const storageStoreSpy = jest.spyOn(ScopedAsyncStorage.prototype, 'storeObject');
Expand Down Expand Up @@ -165,6 +168,59 @@ describe('SCWSigner', () => {
expect(result).toEqual('0xSignature');
});

it.each([
'eth_ecRecover',
'personal_sign',
'personal_ecRecover',
'eth_signTransaction',
'eth_sendTransaction',
'eth_signTypedData_v1',
'eth_signTypedData_v3',
'eth_signTypedData_v4',
'eth_signTypedData',
'wallet_addEthereumChain',
'wallet_watchAsset',
'wallet_sendCalls',
'wallet_showCallsStatus',
'wallet_grantPermissions',
])('should send request to popup for %s', async (method) => {
const mockRequest: RequestArguments = {
method,
params: [],
};

(decryptContent as jest.Mock).mockResolvedValueOnce({
result: {
value: '0xSignature',
},
});

await signer.request(mockRequest);

expect(mockCommunicator.postRequestAndWaitForResponse).toHaveBeenCalledWith(
expect.objectContaining({
sender: '0xPublicKey',
content: { encrypted: encryptedData },
})
);
});

it.each([
'wallet_prepareCalls',
'wallet_sendPreparedCalls',
'eth_getBalance',
'eth_getTransactionCount',
])('should fetch rpc request for %s', async (method) => {
const mockRequest: RequestArguments = {
method,
params: [],
};

await signer.request(mockRequest);

expect(fetchRPCRequest).toHaveBeenCalledWith(mockRequest, 'https://eth-rpc.example.com/1');
});

it('should throw an error if error in decrypted response', async () => {
const mockRequest: RequestArguments = {
method: 'personal_sign',
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-sdk/src/sign/scw/SCWSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class SCWSigner implements Signer {
case 'wallet_watchAsset':
case 'wallet_sendCalls':
case 'wallet_showCallsStatus':
case 'wallet_grantPermissions':
return this.sendRequestToPopup(request);
default:
if (!this.chain.rpcUrl) throw standardErrors.rpc.internal('No RPC URL set for chain');
Expand Down

0 comments on commit 4531713

Please sign in to comment.