From d1b90ff89c25f1d4575cd88a8ee00fb0dc300ade Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:31:40 -0400 Subject: [PATCH 01/20] extracting the handles wrapper from rpc-middleware files to separate file --- .../handlers/handler-wrapper.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts new file mode 100644 index 000000000000..7be0af8f0efe --- /dev/null +++ b/app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts @@ -0,0 +1,25 @@ +import type { + JsonRpcEngineNextCallback, + JsonRpcEngineEndCallback, +} from '@metamask/json-rpc-engine'; +import type { + JsonRpcRequest, + JsonRpcResponse, + JsonRpcParams, + Json, +} from '@metamask/utils'; + +export type HandlerWrapperType< + Params extends JsonRpcParams = JsonRpcParams, + Result extends Json = Json, +> = { + methodNames: [string]; + implementation: ( + _req: JsonRpcRequest, + res: JsonRpcResponse, + _next: JsonRpcEngineNextCallback, + end: JsonRpcEngineEndCallback, + options: Record void>, + ) => Promise; + hookNames: Record; +}; From 65c061e5eab14a56d5581f3e092bc29795950d57 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:14:00 -0400 Subject: [PATCH 02/20] updating with a helper file --- .../handlers/handler-wrapper.ts | 25 ------------------- .../handlers/handlers-helper.ts | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts create mode 100644 app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts deleted file mode 100644 index 7be0af8f0efe..000000000000 --- a/app/scripts/lib/rpc-method-middleware/handlers/handler-wrapper.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { - JsonRpcEngineNextCallback, - JsonRpcEngineEndCallback, -} from '@metamask/json-rpc-engine'; -import type { - JsonRpcRequest, - JsonRpcResponse, - JsonRpcParams, - Json, -} from '@metamask/utils'; - -export type HandlerWrapperType< - Params extends JsonRpcParams = JsonRpcParams, - Result extends Json = Json, -> = { - methodNames: [string]; - implementation: ( - _req: JsonRpcRequest, - res: JsonRpcResponse, - _next: JsonRpcEngineNextCallback, - end: JsonRpcEngineEndCallback, - options: Record void>, - ) => Promise; - hookNames: Record; -}; diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts new file mode 100644 index 000000000000..d9c7d680e12b --- /dev/null +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -0,0 +1,25 @@ +export type HandlerWrapperType = { + methodNames: [string]; + hookNames: Record; +}; + +/** + * @typedef {object} ProviderStateHandlerResult + * @property {string} chainId - The current chain ID. + * @property {boolean} isUnlocked - Whether the extension is unlocked or not. + * @property {string} networkVersion - The current network ID. + * @property {string[]} accounts - List of permitted accounts for the specified origin. + */ +export type ProviderStateHandlerResult = { + chainId: string; + isUnlocked: boolean; + networkVersion: string; + accounts: string[]; +}; + +export type getAccountsType = () => Promise; +export type getProviderStateType = ( + origin: string, +) => Promise; +export type getWeb3ShimUsageStateType = (origin: string) => undefined | 1 | 2; +export type setWeb3ShimUsageRecordedType = (origin: string) => void; From 130cd1c6c77440af4e1437d2485a68d111c86c1b Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:53:58 -0400 Subject: [PATCH 03/20] updating the naming case --- .../handlers/handlers-helper.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts index d9c7d680e12b..c732d1c81bab 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -1,3 +1,9 @@ +import type { + PermissionSubjectMetadata, + SubjectType, +} from '@metamask/permission-controller'; +import type { Json } from '@metamask/utils'; + export type HandlerWrapperType = { methodNames: [string]; hookNames: Record; @@ -17,9 +23,17 @@ export type ProviderStateHandlerResult = { accounts: string[]; }; -export type getAccountsType = () => Promise; -export type getProviderStateType = ( +export type SubjectMetadataToAdd = PermissionSubjectMetadata & { + name?: string | null; + subjectType?: SubjectType | null; + extensionId?: string | null; + iconUrl?: string | null; +} & Record; + +export type GetAccountsType = () => Promise; +export type GetProviderStateType = ( origin: string, ) => Promise; -export type getWeb3ShimUsageStateType = (origin: string) => undefined | 1 | 2; -export type setWeb3ShimUsageRecordedType = (origin: string) => void; +export type GetWeb3ShimUsageStateType = (origin: string) => undefined | 1 | 2; +export type SetWeb3ShimUsageRecordedType = (origin: string) => void; +export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void; From bb1c0deba140805aa80c6a16fa4df48312ac198e Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:50:31 -0400 Subject: [PATCH 04/20] remaining the types and rearranging the order --- .../handlers/handlers-helper.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts index c732d1c81bab..66e9c81186e0 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -4,7 +4,7 @@ import type { } from '@metamask/permission-controller'; import type { Json } from '@metamask/utils'; -export type HandlerWrapperType = { +export type HandlerWrapper = { methodNames: [string]; hookNames: Record; }; @@ -30,10 +30,16 @@ export type SubjectMetadataToAdd = PermissionSubjectMetadata & { iconUrl?: string | null; } & Record; -export type GetAccountsType = () => Promise; -export type GetProviderStateType = ( +export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void; +export type GetAccounts = () => Promise; +export type GetProviderState = ( origin: string, ) => Promise; -export type GetWeb3ShimUsageStateType = (origin: string) => undefined | 1 | 2; -export type SetWeb3ShimUsageRecordedType = (origin: string) => void; -export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void; +export type GetWeb3ShimUsageState = (origin: string) => undefined | 1 | 2; +export type HandleWatchAssetRequest = ({ + asset, + type, + origin, + networkClientId, +}: Record) => Promise; +export type SetWeb3ShimUsageRecorded = (origin: string) => void; From 5e3fbcb79b2c12c1df902697588878e8dd1304a0 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:47:39 -0400 Subject: [PATCH 05/20] converting eth-accounts file to typescript --- .../handlers/eth-accounts.ts | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts new file mode 100644 index 000000000000..d53e02fd0c30 --- /dev/null +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -0,0 +1,58 @@ +import { + JsonRpcRequest, + PendingJsonRpcResponse, + JsonRpcEngineNextCallback, + JsonRpcEngineEndCallback, +} from 'json-rpc-engine'; +import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; + +type ethereumAccountsRequestType = { + methodNames: [string]; + implementation: ( + _req: JsonRpcRequest, + res: PendingJsonRpcResponse, + _next: JsonRpcEngineNextCallback, + end: JsonRpcEngineEndCallback, + { getAccounts }: Record Promise>, + ) => Promise; + hookNames: Record; +}; + +/** + * A wrapper for `eth_accounts` that returns an empty array when permission is denied. + */ + +const requestEthereumAccounts: ethereumAccountsRequestType = { + methodNames: [MESSAGE_TYPE.ETH_ACCOUNTS], + implementation: ethAccountsHandler, + hookNames: { + getAccounts: true, + }, +}; +export default requestEthereumAccounts; + +/** + * @typedef {Record} EthAccountsOptions + * @property {Function} getAccounts - Gets the accounts for the requesting + * origin. + */ + +/** + * + * @param _req - The JSON-RPC request object. + * @param res - The JSON-RPC response object. + * @param _next - The json-rpc-engine 'next' callback. + * @param end - The json-rpc-engine 'end' callback. + * @param options - The RPC method hooks. + * @param options.getAccounts + */ +async function ethAccountsHandler( + _req: JsonRpcRequest, + res: PendingJsonRpcResponse, + _next: JsonRpcEngineNextCallback, + end: JsonRpcEngineEndCallback, + { getAccounts }: Record Promise>, +): Promise { + res.result = await getAccounts(); + return end(); +} From aa0c21fd9147412c0fbf27e21075fcddc75b876e Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:46:37 -0400 Subject: [PATCH 06/20] converting eth-accounts file to typescript --- .../handlers/eth-accounts.js | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.js diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.js b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.js deleted file mode 100644 index ab603e7de021..000000000000 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.js +++ /dev/null @@ -1,33 +0,0 @@ -import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; - -/** - * A wrapper for `eth_accounts` that returns an empty array when permission is denied. - */ - -const requestEthereumAccounts = { - methodNames: [MESSAGE_TYPE.ETH_ACCOUNTS], - implementation: ethAccountsHandler, - hookNames: { - getAccounts: true, - }, -}; -export default requestEthereumAccounts; - -/** - * @typedef {Record} EthAccountsOptions - * @property {Function} getAccounts - Gets the accounts for the requesting - * origin. - */ - -/** - * - * @param {import('json-rpc-engine').JsonRpcRequest} _req - The JSON-RPC request object. - * @param {import('json-rpc-engine').JsonRpcResponse} res - The JSON-RPC response object. - * @param {Function} _next - The json-rpc-engine 'next' callback. - * @param {Function} end - The json-rpc-engine 'end' callback. - * @param {EthAccountsOptions} options - The RPC method hooks. - */ -async function ethAccountsHandler(_req, res, _next, end, { getAccounts }) { - res.result = await getAccounts(); - return end(); -} From 7e3ec6b8f3fc14cdb8bc093e2e0f2089f64f4bef Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:16:02 -0400 Subject: [PATCH 07/20] updating json-rpc-engin e with @metamask/json-rpc-engine --- .../handlers/eth-accounts.ts | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index d53e02fd0c30..f1a87af6aeb5 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -1,16 +1,23 @@ -import { - JsonRpcRequest, - PendingJsonRpcResponse, +import type { JsonRpcEngineNextCallback, JsonRpcEngineEndCallback, -} from 'json-rpc-engine'; +} from '@metamask/json-rpc-engine'; +import type { + JsonRpcRequest, + JsonRpcResponse, + JsonRpcParams, + Json, +} from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; -type ethereumAccountsRequestType = { +type EthereumAccountsRequestType< + Params extends JsonRpcParams = JsonRpcParams, + Result extends Json = Json, +> = { methodNames: [string]; implementation: ( - _req: JsonRpcRequest, - res: PendingJsonRpcResponse, + _req: JsonRpcRequest, + res: JsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, { getAccounts }: Record Promise>, @@ -22,7 +29,7 @@ type ethereumAccountsRequestType = { * A wrapper for `eth_accounts` that returns an empty array when permission is denied. */ -const requestEthereumAccounts: ethereumAccountsRequestType = { +const requestEthereumAccounts: EthereumAccountsRequestType = { methodNames: [MESSAGE_TYPE.ETH_ACCOUNTS], implementation: ethAccountsHandler, hookNames: { @@ -46,9 +53,12 @@ export default requestEthereumAccounts; * @param options - The RPC method hooks. * @param options.getAccounts */ -async function ethAccountsHandler( - _req: JsonRpcRequest, - res: PendingJsonRpcResponse, +async function ethAccountsHandler< + Params extends JsonRpcParams = JsonRpcParams, + Result extends Json = Json, +>( + _req: JsonRpcRequest, + res: JsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, { getAccounts }: Record Promise>, From 4fa56f8378b5ce2620369bcd1dfd8afe1a511943 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:07:35 -0400 Subject: [PATCH 08/20] updating type --- .../handlers/eth-accounts.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index f1a87af6aeb5..1051bbe70e98 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -9,21 +9,24 @@ import type { Json, } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; +import { HandlerWrapperType, GetAccountsType } from './handlers-helper'; + +type ethAccountsHandlerOptionsType = { + getAccounts: GetAccountsType; +}; type EthereumAccountsRequestType< Params extends JsonRpcParams = JsonRpcParams, Result extends Json = Json, > = { - methodNames: [string]; implementation: ( _req: JsonRpcRequest, res: JsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, - { getAccounts }: Record Promise>, + { getAccounts }: ethAccountsHandlerOptionsType, ) => Promise; - hookNames: Record; -}; +} & HandlerWrapperType; /** * A wrapper for `eth_accounts` that returns an empty array when permission is denied. @@ -38,12 +41,6 @@ const requestEthereumAccounts: EthereumAccountsRequestType = { }; export default requestEthereumAccounts; -/** - * @typedef {Record} EthAccountsOptions - * @property {Function} getAccounts - Gets the accounts for the requesting - * origin. - */ - /** * * @param _req - The JSON-RPC request object. @@ -51,7 +48,8 @@ export default requestEthereumAccounts; * @param _next - The json-rpc-engine 'next' callback. * @param end - The json-rpc-engine 'end' callback. * @param options - The RPC method hooks. - * @param options.getAccounts + * @param options.getAccounts - Gets the accounts for the requesting + * origin. */ async function ethAccountsHandler< Params extends JsonRpcParams = JsonRpcParams, @@ -61,7 +59,7 @@ async function ethAccountsHandler< res: JsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, - { getAccounts }: Record Promise>, + { getAccounts }: ethAccountsHandlerOptionsType, ): Promise { res.result = await getAccounts(); return end(); From d41fcb05a1eaa56acd9149ef70f9c3395b15086e Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:44:42 -0400 Subject: [PATCH 09/20] updating the typescript file based on new type name --- .../handlers/eth-accounts.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index 1051bbe70e98..9c932c8f3da9 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -9,13 +9,13 @@ import type { Json, } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; -import { HandlerWrapperType, GetAccountsType } from './handlers-helper'; +import { HandlerWrapper, GetAccounts } from './handlers-helper'; -type ethAccountsHandlerOptionsType = { - getAccounts: GetAccountsType; +type EthAccountsHandlerOptions = { + getAccounts: GetAccounts; }; -type EthereumAccountsRequestType< +type EthereumAccountsRequestConstraint< Params extends JsonRpcParams = JsonRpcParams, Result extends Json = Json, > = { @@ -24,15 +24,15 @@ type EthereumAccountsRequestType< res: JsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, - { getAccounts }: ethAccountsHandlerOptionsType, + { getAccounts }: EthAccountsHandlerOptions, ) => Promise; -} & HandlerWrapperType; +} & HandlerWrapper; /** * A wrapper for `eth_accounts` that returns an empty array when permission is denied. */ -const requestEthereumAccounts: EthereumAccountsRequestType = { +const requestEthereumAccounts: EthereumAccountsRequestConstraint = { methodNames: [MESSAGE_TYPE.ETH_ACCOUNTS], implementation: ethAccountsHandler, hookNames: { @@ -59,7 +59,7 @@ async function ethAccountsHandler< res: JsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, - { getAccounts }: ethAccountsHandlerOptionsType, + { getAccounts }: EthAccountsHandlerOptions, ): Promise { res.result = await getAccounts(); return end(); From 419152b14dffd88c8f5f1cc6aec1b4c6a6b34a15 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:48:39 -0400 Subject: [PATCH 10/20] replacing JsonRpcResponse with PendingJsonRpcResponse --- .../handlers/eth-accounts.ts | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index 9c932c8f3da9..b93852e749f3 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -4,9 +4,8 @@ import type { } from '@metamask/json-rpc-engine'; import type { JsonRpcRequest, - JsonRpcResponse, JsonRpcParams, - Json, + PendingJsonRpcResponse, } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; import { HandlerWrapper, GetAccounts } from './handlers-helper'; @@ -14,31 +13,27 @@ import { HandlerWrapper, GetAccounts } from './handlers-helper'; type EthAccountsHandlerOptions = { getAccounts: GetAccounts; }; - type EthereumAccountsRequestConstraint< Params extends JsonRpcParams = JsonRpcParams, - Result extends Json = Json, > = { implementation: ( _req: JsonRpcRequest, - res: JsonRpcResponse, + res: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, { getAccounts }: EthAccountsHandlerOptions, ) => Promise; } & HandlerWrapper; - /** * A wrapper for `eth_accounts` that returns an empty array when permission is denied. */ - -const requestEthereumAccounts: EthereumAccountsRequestConstraint = { +const requestEthereumAccounts = { methodNames: [MESSAGE_TYPE.ETH_ACCOUNTS], implementation: ethAccountsHandler, hookNames: { getAccounts: true, }, -}; +} satisfies EthereumAccountsRequestConstraint; export default requestEthereumAccounts; /** @@ -51,12 +46,9 @@ export default requestEthereumAccounts; * @param options.getAccounts - Gets the accounts for the requesting * origin. */ -async function ethAccountsHandler< - Params extends JsonRpcParams = JsonRpcParams, - Result extends Json = Json, ->( +async function ethAccountsHandler( _req: JsonRpcRequest, - res: JsonRpcResponse, + res: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, { getAccounts }: EthAccountsHandlerOptions, From 9a1c6c972e1a0b24f68a7caeb1f7b83f7d78e7af Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Wed, 27 Mar 2024 17:10:34 -0400 Subject: [PATCH 11/20] updating jsdoc --- .../rpc-method-middleware/handlers/handlers-helper.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts index 66e9c81186e0..3c05429631a4 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -10,11 +10,10 @@ export type HandlerWrapper = { }; /** - * @typedef {object} ProviderStateHandlerResult - * @property {string} chainId - The current chain ID. - * @property {boolean} isUnlocked - Whether the extension is unlocked or not. - * @property {string} networkVersion - The current network ID. - * @property {string[]} accounts - List of permitted accounts for the specified origin. + * @property chainId - The current chain ID. + * @property isUnlocked - Whether the extension is unlocked or not. + * @property networkVersion - The current network ID. + * @property accounts - List of permitted accounts for the specified origin. */ export type ProviderStateHandlerResult = { chainId: string; From a473d283be65c156fdd58861533c662a3ec83c28 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Fri, 29 Mar 2024 10:53:06 -0400 Subject: [PATCH 12/20] adding the types needed for add-ethereum-chain --- .../handlers/handlers-helper.ts | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts index 3c05429631a4..5043dc28b39e 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -1,8 +1,19 @@ +import { + AddApprovalOptions, + ApprovalFlowStartResult, + EndFlowOptions, + StartFlowOptions, +} from '@metamask/approval-controller'; +import { + NetworkClientId, + NetworkConfiguration, + ProviderConfig, +} from '@metamask/network-controller'; import type { PermissionSubjectMetadata, SubjectType, } from '@metamask/permission-controller'; -import type { Json } from '@metamask/utils'; +import type { Hex, Json } from '@metamask/utils'; export type HandlerWrapper = { methodNames: [string]; @@ -29,16 +40,44 @@ export type SubjectMetadataToAdd = PermissionSubjectMetadata & { iconUrl?: string | null; } & Record; +export type UpsertNetworkConfigurationOptions = { + referrer: string; + source: string; + setActive?: boolean; +}; + export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void; +export type EndApprovalFlow = ({ id }: EndFlowOptions) => void; +export type FindNetworkConfigurationBy = ( + rpcInfo: Record, +) => ProviderConfig | null; +export type HasPermissions = (origin: string) => boolean; export type GetAccounts = () => Promise; +export type GetCurrentChainId = () => Hex; +export type GetCurrentRpcUrl = () => string | undefined; +export type GetProviderConfig = () => ProviderConfig; export type GetProviderState = ( origin: string, ) => Promise; export type GetWeb3ShimUsageState = (origin: string) => undefined | 1 | 2; -export type HandleWatchAssetRequest = ({ - asset, - type, - origin, - networkClientId, -}: Record) => Promise; +export type HandleWatchAssetRequest = ( + options: Record, +) => Promise; +export type StartApprovalFlow = ( + options?: StartFlowOptions, +) => ApprovalFlowStartResult; +export type SetNetworkClientIdForDomain = ( + domain: string, + networkClientId: NetworkClientId, +) => void; +export type SetActiveNetwork = ( + networkConfigurationIdOrType: string, +) => Promise; export type SetWeb3ShimUsageRecorded = (origin: string) => void; +export type RequestUserApproval = ( + options?: AddApprovalOptions, +) => Promise; +export type UpsertNetworkConfiguration = ( + networkConfiguration: NetworkConfiguration, + options?: UpsertNetworkConfigurationOptions, +) => Promise; From 042d782d1e72e11ba8d31b7cb5fce7918becb277 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:05:37 -0400 Subject: [PATCH 13/20] adding the types needed for request_accounts file --- .../handlers/handlers-helper.ts | 79 ++++++++++++++++--- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts index 5043dc28b39e..dcb42075ec00 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -10,10 +10,22 @@ import { ProviderConfig, } from '@metamask/network-controller'; import type { + CaveatSpecificationConstraint, + ExtractCaveats, + ExtractPermission, + OriginString, + PermissionSpecificationConstraint, PermissionSubjectMetadata, + RequestedPermissions, + SubjectPermissions, SubjectType, + ValidPermission, } from '@metamask/permission-controller'; import type { Hex, Json } from '@metamask/utils'; +import { + MetaMetricsEventPayload, + MetaMetricsPageOptions, +} from '../../../../../shared/constants/metametrics'; export type HandlerWrapper = { methodNames: [string]; @@ -51,32 +63,73 @@ export type EndApprovalFlow = ({ id }: EndFlowOptions) => void; export type FindNetworkConfigurationBy = ( rpcInfo: Record, ) => ProviderConfig | null; -export type HasPermissions = (origin: string) => boolean; +export type HasPermissions = (origin: OriginString) => boolean; export type GetAccounts = () => Promise; export type GetCurrentChainId = () => Hex; export type GetCurrentRpcUrl = () => string | undefined; +export type GetPermissionsForOrigin< + ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint, +> = ( + origin: OriginString, +) => + | SubjectPermissions< + ValidPermission> + > + | undefined; export type GetProviderConfig = () => ProviderConfig; export type GetProviderState = ( - origin: string, + origin: OriginString, ) => Promise; -export type GetWeb3ShimUsageState = (origin: string) => undefined | 1 | 2; +export type GetUnlockPromise = ( + shouldShowUnlockRequest: boolean, +) => Promise; +export type GetWeb3ShimUsageState = (origin: OriginString) => undefined | 1 | 2; export type HandleWatchAssetRequest = ( options: Record, ) => Promise; -export type StartApprovalFlow = ( - options?: StartFlowOptions, -) => ApprovalFlowStartResult; -export type SetNetworkClientIdForDomain = ( - domain: string, - networkClientId: NetworkClientId, +export type RequestAccountsPermission< + ControllerPermissionSpecification extends PermissionSpecificationConstraint = PermissionSpecificationConstraint, + ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint, +> = ( + subject?: PermissionSubjectMetadata, + requestedPermissions?: RequestedPermissions, + options?: { + id?: string; + preserveExistingPermissions?: boolean; + }, +) => Promise< + [ + SubjectPermissions< + ExtractPermission< + ControllerPermissionSpecification, + ControllerCaveatSpecification + > + >, + { + data?: Record; + id: string; + origin: OriginString; + }, + ] +>; +export type RequestUserApproval = ( + options?: AddApprovalOptions, +) => Promise; +export type SendMetrics = ( + payload: MetaMetricsEventPayload, + options?: MetaMetricsPageOptions, ) => void; export type SetActiveNetwork = ( networkConfigurationIdOrType: string, ) => Promise; -export type SetWeb3ShimUsageRecorded = (origin: string) => void; -export type RequestUserApproval = ( - options?: AddApprovalOptions, -) => Promise; +export type SetNetworkClientIdForDomain = ( + domain: string, + networkClientId: NetworkClientId, +) => void; +export type SetWeb3ShimUsageRecorded = (origin: OriginString) => void; +export type StartApprovalFlow = ( + options?: StartFlowOptions, +) => ApprovalFlowStartResult; export type UpsertNetworkConfiguration = ( networkConfiguration: NetworkConfiguration, options?: UpsertNetworkConfigurationOptions, From 0c1233afa3b9fd904c939df046c71747c2f26d5c Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Mon, 8 Apr 2024 23:59:04 -0400 Subject: [PATCH 14/20] adding the types for switch-ethereum-chain --- .../handlers/handlers-helper.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts index dcb42075ec00..920fefa23d27 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -22,16 +22,26 @@ import type { ValidPermission, } from '@metamask/permission-controller'; import type { Hex, Json } from '@metamask/utils'; +import { InfuraNetworkType } from '@metamask/controller-utils'; import { MetaMetricsEventPayload, MetaMetricsPageOptions, } from '../../../../../shared/constants/metametrics'; +export type ExistingNetworkChainIds = '0x1' | '0xaa36a7' | '0xe704' | '0xe708'; + export type HandlerWrapper = { methodNames: [string]; hookNames: Record; }; +export type NetworkConfigurations = Record< + string, + NetworkConfiguration & { + id: string; + } +>; + /** * @property chainId - The current chain ID. * @property isUnlocked - Whether the extension is unlocked or not. @@ -60,13 +70,15 @@ export type UpsertNetworkConfigurationOptions = { export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void; export type EndApprovalFlow = ({ id }: EndFlowOptions) => void; +export type FindNetworkClientIdByChainId = (chainId: Hex) => NetworkClientId; export type FindNetworkConfigurationBy = ( rpcInfo: Record, ) => ProviderConfig | null; -export type HasPermissions = (origin: OriginString) => boolean; +export type HasPermission = (origin: OriginString) => boolean; export type GetAccounts = () => Promise; export type GetCurrentChainId = () => Hex; export type GetCurrentRpcUrl = () => string | undefined; +export type GetNetworkConfigurations = () => NetworkConfiguration; export type GetPermissionsForOrigin< ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint, > = ( @@ -126,6 +138,7 @@ export type SetNetworkClientIdForDomain = ( domain: string, networkClientId: NetworkClientId, ) => void; +export type SetProviderType = (type: InfuraNetworkType) => Promise; export type SetWeb3ShimUsageRecorded = (origin: OriginString) => void; export type StartApprovalFlow = ( options?: StartFlowOptions, From a6d77dc8c32d44d2e563f1d51077fb4bd4cb5118 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:33:45 -0400 Subject: [PATCH 15/20] updating HandlerWrapper.methodNames type --- .../lib/rpc-method-middleware/handlers/handlers-helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts index 920fefa23d27..35b384e3d565 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts @@ -31,7 +31,7 @@ import { export type ExistingNetworkChainIds = '0x1' | '0xaa36a7' | '0xe704' | '0xe708'; export type HandlerWrapper = { - methodNames: [string]; + methodNames: [string] | string[]; hookNames: Record; }; From 08a8c7ff24e110f54ad55a8e7fe5f6acb2f261cc Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:41:50 -0400 Subject: [PATCH 16/20] changing the file name --- .../handlers/{handlers-helper.ts => types.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/scripts/lib/rpc-method-middleware/handlers/{handlers-helper.ts => types.ts} (100%) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts b/app/scripts/lib/rpc-method-middleware/handlers/types.ts similarity index 100% rename from app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts rename to app/scripts/lib/rpc-method-middleware/handlers/types.ts From 34b4ad7335558ce197350024d1e75a988bba5bde Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:56:59 -0400 Subject: [PATCH 17/20] updating the imports" --- .../lib/rpc-method-middleware/handlers/eth-accounts.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index b93852e749f3..a50bed457a8d 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -1,14 +1,14 @@ import type { - JsonRpcEngineNextCallback, JsonRpcEngineEndCallback, -} from '@metamask/json-rpc-engine'; + JsonRpcEngineNextCallback, +} from 'json-rpc-engine'; import type { JsonRpcRequest, JsonRpcParams, PendingJsonRpcResponse, } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; -import { HandlerWrapper, GetAccounts } from './handlers-helper'; +import { HandlerWrapper, GetAccounts } from './types'; type EthAccountsHandlerOptions = { getAccounts: GetAccounts; From 7575c8f7db87963be4b4c7ff2d02aac52c4c49c5 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:54:43 -0400 Subject: [PATCH 18/20] updating the types file --- .../handlers/eth-accounts.ts | 16 +- .../rpc-method-middleware/handlers/types.ts | 145 ------------------ 2 files changed, 8 insertions(+), 153 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index a50bed457a8d..220cac0c7fa8 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -8,14 +8,13 @@ import type { PendingJsonRpcResponse, } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; -import { HandlerWrapper, GetAccounts } from './types'; +import { HandlerWrapper } from './types'; type EthAccountsHandlerOptions = { - getAccounts: GetAccounts; + getAccounts: () => Promise; }; -type EthereumAccountsRequestConstraint< - Params extends JsonRpcParams = JsonRpcParams, -> = { + +type EthAccountsConstraint = { implementation: ( _req: JsonRpcRequest, res: PendingJsonRpcResponse, @@ -24,17 +23,18 @@ type EthereumAccountsRequestConstraint< { getAccounts }: EthAccountsHandlerOptions, ) => Promise; } & HandlerWrapper; + /** * A wrapper for `eth_accounts` that returns an empty array when permission is denied. */ -const requestEthereumAccounts = { +const ethAccounts = { methodNames: [MESSAGE_TYPE.ETH_ACCOUNTS], implementation: ethAccountsHandler, hookNames: { getAccounts: true, }, -} satisfies EthereumAccountsRequestConstraint; -export default requestEthereumAccounts; +} satisfies EthAccountsConstraint; +export default ethAccounts; /** * diff --git a/app/scripts/lib/rpc-method-middleware/handlers/types.ts b/app/scripts/lib/rpc-method-middleware/handlers/types.ts index 35b384e3d565..f2ae5a3db51c 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/types.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/types.ts @@ -1,149 +1,4 @@ -import { - AddApprovalOptions, - ApprovalFlowStartResult, - EndFlowOptions, - StartFlowOptions, -} from '@metamask/approval-controller'; -import { - NetworkClientId, - NetworkConfiguration, - ProviderConfig, -} from '@metamask/network-controller'; -import type { - CaveatSpecificationConstraint, - ExtractCaveats, - ExtractPermission, - OriginString, - PermissionSpecificationConstraint, - PermissionSubjectMetadata, - RequestedPermissions, - SubjectPermissions, - SubjectType, - ValidPermission, -} from '@metamask/permission-controller'; -import type { Hex, Json } from '@metamask/utils'; -import { InfuraNetworkType } from '@metamask/controller-utils'; -import { - MetaMetricsEventPayload, - MetaMetricsPageOptions, -} from '../../../../../shared/constants/metametrics'; - -export type ExistingNetworkChainIds = '0x1' | '0xaa36a7' | '0xe704' | '0xe708'; - export type HandlerWrapper = { methodNames: [string] | string[]; hookNames: Record; }; - -export type NetworkConfigurations = Record< - string, - NetworkConfiguration & { - id: string; - } ->; - -/** - * @property chainId - The current chain ID. - * @property isUnlocked - Whether the extension is unlocked or not. - * @property networkVersion - The current network ID. - * @property accounts - List of permitted accounts for the specified origin. - */ -export type ProviderStateHandlerResult = { - chainId: string; - isUnlocked: boolean; - networkVersion: string; - accounts: string[]; -}; - -export type SubjectMetadataToAdd = PermissionSubjectMetadata & { - name?: string | null; - subjectType?: SubjectType | null; - extensionId?: string | null; - iconUrl?: string | null; -} & Record; - -export type UpsertNetworkConfigurationOptions = { - referrer: string; - source: string; - setActive?: boolean; -}; - -export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void; -export type EndApprovalFlow = ({ id }: EndFlowOptions) => void; -export type FindNetworkClientIdByChainId = (chainId: Hex) => NetworkClientId; -export type FindNetworkConfigurationBy = ( - rpcInfo: Record, -) => ProviderConfig | null; -export type HasPermission = (origin: OriginString) => boolean; -export type GetAccounts = () => Promise; -export type GetCurrentChainId = () => Hex; -export type GetCurrentRpcUrl = () => string | undefined; -export type GetNetworkConfigurations = () => NetworkConfiguration; -export type GetPermissionsForOrigin< - ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint, -> = ( - origin: OriginString, -) => - | SubjectPermissions< - ValidPermission> - > - | undefined; -export type GetProviderConfig = () => ProviderConfig; -export type GetProviderState = ( - origin: OriginString, -) => Promise; -export type GetUnlockPromise = ( - shouldShowUnlockRequest: boolean, -) => Promise; -export type GetWeb3ShimUsageState = (origin: OriginString) => undefined | 1 | 2; -export type HandleWatchAssetRequest = ( - options: Record, -) => Promise; -export type RequestAccountsPermission< - ControllerPermissionSpecification extends PermissionSpecificationConstraint = PermissionSpecificationConstraint, - ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint, -> = ( - subject?: PermissionSubjectMetadata, - requestedPermissions?: RequestedPermissions, - options?: { - id?: string; - preserveExistingPermissions?: boolean; - }, -) => Promise< - [ - SubjectPermissions< - ExtractPermission< - ControllerPermissionSpecification, - ControllerCaveatSpecification - > - >, - { - data?: Record; - id: string; - origin: OriginString; - }, - ] ->; -export type RequestUserApproval = ( - options?: AddApprovalOptions, -) => Promise; -export type SendMetrics = ( - payload: MetaMetricsEventPayload, - options?: MetaMetricsPageOptions, -) => void; -export type SetActiveNetwork = ( - networkConfigurationIdOrType: string, -) => Promise; -export type SetNetworkClientIdForDomain = ( - domain: string, - networkClientId: NetworkClientId, -) => void; -export type SetProviderType = (type: InfuraNetworkType) => Promise; -export type SetWeb3ShimUsageRecorded = (origin: OriginString) => void; -export type StartApprovalFlow = ( - options?: StartFlowOptions, -) => ApprovalFlowStartResult; -export type UpsertNetworkConfiguration = ( - networkConfiguration: NetworkConfiguration, - options?: UpsertNetworkConfigurationOptions, -) => Promise; From cb2e49a260139f153dfdae4f8dbbc3c5745437d9 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:41:01 -0400 Subject: [PATCH 19/20] changing string type to AccountAddress --- .../lib/rpc-method-middleware/handlers/eth-accounts.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts index 220cac0c7fa8..003cbd88281b 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.ts @@ -8,16 +8,17 @@ import type { PendingJsonRpcResponse, } from '@metamask/utils'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; +import { AccountAddress } from '../../../controllers/account-order'; import { HandlerWrapper } from './types'; type EthAccountsHandlerOptions = { - getAccounts: () => Promise; + getAccounts: () => Promise; }; type EthAccountsConstraint = { implementation: ( _req: JsonRpcRequest, - res: PendingJsonRpcResponse, + res: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, { getAccounts }: EthAccountsHandlerOptions, @@ -48,7 +49,7 @@ export default ethAccounts; */ async function ethAccountsHandler( _req: JsonRpcRequest, - res: PendingJsonRpcResponse, + res: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, { getAccounts }: EthAccountsHandlerOptions, From 54ab60215a6b177ef042015a3c20ac09481d29c5 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:21:55 -0400 Subject: [PATCH 20/20] updating message_type --- app/scripts/lib/rpc-method-middleware/handlers/types.ts | 4 +++- shared/constants/app.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/types.ts b/app/scripts/lib/rpc-method-middleware/handlers/types.ts index f2ae5a3db51c..5b7a2a7494d4 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/types.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/types.ts @@ -1,4 +1,6 @@ +import { MessageType } from '../../../../../shared/constants/app'; + export type HandlerWrapper = { - methodNames: [string] | string[]; + methodNames: [MessageType] | MessageType[]; hookNames: Record; }; diff --git a/shared/constants/app.ts b/shared/constants/app.ts index 70a393626b58..f3717b7cece9 100644 --- a/shared/constants/app.ts +++ b/shared/constants/app.ts @@ -65,6 +65,8 @@ export const MESSAGE_TYPE = { ///: END:ONLY_INCLUDE_IF } as const; +export type MessageType = (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]; + ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) export const SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES = { confirmAccountCreation: 'snap_manageAccounts:confirmAccountCreation',