@injectivelabs/wallet-cosmos 1.17.2-alpha.0 → 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.
@@ -50,7 +50,7 @@ function _defineProperty(e, r, t) {
50
50
 
51
51
  //#endregion
52
52
  //#region src/wallet.ts
53
- const $window = typeof window !== "undefined" ? window : {};
53
+ const getWindow = () => typeof window !== "undefined" ? window : {};
54
54
  var CosmosWallet = class CosmosWallet {
55
55
  constructor({ wallet, chainId }) {
56
56
  _defineProperty(this, "wallet", void 0);
@@ -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,16 +199,36 @@ 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;
231
+ const $window = getWindow();
212
232
  if (!$window) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${(0, __injectivelabs_utils.capitalize)(wallet)} extension`), {
213
233
  code: __injectivelabs_exceptions.UnspecifiedErrorCode,
214
234
  type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError,
@@ -219,6 +239,10 @@ var CosmosWallet = class CosmosWallet {
219
239
  if (wallet === __injectivelabs_wallet_base.Wallet.Keplr) cosmos = $window.keplr;
220
240
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) cosmos = $window.ninji;
221
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
+ }
222
246
  if (!cosmos) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${(0, __injectivelabs_utils.capitalize)(wallet)} extension`), {
223
247
  code: __injectivelabs_exceptions.UnspecifiedErrorCode,
224
248
  type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError,
@@ -258,18 +282,22 @@ const cosmosWallets$1 = [
258
282
  __injectivelabs_wallet_base.Wallet.Leap,
259
283
  __injectivelabs_wallet_base.Wallet.Ninji,
260
284
  __injectivelabs_wallet_base.Wallet.Keplr,
261
- __injectivelabs_wallet_base.Wallet.OWallet
285
+ __injectivelabs_wallet_base.Wallet.OWallet,
286
+ __injectivelabs_wallet_base.Wallet.Cosmostation
262
287
  ];
263
288
 
264
289
  //#endregion
265
290
  //#region src/utils/index.ts
266
291
  const isCosmosWalletInstalled = (wallet) => {
267
- const $window$1 = typeof window !== "undefined" ? window : {};
292
+ const $window = typeof window !== "undefined" ? window : {};
268
293
  switch (wallet) {
269
- case __injectivelabs_wallet_base.Wallet.Keplr: return $window$1.keplr !== void 0;
270
- case __injectivelabs_wallet_base.Wallet.Ninji: return $window$1.ninji !== void 0;
271
- case __injectivelabs_wallet_base.Wallet.Leap: return $window$1.leap !== void 0;
272
- case __injectivelabs_wallet_base.Wallet.OWallet: return $window$1.oWallet !== void 0;
294
+ case __injectivelabs_wallet_base.Wallet.Keplr: return $window.keplr !== void 0;
295
+ case __injectivelabs_wallet_base.Wallet.Ninji: return $window.ninji !== void 0;
296
+ case __injectivelabs_wallet_base.Wallet.Leap: return $window.leap !== void 0;
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;
273
301
  default: return false;
274
302
  }
275
303
  };
@@ -319,6 +347,7 @@ var CosmosWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcret
319
347
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) window.ninji.off("accountsChanged", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
320
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]);
321
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]);
322
351
  }
323
352
  this.listeners = {};
324
353
  }
@@ -437,6 +466,7 @@ var CosmosWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcret
437
466
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) window.ninji.on("accountsChanged", listener);
438
467
  if ([__injectivelabs_wallet_base.Wallet.Keplr, __injectivelabs_wallet_base.Wallet.OWallet].includes(wallet)) window.addEventListener("keplr_keystorechange", listener);
439
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);
440
470
  }
441
471
  getCosmosWallet(chainId) {
442
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
@@ -50,7 +50,7 @@ function _defineProperty(e, r, t) {
50
50
 
51
51
  //#endregion
52
52
  //#region src/wallet.ts
53
- const $window = typeof window !== "undefined" ? window : {};
53
+ const getWindow = () => typeof window !== "undefined" ? window : {};
54
54
  var CosmosWallet = class CosmosWallet {
55
55
  constructor({ wallet, chainId }) {
56
56
  _defineProperty(this, "wallet", void 0);
@@ -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,16 +199,36 @@ 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;
231
+ const $window = getWindow();
212
232
  if (!$window) throw new CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${capitalize(wallet)} extension`), {
213
233
  code: UnspecifiedErrorCode,
214
234
  type: ErrorType.WalletNotInstalledError,
@@ -219,6 +239,10 @@ var CosmosWallet = class CosmosWallet {
219
239
  if (wallet === Wallet.Keplr) cosmos = $window.keplr;
220
240
  if (wallet === Wallet.Ninji) cosmos = $window.ninji;
221
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
+ }
222
246
  if (!cosmos) throw new CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${capitalize(wallet)} extension`), {
223
247
  code: UnspecifiedErrorCode,
224
248
  type: ErrorType.WalletNotInstalledError,
@@ -258,18 +282,22 @@ const cosmosWallets$1 = [
258
282
  Wallet.Leap,
259
283
  Wallet.Ninji,
260
284
  Wallet.Keplr,
261
- Wallet.OWallet
285
+ Wallet.OWallet,
286
+ Wallet.Cosmostation
262
287
  ];
263
288
 
264
289
  //#endregion
265
290
  //#region src/utils/index.ts
266
291
  const isCosmosWalletInstalled = (wallet) => {
267
- const $window$1 = typeof window !== "undefined" ? window : {};
292
+ const $window = typeof window !== "undefined" ? window : {};
268
293
  switch (wallet) {
269
- case Wallet.Keplr: return $window$1.keplr !== void 0;
270
- case Wallet.Ninji: return $window$1.ninji !== void 0;
271
- case Wallet.Leap: return $window$1.leap !== void 0;
272
- case Wallet.OWallet: return $window$1.oWallet !== void 0;
294
+ case Wallet.Keplr: return $window.keplr !== void 0;
295
+ case Wallet.Ninji: return $window.ninji !== void 0;
296
+ case Wallet.Leap: return $window.leap !== void 0;
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;
273
301
  default: return false;
274
302
  }
275
303
  };
@@ -319,6 +347,7 @@ var CosmosWalletStrategy = class extends BaseConcreteStrategy {
319
347
  if (wallet === Wallet.Ninji) window.ninji.off("accountsChanged", this.listeners[WalletEventListener.AccountChange]);
320
348
  if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) window.removeEventListener("keplr_keystorechange", this.listeners[WalletEventListener.AccountChange]);
321
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]);
322
351
  }
323
352
  this.listeners = {};
324
353
  }
@@ -437,6 +466,7 @@ var CosmosWalletStrategy = class extends BaseConcreteStrategy {
437
466
  if (wallet === Wallet.Ninji) window.ninji.on("accountsChanged", listener);
438
467
  if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) window.addEventListener("keplr_keystorechange", listener);
439
468
  if (wallet === Wallet.Leap) window.addEventListener("leap_keystorechange", listener);
469
+ if (wallet === Wallet.Cosmostation) window.addEventListener("cosmostation_keystorechange", listener);
440
470
  }
441
471
  getCosmosWallet(chainId) {
442
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.0",
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.0",
45
- "@injectivelabs/ts-types": "1.17.2-alpha.0",
46
- "@injectivelabs/sdk-ts": "1.17.2-alpha.0",
47
- "@injectivelabs/wallet-base": "1.17.2-alpha.0",
48
- "@injectivelabs/utils": "1.17.2-alpha.0"
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"