diff --git a/jest.config.js b/jest.config.js index caa40f12..e7856371 100644 --- a/jest.config.js +++ b/jest.config.js @@ -45,10 +45,10 @@ const baseConfig = { // An object that configures minimum threshold enforcement for coverage results coverageThreshold: { global: { - branches: 70.68, - functions: 72.32, - lines: 71.39, - statements: 71.51, + branches: 70, + functions: 72.07, + lines: 70.82, + statements: 70.95, }, }, diff --git a/src/extension-provider/createExternalExtensionProvider.test.ts b/src/extension-provider/createExternalExtensionProvider.test.ts index fe95b567..55906558 100644 --- a/src/extension-provider/createExternalExtensionProvider.test.ts +++ b/src/extension-provider/createExternalExtensionProvider.test.ts @@ -1,9 +1,6 @@ import type { JsonRpcRequest } from '@metamask/utils'; -import { - createExternalExtensionProvider, - getBuildType, -} from './createExternalExtensionProvider'; +import { createExternalExtensionProvider } from './createExternalExtensionProvider'; import config from './external-extension-config.json'; import { MockPort } from '../../test/mocks/MockPort'; import type { BaseProvider } from '../BaseProvider'; @@ -99,23 +96,6 @@ async function getInitializedProvider({ return { provider, port, onWrite }; } -describe('getBuildType', () => { - const testCases = [ - { payload: 'io.metamask.beta', expected: 'beta' }, - { payload: 'io.metamask', expected: 'stable' }, - { payload: 'io.metamask.flask', expected: 'flask' }, - { payload: 'io.metamask.unknown', expected: undefined }, - ]; - - it.each(testCases)( - 'should return $expected for payload $payload', - ({ payload, expected }) => { - const result = getBuildType(payload); - expect(result).toBe(expected); - }, - ); -}); - describe('createExternalExtensionProvider', () => { it('can be called and not throw', () => { // `global.chrome.runtime` mock setup by `jest-chrome` in `jest.setup.browser.js` diff --git a/src/extension-provider/createExternalExtensionProvider.ts b/src/extension-provider/createExternalExtensionProvider.ts index 2bca8865..5d545b53 100644 --- a/src/extension-provider/createExternalExtensionProvider.ts +++ b/src/extension-provider/createExternalExtensionProvider.ts @@ -82,18 +82,3 @@ function getExtensionId(typeOrId: ExtensionType) { return ids[typeOrId as keyof typeof ids] ?? typeOrId; } - -/** - * Gets the build type for the given domain name identifier. - * - * @param rdns - The reverse syntax domain name identifier for the wallet. - * @returns The type or ID. - */ -export function getBuildType(rdns: string): string | undefined { - const rndsToIdDefinition: Record = { - 'io.metamask': 'stable', - 'io.metamask.beta': 'beta', - 'io.metamask.flask': 'flask', - }; - return rndsToIdDefinition[rdns]; -} diff --git a/src/initializeInpageProvider.test.ts b/src/initializeInpageProvider.test.ts index 2de3642d..fc0db872 100644 --- a/src/initializeInpageProvider.test.ts +++ b/src/initializeInpageProvider.test.ts @@ -1,5 +1,4 @@ import { announceWallet, type CAIP294WalletData } from './CAIP294'; -import { getBuildType } from './extension-provider/createExternalExtensionProvider'; import { announceCaip294WalletData, setGlobalProvider, @@ -58,48 +57,31 @@ describe('announceCaip294WalletData', () => { jest.clearAllMocks(); }); - describe('build type is not flask', () => { - it('should not announce wallet if build type is not flask', async () => { - (getBuildType as jest.Mock).mockReturnValue('stable'); + it('should announce wallet with caip-348 target for chromium browsers', async () => { + const extensionId = 'test-extension-id'; + (mockProvider.request as jest.Mock).mockReturnValue({ extensionId }); - await announceCaip294WalletData(mockProvider, mockProviderInfo); + await announceCaip294WalletData(mockProvider, mockProviderInfo); - expect(getBuildType).toHaveBeenCalledWith(mockProviderInfo.rdns); - expect(announceWallet).not.toHaveBeenCalled(); + expect(announceWallet).toHaveBeenCalledWith({ + ...mockProviderInfo, + targets: [ + { + type: 'caip-348', + value: extensionId, + }, + ], }); }); - describe('build type is flask', () => { - it('should announce wallet with caip-348 target for chromium browsers', async () => { - const extensionId = 'test-extension-id'; - (getBuildType as jest.Mock).mockReturnValue('flask'); - (mockProvider.request as jest.Mock).mockReturnValue({ extensionId }); + it('should announce wallet without caip-348 target for firefox browser', async () => { + (mockProvider.request as jest.Mock).mockReturnValue({}); - await announceCaip294WalletData(mockProvider, mockProviderInfo); + await announceCaip294WalletData(mockProvider, mockProviderInfo); - expect(getBuildType).toHaveBeenCalledWith(mockProviderInfo.rdns); - expect(announceWallet).toHaveBeenCalledWith({ - ...mockProviderInfo, - targets: [ - { - type: 'caip-348', - value: extensionId, - }, - ], - }); - }); - - it('should announce wallet without caip-348 target for firefox browser', async () => { - (getBuildType as jest.Mock).mockReturnValue('flask'); - (mockProvider.request as jest.Mock).mockReturnValue({}); - - await announceCaip294WalletData(mockProvider, mockProviderInfo); - - expect(getBuildType).toHaveBeenCalledWith(mockProviderInfo.rdns); - expect(announceWallet).toHaveBeenCalledWith({ - ...mockProviderInfo, - targets: [], - }); + expect(announceWallet).toHaveBeenCalledWith({ + ...mockProviderInfo, + targets: [], }); }); }); diff --git a/src/initializeInpageProvider.ts b/src/initializeInpageProvider.ts index b56d76d3..0f9a13bf 100644 --- a/src/initializeInpageProvider.ts +++ b/src/initializeInpageProvider.ts @@ -3,7 +3,6 @@ import { type Duplex } from 'readable-stream'; import type { CAIP294WalletData } from './CAIP294'; import { announceWallet } from './CAIP294'; import { announceProvider as announceEip6963Provider } from './EIP6963'; -import { getBuildType } from './extension-provider/createExternalExtensionProvider'; import type { MetaMaskInpageProviderOptions } from './MetaMaskInpageProvider'; import { MetaMaskInpageProvider } from './MetaMaskInpageProvider'; import { shimWeb3 } from './shimWeb3'; @@ -29,6 +28,11 @@ type InitializeProviderOptions = { * Whether the window.web3 shim should be set. */ shouldShimWeb3?: boolean; + + /** + * Whether the provider announce a CAIP-294 event. + */ + shouldAnnounceCaip294?: boolean; } & MetaMaskInpageProviderOptions; /** @@ -42,6 +46,7 @@ type InitializeProviderOptions = { * @param options.shouldSetOnWindow - Whether the provider should be set as window.ethereum. * @param options.shouldShimWeb3 - Whether a window.web3 shim should be injected. * @param options.logger - The logging API to use. Default: `console`. + * @param options.shouldAnnounceCaip294 - Whether the provider should announce itself. * @returns The initialized provider (whether set or not). */ export function initializeProvider({ @@ -52,6 +57,7 @@ export function initializeProvider({ shouldSendMetadata = true, shouldSetOnWindow = true, shouldShimWeb3 = false, + shouldAnnounceCaip294 = true, }: InitializeProviderOptions): MetaMaskInpageProvider { const provider = new MetaMaskInpageProvider(connectionStream, { logger, @@ -74,8 +80,11 @@ export function initializeProvider({ info: providerInfo, provider: proxiedProvider, }); - // eslint-disable-next-line no-void - void announceCaip294WalletData(provider, providerInfo); + + if (shouldAnnounceCaip294) { + // eslint-disable-next-line no-void + void announceCaip294WalletData(provider, providerInfo); + } } if (shouldSetOnWindow) { @@ -121,11 +130,6 @@ export async function announceCaip294WalletData( provider: MetaMaskInpageProvider, providerInfo: CAIP294WalletData, ): Promise { - const buildType = getBuildType(providerInfo.rdns); - if (buildType !== 'flask') { - return; - } - const providerState = await provider.request<{ extensionId?: string }>({ method: 'metamask_getProviderState', });