{"version":3,"file":"rabet.module.cjs","sources":["../../src/modules/rabet.module.ts"],"sourcesContent":["import { ModuleInterface, ModuleType, WalletNetwork } from '../types';\nimport { parseError } from '../utils';\n\ndeclare const window: Window &\n  typeof globalThis & {\n    rabet?: {\n      connect: () => Promise<{ publicKey: string }>;\n      sign: (xdr: string, network: RabetNetwork) => Promise<{ xdr: string }>;\n    };\n  };\n\nexport const RABET_ID = 'rabet';\n\nexport class RabetModule implements ModuleInterface {\n  moduleType: ModuleType = ModuleType.HOT_WALLET;\n\n  productId: string = RABET_ID;\n  productName: string = 'Rabet';\n  productUrl: string = 'https://rabet.io/';\n  productIcon: string = 'https://stellar.creit.tech/wallet-icons/rabet.png';\n\n  async isAvailable(): Promise<boolean> {\n    return typeof window !== 'undefined' && !!window.rabet;\n  }\n\n  async getAddress(): Promise<{ address: string }> {\n    const runChecks = async () => {\n      if (!(await this.isAvailable())) {\n        throw new Error('Rabet is not installed');\n      }\n    };\n\n    return runChecks()\n      .then(() => window.rabet!.connect())\n      .then(({ publicKey }) => ({ address: publicKey }))\n      .catch(e => {\n        throw parseError(e);\n      });\n  }\n\n  async signTransaction(\n    xdr: string,\n    opts?: {\n      networkPassphrase?: string;\n      address?: string;\n      path?: string;\n      submit?: boolean;\n      submitUrl?: string;\n    }\n  ): Promise<{ signedTxXdr: string; signerAddress?: string }> {\n    const runChecks = async () => {\n      if (!(await this.isAvailable())) {\n        throw new Error('Rabet is not installed');\n      }\n\n      if (\n        opts?.address &&\n        opts.networkPassphrase !== WalletNetwork.PUBLIC &&\n        opts.networkPassphrase !== WalletNetwork.TESTNET\n      ) {\n        throw new Error(`Rabet doesn't support the network: ${opts.networkPassphrase}`);\n      }\n\n      if (opts?.address) {\n        console.warn(`Rabet doesn't allow specifying the network that should be used, we skip the value`);\n      }\n    };\n\n    const sign = async () =>\n      window.rabet!.sign(\n        xdr,\n        opts?.networkPassphrase === WalletNetwork.PUBLIC ? RabetNetwork.PUBLIC : RabetNetwork.TESTNET\n      );\n\n    return runChecks()\n      .then(sign)\n      .then(result => ({ signedTxXdr: result?.xdr }))\n      .catch(e => {\n        throw parseError(e);\n      });\n  }\n\n  async signAuthEntry(): Promise<{ signedAuthEntry: string; signerAddress?: string }> {\n    throw {\n      code: -3,\n      message: 'Rabet does not support the \"signAuthEntry\" function',\n    };\n  }\n\n  async signMessage(): Promise<{ signedMessage: string; signerAddress?: string }> {\n    throw {\n      code: -3,\n      message: 'Rabet does not support the \"signMessage\" function',\n    };\n  }\n\n  async getNetwork(): Promise<{ network: string; networkPassphrase: string }> {\n    throw {\n      code: -3,\n      message: 'Rabet does not support the \"getNetwork\" function',\n    };\n  }\n}\n\nexport enum RabetNetwork {\n  PUBLIC = 'mainnet',\n  TESTNET = 'testnet',\n}\n"],"names":["ModuleType","parseError","WalletNetwork","RabetNetwork"],"mappings":";;;;;AAWO,MAAM,QAAQ,GAAG;MAEX,WAAW,CAAA;AAAxB,IAAA,WAAA,GAAA;AACE,QAAA,IAAA,CAAA,UAAU,GAAeA,gBAAU,CAAC,UAAU;QAE9C,IAAS,CAAA,SAAA,GAAW,QAAQ;QAC5B,IAAW,CAAA,WAAA,GAAW,OAAO;QAC7B,IAAU,CAAA,UAAA,GAAW,mBAAmB;QACxC,IAAW,CAAA,WAAA,GAAW,mDAAmD;;AAEzE,IAAA,MAAM,WAAW,GAAA;QACf,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK;;AAGxD,IAAA,MAAM,UAAU,GAAA;AACd,QAAA,MAAM,SAAS,GAAG,YAAW;YAC3B,IAAI,EAAE,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;AAC/B,gBAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;;AAE7C,SAAC;AAED,QAAA,OAAO,SAAS;aACb,IAAI,CAAC,MAAM,MAAM,CAAC,KAAM,CAAC,OAAO,EAAE;AAClC,aAAA,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,MA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