@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.
@@ -0,0 +1,3 @@
1
+ export { CosmostationWallet } from './wallet.js';
2
+ export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy.js';
3
+ export * from './utils/index.js';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CosmostationWalletStrategy = exports.CosmostationWallet = void 0;
18
+ var wallet_js_1 = require("./wallet.js");
19
+ Object.defineProperty(exports, "CosmostationWallet", { enumerable: true, get: function () { return wallet_js_1.CosmostationWallet; } });
20
+ var strategy_js_1 = require("./strategy/strategy.js");
21
+ Object.defineProperty(exports, "CosmostationWalletStrategy", { enumerable: true, get: function () { return strategy_js_1.Cosmostation; } });
22
+ __exportStar(require("./utils/index.js"), exports);
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
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,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cosmostation = void 0;
4
+ const proto_signing_1 = require("@cosmjs/proto-signing");
5
+ const ts_types_1 = require("@injectivelabs/ts-types");
6
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
7
+ const extension_client_1 = require("@cosmostation/extension-client");
8
+ const cosmos_client_1 = require("@cosmostation/cosmos-client");
9
+ const cosmos_js_1 = require("@cosmostation/extension-client/cosmos.js");
10
+ const sdk_ts_2 = require("@injectivelabs/sdk-ts");
11
+ const exceptions_1 = require("@injectivelabs/exceptions");
12
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
13
+ const wallet_js_1 = require("./../wallet.js");
14
+ const getChainNameFromChainId = (chainId) => {
15
+ const [chainName] = chainId.split('-');
16
+ if (chainName.includes('cosmoshub')) {
17
+ return 'cosmos';
18
+ }
19
+ if (chainName.includes('core')) {
20
+ return 'persistence';
21
+ }
22
+ if (chainName.includes('evmos')) {
23
+ return 'evmos';
24
+ }
25
+ if (chainId.includes('ssc') || chainId.includes('fetch')) {
26
+ return chainId;
27
+ }
28
+ return chainName;
29
+ };
30
+ class Cosmostation extends wallet_base_1.BaseConcreteStrategy {
31
+ cosmostationWallet;
32
+ chainName;
33
+ constructor(args) {
34
+ super(args);
35
+ this.chainId = args.chainId || ts_types_1.CosmosChainId.Injective;
36
+ this.chainName = getChainNameFromChainId(this.chainId);
37
+ }
38
+ async getWalletDeviceType() {
39
+ return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
40
+ }
41
+ async enable() {
42
+ return Promise.resolve(true);
43
+ }
44
+ async getAddresses() {
45
+ const cosmostationWallet = await this.getCosmostationWallet();
46
+ try {
47
+ const accounts = await cosmostationWallet.requestAccount(this.chainName);
48
+ return [accounts.address];
49
+ }
50
+ catch (e) {
51
+ if (e.code === 4001) {
52
+ throw new exceptions_1.CosmosWalletException(new Error('The user rejected the request'), {
53
+ code: exceptions_1.UnspecifiedErrorCode,
54
+ context: wallet_base_1.WalletAction.GetAccounts,
55
+ });
56
+ }
57
+ throw new exceptions_1.CosmosWalletException(new Error(e.message), {
58
+ code: exceptions_1.UnspecifiedErrorCode,
59
+ context: wallet_base_1.WalletAction.GetAccounts,
60
+ });
61
+ }
62
+ }
63
+ async getSessionOrConfirm(address) {
64
+ return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
65
+ }
66
+ async sendEvmTransaction(_transaction, _options) {
67
+ throw new exceptions_1.CosmosWalletException(new Error('sendEvmTransaction is not supported. Cosmostation only supports sending cosmos transactions'), {
68
+ code: exceptions_1.UnspecifiedErrorCode,
69
+ context: wallet_base_1.WalletAction.SendEvmTransaction,
70
+ });
71
+ }
72
+ async sendTransaction(transaction, _options) {
73
+ const cosmostationWallet = await this.getCosmostationWallet();
74
+ const txRaw = (0, sdk_ts_2.createTxRawFromSigResponse)(transaction);
75
+ try {
76
+ const response = await cosmostationWallet.sendTransaction(this.chainName, sdk_ts_1.CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(), cosmos_js_1.SEND_TRANSACTION_MODE.SYNC);
77
+ return {
78
+ ...response.tx_response,
79
+ gasUsed: parseInt((response.tx_response.gas_used || '0'), 10),
80
+ gasWanted: parseInt((response.tx_response.gas_wanted || '0'), 10),
81
+ height: parseInt((response.tx_response.height || '0'), 10),
82
+ txHash: response.tx_response.txhash,
83
+ rawLog: response.tx_response.raw_log,
84
+ };
85
+ }
86
+ catch (e) {
87
+ if (e instanceof exceptions_1.TransactionException) {
88
+ throw e;
89
+ }
90
+ throw new exceptions_1.TransactionException(new Error(e.message), {
91
+ code: exceptions_1.UnspecifiedErrorCode,
92
+ context: wallet_base_1.WalletAction.SendTransaction,
93
+ });
94
+ }
95
+ }
96
+ async signAminoCosmosTransaction(_transaction) {
97
+ throw new exceptions_1.CosmosWalletException(new Error('This wallet does not support signing using amino'), {
98
+ code: exceptions_1.UnspecifiedErrorCode,
99
+ context: wallet_base_1.WalletAction.SendTransaction,
100
+ });
101
+ }
102
+ async signCosmosTransaction(transaction) {
103
+ const { chainId } = this;
104
+ const cosmostationWallet = await this.getCosmostationWallet();
105
+ const signDoc = (0, sdk_ts_2.createSignDocFromTransaction)(transaction);
106
+ try {
107
+ /* Sign the transaction */
108
+ const signDirectResponse = await cosmostationWallet.signDirect(this.chainName, {
109
+ chain_id: chainId,
110
+ body_bytes: signDoc.bodyBytes,
111
+ auth_info_bytes: signDoc.authInfoBytes,
112
+ account_number: signDoc.accountNumber.toString(),
113
+ }, { fee: true, memo: true });
114
+ return {
115
+ signed: (0, proto_signing_1.makeSignDoc)(signDirectResponse.signed_doc.body_bytes, signDirectResponse.signed_doc.auth_info_bytes, signDirectResponse.signed_doc.chain_id, parseInt(signDirectResponse.signed_doc.account_number, 10)),
116
+ signature: {
117
+ signature: signDirectResponse.signature,
118
+ },
119
+ };
120
+ }
121
+ catch (e) {
122
+ throw new exceptions_1.CosmosWalletException(new Error(e.message), {
123
+ code: exceptions_1.UnspecifiedErrorCode,
124
+ context: wallet_base_1.WalletAction.SendTransaction,
125
+ });
126
+ }
127
+ }
128
+ async getPubKey() {
129
+ const cosmostationWallet = await this.getCosmostationWallet();
130
+ try {
131
+ const account = await cosmostationWallet.requestAccount(this.chainName);
132
+ return Buffer.from(account.publicKey).toString('base64');
133
+ }
134
+ catch (e) {
135
+ if (e.code === 4001) {
136
+ throw new exceptions_1.CosmosWalletException(new Error('The user rejected the request'), {
137
+ code: exceptions_1.UnspecifiedErrorCode,
138
+ context: wallet_base_1.WalletAction.GetAccounts,
139
+ });
140
+ }
141
+ throw new exceptions_1.CosmosWalletException(new Error(e.message), {
142
+ code: exceptions_1.UnspecifiedErrorCode,
143
+ context: wallet_base_1.WalletAction.GetAccounts,
144
+ });
145
+ }
146
+ }
147
+ async signEip712TypedData(_eip712TypedData, _address) {
148
+ throw new exceptions_1.CosmosWalletException(new Error('This wallet does not support signing Evm transactions'), {
149
+ code: exceptions_1.UnspecifiedErrorCode,
150
+ context: wallet_base_1.WalletAction.SendTransaction,
151
+ });
152
+ }
153
+ async signArbitrary(signer, data) {
154
+ try {
155
+ const cosmostationWallet = await this.getCosmostationWallet();
156
+ const signature = await cosmostationWallet.signMessage(this.chainName, signer, (0, sdk_ts_2.toUtf8)(data));
157
+ return signature.signature;
158
+ }
159
+ catch (e) {
160
+ throw new exceptions_1.CosmosWalletException(new Error(e.message), {
161
+ code: exceptions_1.UnspecifiedErrorCode,
162
+ context: wallet_base_1.WalletAction.SignArbitrary,
163
+ });
164
+ }
165
+ }
166
+ async getEthereumChainId() {
167
+ throw new exceptions_1.CosmosWalletException(new Error('getEthereumChainId is not supported on Cosmostation'), {
168
+ code: exceptions_1.UnspecifiedErrorCode,
169
+ context: wallet_base_1.WalletAction.GetChainId,
170
+ });
171
+ }
172
+ async getEvmTransactionReceipt(_txHash) {
173
+ throw new exceptions_1.CosmosWalletException(new Error('getEvmTransactionReceipt is not supported on Cosmostation'), {
174
+ code: exceptions_1.UnspecifiedErrorCode,
175
+ type: exceptions_1.ErrorType.WalletError,
176
+ context: wallet_base_1.WalletAction.GetEvmTransactionReceipt,
177
+ });
178
+ }
179
+ async getOfflineSigner(chainId) {
180
+ return (await (0, cosmos_client_1.getOfflineSigner)(chainId));
181
+ }
182
+ async getCosmostationWallet() {
183
+ if (this.cosmostationWallet) {
184
+ return this.cosmostationWallet;
185
+ }
186
+ const cosmostationWallet = new wallet_js_1.CosmostationWallet(this.chainId);
187
+ try {
188
+ const provider = await cosmostationWallet.getCosmostationWallet();
189
+ this.cosmostationWallet = provider;
190
+ return provider;
191
+ }
192
+ catch (e) {
193
+ if (e instanceof extension_client_1.InstallError) {
194
+ throw new exceptions_1.CosmosWalletException(new Error('Please install the Cosmostation extension'), {
195
+ code: exceptions_1.UnspecifiedErrorCode,
196
+ type: exceptions_1.ErrorType.WalletNotInstalledError,
197
+ });
198
+ }
199
+ throw new exceptions_1.CosmosWalletException(new Error(e.message), {
200
+ code: exceptions_1.UnspecifiedErrorCode,
201
+ });
202
+ }
203
+ }
204
+ }
205
+ exports.Cosmostation = Cosmostation;
@@ -0,0 +1 @@
1
+ export declare const isCosmosStationWalletInstalled: () => boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCosmosStationWalletInstalled = void 0;
4
+ const isCosmosStationWalletInstalled = () => {
5
+ const $window = (typeof window !== 'undefined' ? window : {});
6
+ return $window.cosmostation !== undefined;
7
+ };
8
+ exports.isCosmosStationWalletInstalled = isCosmosStationWalletInstalled;
@@ -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")>;
8
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CosmostationWallet = void 0;
4
+ const extension_client_1 = require("@cosmostation/extension-client");
5
+ const exceptions_1 = require("@injectivelabs/exceptions");
6
+ class CosmostationWallet {
7
+ chainId;
8
+ constructor(chainId) {
9
+ this.chainId = chainId;
10
+ }
11
+ static async isChainIdSupported(chainId) {
12
+ return new CosmostationWallet(chainId).checkChainIdSupport();
13
+ }
14
+ async checkChainIdSupport() {
15
+ const { chainId: actualChainId } = this;
16
+ const provider = await this.getCosmostationWallet();
17
+ const chainName = actualChainId.split('-');
18
+ try {
19
+ const supportedChainIds = await provider.getSupportedChainIds();
20
+ return !!supportedChainIds.official.find((chainId) => chainId === actualChainId);
21
+ }
22
+ catch {
23
+ throw new exceptions_1.CosmosWalletException(new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
24
+ }
25
+ }
26
+ async getCosmostationWallet() {
27
+ try {
28
+ const provider = await (0, extension_client_1.cosmos)();
29
+ return provider;
30
+ }
31
+ catch (e) {
32
+ if (e instanceof extension_client_1.InstallError) {
33
+ throw new exceptions_1.CosmosWalletException(new Error('Please install the Cosmostation extension'), {
34
+ code: exceptions_1.UnspecifiedErrorCode,
35
+ type: exceptions_1.ErrorType.WalletNotInstalledError,
36
+ });
37
+ }
38
+ throw new exceptions_1.CosmosWalletException(new Error(e.message), {
39
+ code: exceptions_1.UnspecifiedErrorCode,
40
+ });
41
+ }
42
+ }
43
+ }
44
+ exports.CosmostationWallet = CosmostationWallet;
@@ -1,64 +1,3 @@
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 };
1
+ export { CosmostationWallet } from './wallet.js';
2
+ export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy.js';
3
+ export * from './utils/index.js';