@injectivelabs/wallet-cosmostation 1.16.38 → 1.16.39-alpha.0

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.
@@ -0,0 +1,265 @@
1
+ let __cosmostation_extension_client = require("@cosmostation/extension-client");
2
+ let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
3
+ let __cosmjs_proto_signing = require("@cosmjs/proto-signing");
4
+ let __injectivelabs_ts_types = require("@injectivelabs/ts-types");
5
+ let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
6
+ let __cosmostation_cosmos_client = require("@cosmostation/cosmos-client");
7
+ let __cosmostation_extension_client_cosmos_js = require("@cosmostation/extension-client/cosmos.js");
8
+ let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
9
+ let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
10
+ let __injectivelabs_wallet_base = require("@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 __injectivelabs_exceptions.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 (0, __cosmostation_extension_client.cosmos)();
82
+ } catch (e) {
83
+ if (e instanceof __cosmostation_extension_client.InstallError) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
84
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
85
+ type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
86
+ });
87
+ throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.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 __injectivelabs_wallet_base.BaseConcreteStrategy {
103
+ constructor(args) {
104
+ super(args);
105
+ _defineProperty(this, "cosmostationWallet", void 0);
106
+ _defineProperty(this, "chainName", void 0);
107
+ this.chainId = args.chainId || __injectivelabs_ts_types.CosmosChainId.Injective;
108
+ this.chainName = getChainNameFromChainId(this.chainId);
109
+ }
110
+ async getWalletDeviceType() {
111
+ return Promise.resolve(__injectivelabs_wallet_base.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 __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
122
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
123
+ context: __injectivelabs_wallet_base.WalletAction.GetAccounts
124
+ });
125
+ throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
126
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
127
+ context: __injectivelabs_wallet_base.WalletAction.GetAccounts
128
+ });
129
+ }
130
+ }
131
+ async getAddressesInfo() {
132
+ throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getAddressesInfo is not implemented"), {
133
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
134
+ context: __injectivelabs_wallet_base.WalletAction.GetAccounts
135
+ });
136
+ }
137
+ async getSessionOrConfirm(address) {
138
+ return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts_utils.uint8ArrayToHex)((0, __injectivelabs_sdk_ts_utils.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
139
+ }
140
+ async sendEvmTransaction(_transaction, _options) {
141
+ throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("sendEvmTransaction is not supported. Cosmostation only supports sending cosmos transactions"), {
142
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
143
+ context: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
144
+ });
145
+ }
146
+ async sendTransaction(transaction, _options) {
147
+ const cosmostationWallet = await this.getCosmostationWallet();
148
+ const txRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(transaction);
149
+ try {
150
+ const response = await cosmostationWallet.sendTransaction(this.chainName, __injectivelabs_sdk_ts.CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw), __cosmostation_extension_client_cosmos_js.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 __injectivelabs_exceptions.TransactionException) throw e;
161
+ throw new __injectivelabs_exceptions.TransactionException(new Error(e.message), {
162
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
163
+ context: __injectivelabs_wallet_base.WalletAction.SendTransaction
164
+ });
165
+ }
166
+ }
167
+ async signAminoCosmosTransaction(_transaction) {
168
+ throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing using amino"), {
169
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
170
+ context: __injectivelabs_wallet_base.WalletAction.SendTransaction
171
+ });
172
+ }
173
+ async signCosmosTransaction(transaction) {
174
+ const { chainId } = this;
175
+ const cosmostationWallet = await this.getCosmostationWallet();
176
+ const signDoc = (0, __injectivelabs_sdk_ts_core_tx.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: (0, __cosmjs_proto_signing.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 __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
193
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
194
+ context: __injectivelabs_wallet_base.WalletAction.SendTransaction
195
+ });
196
+ }
197
+ }
198
+ async getPubKey() {
199
+ const cosmostationWallet = await this.getCosmostationWallet();
200
+ try {
201
+ return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await cosmostationWallet.requestAccount(this.chainName)).publicKey);
202
+ } catch (e) {
203
+ if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
204
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
205
+ context: __injectivelabs_wallet_base.WalletAction.GetAccounts
206
+ });
207
+ throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
208
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
209
+ context: __injectivelabs_wallet_base.WalletAction.GetAccounts
210
+ });
211
+ }
212
+ }
213
+ async signEip712TypedData(_eip712TypedData, _address) {
214
+ throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing Evm transactions"), {
215
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
216
+ context: __injectivelabs_wallet_base.WalletAction.SendTransaction
217
+ });
218
+ }
219
+ async signArbitrary(signer, data) {
220
+ try {
221
+ return (await (await this.getCosmostationWallet()).signMessage(this.chainName, signer, (0, __injectivelabs_sdk_ts_utils.toUtf8)(data))).signature;
222
+ } catch (e) {
223
+ throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
224
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
225
+ context: __injectivelabs_wallet_base.WalletAction.SignArbitrary
226
+ });
227
+ }
228
+ }
229
+ async getEthereumChainId() {
230
+ throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEthereumChainId is not supported on Cosmostation"), {
231
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
232
+ context: __injectivelabs_wallet_base.WalletAction.GetChainId
233
+ });
234
+ }
235
+ async getEvmTransactionReceipt(_txHash) {
236
+ throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEvmTransactionReceipt is not supported on Cosmostation"), {
237
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
238
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
239
+ context: __injectivelabs_wallet_base.WalletAction.GetEvmTransactionReceipt
240
+ });
241
+ }
242
+ async getOfflineSigner(chainId) {
243
+ return await (0, __cosmostation_cosmos_client.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 __cosmostation_extension_client.InstallError) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
254
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
255
+ type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
256
+ });
257
+ throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
258
+ }
259
+ }
260
+ };
261
+
262
+ //#endregion
263
+ exports.CosmostationWallet = CosmostationWallet;
264
+ exports.CosmostationWalletStrategy = Cosmostation;
265
+ exports.isCosmosStationWalletInstalled = isCosmosStationWalletInstalled;
@@ -0,0 +1,64 @@
1
+ import * as _cosmostation_extension_client_cosmos0 from "@cosmostation/extension-client/cosmos";
2
+ import { AccountAddress, ChainId, CosmosChainId, EvmChainId, TestnetCosmosChainId } from "@injectivelabs/ts-types";
3
+ import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
4
+ import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
5
+ import { OfflineSigner } from "@cosmjs/proto-signing";
6
+ import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
7
+ import { AminoSignResponse, DirectSignResponse } from "@injectivelabs/sdk-ts/types";
8
+
9
+ //#region src/utils/index.d.ts
10
+ declare const isCosmosStationWalletInstalled: () => boolean;
11
+ //#endregion
12
+ //#region src/wallet.d.ts
13
+ declare class CosmostationWallet {
14
+ private chainId;
15
+ constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
16
+ static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
17
+ checkChainIdSupport(): Promise<boolean>;
18
+ getCosmostationWallet(): Promise<typeof _cosmostation_extension_client_cosmos0>;
19
+ }
20
+ //#endregion
21
+ //#region src/strategy/strategy.d.ts
22
+ declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
23
+ private cosmostationWallet?;
24
+ chainName: string;
25
+ constructor(args: {
26
+ chainId: ChainId | CosmosChainId;
27
+ });
28
+ getWalletDeviceType(): Promise<WalletDeviceType>;
29
+ enable(): Promise<boolean>;
30
+ getAddresses(): Promise<string[]>;
31
+ getAddressesInfo(): Promise<{
32
+ address: string;
33
+ derivationPath: string;
34
+ baseDerivationPath: string;
35
+ }[]>;
36
+ getSessionOrConfirm(address?: AccountAddress): Promise<string>;
37
+ sendEvmTransaction(_transaction: unknown, _options: {
38
+ address: AccountAddress;
39
+ evmChainId: EvmChainId;
40
+ }): Promise<string>;
41
+ sendTransaction(transaction: DirectSignResponse | CosmosTxV1Beta1TxPb.TxRaw, _options: {
42
+ address: AccountAddress;
43
+ chainId: ChainId;
44
+ }): Promise<TxResponse>;
45
+ signAminoCosmosTransaction(_transaction: {
46
+ address: string;
47
+ signDoc: StdSignDoc;
48
+ }): Promise<AminoSignResponse>;
49
+ signCosmosTransaction(transaction: {
50
+ txRaw: CosmosTxV1Beta1TxPb.TxRaw;
51
+ chainId: string;
52
+ address: string;
53
+ accountNumber: number;
54
+ }): Promise<DirectSignResponse>;
55
+ getPubKey(): Promise<string>;
56
+ signEip712TypedData(_eip712TypedData: string, _address: AccountAddress): Promise<string>;
57
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
58
+ getEthereumChainId(): Promise<string>;
59
+ getEvmTransactionReceipt(_txHash: string): Promise<string>;
60
+ getOfflineSigner(chainId: string): Promise<OfflineSigner>;
61
+ private getCosmostationWallet;
62
+ }
63
+ //#endregion
64
+ export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -1,3 +1,64 @@
1
- export { CosmostationWallet } from './wallet.js';
2
- export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy.js';
3
- export * from './utils/index.js';
1
+ import { OfflineSigner } from "@cosmjs/proto-signing";
2
+ import { AccountAddress, ChainId, CosmosChainId, EvmChainId, TestnetCosmosChainId } from "@injectivelabs/ts-types";
3
+ import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
4
+ import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
5
+ import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
6
+ import * as _cosmostation_extension_client_cosmos0 from "@cosmostation/extension-client/cosmos";
7
+ import { AminoSignResponse, DirectSignResponse } from "@injectivelabs/sdk-ts/types";
8
+
9
+ //#region src/utils/index.d.ts
10
+ declare const isCosmosStationWalletInstalled: () => boolean;
11
+ //#endregion
12
+ //#region src/wallet.d.ts
13
+ declare class CosmostationWallet {
14
+ private chainId;
15
+ constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
16
+ static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
17
+ checkChainIdSupport(): Promise<boolean>;
18
+ getCosmostationWallet(): Promise<typeof _cosmostation_extension_client_cosmos0>;
19
+ }
20
+ //#endregion
21
+ //#region src/strategy/strategy.d.ts
22
+ declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
23
+ private cosmostationWallet?;
24
+ chainName: string;
25
+ constructor(args: {
26
+ chainId: ChainId | CosmosChainId;
27
+ });
28
+ getWalletDeviceType(): Promise<WalletDeviceType>;
29
+ enable(): Promise<boolean>;
30
+ getAddresses(): Promise<string[]>;
31
+ getAddressesInfo(): Promise<{
32
+ address: string;
33
+ derivationPath: string;
34
+ baseDerivationPath: string;
35
+ }[]>;
36
+ getSessionOrConfirm(address?: AccountAddress): Promise<string>;
37
+ sendEvmTransaction(_transaction: unknown, _options: {
38
+ address: AccountAddress;
39
+ evmChainId: EvmChainId;
40
+ }): Promise<string>;
41
+ sendTransaction(transaction: DirectSignResponse | CosmosTxV1Beta1TxPb.TxRaw, _options: {
42
+ address: AccountAddress;
43
+ chainId: ChainId;
44
+ }): Promise<TxResponse>;
45
+ signAminoCosmosTransaction(_transaction: {
46
+ address: string;
47
+ signDoc: StdSignDoc;
48
+ }): Promise<AminoSignResponse>;
49
+ signCosmosTransaction(transaction: {
50
+ txRaw: CosmosTxV1Beta1TxPb.TxRaw;
51
+ chainId: string;
52
+ address: string;
53
+ accountNumber: number;
54
+ }): Promise<DirectSignResponse>;
55
+ getPubKey(): Promise<string>;
56
+ signEip712TypedData(_eip712TypedData: string, _address: AccountAddress): Promise<string>;
57
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
58
+ getEthereumChainId(): Promise<string>;
59
+ getEvmTransactionReceipt(_txHash: string): Promise<string>;
60
+ getOfflineSigner(chainId: string): Promise<OfflineSigner>;
61
+ private getCosmostationWallet;
62
+ }
63
+ //#endregion
64
+ export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
package/dist/esm/index.js CHANGED
@@ -1,3 +1,263 @@
1
- export { CosmostationWallet } from './wallet.js';
2
- export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy.js';
3
- export * from './utils/index.js';
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,3 +1,3 @@
1
1
  {
2
- "type": "module"
3
- }
2
+ "type": "module"
3
+ }