import { OfflineAminoSigner } from '@cosmjs/amino'; import { OfflineDirectSigner } from '@cosmjs/proto-signing'; /** * The two signer types. */ type SignerType = 'amino' | 'direct'; /** * The types of origins accepted. */ type Origin = string | RegExp; /** * A message sent from the iframe to the parent requesting a method be called. */ type RequestMethodCallMessage = { id: string; method: string; params: any[]; chainId?: string; signerType?: SignerType; /** * @deprecated Backwards compatibility. */ signType?: SignerType; internal?: boolean; }; type RequestMethodCallMessageNoId = Omit; /** * A message sent from the parent to the iframe with the result of a method * call. */ type MethodCallResultMessage = { id: string; } & ({ type: 'success'; response: T; error?: never; } | { type: 'error'; error: string; response?: never; }); type MethodCallResultMessageNoId = Omit, 'id'>; /** * The result with metadata from calling a parent method. */ type CalledParentMethodResult = { /** * The parent's result for the requested method. */ result: T; /** * The origin of the parent response message, which should be the parent's * origin. This is pulled directly from the `MessageEvent`. */ origin: string; }; /** * The override handler that throws an error, defaulting to "Handled by outer * wallet." */ type OverrideHandlerError = { type: 'error'; error?: string; }; /** * The override handler that returns a specific value. */ type OverrideHandlerSuccess = { type: 'success'; value?: unknown; }; /** * The override handler that calls the method normally. */ type OverrideHandlerCall = { type: 'call'; }; /** * An override handler defines how a message from the iframe should be handled * by the parent and is called with the original method's parameters. This is * set when listening. If nothing is returned from an override handler, an error * will be thrown with the message "Handled by parent." */ type OverrideHandler = OverrideHandlerError | OverrideHandlerSuccess | OverrideHandlerCall | undefined | void; /** * Object containing override handlers for methods. */ type Overrides = Record OverrideHandler | Promise | undefined>; /** * Options passed when setting up listening by the parent. */ type ListenOptions = { /** * The iframe HTML element to listen to. */ iframe: HTMLIFrameElement; /** * The client or object whose methods to call. */ target: Record; /** * A function to retrieve the offline direct signer. */ getOfflineSignerDirect: (chainId: string) => OfflineDirectSigner | Promise; /** * A function to retrieve the offline amino signer. */ getOfflineSignerAmino: (chainId: string) => OfflineAminoSigner | Promise; /** * Overrides applied to non-signer message requests. */ nonSignerOverrides?: Overrides | (() => Overrides) | (() => Promise); /** * Overrides applied to signer message requests. */ signerOverrides?: Overrides | ((chainId: string) => Overrides) | ((chainId: string) => Promise); /** * Restrict iframe origins that are allowed to connect to this listening * instance of Cosmiframe. If undefined or empty, all origins are allowed. * * It is safe to allow all origins since the current window is the listening * parent and is responsible for handling signing requests from the iframe. * The iframe, on the other hand, should not trust us. */ origins?: Origin[]; /** * Optionally set a name and imageUrl that represent the parent window to be * shown by the iframe. */ metadata?: ParentMetadata; }; type ParentMetadata = { name?: string; imageUrl?: string; }; /** * Internal methods. */ declare enum InternalMethod { IsCosmiframe = "isCosmiframe", GetMetadata = "getMetadata" } export { type CalledParentMethodResult, InternalMethod, type ListenOptions, type MethodCallResultMessage, type MethodCallResultMessageNoId, type Origin, type OverrideHandler, type OverrideHandlerCall, type OverrideHandlerError, type OverrideHandlerSuccess, type Overrides, type ParentMetadata, type RequestMethodCallMessage, type RequestMethodCallMessageNoId, type SignerType };