@metamask/providers
Version:
A JavaScript Ethereum provider that connects to the wallet over a stream
76 lines • 2.64 kB
text/typescript
import type { BaseProviderInfo } from "./types.mjs";
/**
* Describes the possible CAIP-294 event names
*/
export declare enum CAIP294EventNames {
Announce = "caip294:wallet_announce",
Prompt = "caip294:wallet_prompt"
}
declare global {
interface WindowEventMap {
[CAIP294EventNames.Prompt]: CAIP294RequestWalletEvent;
[CAIP294EventNames.Announce]: CAIP294AnnounceWalletEvent;
}
}
/**
* Represents the assets needed to display and identify a wallet.
* @type CAIP294WalletData
* @property uuid - A locally unique identifier for the wallet. MUST be a v4 UUID.
* @property name - The name of the wallet.
* @property icon - The icon for the wallet. MUST be data URI.
* @property rdns - The reverse syntax domain name identifier for the wallet.
* @property extensionId - The canonical extension ID of the wallet provider for the active browser.
*/
export type CAIP294WalletData = BaseProviderInfo & {
extensionId?: string | undefined;
};
/**
* Event for requesting a wallet.
*
* @type CAIP294RequestWalletEvent
* @property detail - The detail object of the event.
* @property type - The name of the event.
*/
export type CAIP294RequestWalletEvent = CustomEvent & {
detail: {
id: number;
jsonrpc: '2.0';
method: 'wallet_prompt';
params: Record<string, any>;
};
type: CAIP294EventNames.Prompt;
};
/**
* Event for announcing a wallet.
*
* @type CAIP294AnnounceWalletEvent
* @property detail - The detail object of the event.
* @property type - The name of the event.
*/
export type CAIP294AnnounceWalletEvent = CustomEvent & {
detail: {
id: number;
jsonrpc: '2.0';
method: 'wallet_announce';
params: CAIP294WalletData;
};
type: CAIP294EventNames.Announce;
};
/**
* Intended to be used by a wallet. Announces a wallet by dispatching
* an {@link CAIP294AnnounceWalletEvent}, and listening for
* {@link CAIP294RequestWalletEvent} to re-announce.
*
* @throws If the {@link CAIP294WalletData} is invalid.
* @param walletData - The {@link CAIP294WalletData} to announce.
*/
export declare function announceWallet(walletData: CAIP294WalletData): void;
/**
* Intended to be used by a dapp. Forwards announced wallet to the
* provided handler by listening for * {@link CAIP294AnnounceWalletEvent},
* and dispatches an {@link CAIP294RequestWalletEvent}.
*
* @param handleWallet - A function that handles an announced wallet.
*/
export declare function requestWallet<HandlerReturnType>(handleWallet: (walletData: CAIP294WalletData) => HandlerReturnType): void;
//# sourceMappingURL=CAIP294.d.mts.map