Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

feat: remove account name from KeyringAccount type #55

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 2 additions & 6 deletions src/KeyringClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('KeyringClient', () => {
const expectedResponse: KeyringAccount[] = [
{
id: '49116980-0712-4fa5-b045-e4294f1d440e',
name: 'Account 1',
address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae',
options: {},
methods: [],
Expand All @@ -45,7 +44,6 @@ describe('KeyringClient', () => {
const id = '49116980-0712-4fa5-b045-e4294f1d440e';
const expectedResponse = {
id: '49116980-0712-4fa5-b045-e4294f1d440e',
name: 'Account 1',
address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae',
options: {},
methods: [],
Expand All @@ -68,20 +66,19 @@ describe('KeyringClient', () => {
it('should send a request to create an account and return the response', async () => {
const expectedResponse = {
id: '49116980-0712-4fa5-b045-e4294f1d440e',
name: 'Account 1',
address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae',
options: {},
methods: [],
type: 'eip155:eoa',
};

mockSender.send.mockResolvedValue(expectedResponse);
const account = await keyring.createAccount('Account 1');
const account = await keyring.createAccount();
expect(mockSender.send).toHaveBeenCalledWith({
jsonrpc: '2.0',
id: expect.any(String),
method: 'keyring_createAccount',
params: { name: 'Account 1', options: {} },
params: { options: {} },
});
expect(account).toStrictEqual(expectedResponse);
});
Expand Down Expand Up @@ -111,7 +108,6 @@ describe('KeyringClient', () => {
it('should send a request to update an account', async () => {
const account: KeyringAccount = {
id: '49116980-0712-4fa5-b045-e4294f1d440e',
name: 'Account 1',
address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae',
options: {},
methods: [],
Expand Down
3 changes: 1 addition & 2 deletions src/KeyringClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ export class KeyringClient implements Keyring {
}

async createAccount(
name: string,
options: Record<string, Json> = {},
): Promise<KeyringAccount> {
return strictMask(
await this.#send({
method: 'keyring_createAccount',
params: { name, options },
params: { options },
}),
CreateAccountResponseStruct,
);
Expand Down
1 change: 0 additions & 1 deletion src/KeyringSnapControllerClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('KeyringSnapControllerClient', () => {
const accountsList: KeyringAccount[] = [
{
id: '13f94041-6ae6-451f-a0fe-afdd2fda18a7',
name: 'Account 1',
address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae',
options: {},
methods: [],
Expand Down
1 change: 0 additions & 1 deletion src/KeyringSnapRpcClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('KeyringSnapRpcClient', () => {
const accountsList: KeyringAccount[] = [
{
id: '13f94041-6ae6-451f-a0fe-afdd2fda18a7',
name: 'Account 1',
address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae',
options: {},
methods: [],
Expand Down
14 changes: 2 additions & 12 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ export const KeyringAccountStruct = object({
*/
id: UuidStruct,

/**
* User-chosen account name.
*/
name: string(),

/**
* Account address or next receive address (UTXO).
*/
Expand Down Expand Up @@ -136,18 +131,13 @@ export type Keyring = {
/**
* Create an account.
*
* Creates a new account with the given name, supported chains, and optional
* account options.
* Creates a new account with optional, keyring-defined, account options.
*
* @param name - The name of the account.
* @param options - Keyring-defined options for the account (optional).
* @returns A promise that resolves to the newly created KeyringAccount
* object without any private information.
*/
createAccount(
name: string,
options?: Record<string, Json>,
): Promise<KeyringAccount>;
createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;

/**
* Filter supported chains for a given account.
Expand Down
1 change: 0 additions & 1 deletion src/internal-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const CreateAccountRequestStruct = object({
...CommonHeader,
method: literal('keyring_createAccount'),
params: object({
name: string(),
options: record(string(), JsonStruct),
}),
});
Expand Down
6 changes: 2 additions & 4 deletions src/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ describe('keyringRpcDispatcher', () => {
jsonrpc: '2.0',
id: '7c507ff0-365f-4de0-8cd5-eb83c30ebda4',
method: 'keyring_createAccount',
params: { name: 'account_name', options: {} },
params: { options: {} },
};

keyring.createAccount.mockResolvedValue('CreateAccount result');
const result = await handleKeyringRequest(keyring, request);

expect(keyring.createAccount).toHaveBeenCalledWith('account_name', {});
expect(keyring.createAccount).toHaveBeenCalledWith({});
expect(result).toBe('CreateAccount result');
});

Expand Down Expand Up @@ -235,7 +235,6 @@ describe('keyringRpcDispatcher', () => {
params: {
account: {
id: '4f983fa2-4f53-4c63-a7c2-f9a5ed750041',
name: 'test',
address: '0x0',
options: {},
methods: [],
Expand All @@ -249,7 +248,6 @@ describe('keyringRpcDispatcher', () => {

expect(keyring.updateAccount).toHaveBeenCalledWith({
id: '4f983fa2-4f53-4c63-a7c2-f9a5ed750041',
name: 'test',
address: '0x0',
options: {},
methods: [],
Expand Down
5 changes: 1 addition & 4 deletions src/rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ export async function handleKeyringRequest(

case 'keyring_createAccount': {
assert(request, CreateAccountRequestStruct);
return await keyring.createAccount(
request.params.name,
request.params.options,
);
return await keyring.createAccount(request.params.options);
}

case 'keyring_filterAccountChains': {
Expand Down