Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: forward options for exportAccount
  • Loading branch information
ccharly committed Dec 8, 2025
commit b74cf0846a20045502aa294bfa7af180b261d5d6
34 changes: 31 additions & 3 deletions packages/keyring-snap-sdk/src/v2/rpc-handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyringRpcV2Method } from '@metamask/keyring-api';
import { KeyringRpcV2Method, PrivateKeyEncoding } from '@metamask/keyring-api';
import type {
KeyringType,
CreateAccountsV2Request,
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('handleKeyringRequestV2', () => {
expect(result).toBe(mockedResult);
});

it('calls `keyring_v2_exportAccount`', async () => {
it('calls `keyring_v2_exportAccount` (without options)', async () => {
const request: ExportAccountV2Request = {
jsonrpc: '2.0',
id: '7c507ff0-365f-4de0-8cd5-eb83c30ebda4',
Expand All @@ -161,7 +161,35 @@ describe('handleKeyringRequestV2', () => {
const result = await handleKeyringRequestV2(keyring, request);

expect(keyring.exportAccount).toHaveBeenCalledWith(
'4f983fa2-4f53-4c63-a7c2-f9a5ed750041',
request.params.id,
undefined,
);
expect(result).toStrictEqual(mockedResult);
});

it('calls `keyring_v2_exportAccount` (with options)', async () => {
const request: ExportAccountV2Request = {
jsonrpc: '2.0',
id: '7c507ff0-365f-4de0-8cd5-eb83c30ebda4',
method: `${KeyringRpcV2Method.ExportAccount}`,
params: {
id: '4f983fa2-4f53-4c63-a7c2-f9a5ed750041',
options: {
type: 'private-key',
encoding: PrivateKeyEncoding.Hexadecimal,
},
},
};

const mockedResult = {
privateKey: '0x0123',
};
keyring.exportAccount.mockResolvedValue(mockedResult);
const result = await handleKeyringRequestV2(keyring, request);

expect(keyring.exportAccount).toHaveBeenCalledWith(
request.params.id,
request.params.options,
);
expect(result).toStrictEqual(mockedResult);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-snap-sdk/src/v2/rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function dispatchKeyringRequestV2(
throw new MethodNotSupportedError(request.method);
}
assert(request, ExportAccountV2RequestStruct);
return keyring.exportAccount(request.params.id);
return keyring.exportAccount(request.params.id, request.params.options);
}

case `${KeyringRpcV2Method.SubmitRequest}`: {
Expand Down