@injectivelabs/wallet-cosmostation 1.16.25-alpha.0 → 1.16.25

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,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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-cosmostation",
3
3
  "description": "Cosmostation strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.16.25-alpha.0",
4
+ "version": "1.16.25",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -41,35 +41,35 @@
41
41
  }
42
42
  },
43
43
  "scripts": {
44
- "build": "pnpm type-check && tsdown",
45
- "build:fast": "tsdown",
46
- "build:watch": "tsdown --watch",
47
- "clean": "shx rm -rf dist coverage *.log junit.xml && shx mkdir -p dist",
48
- "type-check": "tsc --noEmit",
49
- "test": "vitest",
50
- "test:watch": "vitest --watch",
51
- "test:ci": "vitest run --coverage --reporter=verbose",
52
- "coverage": "vitest run --coverage",
44
+ "build": "pnpm build:cjs && pnpm build:esm && pnpm build:post",
45
+ "build:cjs": "tsc --build --force tsconfig.build.json",
46
+ "build:esm": "tsc --build --force tsconfig.build.esm.json",
47
+ "build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && pnpm build:post",
48
+ "build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
49
+ "clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
50
+ "test": "jest",
51
+ "test:watch": "jest --watch",
52
+ "test:ci": "jest --coverage --ci --reporters='jest-junit'",
53
+ "coverage": "jest --coverage",
53
54
  "coverage:show": "live-server coverage",
54
55
  "dev": "ts-node -r tsconfig-paths/register src/index.ts",
55
- "start": "node dist/index.js",
56
- "lint": "eslint . --ext .ts,.js"
56
+ "start": "node dist/index.js"
57
57
  },
58
58
  "dependencies": {
59
59
  "@cosmjs/proto-signing": "^0.32.3",
60
60
  "@cosmostation/cosmos-client": "^0.0.5",
61
61
  "@cosmostation/extension-client": "^0.1.15",
62
- "@injectivelabs/exceptions": "1.16.25-alpha.0",
63
- "@injectivelabs/sdk-ts": "1.16.25-alpha.0",
64
- "@injectivelabs/ts-types": "1.16.25-alpha.0",
65
- "@injectivelabs/utils": "1.16.25-alpha.0",
66
- "@injectivelabs/wallet-base": "1.16.25-alpha.0",
62
+ "@injectivelabs/exceptions": "1.16.25",
63
+ "@injectivelabs/sdk-ts": "1.16.25",
64
+ "@injectivelabs/ts-types": "1.16.25",
65
+ "@injectivelabs/utils": "1.16.25",
66
+ "@injectivelabs/wallet-base": "1.16.25",
67
67
  "@walletconnect/ethereum-provider": "2.18.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "shx": "^0.3.4"
71
71
  },
72
- "gitHead": "8766fbe2bf8e2b54c7ee70430dd02b2a5da8e924",
72
+ "gitHead": "8d76833757d81a27d05410ddab96bd9f513d6f5b",
73
73
  "typedoc": {
74
74
  "entryPoint": "./src/index.ts",
75
75
  "readmeFile": "./README.md",
@@ -1,257 +0,0 @@
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_wallet_base = require("@injectivelabs/wallet-base");
9
-
10
- //#region src/utils/index.ts
11
- const isCosmosStationWalletInstalled = () => {
12
- return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
13
- };
14
-
15
- //#endregion
16
- //#region \0@oxc-project+runtime@0.96.0/helpers/typeof.js
17
- function _typeof(o) {
18
- "@babel/helpers - typeof";
19
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
20
- return typeof o$1;
21
- } : function(o$1) {
22
- return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
23
- }, _typeof(o);
24
- }
25
-
26
- //#endregion
27
- //#region \0@oxc-project+runtime@0.96.0/helpers/toPrimitive.js
28
- function toPrimitive(t, r) {
29
- if ("object" != _typeof(t) || !t) return t;
30
- var e = t[Symbol.toPrimitive];
31
- if (void 0 !== e) {
32
- var i = e.call(t, r || "default");
33
- if ("object" != _typeof(i)) return i;
34
- throw new TypeError("@@toPrimitive must return a primitive value.");
35
- }
36
- return ("string" === r ? String : Number)(t);
37
- }
38
-
39
- //#endregion
40
- //#region \0@oxc-project+runtime@0.96.0/helpers/toPropertyKey.js
41
- function toPropertyKey(t) {
42
- var i = toPrimitive(t, "string");
43
- return "symbol" == _typeof(i) ? i : i + "";
44
- }
45
-
46
- //#endregion
47
- //#region \0@oxc-project+runtime@0.96.0/helpers/defineProperty.js
48
- function _defineProperty(e, r, t) {
49
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
50
- value: t,
51
- enumerable: !0,
52
- configurable: !0,
53
- writable: !0
54
- }) : e[r] = t, e;
55
- }
56
-
57
- //#endregion
58
- //#region src/wallet.ts
59
- var CosmostationWallet = class CosmostationWallet {
60
- constructor(chainId) {
61
- _defineProperty(this, "chainId", void 0);
62
- this.chainId = chainId;
63
- }
64
- static async isChainIdSupported(chainId) {
65
- return new CosmostationWallet(chainId).checkChainIdSupport();
66
- }
67
- async checkChainIdSupport() {
68
- const { chainId: actualChainId } = this;
69
- const provider = await this.getCosmostationWallet();
70
- const chainName = actualChainId.split("-");
71
- try {
72
- return !!(await provider.getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
73
- } catch (_unused) {
74
- throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
75
- }
76
- }
77
- async getCosmostationWallet() {
78
- try {
79
- return await (0, __cosmostation_extension_client.cosmos)();
80
- } catch (e) {
81
- if (e instanceof __cosmostation_extension_client.InstallError) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
82
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
83
- type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
84
- });
85
- throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
86
- }
87
- }
88
- };
89
-
90
- //#endregion
91
- //#region src/strategy/strategy.ts
92
- const getChainNameFromChainId = (chainId) => {
93
- const [chainName] = chainId.split("-");
94
- if (chainName.includes("cosmoshub")) return "cosmos";
95
- if (chainName.includes("core")) return "persistence";
96
- if (chainName.includes("evmos")) return "evmos";
97
- if (chainId.includes("ssc") || chainId.includes("fetch")) return chainId;
98
- return chainName;
99
- };
100
- var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
101
- constructor(args) {
102
- super(args);
103
- _defineProperty(this, "cosmostationWallet", void 0);
104
- _defineProperty(this, "chainName", void 0);
105
- this.chainId = args.chainId || __injectivelabs_ts_types.CosmosChainId.Injective;
106
- this.chainName = getChainNameFromChainId(this.chainId);
107
- }
108
- async getWalletDeviceType() {
109
- return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Browser);
110
- }
111
- async enable() {
112
- return Promise.resolve(true);
113
- }
114
- async getAddresses() {
115
- const cosmostationWallet = await this.getCosmostationWallet();
116
- try {
117
- return [(await cosmostationWallet.requestAccount(this.chainName)).address];
118
- } catch (e) {
119
- if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
120
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
121
- context: __injectivelabs_wallet_base.WalletAction.GetAccounts
122
- });
123
- throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
124
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
125
- context: __injectivelabs_wallet_base.WalletAction.GetAccounts
126
- });
127
- }
128
- }
129
- async getSessionOrConfirm(address) {
130
- return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
131
- }
132
- async sendEvmTransaction(_transaction, _options) {
133
- throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("sendEvmTransaction is not supported. Cosmostation only supports sending cosmos transactions"), {
134
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
135
- context: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
136
- });
137
- }
138
- async sendTransaction(transaction, _options) {
139
- const cosmostationWallet = await this.getCosmostationWallet();
140
- const txRaw = (0, __injectivelabs_sdk_ts.createTxRawFromSigResponse)(transaction);
141
- try {
142
- const response = await cosmostationWallet.sendTransaction(this.chainName, __injectivelabs_sdk_ts.CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw), __cosmostation_extension_client_cosmos_js.SEND_TRANSACTION_MODE.SYNC);
143
- return {
144
- ...response.tx_response,
145
- gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
146
- gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
147
- height: parseInt(response.tx_response.height || "0", 10),
148
- txHash: response.tx_response.txhash,
149
- rawLog: response.tx_response.raw_log
150
- };
151
- } catch (e) {
152
- if (e instanceof __injectivelabs_exceptions.TransactionException) throw e;
153
- throw new __injectivelabs_exceptions.TransactionException(new Error(e.message), {
154
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
155
- context: __injectivelabs_wallet_base.WalletAction.SendTransaction
156
- });
157
- }
158
- }
159
- async signAminoCosmosTransaction(_transaction) {
160
- throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing using amino"), {
161
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
162
- context: __injectivelabs_wallet_base.WalletAction.SendTransaction
163
- });
164
- }
165
- async signCosmosTransaction(transaction) {
166
- const { chainId } = this;
167
- const cosmostationWallet = await this.getCosmostationWallet();
168
- const signDoc = (0, __injectivelabs_sdk_ts.createSignDocFromTransaction)(transaction);
169
- try {
170
- const signDirectResponse = await cosmostationWallet.signDirect(this.chainName, {
171
- chain_id: chainId,
172
- body_bytes: signDoc.bodyBytes,
173
- auth_info_bytes: signDoc.authInfoBytes,
174
- account_number: signDoc.accountNumber.toString()
175
- }, {
176
- fee: true,
177
- memo: true
178
- });
179
- return {
180
- 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)),
181
- signature: { signature: signDirectResponse.signature }
182
- };
183
- } catch (e) {
184
- throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
185
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
186
- context: __injectivelabs_wallet_base.WalletAction.SendTransaction
187
- });
188
- }
189
- }
190
- async getPubKey() {
191
- const cosmostationWallet = await this.getCosmostationWallet();
192
- try {
193
- return (0, __injectivelabs_sdk_ts.uint8ArrayToBase64)((await cosmostationWallet.requestAccount(this.chainName)).publicKey);
194
- } catch (e) {
195
- if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
196
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
197
- context: __injectivelabs_wallet_base.WalletAction.GetAccounts
198
- });
199
- throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
200
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
201
- context: __injectivelabs_wallet_base.WalletAction.GetAccounts
202
- });
203
- }
204
- }
205
- async signEip712TypedData(_eip712TypedData, _address) {
206
- throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing Evm transactions"), {
207
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
208
- context: __injectivelabs_wallet_base.WalletAction.SendTransaction
209
- });
210
- }
211
- async signArbitrary(signer, data) {
212
- try {
213
- return (await (await this.getCosmostationWallet()).signMessage(this.chainName, signer, (0, __injectivelabs_sdk_ts.toUtf8)(data))).signature;
214
- } catch (e) {
215
- throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
216
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
217
- context: __injectivelabs_wallet_base.WalletAction.SignArbitrary
218
- });
219
- }
220
- }
221
- async getEthereumChainId() {
222
- throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEthereumChainId is not supported on Cosmostation"), {
223
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
224
- context: __injectivelabs_wallet_base.WalletAction.GetChainId
225
- });
226
- }
227
- async getEvmTransactionReceipt(_txHash) {
228
- throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEvmTransactionReceipt is not supported on Cosmostation"), {
229
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
230
- type: __injectivelabs_exceptions.ErrorType.WalletError,
231
- context: __injectivelabs_wallet_base.WalletAction.GetEvmTransactionReceipt
232
- });
233
- }
234
- async getOfflineSigner(chainId) {
235
- return await (0, __cosmostation_cosmos_client.getOfflineSigner)(chainId);
236
- }
237
- async getCosmostationWallet() {
238
- if (this.cosmostationWallet) return this.cosmostationWallet;
239
- const cosmostationWallet = new CosmostationWallet(this.chainId);
240
- try {
241
- const provider = await cosmostationWallet.getCosmostationWallet();
242
- this.cosmostationWallet = provider;
243
- return provider;
244
- } catch (e) {
245
- if (e instanceof __cosmostation_extension_client.InstallError) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
246
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
247
- type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
248
- });
249
- throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
250
- }
251
- }
252
- };
253
-
254
- //#endregion
255
- exports.CosmostationWallet = CosmostationWallet;
256
- exports.CosmostationWalletStrategy = Cosmostation;
257
- exports.isCosmosStationWalletInstalled = isCosmosStationWalletInstalled;