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

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.
@@ -3,10 +3,17 @@ let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
3
3
  let __injectivelabs_sdk_ts_core_accounts = require("@injectivelabs/sdk-ts/core/accounts");
4
4
  let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
5
5
  let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
6
- let __cosmjs_stargate = require("@cosmjs/stargate");
7
6
  let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
8
7
  let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
9
8
 
9
+ //#region src/lib.ts
10
+ let cachedSigningStargateClient = null;
11
+ const loadSigningStargateClient = async () => {
12
+ if (!cachedSigningStargateClient) cachedSigningStargateClient = (await import("@cosmjs/stargate")).SigningStargateClient;
13
+ return cachedSigningStargateClient;
14
+ };
15
+
16
+ //#endregion
10
17
  //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
11
18
  function _typeof(o) {
12
19
  "@babel/helpers - typeof";
@@ -167,14 +174,15 @@ var CosmosWallet = class CosmosWallet {
167
174
  const cosmosWallet = await this.getCosmosWallet();
168
175
  if (![__injectivelabs_wallet_base.Wallet.Keplr, __injectivelabs_wallet_base.Wallet.OWallet].includes(wallet)) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`signAndBroadcastAminoUsingCosmjs is not support on ${(0, __injectivelabs_utils.capitalize)(wallet)}`));
169
176
  if (!endpoints.rpc) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error(`Please provide rpc endpoint`));
177
+ const SigningStargateClient = await loadSigningStargateClient();
170
178
  const offlineSigner = cosmosWallet.getOfflineSignerOnlyAmino(chainId);
171
179
  const [account] = await offlineSigner.getAccounts();
172
- return await (await __cosmjs_stargate.SigningStargateClient.connectWithSigner(endpoints.rpc, offlineSigner)).signAndBroadcast(account.address, messages, stdFee);
180
+ return await (await SigningStargateClient.connectWithSigner(endpoints.rpc, offlineSigner)).signAndBroadcast(account.address, messages, stdFee);
173
181
  }
174
182
  async signArbitrary({ data, signer }) {
175
183
  const { chainId, wallet } = this;
176
184
  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)}`));
185
+ 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
186
  try {
179
187
  return (await cosmosWallet.signArbitrary(chainId, signer, data)).signature;
180
188
  } catch (e) {
@@ -199,14 +207,33 @@ var CosmosWallet = class CosmosWallet {
199
207
  }
200
208
  async checkChainIdSupport() {
201
209
  const { chainId, wallet } = this;
202
- const cosmos = this.getCosmos();
203
210
  const chainName = chainId.split("-");
211
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) return this.checkCosmostationChainSupport();
212
+ const cosmos = this.getCosmos();
204
213
  try {
205
214
  return !!await cosmos.getKey(chainId);
206
215
  } catch (_unused) {
207
216
  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
217
  }
209
218
  }
219
+ async checkCosmostationChainSupport() {
220
+ var _$window$cosmostation;
221
+ const { chainId } = this;
222
+ const $window = getWindow();
223
+ const chainName = chainId.split("-");
224
+ 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"), {
225
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
226
+ type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError,
227
+ contextModule: __injectivelabs_wallet_base.Wallet.Cosmostation
228
+ });
229
+ try {
230
+ 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`));
231
+ return true;
232
+ } catch (e) {
233
+ if (e instanceof __injectivelabs_exceptions.CosmosWalletException) throw e;
234
+ throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message));
235
+ }
236
+ }
210
237
  getCosmos() {
211
238
  const { wallet } = this;
212
239
  const $window = getWindow();
@@ -220,6 +247,10 @@ var CosmosWallet = class CosmosWallet {
220
247
  if (wallet === __injectivelabs_wallet_base.Wallet.Keplr) cosmos = $window.keplr;
221
248
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) cosmos = $window.ninji;
222
249
  if (wallet === __injectivelabs_wallet_base.Wallet.Leap) cosmos = $window.leap;
250
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) {
251
+ var _$window$cosmostation2;
252
+ 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;
253
+ }
223
254
  if (!cosmos) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${(0, __injectivelabs_utils.capitalize)(wallet)} extension`), {
224
255
  code: __injectivelabs_exceptions.UnspecifiedErrorCode,
225
256
  type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError,
@@ -259,7 +290,8 @@ const cosmosWallets$1 = [
259
290
  __injectivelabs_wallet_base.Wallet.Leap,
260
291
  __injectivelabs_wallet_base.Wallet.Ninji,
261
292
  __injectivelabs_wallet_base.Wallet.Keplr,
262
- __injectivelabs_wallet_base.Wallet.OWallet
293
+ __injectivelabs_wallet_base.Wallet.OWallet,
294
+ __injectivelabs_wallet_base.Wallet.Cosmostation
263
295
  ];
264
296
 
265
297
  //#endregion
@@ -271,6 +303,9 @@ const isCosmosWalletInstalled = (wallet) => {
271
303
  case __injectivelabs_wallet_base.Wallet.Ninji: return $window.ninji !== void 0;
272
304
  case __injectivelabs_wallet_base.Wallet.Leap: return $window.leap !== void 0;
273
305
  case __injectivelabs_wallet_base.Wallet.OWallet: return $window.oWallet !== void 0;
306
+ case __injectivelabs_wallet_base.Wallet.Cosmostation:
307
+ var _$window$cosmostation;
308
+ 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
309
  default: return false;
275
310
  }
276
311
  };
@@ -320,6 +355,7 @@ var CosmosWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcret
320
355
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) window.ninji.off("accountsChanged", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
321
356
  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
357
  if (wallet === __injectivelabs_wallet_base.Wallet.Leap) window.removeEventListener("leap_keystorechange", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
358
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) window.removeEventListener("cosmostation_keystorechange", this.listeners[__injectivelabs_wallet_base.WalletEventListener.AccountChange]);
323
359
  }
324
360
  this.listeners = {};
325
361
  }
@@ -438,6 +474,7 @@ var CosmosWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcret
438
474
  if (wallet === __injectivelabs_wallet_base.Wallet.Ninji) window.ninji.on("accountsChanged", listener);
439
475
  if ([__injectivelabs_wallet_base.Wallet.Keplr, __injectivelabs_wallet_base.Wallet.OWallet].includes(wallet)) window.addEventListener("keplr_keystorechange", listener);
440
476
  if (wallet === __injectivelabs_wallet_base.Wallet.Leap) window.addEventListener("leap_keystorechange", listener);
477
+ if (wallet === __injectivelabs_wallet_base.Wallet.Cosmostation) window.addEventListener("cosmostation_keystorechange", listener);
441
478
  }
442
479
  getCosmosWallet(chainId) {
443
480
  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>;
@@ -1,8 +1,8 @@
1
1
  import { BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, Wallet, WalletDeviceType } from "@injectivelabs/wallet-base";
2
- import * as _cosmjs_stargate0 from "@cosmjs/stargate";
3
- import { StdFee } from "@cosmjs/stargate";
4
2
  import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
5
3
  import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
4
+ import * as _cosmjs_stargate0 from "@cosmjs/stargate";
5
+ import { StdFee } from "@cosmjs/stargate";
6
6
  import { AccountAddress, ChainId, CosmosChainId, EvmChainId, TestnetCosmosChainId } from "@injectivelabs/ts-types";
7
7
  import * as _keplr_wallet_types0 from "@keplr-wallet/types";
8
8
  import { AminoSignResponse, Keplr, OfflineAminoSigner, StdSignDoc as StdSignDoc$1 } from "@keplr-wallet/types";
@@ -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
@@ -3,10 +3,17 @@ import { BaseConcreteStrategy, BroadcastMode, Wallet, WalletAction, WalletDevice
3
3
  import { PublicKey } from "@injectivelabs/sdk-ts/core/accounts";
4
4
  import { stringToUint8Array, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
5
5
  import { CosmosWalletException, ErrorType, GeneralException, TransactionException, UnspecifiedErrorCode, WalletErrorActionModule } from "@injectivelabs/exceptions";
6
- import { SigningStargateClient } from "@cosmjs/stargate";
7
6
  import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
8
7
  import { createSignDocFromTransaction, createTxRawFromSigResponse, waitTxBroadcasted } from "@injectivelabs/sdk-ts/core/tx";
9
8
 
9
+ //#region src/lib.ts
10
+ let cachedSigningStargateClient = null;
11
+ const loadSigningStargateClient = async () => {
12
+ if (!cachedSigningStargateClient) cachedSigningStargateClient = (await import("@cosmjs/stargate")).SigningStargateClient;
13
+ return cachedSigningStargateClient;
14
+ };
15
+
16
+ //#endregion
10
17
  //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
11
18
  function _typeof(o) {
12
19
  "@babel/helpers - typeof";
@@ -167,6 +174,7 @@ var CosmosWallet = class CosmosWallet {
167
174
  const cosmosWallet = await this.getCosmosWallet();
168
175
  if (![Wallet.Keplr, Wallet.OWallet].includes(wallet)) throw new CosmosWalletException(/* @__PURE__ */ new Error(`signAndBroadcastAminoUsingCosmjs is not support on ${capitalize(wallet)}`));
169
176
  if (!endpoints.rpc) throw new GeneralException(/* @__PURE__ */ new Error(`Please provide rpc endpoint`));
177
+ const SigningStargateClient = await loadSigningStargateClient();
170
178
  const offlineSigner = cosmosWallet.getOfflineSignerOnlyAmino(chainId);
171
179
  const [account] = await offlineSigner.getAccounts();
172
180
  return await (await SigningStargateClient.connectWithSigner(endpoints.rpc, offlineSigner)).signAndBroadcast(account.address, messages, stdFee);
@@ -174,7 +182,7 @@ var CosmosWallet = class CosmosWallet {
174
182
  async signArbitrary({ data, signer }) {
175
183
  const { chainId, wallet } = this;
176
184
  const cosmosWallet = await this.getCosmosWallet();
177
- if (wallet !== Wallet.Keplr) throw new CosmosWalletException(/* @__PURE__ */ new Error(`signArbitrary is not supported on ${capitalize(wallet)}`));
185
+ if (![Wallet.Keplr, Wallet.Cosmostation].includes(wallet)) throw new CosmosWalletException(/* @__PURE__ */ new Error(`signArbitrary is not supported on ${capitalize(wallet)}`));
178
186
  try {
179
187
  return (await cosmosWallet.signArbitrary(chainId, signer, data)).signature;
180
188
  } catch (e) {
@@ -199,14 +207,33 @@ var CosmosWallet = class CosmosWallet {
199
207
  }
200
208
  async checkChainIdSupport() {
201
209
  const { chainId, wallet } = this;
202
- const cosmos = this.getCosmos();
203
210
  const chainName = chainId.split("-");
211
+ if (wallet === Wallet.Cosmostation) return this.checkCosmostationChainSupport();
212
+ const cosmos = this.getCosmos();
204
213
  try {
205
214
  return !!await cosmos.getKey(chainId);
206
215
  } catch (_unused) {
207
216
  throw new CosmosWalletException(/* @__PURE__ */ new Error(`${capitalize(wallet)} doesn't support ${chainName[0] || chainId} network. Please use another Cosmos wallet`));
208
217
  }
209
218
  }
219
+ async checkCosmostationChainSupport() {
220
+ var _$window$cosmostation;
221
+ const { chainId } = this;
222
+ const $window = getWindow();
223
+ const chainName = chainId.split("-");
224
+ 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"), {
225
+ code: UnspecifiedErrorCode,
226
+ type: ErrorType.WalletNotInstalledError,
227
+ contextModule: Wallet.Cosmostation
228
+ });
229
+ try {
230
+ 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`));
231
+ return true;
232
+ } catch (e) {
233
+ if (e instanceof CosmosWalletException) throw e;
234
+ throw new CosmosWalletException(new Error(e.message));
235
+ }
236
+ }
210
237
  getCosmos() {
211
238
  const { wallet } = this;
212
239
  const $window = getWindow();
@@ -220,6 +247,10 @@ var CosmosWallet = class CosmosWallet {
220
247
  if (wallet === Wallet.Keplr) cosmos = $window.keplr;
221
248
  if (wallet === Wallet.Ninji) cosmos = $window.ninji;
222
249
  if (wallet === Wallet.Leap) cosmos = $window.leap;
250
+ if (wallet === Wallet.Cosmostation) {
251
+ var _$window$cosmostation2;
252
+ 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;
253
+ }
223
254
  if (!cosmos) throw new CosmosWalletException(/* @__PURE__ */ new Error(`Please install ${capitalize(wallet)} extension`), {
224
255
  code: UnspecifiedErrorCode,
225
256
  type: ErrorType.WalletNotInstalledError,
@@ -259,7 +290,8 @@ const cosmosWallets$1 = [
259
290
  Wallet.Leap,
260
291
  Wallet.Ninji,
261
292
  Wallet.Keplr,
262
- Wallet.OWallet
293
+ Wallet.OWallet,
294
+ Wallet.Cosmostation
263
295
  ];
264
296
 
265
297
  //#endregion
@@ -271,6 +303,9 @@ const isCosmosWalletInstalled = (wallet) => {
271
303
  case Wallet.Ninji: return $window.ninji !== void 0;
272
304
  case Wallet.Leap: return $window.leap !== void 0;
273
305
  case Wallet.OWallet: return $window.oWallet !== void 0;
306
+ case Wallet.Cosmostation:
307
+ var _$window$cosmostation;
308
+ 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
309
  default: return false;
275
310
  }
276
311
  };
@@ -320,6 +355,7 @@ var CosmosWalletStrategy = class extends BaseConcreteStrategy {
320
355
  if (wallet === Wallet.Ninji) window.ninji.off("accountsChanged", this.listeners[WalletEventListener.AccountChange]);
321
356
  if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) window.removeEventListener("keplr_keystorechange", this.listeners[WalletEventListener.AccountChange]);
322
357
  if (wallet === Wallet.Leap) window.removeEventListener("leap_keystorechange", this.listeners[WalletEventListener.AccountChange]);
358
+ if (wallet === Wallet.Cosmostation) window.removeEventListener("cosmostation_keystorechange", this.listeners[WalletEventListener.AccountChange]);
323
359
  }
324
360
  this.listeners = {};
325
361
  }
@@ -438,6 +474,7 @@ var CosmosWalletStrategy = class extends BaseConcreteStrategy {
438
474
  if (wallet === Wallet.Ninji) window.ninji.on("accountsChanged", listener);
439
475
  if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) window.addEventListener("keplr_keystorechange", listener);
440
476
  if (wallet === Wallet.Leap) window.addEventListener("leap_keystorechange", listener);
477
+ if (wallet === Wallet.Cosmostation) window.addEventListener("cosmostation_keystorechange", listener);
441
478
  }
442
479
  getCosmosWallet(chainId) {
443
480
  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.3",
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/exceptions": "1.17.2-alpha.3",
45
+ "@injectivelabs/sdk-ts": "1.17.2-alpha.3",
46
+ "@injectivelabs/utils": "1.17.2-alpha.3",
47
+ "@injectivelabs/wallet-base": "1.17.2-alpha.3",
48
+ "@injectivelabs/ts-types": "1.17.2-alpha.3"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"