@airgap/beacon-dapp
Version:
Use this package on your dApp to instanciate a DAppClient object and communicate to wallets.
210 lines (209 loc) • 8.64 kB
TypeScript
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<void>;
}
interface RequestSentInfo {
extraInfo: ExtraInfo;
walletInfo: WalletInfo;
}
/**
* The type of the payload of the different BeaconEvents
*/
export interface BeaconEventType {
[]: RequestSentInfo;
[]: {
account: AccountInfo;
output: PermissionResponseOutput;
blockExplorer: BlockExplorer;
connectionContext: ConnectionContext;
walletInfo: WalletInfo;
};
[]: {
errorResponse: ErrorResponse;
walletInfo: WalletInfo;
};
[]: RequestSentInfo;
[]: {
account: AccountInfo;
output: ProofOfEventChallengeResponseOutput;
blockExplorer: BlockExplorer;
connectionContext: ConnectionContext;
walletInfo: WalletInfo;
};
[]: {
errorResponse: ErrorResponse;
walletInfo: WalletInfo;
};
[]: RequestSentInfo;
[]: {
account: AccountInfo;
output: SimulatedProofOfEventChallengeResponseOutput;
blockExplorer: BlockExplorer;
connectionContext: ConnectionContext;
walletInfo: WalletInfo;
};
[]: {
errorResponse: ErrorResponse;
walletInfo: WalletInfo;
};
[]: RequestSentInfo;
[]: {
account: AccountInfo;
output: OperationResponseOutput;
blockExplorer: BlockExplorer;
connectionContext: ConnectionContext;
walletInfo: WalletInfo;
};
[]: {
errorResponse: ErrorResponse;
walletInfo: WalletInfo;
errorMessages: Record<string, Record<string | number, string>>;
};
[]: RequestSentInfo;
[]: {
output: SignPayloadResponseOutput;
connectionContext: ConnectionContext;
walletInfo: WalletInfo;
};
[]: {
errorResponse: ErrorResponse;
walletInfo: WalletInfo;
};
[]: RequestSentInfo;
[]: RequestSentInfo;
[]: {
network: Network;
output: BroadcastResponseOutput;
blockExplorer: BlockExplorer;
connectionContext: ConnectionContext;
walletInfo: WalletInfo;
};
[]: {
errorResponse: ErrorResponse;
walletInfo: WalletInfo;
};
[]: {
message: AcknowledgeResponse;
extraInfo: ExtraInfo;
walletInfo: WalletInfo;
};
[]: undefined;
[]: undefined;
[]: AccountInfo;
[]: Transport;
[]: undefined;
[]: string;
[]: undefined;
[]: {
walletInfo?: WalletInfo;
};
[]: ('alert' | 'toast')[] | undefined;
[]: {
p2pPeerInfo: Promise<string>;
postmessagePeerInfo: Promise<string>;
walletConnectPeerInfo: Promise<string>;
networkType: NetworkType;
abortedHandler?(): void;
disclaimerText?: string;
analytics: AnalyticsInterface;
featuredWallets?: string[];
substratePairing?: boolean;
};
[]: ExtendedPostMessagePairingResponse | ExtendedP2PPairingResponse | ExtendedWalletConnectPairingResponse;
[]: string;
[]: {
text: string;
buttons?: AlertButton[];
};
[]: undefined;
[]: undefined;
[]: undefined;
}
export type BeaconEventHandlerFunction<T = unknown> = (data: T, eventCallback?: AlertButton[]) => void | Promise<void>;
/**
* The default event handlers
*/
export declare const defaultEventCallbacks: {
[]: BeaconEventHandlerFunction<BeaconEventType[key]>;
};
/**
* @internalapi
*
* Handles beacon events
*/
export declare class BeaconEventHandler {
private readonly callbackMap;
constructor(eventsToOverride?: {
[]?: {
handler: BeaconEventHandlerFunction<BeaconEventType[key]>;
};
}, 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<K extends BeaconEvent>(event: K, eventCallback: BeaconEventHandlerFunction<BeaconEventType[K]>): Promise<void>;
/**
* Emit a beacon event
*
* @param event The event being emitted
* @param data The data to be emit
*/
emit<K extends BeaconEvent>(event: K, data?: BeaconEventType[K], eventCallback?: AlertButton[]): Promise<void>;
/**
* 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 {};