From b60224315a490e256e9665284f3918ca8e73ceae Mon Sep 17 00:00:00 2001 From: Daniel Rocha <68558152+danroc@users.noreply.github.com> Date: Mon, 10 Jul 2023 12:07:15 +0200 Subject: [PATCH] feat: make `options` a mandatory field (i.e. cannot be `null`) BREAKING CHANGE: This API modification is incompatible with previous versions. --- src/KeyringClient.test.ts | 10 +++++----- src/KeyringClient.ts | 2 +- src/KeyringSnapControllerClient.test.ts | 2 +- src/KeyringSnapRpcClient.test.ts | 2 +- src/api.ts | 4 ++-- src/internal-api.ts | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/KeyringClient.test.ts b/src/KeyringClient.test.ts index ae7d99301..d350f1c10 100644 --- a/src/KeyringClient.test.ts +++ b/src/KeyringClient.test.ts @@ -23,7 +23,7 @@ describe('KeyringClient', () => { id: '49116980-0712-4fa5-b045-e4294f1d440e', name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', - options: null, + options: {}, supportedMethods: [], type: 'eip155:eoa', }, @@ -47,7 +47,7 @@ describe('KeyringClient', () => { id: '49116980-0712-4fa5-b045-e4294f1d440e', name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', - options: null, + options: {}, supportedMethods: [], type: 'eip155:eoa', }; @@ -70,7 +70,7 @@ describe('KeyringClient', () => { id: '49116980-0712-4fa5-b045-e4294f1d440e', name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', - options: null, + options: {}, supportedMethods: [], type: 'eip155:eoa', }; @@ -81,7 +81,7 @@ describe('KeyringClient', () => { jsonrpc: '2.0', id: expect.any(String), method: 'keyring_createAccount', - params: { name: 'Account 1', options: null }, + params: { name: 'Account 1', options: {} }, }); expect(account).toStrictEqual(expectedResponse); }); @@ -113,7 +113,7 @@ describe('KeyringClient', () => { id: '49116980-0712-4fa5-b045-e4294f1d440e', name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', - options: null, + options: {}, supportedMethods: [], type: 'eip155:eoa', }; diff --git a/src/KeyringClient.ts b/src/KeyringClient.ts index f580730ec..3d8db7002 100644 --- a/src/KeyringClient.ts +++ b/src/KeyringClient.ts @@ -78,7 +78,7 @@ export class KeyringClient implements Keyring { async createAccount( name: string, - options: Record | null = null, + options: Record = {}, ): Promise { return strictMask( await this.#send({ diff --git a/src/KeyringSnapControllerClient.test.ts b/src/KeyringSnapControllerClient.test.ts index bf5426a06..34d82a5d0 100644 --- a/src/KeyringSnapControllerClient.test.ts +++ b/src/KeyringSnapControllerClient.test.ts @@ -11,7 +11,7 @@ describe('KeyringSnapControllerClient', () => { id: '13f94041-6ae6-451f-a0fe-afdd2fda18a7', name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', - options: null, + options: {}, supportedMethods: [], type: 'eip155:eoa', }, diff --git a/src/KeyringSnapRpcClient.test.ts b/src/KeyringSnapRpcClient.test.ts index 195f413a2..c38fc0560 100644 --- a/src/KeyringSnapRpcClient.test.ts +++ b/src/KeyringSnapRpcClient.test.ts @@ -11,7 +11,7 @@ describe('KeyringSnapRpcClient', () => { id: '13f94041-6ae6-451f-a0fe-afdd2fda18a7', name: 'Account 1', address: '0xE9A74AACd7df8112911ca93260fC5a046f8a64Ae', - options: null, + options: {}, supportedMethods: [], type: 'eip155:eoa', }, diff --git a/src/api.ts b/src/api.ts index 5bcbb2340..3be71b142 100644 --- a/src/api.ts +++ b/src/api.ts @@ -33,7 +33,7 @@ export const KeyringAccountStruct = object({ /** * Keyring-dependent account options. */ - options: nullable(record(string(), JsonStruct)), + options: record(string(), JsonStruct), /** * Account supported methods. @@ -147,7 +147,7 @@ export type Keyring = { */ createAccount( name: string, - options?: Record | null, + options?: Record, ): Promise; /** diff --git a/src/internal-api.ts b/src/internal-api.ts index b2333e99a..bc1869839 100644 --- a/src/internal-api.ts +++ b/src/internal-api.ts @@ -62,7 +62,7 @@ export const CreateAccountRequestStruct = object({ method: literal('keyring_createAccount'), params: object({ name: string(), - options: nullable(record(string(), JsonStruct)), + options: record(string(), JsonStruct), }), });