text: "use strict";
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
      function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
      return new (P || (P = Promise))(function (resolve, reject) {
          function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
          function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
          function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
          step((generator = generator.apply(thisArg, _arguments || [])).next());
      });
  };
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.Coin98WalletAdapter = exports.Coin98WalletName = void 0;
  const wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
  const web3_js_1 = require("@solana/web3.js");
  const bs58_1 = __importDefault(require("bs58"));
  exports.Coin98WalletName = 'Coin98';
  class Coin98WalletAdapter extends wallet_adapter_base_1.BaseMessageSignerWalletAdapter {
      constructor(config = {}) {
          super();
          this.name = exports.Coin98WalletName;
          this.url = 'https://coin98.com';
          this.icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA3NiA3NSI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImEiIHgxPSIxMDEuNjgxJSIgeDI9Ii0xLjU1NyUiIHkxPSIxNS4yNjglIiB5Mj0iODQuOTE3JSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiNGMUQ5NjEiLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjQ0RBMTQ2Ii8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogIDwvZGVmcz4KICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgPHJlY3Qgd2lkd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ined' || typeof document === 'undefined'
              ? wallet_adapter_base_1.WalletReadyState.Unsupported
              : wallet_adapter_base_1.WalletReadyState.NotDetected;
          this._connecting = false;
          this._wallet = null;
          this._publicKey = null;
          if (this._readyState !== wallet_adapter_base_1.WalletReadyState.Unsupported) {
              (0, wallet_adapter_base_1.scopePollingDetectionStrategy)(() => {
                  var _a;
                  if ((_a = window.coin98) === null || _a === void 0 ? void 0 : _a.sol) {
                      this._readyState = wallet_adapter_base_1.WalletReadyState.Installed;
                      this.emit('readyStateChange', this._readyState);
                      return true;
                  }
                  return false;
              });
          }
      }
      get publicKey() {
          return this._publicKey;
      }
      get connecting() {
          return this._connecting;
      }
      get connected() {
          var _a;
          return !!((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.isConnected());
      }
      get readyState() {
          return this._readyState;
      }
      connect() {
          return __awaiter(this, void 0, void 0, function* () {
              try {
                  if (this.connected || this.connecting)
                      return;
                  if (this._readyState !== wallet_adapter_base_1.WalletReadyState.Installed)
                      throw new wallet_adapter_base_1.WalletNotReadyError();
                  this._connecting = true;
                  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
                  const wallet = window.coin98.sol;
                  let account;
                  try {
                      [account] = yield wallet.connect();
                  }
                  catch (error) {
                      throw new wallet_adapter_base_1.WalletAccountError(error === null || error === void 0 ? void 0 : error.message, error);
                  }
                  let publicKey;
                  try {
                      publicKey = new web3_js_1.PublicKey(account);
                  }
                  catch (error) {
                      throw new wallet_adapter_base_1.WalletPublicKeyError(error === null || error === void 0 ? void 0 : error.message, error);
                  }
                  this._wallet = wallet;
                  this._publicKey = publicKey;
                  this.emit('connect', publicKey);
              }
              catch (error) {
                  this.emit('error', error);
                  throw error;
              }
              finally {
                  this._connecting = false;
              }
          });
      }
      disconnect() {
          return __awaiter(this, void 0, void 0, function* () {
              const wallet = this._wallet;
              if (wallet) {
                  this._wallet = null;
                  this._publicKey = null;
                  yield wallet.disconnect();
              }
              this.emit('disconnect');
          });
      }
      signTransaction(transaction) {
          return __awaiter(this, void 0, void 0, function* () {
              try {
                  const wallet = this._wallet;
                  if (!wallet)
                      throw new wallet_adapter_base_1.WalletNotConnectedError();
                  try {
                      const response = yield wallet.request({ method: 'sol_sign', params: [transaction] });
                      const publicKey = new web3_js_1.PublicKey(response.publicKey);
                      const signature = bs58_1.default.decode(response.signature);
                      transaction.addSignature(publicKey, signature);
                      return transaction;
                  }
                  catch (error) {
                      throw new wallet_adapter_base_1.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
                  }
              }
              catch (error) {
                  this.emit('error', error);
                  throw error;
              }
          });
      }
      signAllTransactions(transactions) {
          return __awaiter(this, void 0, void 0, function* () {
              try {
                  const wallet = this._wallet;
                  if (!wallet)
                      throw new wallet_adapter_base_1.WalletNotConnectedError();
                  try {
                      const response = yield wallet.request({ method: 'sol_signAllTransactions', params: [transactions] });
                      const publicKey = new web3_js_1.PublicKey(response.publicKey);
                      const signatures = response.signatures;
                      return transactions.map((transaction, index) => {
                          const signature = bs58_1.default.decode(signatures[index]);
                          transaction.addSignature(publicKey, signature);
                          return transaction;
                      });
                  }
                  catch (error) {
                      throw new wallet_adapter_base_1.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
                  }
              }
              catch (error) {
                  this.emit('error', error);
                  throw error;
              }
          });
      }
      signMessage(message) {
          return __awaiter(this, void 0, void 0, function* () {
              try {
                  const wallet = this._wallet;
                  if (!wallet)
                      throw new wallet_adapter_base_1.WalletNotConnectedError();
                  try {
                      const response = yield wallet.request({ method: 'sol_signMessage', params: [message] });
                      return bs58_1.default.decode(response.signature);
                  }
                  catch (error) {
                      throw new wallet_adapter_base_1.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
                  }
              }
              catch (error) {
                  this.emit('error', error);
                  throw error;
              }
          });
      }
  }
  exports.Coin98WalletAdapter = Coin98WalletAdapter;
  //# sourceMappingURL=adapter.js.map