import { BlockExplorer, AlertButton } from '@airgap/beacon-dapp'; import { ExtendedPostMessagePairingResponse, ExtendedP2PPairingResponse, AccountInfo, ErrorResponse, PermissionResponseOutput, OperationResponseOutput, BroadcastResponseOutput, SignPayloadResponseOutput, Network, ConnectionContext, NetworkType, AcknowledgeResponse, WalletInfo, ExtendedWalletConnectPairingResponse, AnalyticsInterface, ProofOfEventChallengeResponseOutput, SimulatedProofOfEventChallengeResponseOutput } from '@airgap/beacon-types'; import { Transport } from '@airgap/beacon-core'; /** * The different events that can be emitted by the beacon-sdk */ export declare enum BeaconEvent { PERMISSION_REQUEST_SENT = "PERMISSION_REQUEST_SENT", PERMISSION_REQUEST_SUCCESS = "PERMISSION_REQUEST_SUCCESS", PERMISSION_REQUEST_ERROR = "PERMISSION_REQUEST_ERROR", PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT = "PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT", PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS = "PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS", PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR = "PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR", SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT = "SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT", SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS = "SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS", SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR = "SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR", OPERATION_REQUEST_SENT = "OPERATION_REQUEST_SENT", OPERATION_REQUEST_SUCCESS = "OPERATION_REQUEST_SUCCESS", OPERATION_REQUEST_ERROR = "OPERATION_REQUEST_ERROR", SIGN_REQUEST_SENT = "SIGN_REQUEST_SENT", SIGN_REQUEST_SUCCESS = "SIGN_REQUEST_SUCCESS", SIGN_REQUEST_ERROR = "SIGN_REQUEST_ERROR", BLOCKCHAIN_REQUEST_SUCCESS = "BLOCKCHAIN_REQUEST_SUCCESS", BROADCAST_REQUEST_SENT = "BROADCAST_REQUEST_SENT", BROADCAST_REQUEST_SUCCESS = "BROADCAST_REQUEST_SUCCESS", BROADCAST_REQUEST_ERROR = "BROADCAST_REQUEST_ERROR", ACKNOWLEDGE_RECEIVED = "ACKNOWLEDGE_RECEIVED", LOCAL_RATE_LIMIT_REACHED = "LOCAL_RATE_LIMIT_REACHED", NO_PERMISSIONS = "NO_PERMISSIONS", ACTIVE_ACCOUNT_SET = "ACTIVE_ACCOUNT_SET", ACTIVE_TRANSPORT_SET = "ACTIVE_TRANSPORT_SET", SHOW_PREPARE = "SHOW_PREPARE", HIDE_UI = "HIDE_UI", INVALID_ACTIVE_ACCOUNT_STATE = "INVALID_ACTIVE_ACCOUNT_STATE", INVALID_ACCOUNT_DEACTIVATED = "INVALID_ACCOUNT_DEACTIVATED", PAIR_INIT = "PAIR_INIT", PAIR_SUCCESS = "PAIR_SUCCESS", CHANNEL_CLOSED = "CHANNEL_CLOSED", GENERIC_ERROR = "GENERIC_ERROR", OPEN_BUG_REPORT = "OPEN_BUG_REPORT", RELAYER_ERROR = "RELAYER_ERROR", INTERNAL_ERROR = "INTERNAL_ERROR", UNKNOWN = "UNKNOWN" } export interface ExtraInfo { resetCallback?(): Promise; } interface RequestSentInfo { extraInfo: ExtraInfo; walletInfo: WalletInfo; } /** * The type of the payload of the different BeaconEvents */ export interface BeaconEventType { [BeaconEvent.PERMISSION_REQUEST_SENT]: RequestSentInfo; [BeaconEvent.PERMISSION_REQUEST_SUCCESS]: { account: AccountInfo; output: PermissionResponseOutput; blockExplorer: BlockExplorer; connectionContext: ConnectionContext; walletInfo: WalletInfo; }; [BeaconEvent.PERMISSION_REQUEST_ERROR]: { errorResponse: ErrorResponse; walletInfo: WalletInfo; }; [BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT]: RequestSentInfo; [BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS]: { account: AccountInfo; output: ProofOfEventChallengeResponseOutput; blockExplorer: BlockExplorer; connectionContext: ConnectionContext; walletInfo: WalletInfo; }; [BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR]: { errorResponse: ErrorResponse; walletInfo: WalletInfo; }; [BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT]: RequestSentInfo; [BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS]: { account: AccountInfo; output: SimulatedProofOfEventChallengeResponseOutput; blockExplorer: BlockExplorer; connectionContext: ConnectionContext; walletInfo: WalletInfo; }; [BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR]: { errorResponse: ErrorResponse; walletInfo: WalletInfo; }; [BeaconEvent.OPERATION_REQUEST_SENT]: RequestSentInfo; [BeaconEvent.OPERATION_REQUEST_SUCCESS]: { account: AccountInfo; output: OperationResponseOutput; blockExplorer: BlockExplorer; connectionContext: ConnectionContext; walletInfo: WalletInfo; }; [BeaconEvent.OPERATION_REQUEST_ERROR]: { errorResponse: ErrorResponse; walletInfo: WalletInfo; errorMessages: Record>; }; [BeaconEvent.SIGN_REQUEST_SENT]: RequestSentInfo; [BeaconEvent.SIGN_REQUEST_SUCCESS]: { output: SignPayloadResponseOutput; connectionContext: ConnectionContext; walletInfo: WalletInfo; }; [BeaconEvent.SIGN_REQUEST_ERROR]: { errorResponse: ErrorResponse; walletInfo: WalletInfo; }; [BeaconEvent.BLOCKCHAIN_REQUEST_SUCCESS]: RequestSentInfo; [BeaconEvent.BROADCAST_REQUEST_SENT]: RequestSentInfo; [BeaconEvent.BROADCAST_REQUEST_SUCCESS]: { network: Network; output: BroadcastResponseOutput; blockExplorer: BlockExplorer; connectionContext: ConnectionContext; walletInfo: WalletInfo; }; [BeaconEvent.BROADCAST_REQUEST_ERROR]: { errorResponse: ErrorResponse; walletInfo: WalletInfo; }; [BeaconEvent.ACKNOWLEDGE_RECEIVED]: { message: AcknowledgeResponse; extraInfo: ExtraInfo; walletInfo: WalletInfo; }; [BeaconEvent.LOCAL_RATE_LIMIT_REACHED]: undefined; [BeaconEvent.NO_PERMISSIONS]: undefined; [BeaconEvent.ACTIVE_ACCOUNT_SET]: AccountInfo; [BeaconEvent.ACTIVE_TRANSPORT_SET]: Transport; [BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: undefined; [BeaconEvent.GENERIC_ERROR]: string; [BeaconEvent.INVALID_ACCOUNT_DEACTIVATED]: undefined; [BeaconEvent.SHOW_PREPARE]: { walletInfo?: WalletInfo; }; [BeaconEvent.HIDE_UI]: ('alert' | 'toast')[] | undefined; [BeaconEvent.PAIR_INIT]: { p2pPeerInfo: Promise; postmessagePeerInfo: Promise; walletConnectPeerInfo: Promise; networkType: NetworkType; abortedHandler?(): void; disclaimerText?: string; analytics: AnalyticsInterface; featuredWallets?: string[]; substratePairing?: boolean; }; [BeaconEvent.PAIR_SUCCESS]: ExtendedPostMessagePairingResponse | ExtendedP2PPairingResponse | ExtendedWalletConnectPairingResponse; [BeaconEvent.CHANNEL_CLOSED]: string; [BeaconEvent.INTERNAL_ERROR]: { text: string; buttons?: AlertButton[]; }; [BeaconEvent.OPEN_BUG_REPORT]: undefined; [BeaconEvent.RELAYER_ERROR]: undefined; [BeaconEvent.UNKNOWN]: undefined; } export type BeaconEventHandlerFunction = (data: T, eventCallback?: AlertButton[]) => void | Promise; /** * The default event handlers */ export declare const defaultEventCallbacks: { [key in BeaconEvent]: BeaconEventHandlerFunction; }; /** * @internalapi * * Handles beacon events */ export declare class BeaconEventHandler { private readonly callbackMap; constructor(eventsToOverride?: { [key in BeaconEvent]?: { handler: BeaconEventHandlerFunction; }; }, overrideAll?: boolean); /** * A method to subscribe to a specific beacon event and register a callback * * @param event The event being emitted * @param eventCallback The callback that will be invoked */ on(event: K, eventCallback: BeaconEventHandlerFunction): Promise; /** * Emit a beacon event * * @param event The event being emitted * @param data The data to be emit */ emit(event: K, data?: BeaconEventType[K], eventCallback?: AlertButton[]): Promise; /** * Override beacon event default callbacks. This can be used to disable default alert/toast behaviour * * @param eventsToOverride An object with the events to override */ private overrideDefaults; /** * Set all event callbacks to a specific handler. */ private setAllHandlers; } export {};