@injectivelabs/wallet-cosmostation 1.16.38 → 1.16.39-alpha.1
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/cjs/index.cjs +265 -0
- package/dist/cjs/index.d.cts +64 -0
- package/dist/cjs/package.json +2 -2
- package/dist/esm/index.d.ts +64 -3
- package/dist/esm/index.js +263 -3
- package/dist/esm/package.json +2 -2
- package/package.json +42 -50
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/strategy/strategy.d.ts +0 -43
- package/dist/cjs/strategy/strategy.js +0 -205
- package/dist/cjs/utils/index.d.ts +0 -1
- package/dist/cjs/utils/index.js +0 -8
- package/dist/cjs/wallet.d.ts +0 -8
- package/dist/cjs/wallet.js +0 -44
- package/dist/esm/strategy/strategy.d.ts +0 -43
- package/dist/esm/strategy/strategy.js +0 -201
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +0 -4
- package/dist/esm/wallet.d.ts +0 -8
- package/dist/esm/wallet.js +0 -40
|
@@ -1,201 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isCosmosStationWalletInstalled: () => boolean;
|
package/dist/esm/utils/index.js
DELETED
package/dist/esm/wallet.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/esm/wallet.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
}
|