UNPKG

@metamask/providers

Version:

A JavaScript Ethereum provider that connects to the wallet over a stream

55 lines 3.02 kB
import { type Duplex } from "readable-stream"; import type { CAIP294WalletData } from "./CAIP294.cjs"; import type { MetaMaskInpageProviderOptions } from "./MetaMaskInpageProvider.cjs"; import { MetaMaskInpageProvider } from "./MetaMaskInpageProvider.cjs"; import type { BaseProviderInfo } from "./types.cjs"; type InitializeProviderOptions = { /** * The stream used to connect to the wallet. */ connectionStream: Duplex; /** * The EIP-6963 provider info / CAIP-294 wallet data that should be announced if set. */ providerInfo?: BaseProviderInfo; /** * Whether the provider should be set as window.ethereum. */ shouldSetOnWindow?: boolean; /** * Whether the window.web3 shim should be set. */ shouldShimWeb3?: boolean; } & MetaMaskInpageProviderOptions; /** * Initializes a MetaMaskInpageProvider and (optionally) assigns it as window.ethereum. * * @param options - An options bag. * @param options.connectionStream - A Node.js stream. * @param options.maxEventListeners - The maximum number of event listeners. * @param options.providerInfo - The EIP-6963 provider info / CAIP-294 wallet data that should be announced if set. * @param options.shouldSendMetadata - Whether the provider should send page metadata. * @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`. * @returns The initialized provider (whether set or not). */ export declare function initializeProvider({ connectionStream, logger, maxEventListeners, providerInfo, shouldSendMetadata, shouldSetOnWindow, shouldShimWeb3, }: InitializeProviderOptions): MetaMaskInpageProvider; /** * Sets the given provider instance as window.ethereum and dispatches the * 'ethereum#initialized' event on window. * * @param providerInstance - The provider instance. */ export declare function setGlobalProvider(providerInstance: MetaMaskInpageProvider): void; /** * Announces [CAIP-294](https://github.com/ChainAgnostic/CAIPs/blob/bc4942857a8e04593ed92f7dc66653577a1c4435/CAIPs/caip-294.md) wallet data according to build type and browser. * Until released to stable, `extensionId` is only set in the `metamask_getProviderState` result if the build type is `flask`. * `extensionId` is included if browser is chromium based because it is only useable by browsers that support [externally_connectable](https://developer.chrome.com/docs/extensions/reference/manifest/externally-connectable). * * @param provider - The provider {@link MetaMaskInpageProvider} used for retrieving `extensionId`. * @param providerInfo - The provider info {@link BaseProviderInfo} that should be announced if set. */ export declare function announceCaip294WalletData(provider: MetaMaskInpageProvider, providerInfo: CAIP294WalletData): Promise<void>; export {}; //# sourceMappingURL=initializeInpageProvider.d.cts.map