From a6f59769743d11b8045f0d3f335e4743b5fd7a69 Mon Sep 17 00:00:00 2001 From: Daniel Rocha Date: Fri, 28 Jul 2023 18:37:32 +0200 Subject: [PATCH] feat: remove account name from `KeyringAccount` type (#55) BREAKING CHANGE: This commit changes the `KeyringAccount` type and the `Keyring` interface. --- src/KeyringClient.test.ts | 8 ++------ src/KeyringClient.ts | 3 +-- src/KeyringSnapControllerClient.test.ts | 1 - src/KeyringSnapRpcClient.test.ts | 1 - src/api.ts | 14 ++------------ src/internal-api.ts | 1 - src/rpc-handler.test.ts | 6 ++---- src/rpc-handler.ts | 5 +---- 8 files changed, 8 insertions(+), 31 deletions(-) diff --git a/src/KeyringClient.test.ts b/src/KeyringClient.test.ts index 2eb97056d..6a5de1522 100644 --- a/src/KeyringClient.test.ts +++ b/src/KeyringClient.test.ts @@ -21,7 +21,6 @@ describe('KeyringClient', () => { const expectedResponse: KeyringAccount[] = [ { id: '49116980-0712-4fa5-b045-e4294f1d440e', - name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', options: {}, methods: [], @@ -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: [], @@ -68,7 +66,6 @@ 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: [], @@ -76,12 +73,12 @@ describe('KeyringClient', () => { }; 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); }); @@ -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: [], diff --git a/src/KeyringClient.ts b/src/KeyringClient.ts index 022545501..d9ae603de 100644 --- a/src/KeyringClient.ts +++ b/src/KeyringClient.ts @@ -77,13 +77,12 @@ export class KeyringClient implements Keyring { } async createAccount( - name: string, options: Record = {}, ): Promise { return strictMask( await this.#send({ method: 'keyring_createAccount', - params: { name, options }, + params: { options }, }), CreateAccountResponseStruct, ); diff --git a/src/KeyringSnapControllerClient.test.ts b/src/KeyringSnapControllerClient.test.ts index 2d69b911b..642166cf0 100644 --- a/src/KeyringSnapControllerClient.test.ts +++ b/src/KeyringSnapControllerClient.test.ts @@ -9,7 +9,6 @@ describe('KeyringSnapControllerClient', () => { const accountsList: KeyringAccount[] = [ { id: '13f94041-6ae6-451f-a0fe-afdd2fda18a7', - name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', options: {}, methods: [], diff --git a/src/KeyringSnapRpcClient.test.ts b/src/KeyringSnapRpcClient.test.ts index 00c96a0d7..8c6c0e6bb 100644 --- a/src/KeyringSnapRpcClient.test.ts +++ b/src/KeyringSnapRpcClient.test.ts @@ -9,7 +9,6 @@ describe('KeyringSnapRpcClient', () => { const accountsList: KeyringAccount[] = [ { id: '13f94041-6ae6-451f-a0fe-afdd2fda18a7', - name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', options: {}, methods: [], diff --git a/src/api.ts b/src/api.ts index dd1423c94..88a9f9ab8 100644 --- a/src/api.ts +++ b/src/api.ts @@ -20,11 +20,6 @@ export const KeyringAccountStruct = object({ */ id: UuidStruct, - /** - * User-chosen account name. - */ - name: string(), - /** * Account address or next receive address (UTXO). */ @@ -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, - ): Promise; + createAccount(options?: Record): Promise; /** * Filter supported chains for a given account. diff --git a/src/internal-api.ts b/src/internal-api.ts index c50227494..6853dc183 100644 --- a/src/internal-api.ts +++ b/src/internal-api.ts @@ -61,7 +61,6 @@ export const CreateAccountRequestStruct = object({ ...CommonHeader, method: literal('keyring_createAccount'), params: object({ - name: string(), options: record(string(), JsonStruct), }), }); diff --git a/src/rpc-handler.test.ts b/src/rpc-handler.test.ts index af67820dc..45aa88319 100644 --- a/src/rpc-handler.test.ts +++ b/src/rpc-handler.test.ts @@ -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'); }); @@ -235,7 +235,6 @@ describe('keyringRpcDispatcher', () => { params: { account: { id: '4f983fa2-4f53-4c63-a7c2-f9a5ed750041', - name: 'test', address: '0x0', options: {}, methods: [], @@ -249,7 +248,6 @@ describe('keyringRpcDispatcher', () => { expect(keyring.updateAccount).toHaveBeenCalledWith({ id: '4f983fa2-4f53-4c63-a7c2-f9a5ed750041', - name: 'test', address: '0x0', options: {}, methods: [], diff --git a/src/rpc-handler.ts b/src/rpc-handler.ts index c7045c41d..8cab3eff2 100644 --- a/src/rpc-handler.ts +++ b/src/rpc-handler.ts @@ -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': {