@injectivelabs/wallet-cosmostation 1.16.25-alpha.1 → 1.16.26
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.d.ts +3 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/strategy/strategy.d.ts +43 -0
- package/dist/cjs/strategy/strategy.js +205 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/wallet.d.ts +8 -0
- package/dist/cjs/wallet.js +44 -0
- package/dist/esm/index.d.ts +3 -57
- package/dist/esm/index.js +3 -255
- package/dist/esm/package.json +2 -2
- package/dist/esm/strategy/strategy.d.ts +43 -0
- package/dist/esm/strategy/strategy.js +201 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/wallet.d.ts +8 -0
- package/dist/esm/wallet.js +40 -0
- package/package.json +18 -18
- package/dist/cjs/index.cjs +0 -257
- package/dist/cjs/index.d.cts +0 -57
|
@@ -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);
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
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;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,57 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import * as _cosmostation_extension_client_cosmos_js0 from "@cosmostation/extension-client/cosmos.js";
|
|
5
|
-
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
6
|
-
|
|
7
|
-
//#region src/utils/index.d.ts
|
|
8
|
-
declare const isCosmosStationWalletInstalled: () => boolean;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/wallet.d.ts
|
|
11
|
-
declare class CosmostationWallet {
|
|
12
|
-
private chainId;
|
|
13
|
-
constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
|
|
14
|
-
static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
|
|
15
|
-
checkChainIdSupport(): Promise<boolean>;
|
|
16
|
-
getCosmostationWallet(): Promise<typeof _cosmostation_extension_client_cosmos_js0>;
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/strategy/strategy.d.ts
|
|
20
|
-
declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
21
|
-
private cosmostationWallet?;
|
|
22
|
-
chainName: string;
|
|
23
|
-
constructor(args: {
|
|
24
|
-
chainId: ChainId | CosmosChainId;
|
|
25
|
-
});
|
|
26
|
-
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
27
|
-
enable(): Promise<boolean>;
|
|
28
|
-
getAddresses(): Promise<string[]>;
|
|
29
|
-
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
30
|
-
sendEvmTransaction(_transaction: unknown, _options: {
|
|
31
|
-
address: AccountAddress;
|
|
32
|
-
evmChainId: EvmChainId;
|
|
33
|
-
}): Promise<string>;
|
|
34
|
-
sendTransaction(transaction: DirectSignResponse | CosmosTxV1Beta1TxPb.TxRaw, _options: {
|
|
35
|
-
address: AccountAddress;
|
|
36
|
-
chainId: ChainId;
|
|
37
|
-
}): Promise<TxResponse>;
|
|
38
|
-
signAminoCosmosTransaction(_transaction: {
|
|
39
|
-
address: string;
|
|
40
|
-
signDoc: StdSignDoc;
|
|
41
|
-
}): Promise<AminoSignResponse>;
|
|
42
|
-
signCosmosTransaction(transaction: {
|
|
43
|
-
txRaw: CosmosTxV1Beta1TxPb.TxRaw;
|
|
44
|
-
chainId: string;
|
|
45
|
-
address: string;
|
|
46
|
-
accountNumber: number;
|
|
47
|
-
}): Promise<DirectSignResponse>;
|
|
48
|
-
getPubKey(): Promise<string>;
|
|
49
|
-
signEip712TypedData(_eip712TypedData: string, _address: AccountAddress): Promise<string>;
|
|
50
|
-
signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
|
|
51
|
-
getEthereumChainId(): Promise<string>;
|
|
52
|
-
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
53
|
-
getOfflineSigner(chainId: string): Promise<OfflineSigner>;
|
|
54
|
-
private getCosmostationWallet;
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
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';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,255 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { CosmosChainId } from "@injectivelabs/ts-types";
|
|
5
|
-
import { CosmosTxV1Beta1TxPb, createSignDocFromTransaction, createTxRawFromSigResponse, stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts";
|
|
6
|
-
import { getOfflineSigner } from "@cosmostation/cosmos-client";
|
|
7
|
-
import { SEND_TRANSACTION_MODE } from "@cosmostation/extension-client/cosmos.js";
|
|
8
|
-
import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@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 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 cosmos();
|
|
80
|
-
} catch (e) {
|
|
81
|
-
if (e instanceof InstallError) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
82
|
-
code: UnspecifiedErrorCode,
|
|
83
|
-
type: ErrorType.WalletNotInstalledError
|
|
84
|
-
});
|
|
85
|
-
throw new CosmosWalletException(new Error(e.message), { code: 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 BaseConcreteStrategy {
|
|
101
|
-
constructor(args) {
|
|
102
|
-
super(args);
|
|
103
|
-
_defineProperty(this, "cosmostationWallet", void 0);
|
|
104
|
-
_defineProperty(this, "chainName", void 0);
|
|
105
|
-
this.chainId = args.chainId || CosmosChainId.Injective;
|
|
106
|
-
this.chainName = getChainNameFromChainId(this.chainId);
|
|
107
|
-
}
|
|
108
|
-
async getWalletDeviceType() {
|
|
109
|
-
return Promise.resolve(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 CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
120
|
-
code: UnspecifiedErrorCode,
|
|
121
|
-
context: WalletAction.GetAccounts
|
|
122
|
-
});
|
|
123
|
-
throw new CosmosWalletException(new Error(e.message), {
|
|
124
|
-
code: UnspecifiedErrorCode,
|
|
125
|
-
context: WalletAction.GetAccounts
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async getSessionOrConfirm(address) {
|
|
130
|
-
return Promise.resolve(`0x${uint8ArrayToHex(stringToUint8Array(`Confirmation for ${address} at time: ${Date.now()}`))}`);
|
|
131
|
-
}
|
|
132
|
-
async sendEvmTransaction(_transaction, _options) {
|
|
133
|
-
throw new CosmosWalletException(/* @__PURE__ */ new Error("sendEvmTransaction is not supported. Cosmostation only supports sending cosmos transactions"), {
|
|
134
|
-
code: UnspecifiedErrorCode,
|
|
135
|
-
context: WalletAction.SendEvmTransaction
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
async sendTransaction(transaction, _options) {
|
|
139
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
140
|
-
const txRaw = createTxRawFromSigResponse(transaction);
|
|
141
|
-
try {
|
|
142
|
-
const response = await cosmostationWallet.sendTransaction(this.chainName, CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw), 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 TransactionException) throw e;
|
|
153
|
-
throw new TransactionException(new Error(e.message), {
|
|
154
|
-
code: UnspecifiedErrorCode,
|
|
155
|
-
context: WalletAction.SendTransaction
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async signAminoCosmosTransaction(_transaction) {
|
|
160
|
-
throw new CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing using amino"), {
|
|
161
|
-
code: UnspecifiedErrorCode,
|
|
162
|
-
context: WalletAction.SendTransaction
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
async signCosmosTransaction(transaction) {
|
|
166
|
-
const { chainId } = this;
|
|
167
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
168
|
-
const signDoc = 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: 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 CosmosWalletException(new Error(e.message), {
|
|
185
|
-
code: UnspecifiedErrorCode,
|
|
186
|
-
context: WalletAction.SendTransaction
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
async getPubKey() {
|
|
191
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
192
|
-
try {
|
|
193
|
-
return uint8ArrayToBase64((await cosmostationWallet.requestAccount(this.chainName)).publicKey);
|
|
194
|
-
} catch (e) {
|
|
195
|
-
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
196
|
-
code: UnspecifiedErrorCode,
|
|
197
|
-
context: WalletAction.GetAccounts
|
|
198
|
-
});
|
|
199
|
-
throw new CosmosWalletException(new Error(e.message), {
|
|
200
|
-
code: UnspecifiedErrorCode,
|
|
201
|
-
context: WalletAction.GetAccounts
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
async signEip712TypedData(_eip712TypedData, _address) {
|
|
206
|
-
throw new CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing Evm transactions"), {
|
|
207
|
-
code: UnspecifiedErrorCode,
|
|
208
|
-
context: WalletAction.SendTransaction
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
async signArbitrary(signer, data) {
|
|
212
|
-
try {
|
|
213
|
-
return (await (await this.getCosmostationWallet()).signMessage(this.chainName, signer, toUtf8(data))).signature;
|
|
214
|
-
} catch (e) {
|
|
215
|
-
throw new CosmosWalletException(new Error(e.message), {
|
|
216
|
-
code: UnspecifiedErrorCode,
|
|
217
|
-
context: WalletAction.SignArbitrary
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
async getEthereumChainId() {
|
|
222
|
-
throw new CosmosWalletException(/* @__PURE__ */ new Error("getEthereumChainId is not supported on Cosmostation"), {
|
|
223
|
-
code: UnspecifiedErrorCode,
|
|
224
|
-
context: WalletAction.GetChainId
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
async getEvmTransactionReceipt(_txHash) {
|
|
228
|
-
throw new CosmosWalletException(/* @__PURE__ */ new Error("getEvmTransactionReceipt is not supported on Cosmostation"), {
|
|
229
|
-
code: UnspecifiedErrorCode,
|
|
230
|
-
type: ErrorType.WalletError,
|
|
231
|
-
context: WalletAction.GetEvmTransactionReceipt
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
async getOfflineSigner(chainId) {
|
|
235
|
-
return await 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 InstallError) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
246
|
-
code: UnspecifiedErrorCode,
|
|
247
|
-
type: ErrorType.WalletNotInstalledError
|
|
248
|
-
});
|
|
249
|
-
throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
//#endregion
|
|
255
|
-
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';
|
package/dist/esm/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "module"
|
|
3
|
+
}
|