@injectivelabs/wallet-cosmos 1.17.2-alpha.1 → 1.17.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -174,7 +174,7 @@ var CosmosWallet = class CosmosWallet {
174
174
  async signArbitrary({ data, signer }) {
175
175
  const { chainId, wallet } = this;
176
176
  const cosmosWallet = await this.getCosmosWallet();
177
- if (wallet !== __injectivelabs_wallet_base.Wallet.Keplr) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`signArbitrary is not supported on ${(0, __injectivelabs_utils.capitalize)(wallet)}`));
177
+ if (![__injectivelabs_wallet_base.Wallet.Keplr, __injectivelabs_wallet_base.Wallet.Cosmostation].includes(wallet)) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`signArbitrary is not supported on ${(0, __injectivelabs_utils.capitalize)(wallet)}`));
178
178
  try {
179
179
  return (await cosmosWallet.signArbitrary(chainId, signer, data)).signature;
180
180
  } catch (e) {
@@ -199,14 +199,33 @@ var CosmosWallet = class CosmosWallet {
199
199
  }
200
200
  async checkChainIdSupport() {
201
201
  const { chainId, wallet } = this;
202
- const cosmos = this.getCosmos();
203
202
  const chainName = chainId.split("-");
203
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) return this.checkCosmostationChainSupport();
204
+ const cosmos = this.getCosmos();
204
205
  try {
205
206
  return !!await cosmos.getKey(chainId);
206
207
  } catch (_unused) {
207
208
  throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`${(0, __injectivelabs_utils.capitalize)(wallet)} doesn't support ${chainName[0] || chainId} network. Please use another Cosmos wallet`));
208
209
  }
209
210
  }
211
+ async checkCosmostationChainSupport() {
212
+ var _$window$cosmostation;
213
+ const { chainId } = this;
214
+ const $window = getWindow();
215
+ const chainName = chainId.split("-");
216
+ if (!((_$window$cosmostation = $window.cosmostation) === null || _$window$cosmostation === void 0 ? void 0 : _$window$cosmostation.cosmos)) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
217
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
218
+ type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError,
219
+ contextModule: __injectivelabs_wallet_base.Wallet.Cosmostation
220
+ });
221
+ try {
222
+ if (!(await $window.cosmostation.cosmos.request({ method: "cos_supportedChainIds" })).official.includes(chainId)) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || chainId} network. Please use another Cosmos wallet`));
223
+ return true;
224
+ } catch (e) {
225
+ if (e instanceof __injectivelabs_exceptions.CosmosWalletException) throw e;
226
+ throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message));
227
+ }
228
+ }
210
229
  getCosmos() {
211
230
  const { wallet } = this;
212
231
  const $window = getWindow();
@@ -220,6 +239,10 @@ var CosmosWallet = class CosmosWallet {
220
239
  if (wallet === __injectivelabs_wallet_base.Wallet.Keplr) cosmos = $window.keplr;
221
240
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) cosmos = $window.ninji;
222
241
  if (wallet === __injectivelabs_wallet_base.Wallet.Leap) cosmos = $window.leap;
242
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) {
243
+ var _$window$cosmostation2;
244
+ cosmos = (_$window$cosmostation2 = $window.cosmostation) === null || _$window$cosmostation2 === void 0 || (_$window$cosmostation2 = _$window$cosmostation2.providers) === null || _$window$cosmostation2 === void 0 ? void 0 : _$window$cosmostation2.keplr;
245
+ }
223
246
  if (!cosmos) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${(0, __injectivelabs_utils.capitalize)(wallet)} extension`), {
224
247
  code: __injectivelabs_exceptions.UnspecifiedErrorCode,
225
248
  type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError,
@@ -259,7 +282,8 @@ const cosmosWallets$1 = [
259
282
  __injectivelabs_wallet_base.Wallet.Leap,
260
283
  __injectivelabs_wallet_base.Wallet.Ninji,
261
284
  __injectivelabs_wallet_base.Wallet.Keplr,
262
- __injectivelabs_wallet_base.Wallet.OWallet
285
+ __injectivelabs_wallet_base.Wallet.OWallet,
286
+ __injectivelabs_wallet_base.Wallet.Cosmostation
263
287
  ];
264
288
 
265
289
  //#endregion
@@ -271,6 +295,9 @@ const isCosmosWalletInstalled = (wallet) => {
271
295
  case __injectivelabs_wallet_base.Wallet.Ninji: return $window.ninji !== void 0;
272
296
  case __injectivelabs_wallet_base.Wallet.Leap: return $window.leap !== void 0;
273
297
  case __injectivelabs_wallet_base.Wallet.OWallet: return $window.oWallet !== void 0;
298
+ case __injectivelabs_wallet_base.Wallet.Cosmostation:
299
+ var _$window$cosmostation;
300
+ return ((_$window$cosmostation = $window.cosmostation) === null || _$window$cosmostation === void 0 || (_$window$cosmostation = _$window$cosmostation.providers) === null || _$window$cosmostation === void 0 ? void 0 : _$window$cosmostation.keplr) !== void 0;
274
301
  default: return false;
275
302
  }
276
303
  };
@@ -320,6 +347,7 @@ var CosmosWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcret
320
347
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) window.ninji.off("accountsChanged", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
321
348
  if ([__injectivelabs_wallet_base.Wallet.Keplr, __injectivelabs_wallet_base.Wallet.OWallet].includes(wallet)) window.removeEventListener("keplr_keystorechange", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
322
349
  if (wallet === __injectivelabs_wallet_base.Wallet.Leap) window.removeEventListener("leap_keystorechange", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
350
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) window.removeEventListener("cosmostation_keystorechange", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
323
351
  }
324
352
  this.listeners = {};
325
353
  }
@@ -438,6 +466,7 @@ var CosmosWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcret
438
466
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) window.ninji.on("accountsChanged", listener);
439
467
  if ([__injectivelabs_wallet_base.Wallet.Keplr, __injectivelabs_wallet_base.Wallet.OWallet].includes(wallet)) window.addEventListener("keplr_keystorechange", listener);
440
468
  if (wallet === __injectivelabs_wallet_base.Wallet.Leap) window.addEventListener("leap_keystorechange", listener);
469
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) window.addEventListener("cosmostation_keystorechange", listener);
441
470
  }
442
471
  getCosmosWallet(chainId) {
443
472
  const { wallet, cosmosWallet } = this;
@@ -82,6 +82,7 @@ declare class CosmosWallet {
82
82
  signDoc: StdSignDoc$1;
83
83
  }): Promise<AminoSignResponse>;
84
84
  checkChainIdSupport(): Promise<boolean>;
85
+ private checkCosmostationChainSupport;
85
86
  private getCosmos;
86
87
  disableGasCheck(): Promise<void>;
87
88
  enableGasCheck(): Promise<void>;
@@ -82,6 +82,7 @@ declare class CosmosWallet {
82
82
  signDoc: StdSignDoc$1;
83
83
  }): Promise<AminoSignResponse>;
84
84
  checkChainIdSupport(): Promise<boolean>;
85
+ private checkCosmostationChainSupport;
85
86
  private getCosmos;
86
87
  disableGasCheck(): Promise<void>;
87
88
  enableGasCheck(): Promise<void>;
package/dist/esm/index.js CHANGED
@@ -174,7 +174,7 @@ var CosmosWallet = class CosmosWallet {
174
174
  async signArbitrary({ data, signer }) {
175
175
  const { chainId, wallet } = this;
176
176
  const cosmosWallet = await this.getCosmosWallet();
177
- if (wallet !== Wallet.Keplr) throw new CosmosWalletException(/* @__PURE__ */ new Error(`signArbitrary is not supported on ${capitalize(wallet)}`));
177
+ if (![Wallet.Keplr, Wallet.Cosmostation].includes(wallet)) throw new CosmosWalletException(/* @__PURE__ */ new Error(`signArbitrary is not supported on ${capitalize(wallet)}`));
178
178
  try {
179
179
  return (await cosmosWallet.signArbitrary(chainId, signer, data)).signature;
180
180
  } catch (e) {
@@ -199,14 +199,33 @@ var CosmosWallet = class CosmosWallet {
199
199
  }
200
200
  async checkChainIdSupport() {
201
201
  const { chainId, wallet } = this;
202
- const cosmos = this.getCosmos();
203
202
  const chainName = chainId.split("-");
203
+ if (wallet === Wallet.Cosmostation) return this.checkCosmostationChainSupport();
204
+ const cosmos = this.getCosmos();
204
205
  try {
205
206
  return !!await cosmos.getKey(chainId);
206
207
  } catch (_unused) {
207
208
  throw new CosmosWalletException(/* @__PURE__ */ new Error(`${capitalize(wallet)} doesn't support ${chainName[0] || chainId} network. Please use another Cosmos wallet`));
208
209
  }
209
210
  }
211
+ async checkCosmostationChainSupport() {
212
+ var _$window$cosmostation;
213
+ const { chainId } = this;
214
+ const $window = getWindow();
215
+ const chainName = chainId.split("-");
216
+ if (!((_$window$cosmostation = $window.cosmostation) === null || _$window$cosmostation === void 0 ? void 0 : _$window$cosmostation.cosmos)) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
217
+ code: UnspecifiedErrorCode,
218
+ type: ErrorType.WalletNotInstalledError,
219
+ contextModule: Wallet.Cosmostation
220
+ });
221
+ try {
222
+ if (!(await $window.cosmostation.cosmos.request({ method: "cos_supportedChainIds" })).official.includes(chainId)) throw new CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || chainId} network. Please use another Cosmos wallet`));
223
+ return true;
224
+ } catch (e) {
225
+ if (e instanceof CosmosWalletException) throw e;
226
+ throw new CosmosWalletException(new Error(e.message));
227
+ }
228
+ }
210
229
  getCosmos() {
211
230
  const { wallet } = this;
212
231
  const $window = getWindow();
@@ -220,6 +239,10 @@ var CosmosWallet = class CosmosWallet {
220
239
  if (wallet === Wallet.Keplr) cosmos = $window.keplr;
221
240
  if (wallet === Wallet.Ninji) cosmos = $window.ninji;
222
241
  if (wallet === Wallet.Leap) cosmos = $window.leap;
242
+ if (wallet === Wallet.Cosmostation) {
243
+ var _$window$cosmostation2;
244
+ cosmos = (_$window$cosmostation2 = $window.cosmostation) === null || _$window$cosmostation2 === void 0 || (_$window$cosmostation2 = _$window$cosmostation2.providers) === null || _$window$cosmostation2 === void 0 ? void 0 : _$window$cosmostation2.keplr;
245
+ }
223
246
  if (!cosmos) throw new CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${capitalize(wallet)} extension`), {
224
247
  code: UnspecifiedErrorCode,
225
248
  type: ErrorType.WalletNotInstalledError,
@@ -259,7 +282,8 @@ const cosmosWallets$1 = [
259
282
  Wallet.Leap,
260
283
  Wallet.Ninji,
261
284
  Wallet.Keplr,
262
- Wallet.OWallet
285
+ Wallet.OWallet,
286
+ Wallet.Cosmostation
263
287
  ];
264
288
 
265
289
  //#endregion
@@ -271,6 +295,9 @@ const isCosmosWalletInstalled = (wallet) => {
271
295
  case Wallet.Ninji: return $window.ninji !== void 0;
272
296
  case Wallet.Leap: return $window.leap !== void 0;
273
297
  case Wallet.OWallet: return $window.oWallet !== void 0;
298
+ case Wallet.Cosmostation:
299
+ var _$window$cosmostation;
300
+ return ((_$window$cosmostation = $window.cosmostation) === null || _$window$cosmostation === void 0 || (_$window$cosmostation = _$window$cosmostation.providers) === null || _$window$cosmostation === void 0 ? void 0 : _$window$cosmostation.keplr) !== void 0;
274
301
  default: return false;
275
302
  }
276
303
  };
@@ -320,6 +347,7 @@ var CosmosWalletStrategy = class extends BaseConcreteStrategy {
320
347
  if (wallet === Wallet.Ninji) window.ninji.off("accountsChanged", this.listeners[WalletEventListener.AccountChange]);
321
348
  if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) window.removeEventListener("keplr_keystorechange", this.listeners[WalletEventListener.AccountChange]);
322
349
  if (wallet === Wallet.Leap) window.removeEventListener("leap_keystorechange", this.listeners[WalletEventListener.AccountChange]);
350
+ if (wallet === Wallet.Cosmostation) window.removeEventListener("cosmostation_keystorechange", this.listeners[WalletEventListener.AccountChange]);
323
351
  }
324
352
  this.listeners = {};
325
353
  }
@@ -438,6 +466,7 @@ var CosmosWalletStrategy = class extends BaseConcreteStrategy {
438
466
  if (wallet === Wallet.Ninji) window.ninji.on("accountsChanged", listener);
439
467
  if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) window.addEventListener("keplr_keystorechange", listener);
440
468
  if (wallet === Wallet.Leap) window.addEventListener("leap_keystorechange", listener);
469
+ if (wallet === Wallet.Cosmostation) window.addEventListener("cosmostation_keystorechange", listener);
441
470
  }
442
471
  getCosmosWallet(chainId) {
443
472
  const { wallet, cosmosWallet } = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-cosmos",
3
- "version": "1.17.2-alpha.1",
3
+ "version": "1.17.2-alpha.2",
4
4
  "description": "Cosmos wallet strategies for use with @injectivelabs/wallet-core.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -41,11 +41,11 @@
41
41
  "@cosmjs/proto-signing": "0.33.0",
42
42
  "@cosmjs/stargate": "0.33.0",
43
43
  "@keplr-wallet/types": "^0.12.296",
44
- "@injectivelabs/exceptions": "1.17.2-alpha.1",
45
- "@injectivelabs/ts-types": "1.17.2-alpha.1",
46
- "@injectivelabs/utils": "1.17.2-alpha.1",
47
- "@injectivelabs/sdk-ts": "1.17.2-alpha.1",
48
- "@injectivelabs/wallet-base": "1.17.2-alpha.1"
44
+ "@injectivelabs/sdk-ts": "1.17.2-alpha.2",
45
+ "@injectivelabs/utils": "1.17.2-alpha.2",
46
+ "@injectivelabs/ts-types": "1.17.2-alpha.2",
47
+ "@injectivelabs/wallet-base": "1.17.2-alpha.2",
48
+ "@injectivelabs/exceptions": "1.17.2-alpha.2"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"