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