UNPKG

@creit.tech/stellar-wallets-kit

Version:
98 lines (97 loc) 2.85 kB
import { ModuleType } from "../../types/mod.js"; import { parseError } from "../utils.js"; export const BITGET_WALLET_ID = "BitgetWallet"; export class BitgetModule { constructor() { Object.defineProperty(this, "moduleType", { enumerable: true, configurable: true, writable: true, value: ModuleType.HOT_WALLET }); Object.defineProperty(this, "productId", { enumerable: true, configurable: true, writable: true, value: BITGET_WALLET_ID }); Object.defineProperty(this, "productName", { enumerable: true, configurable: true, writable: true, value: "Bitget Wallet" }); Object.defineProperty(this, "productUrl", { enumerable: true, configurable: true, writable: true, value: "https://web3.bitget.com" }); Object.defineProperty(this, "productIcon", { enumerable: true, configurable: true, writable: true, value: "https://stellar.creit.tech/wallet-icons/bitget.png" }); Object.defineProperty(this, "provider", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.provider = window.bitkeep?.stellar; } async runChecks() { if (!(await this.isAvailable())) { throw new Error(`${this.productName} is not connected`); } } async isAvailable() { return !!this.provider; } async getAddress() { try { await this.runChecks(); const address = await this.provider.connect(); return { address }; } catch (e) { throw parseError(e); } } async signMessage(message, opts) { try { await this.runChecks(); const signatureHex = await this.provider.signMessage(message, opts?.address); return { signedMessage: signatureHex }; } catch (e) { throw parseError(e); } } async signTransaction(xdr, opts) { try { await this.runChecks(); const signedTxXdr = await this.provider.signTransaction(xdr, opts); return { signedTxXdr }; } catch (e) { throw parseError(e); } } async signAuthEntry() { throw { code: -3, message: `${this.productName} does not support the "signAuthEntry" function`, }; } async getNetwork() { try { await this.runChecks(); return this.provider.network(); } catch (e) { throw parseError(e); } } }