@injectivelabs/wallet-cosmostation 1.16.38-alpha.7 → 1.16.38

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.
package/dist/esm/index.js CHANGED
@@ -1,263 +1,3 @@
1
- import { InstallError, cosmos } from "@cosmostation/extension-client";
2
- import { CosmosWalletException, ErrorType, TransactionException, UnspecifiedErrorCode } from "@injectivelabs/exceptions";
3
- import { makeSignDoc } from "@cosmjs/proto-signing";
4
- import { CosmosChainId } from "@injectivelabs/ts-types";
5
- import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
6
- import { getOfflineSigner } from "@cosmostation/cosmos-client";
7
- import { SEND_TRANSACTION_MODE } from "@cosmostation/extension-client/cosmos.js";
8
- import { createSignDocFromTransaction, createTxRawFromSigResponse } from "@injectivelabs/sdk-ts/core/tx";
9
- import { stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
10
- import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
11
-
12
- //#region src/utils/index.ts
13
- const isCosmosStationWalletInstalled = () => {
14
- return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
15
- };
16
-
17
- //#endregion
18
- //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
19
- function _typeof(o) {
20
- "@babel/helpers - typeof";
21
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
22
- return typeof o$1;
23
- } : function(o$1) {
24
- return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
25
- }, _typeof(o);
26
- }
27
-
28
- //#endregion
29
- //#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
30
- function toPrimitive(t, r) {
31
- if ("object" != _typeof(t) || !t) return t;
32
- var e = t[Symbol.toPrimitive];
33
- if (void 0 !== e) {
34
- var i = e.call(t, r || "default");
35
- if ("object" != _typeof(i)) return i;
36
- throw new TypeError("@@toPrimitive must return a primitive value.");
37
- }
38
- return ("string" === r ? String : Number)(t);
39
- }
40
-
41
- //#endregion
42
- //#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
43
- function toPropertyKey(t) {
44
- var i = toPrimitive(t, "string");
45
- return "symbol" == _typeof(i) ? i : i + "";
46
- }
47
-
48
- //#endregion
49
- //#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
50
- function _defineProperty(e, r, t) {
51
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
52
- value: t,
53
- enumerable: !0,
54
- configurable: !0,
55
- writable: !0
56
- }) : e[r] = t, e;
57
- }
58
-
59
- //#endregion
60
- //#region src/wallet.ts
61
- var CosmostationWallet = class CosmostationWallet {
62
- constructor(chainId) {
63
- _defineProperty(this, "chainId", void 0);
64
- this.chainId = chainId;
65
- }
66
- static async isChainIdSupported(chainId) {
67
- return new CosmostationWallet(chainId).checkChainIdSupport();
68
- }
69
- async checkChainIdSupport() {
70
- const { chainId: actualChainId } = this;
71
- const provider = await this.getCosmostationWallet();
72
- const chainName = actualChainId.split("-");
73
- try {
74
- return !!(await provider.getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
75
- } catch (_unused) {
76
- throw new CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
77
- }
78
- }
79
- async getCosmostationWallet() {
80
- try {
81
- return await cosmos();
82
- } catch (e) {
83
- if (e instanceof InstallError) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
84
- code: UnspecifiedErrorCode,
85
- type: ErrorType.WalletNotInstalledError
86
- });
87
- throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
88
- }
89
- }
90
- };
91
-
92
- //#endregion
93
- //#region src/strategy/strategy.ts
94
- const getChainNameFromChainId = (chainId) => {
95
- const [chainName] = chainId.split("-");
96
- if (chainName.includes("cosmoshub")) return "cosmos";
97
- if (chainName.includes("core")) return "persistence";
98
- if (chainName.includes("evmos")) return "evmos";
99
- if (chainId.includes("ssc") || chainId.includes("fetch")) return chainId;
100
- return chainName;
101
- };
102
- var Cosmostation = class extends BaseConcreteStrategy {
103
- constructor(args) {
104
- super(args);
105
- _defineProperty(this, "cosmostationWallet", void 0);
106
- _defineProperty(this, "chainName", void 0);
107
- this.chainId = args.chainId || CosmosChainId.Injective;
108
- this.chainName = getChainNameFromChainId(this.chainId);
109
- }
110
- async getWalletDeviceType() {
111
- return Promise.resolve(WalletDeviceType.Browser);
112
- }
113
- async enable() {
114
- return Promise.resolve(true);
115
- }
116
- async getAddresses() {
117
- const cosmostationWallet = await this.getCosmostationWallet();
118
- try {
119
- return [(await cosmostationWallet.requestAccount(this.chainName)).address];
120
- } catch (e) {
121
- if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
122
- code: UnspecifiedErrorCode,
123
- context: WalletAction.GetAccounts
124
- });
125
- throw new CosmosWalletException(new Error(e.message), {
126
- code: UnspecifiedErrorCode,
127
- context: WalletAction.GetAccounts
128
- });
129
- }
130
- }
131
- async getAddressesInfo() {
132
- throw new CosmosWalletException(/* @__PURE__ */ new Error("getAddressesInfo is not implemented"), {
133
- code: UnspecifiedErrorCode,
134
- context: WalletAction.GetAccounts
135
- });
136
- }
137
- async getSessionOrConfirm(address) {
138
- return Promise.resolve(`0x${uint8ArrayToHex(stringToUint8Array(`Confirmation for ${address} at time: ${Date.now()}`))}`);
139
- }
140
- async sendEvmTransaction(_transaction, _options) {
141
- throw new CosmosWalletException(/* @__PURE__ */ new Error("sendEvmTransaction is not supported. Cosmostation only supports sending cosmos transactions"), {
142
- code: UnspecifiedErrorCode,
143
- context: WalletAction.SendEvmTransaction
144
- });
145
- }
146
- async sendTransaction(transaction, _options) {
147
- const cosmostationWallet = await this.getCosmostationWallet();
148
- const txRaw = createTxRawFromSigResponse(transaction);
149
- try {
150
- const response = await cosmostationWallet.sendTransaction(this.chainName, CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw), SEND_TRANSACTION_MODE.SYNC);
151
- return {
152
- ...response.tx_response,
153
- gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
154
- gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
155
- height: parseInt(response.tx_response.height || "0", 10),
156
- txHash: response.tx_response.txhash,
157
- rawLog: response.tx_response.raw_log
158
- };
159
- } catch (e) {
160
- if (e instanceof TransactionException) throw e;
161
- throw new TransactionException(new Error(e.message), {
162
- code: UnspecifiedErrorCode,
163
- context: WalletAction.SendTransaction
164
- });
165
- }
166
- }
167
- async signAminoCosmosTransaction(_transaction) {
168
- throw new CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing using amino"), {
169
- code: UnspecifiedErrorCode,
170
- context: WalletAction.SendTransaction
171
- });
172
- }
173
- async signCosmosTransaction(transaction) {
174
- const { chainId } = this;
175
- const cosmostationWallet = await this.getCosmostationWallet();
176
- const signDoc = createSignDocFromTransaction(transaction);
177
- try {
178
- const signDirectResponse = await cosmostationWallet.signDirect(this.chainName, {
179
- chain_id: chainId,
180
- body_bytes: signDoc.bodyBytes,
181
- auth_info_bytes: signDoc.authInfoBytes,
182
- account_number: signDoc.accountNumber.toString()
183
- }, {
184
- fee: true,
185
- memo: true
186
- });
187
- return {
188
- signed: makeSignDoc(signDirectResponse.signed_doc.body_bytes, signDirectResponse.signed_doc.auth_info_bytes, signDirectResponse.signed_doc.chain_id, parseInt(signDirectResponse.signed_doc.account_number, 10)),
189
- signature: { signature: signDirectResponse.signature }
190
- };
191
- } catch (e) {
192
- throw new CosmosWalletException(new Error(e.message), {
193
- code: UnspecifiedErrorCode,
194
- context: WalletAction.SendTransaction
195
- });
196
- }
197
- }
198
- async getPubKey() {
199
- const cosmostationWallet = await this.getCosmostationWallet();
200
- try {
201
- return uint8ArrayToBase64((await cosmostationWallet.requestAccount(this.chainName)).publicKey);
202
- } catch (e) {
203
- if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
204
- code: UnspecifiedErrorCode,
205
- context: WalletAction.GetAccounts
206
- });
207
- throw new CosmosWalletException(new Error(e.message), {
208
- code: UnspecifiedErrorCode,
209
- context: WalletAction.GetAccounts
210
- });
211
- }
212
- }
213
- async signEip712TypedData(_eip712TypedData, _address) {
214
- throw new CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing Evm transactions"), {
215
- code: UnspecifiedErrorCode,
216
- context: WalletAction.SendTransaction
217
- });
218
- }
219
- async signArbitrary(signer, data) {
220
- try {
221
- return (await (await this.getCosmostationWallet()).signMessage(this.chainName, signer, toUtf8(data))).signature;
222
- } catch (e) {
223
- throw new CosmosWalletException(new Error(e.message), {
224
- code: UnspecifiedErrorCode,
225
- context: WalletAction.SignArbitrary
226
- });
227
- }
228
- }
229
- async getEthereumChainId() {
230
- throw new CosmosWalletException(/* @__PURE__ */ new Error("getEthereumChainId is not supported on Cosmostation"), {
231
- code: UnspecifiedErrorCode,
232
- context: WalletAction.GetChainId
233
- });
234
- }
235
- async getEvmTransactionReceipt(_txHash) {
236
- throw new CosmosWalletException(/* @__PURE__ */ new Error("getEvmTransactionReceipt is not supported on Cosmostation"), {
237
- code: UnspecifiedErrorCode,
238
- type: ErrorType.WalletError,
239
- context: WalletAction.GetEvmTransactionReceipt
240
- });
241
- }
242
- async getOfflineSigner(chainId) {
243
- return await getOfflineSigner(chainId);
244
- }
245
- async getCosmostationWallet() {
246
- if (this.cosmostationWallet) return this.cosmostationWallet;
247
- const cosmostationWallet = new CosmostationWallet(this.chainId);
248
- try {
249
- const provider = await cosmostationWallet.getCosmostationWallet();
250
- this.cosmostationWallet = provider;
251
- return provider;
252
- } catch (e) {
253
- if (e instanceof InstallError) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
254
- code: UnspecifiedErrorCode,
255
- type: ErrorType.WalletNotInstalledError
256
- });
257
- throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
258
- }
259
- }
260
- };
261
-
262
- //#endregion
263
- export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
1
+ export { CosmostationWallet } from './wallet.js';
2
+ export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy.js';
3
+ export * from './utils/index.js';
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "module"
3
- }
2
+ "type": "module"
3
+ }
@@ -0,0 +1,43 @@
1
+ import { CosmosChainId } from '@injectivelabs/ts-types';
2
+ import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
3
+ import { WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
4
+ import type { OfflineSigner } from '@cosmjs/proto-signing';
5
+ import type { ChainId, EvmChainId, AccountAddress } from '@injectivelabs/ts-types';
6
+ import type { StdSignDoc, ConcreteWalletStrategy } from '@injectivelabs/wallet-base';
7
+ import type { TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
8
+ export declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
9
+ private cosmostationWallet?;
10
+ chainName: string;
11
+ constructor(args: {
12
+ chainId: ChainId | CosmosChainId;
13
+ });
14
+ getWalletDeviceType(): Promise<WalletDeviceType>;
15
+ enable(): Promise<boolean>;
16
+ getAddresses(): Promise<string[]>;
17
+ getSessionOrConfirm(address?: AccountAddress): Promise<string>;
18
+ sendEvmTransaction(_transaction: unknown, _options: {
19
+ address: AccountAddress;
20
+ evmChainId: EvmChainId;
21
+ }): Promise<string>;
22
+ sendTransaction(transaction: DirectSignResponse | CosmosTxV1Beta1Tx.TxRaw, _options: {
23
+ address: AccountAddress;
24
+ chainId: ChainId;
25
+ }): Promise<TxResponse>;
26
+ signAminoCosmosTransaction(_transaction: {
27
+ address: string;
28
+ signDoc: StdSignDoc;
29
+ }): Promise<AminoSignResponse>;
30
+ signCosmosTransaction(transaction: {
31
+ txRaw: CosmosTxV1Beta1Tx.TxRaw;
32
+ chainId: string;
33
+ address: string;
34
+ accountNumber: number;
35
+ }): Promise<DirectSignResponse>;
36
+ getPubKey(): Promise<string>;
37
+ signEip712TypedData(_eip712TypedData: string, _address: AccountAddress): Promise<string>;
38
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
39
+ getEthereumChainId(): Promise<string>;
40
+ getEvmTransactionReceipt(_txHash: string): Promise<string>;
41
+ getOfflineSigner(chainId: string): Promise<OfflineSigner>;
42
+ private getCosmostationWallet;
43
+ }
@@ -0,0 +1,201 @@
1
+ import { makeSignDoc } from '@cosmjs/proto-signing';
2
+ import { CosmosChainId } from '@injectivelabs/ts-types';
3
+ import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
4
+ import { InstallError } from '@cosmostation/extension-client';
5
+ import { getOfflineSigner } from '@cosmostation/cosmos-client';
6
+ import { SEND_TRANSACTION_MODE } from '@cosmostation/extension-client/cosmos.js';
7
+ import { toUtf8, createTxRawFromSigResponse, createSignDocFromTransaction, } from '@injectivelabs/sdk-ts';
8
+ import { ErrorType, UnspecifiedErrorCode, CosmosWalletException, TransactionException, } from '@injectivelabs/exceptions';
9
+ import { WalletAction, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
10
+ import { CosmostationWallet } from './../wallet.js';
11
+ const getChainNameFromChainId = (chainId) => {
12
+ const [chainName] = chainId.split('-');
13
+ if (chainName.includes('cosmoshub')) {
14
+ return 'cosmos';
15
+ }
16
+ if (chainName.includes('core')) {
17
+ return 'persistence';
18
+ }
19
+ if (chainName.includes('evmos')) {
20
+ return 'evmos';
21
+ }
22
+ if (chainId.includes('ssc') || chainId.includes('fetch')) {
23
+ return chainId;
24
+ }
25
+ return chainName;
26
+ };
27
+ export class Cosmostation extends BaseConcreteStrategy {
28
+ cosmostationWallet;
29
+ chainName;
30
+ constructor(args) {
31
+ super(args);
32
+ this.chainId = args.chainId || CosmosChainId.Injective;
33
+ this.chainName = getChainNameFromChainId(this.chainId);
34
+ }
35
+ async getWalletDeviceType() {
36
+ return Promise.resolve(WalletDeviceType.Browser);
37
+ }
38
+ async enable() {
39
+ return Promise.resolve(true);
40
+ }
41
+ async getAddresses() {
42
+ const cosmostationWallet = await this.getCosmostationWallet();
43
+ try {
44
+ const accounts = await cosmostationWallet.requestAccount(this.chainName);
45
+ return [accounts.address];
46
+ }
47
+ catch (e) {
48
+ if (e.code === 4001) {
49
+ throw new CosmosWalletException(new Error('The user rejected the request'), {
50
+ code: UnspecifiedErrorCode,
51
+ context: WalletAction.GetAccounts,
52
+ });
53
+ }
54
+ throw new CosmosWalletException(new Error(e.message), {
55
+ code: UnspecifiedErrorCode,
56
+ context: WalletAction.GetAccounts,
57
+ });
58
+ }
59
+ }
60
+ async getSessionOrConfirm(address) {
61
+ return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
62
+ }
63
+ async sendEvmTransaction(_transaction, _options) {
64
+ throw new CosmosWalletException(new Error('sendEvmTransaction is not supported. Cosmostation only supports sending cosmos transactions'), {
65
+ code: UnspecifiedErrorCode,
66
+ context: WalletAction.SendEvmTransaction,
67
+ });
68
+ }
69
+ async sendTransaction(transaction, _options) {
70
+ const cosmostationWallet = await this.getCosmostationWallet();
71
+ const txRaw = createTxRawFromSigResponse(transaction);
72
+ try {
73
+ const response = await cosmostationWallet.sendTransaction(this.chainName, CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(), SEND_TRANSACTION_MODE.SYNC);
74
+ return {
75
+ ...response.tx_response,
76
+ gasUsed: parseInt((response.tx_response.gas_used || '0'), 10),
77
+ gasWanted: parseInt((response.tx_response.gas_wanted || '0'), 10),
78
+ height: parseInt((response.tx_response.height || '0'), 10),
79
+ txHash: response.tx_response.txhash,
80
+ rawLog: response.tx_response.raw_log,
81
+ };
82
+ }
83
+ catch (e) {
84
+ if (e instanceof TransactionException) {
85
+ throw e;
86
+ }
87
+ throw new TransactionException(new Error(e.message), {
88
+ code: UnspecifiedErrorCode,
89
+ context: WalletAction.SendTransaction,
90
+ });
91
+ }
92
+ }
93
+ async signAminoCosmosTransaction(_transaction) {
94
+ throw new CosmosWalletException(new Error('This wallet does not support signing using amino'), {
95
+ code: UnspecifiedErrorCode,
96
+ context: WalletAction.SendTransaction,
97
+ });
98
+ }
99
+ async signCosmosTransaction(transaction) {
100
+ const { chainId } = this;
101
+ const cosmostationWallet = await this.getCosmostationWallet();
102
+ const signDoc = createSignDocFromTransaction(transaction);
103
+ try {
104
+ /* Sign the transaction */
105
+ const signDirectResponse = await cosmostationWallet.signDirect(this.chainName, {
106
+ chain_id: chainId,
107
+ body_bytes: signDoc.bodyBytes,
108
+ auth_info_bytes: signDoc.authInfoBytes,
109
+ account_number: signDoc.accountNumber.toString(),
110
+ }, { fee: true, memo: true });
111
+ return {
112
+ signed: makeSignDoc(signDirectResponse.signed_doc.body_bytes, signDirectResponse.signed_doc.auth_info_bytes, signDirectResponse.signed_doc.chain_id, parseInt(signDirectResponse.signed_doc.account_number, 10)),
113
+ signature: {
114
+ signature: signDirectResponse.signature,
115
+ },
116
+ };
117
+ }
118
+ catch (e) {
119
+ throw new CosmosWalletException(new Error(e.message), {
120
+ code: UnspecifiedErrorCode,
121
+ context: WalletAction.SendTransaction,
122
+ });
123
+ }
124
+ }
125
+ async getPubKey() {
126
+ const cosmostationWallet = await this.getCosmostationWallet();
127
+ try {
128
+ const account = await cosmostationWallet.requestAccount(this.chainName);
129
+ return Buffer.from(account.publicKey).toString('base64');
130
+ }
131
+ catch (e) {
132
+ if (e.code === 4001) {
133
+ throw new CosmosWalletException(new Error('The user rejected the request'), {
134
+ code: UnspecifiedErrorCode,
135
+ context: WalletAction.GetAccounts,
136
+ });
137
+ }
138
+ throw new CosmosWalletException(new Error(e.message), {
139
+ code: UnspecifiedErrorCode,
140
+ context: WalletAction.GetAccounts,
141
+ });
142
+ }
143
+ }
144
+ async signEip712TypedData(_eip712TypedData, _address) {
145
+ throw new CosmosWalletException(new Error('This wallet does not support signing Evm transactions'), {
146
+ code: UnspecifiedErrorCode,
147
+ context: WalletAction.SendTransaction,
148
+ });
149
+ }
150
+ async signArbitrary(signer, data) {
151
+ try {
152
+ const cosmostationWallet = await this.getCosmostationWallet();
153
+ const signature = await cosmostationWallet.signMessage(this.chainName, signer, toUtf8(data));
154
+ return signature.signature;
155
+ }
156
+ catch (e) {
157
+ throw new CosmosWalletException(new Error(e.message), {
158
+ code: UnspecifiedErrorCode,
159
+ context: WalletAction.SignArbitrary,
160
+ });
161
+ }
162
+ }
163
+ async getEthereumChainId() {
164
+ throw new CosmosWalletException(new Error('getEthereumChainId is not supported on Cosmostation'), {
165
+ code: UnspecifiedErrorCode,
166
+ context: WalletAction.GetChainId,
167
+ });
168
+ }
169
+ async getEvmTransactionReceipt(_txHash) {
170
+ throw new CosmosWalletException(new Error('getEvmTransactionReceipt is not supported on Cosmostation'), {
171
+ code: UnspecifiedErrorCode,
172
+ type: ErrorType.WalletError,
173
+ context: WalletAction.GetEvmTransactionReceipt,
174
+ });
175
+ }
176
+ async getOfflineSigner(chainId) {
177
+ return (await getOfflineSigner(chainId));
178
+ }
179
+ async getCosmostationWallet() {
180
+ if (this.cosmostationWallet) {
181
+ return this.cosmostationWallet;
182
+ }
183
+ const cosmostationWallet = new CosmostationWallet(this.chainId);
184
+ try {
185
+ const provider = await cosmostationWallet.getCosmostationWallet();
186
+ this.cosmostationWallet = provider;
187
+ return provider;
188
+ }
189
+ catch (e) {
190
+ if (e instanceof InstallError) {
191
+ throw new CosmosWalletException(new Error('Please install the Cosmostation extension'), {
192
+ code: UnspecifiedErrorCode,
193
+ type: ErrorType.WalletNotInstalledError,
194
+ });
195
+ }
196
+ throw new CosmosWalletException(new Error(e.message), {
197
+ code: UnspecifiedErrorCode,
198
+ });
199
+ }
200
+ }
201
+ }
@@ -0,0 +1 @@
1
+ export declare const isCosmosStationWalletInstalled: () => boolean;
@@ -0,0 +1,4 @@
1
+ export const isCosmosStationWalletInstalled = () => {
2
+ const $window = (typeof window !== 'undefined' ? window : {});
3
+ return $window.cosmostation !== undefined;
4
+ };
@@ -0,0 +1,8 @@
1
+ import type { ChainId, CosmosChainId, TestnetCosmosChainId } from '@injectivelabs/ts-types';
2
+ export declare class CosmostationWallet {
3
+ private chainId;
4
+ constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
5
+ static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
6
+ checkChainIdSupport(): Promise<boolean>;
7
+ getCosmostationWallet(): Promise<typeof import("@cosmostation/extension-client/cosmos.js")>;
8
+ }
@@ -0,0 +1,40 @@
1
+ import { cosmos, InstallError } from '@cosmostation/extension-client';
2
+ import { ErrorType, UnspecifiedErrorCode, CosmosWalletException, } from '@injectivelabs/exceptions';
3
+ export class CosmostationWallet {
4
+ chainId;
5
+ constructor(chainId) {
6
+ this.chainId = chainId;
7
+ }
8
+ static async isChainIdSupported(chainId) {
9
+ return new CosmostationWallet(chainId).checkChainIdSupport();
10
+ }
11
+ async checkChainIdSupport() {
12
+ const { chainId: actualChainId } = this;
13
+ const provider = await this.getCosmostationWallet();
14
+ const chainName = actualChainId.split('-');
15
+ try {
16
+ const supportedChainIds = await provider.getSupportedChainIds();
17
+ return !!supportedChainIds.official.find((chainId) => chainId === actualChainId);
18
+ }
19
+ catch {
20
+ throw new CosmosWalletException(new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
21
+ }
22
+ }
23
+ async getCosmostationWallet() {
24
+ try {
25
+ const provider = await cosmos();
26
+ return provider;
27
+ }
28
+ catch (e) {
29
+ if (e instanceof InstallError) {
30
+ throw new CosmosWalletException(new Error('Please install the Cosmostation extension'), {
31
+ code: UnspecifiedErrorCode,
32
+ type: ErrorType.WalletNotInstalledError,
33
+ });
34
+ }
35
+ throw new CosmosWalletException(new Error(e.message), {
36
+ code: UnspecifiedErrorCode,
37
+ });
38
+ }
39
+ }
40
+ }