@injectivelabs/wallet-cosmostation 1.16.37 → 1.16.38-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 +257 -0
- package/dist/cjs/index.d.cts +57 -0
- package/dist/cjs/package.json +2 -2
- package/dist/esm/index.d.ts +57 -3
- package/dist/esm/index.js +255 -3
- package/dist/esm/package.json +2 -2
- package/package.json +33 -38
- 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
|
@@ -0,0 +1,257 @@
|
|
|
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.98.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.98.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.98.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.98.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;
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { AminoSignResponse, CosmosTxV1Beta1TxPb, DirectSignResponse, TxResponse } from "@injectivelabs/sdk-ts";
|
|
4
|
+
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
5
|
+
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
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_cosmos0>;
|
|
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 };
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "commonjs"
|
|
3
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
2
|
+
import { AccountAddress, ChainId, CosmosChainId, EvmChainId, TestnetCosmosChainId } from "@injectivelabs/ts-types";
|
|
3
|
+
import { AminoSignResponse, CosmosTxV1Beta1TxPb, DirectSignResponse, TxResponse } from "@injectivelabs/sdk-ts";
|
|
4
|
+
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
5
|
+
import * as _cosmostation_extension_client_cosmos0 from "@cosmostation/extension-client/cosmos";
|
|
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_cosmos0>;
|
|
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 };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,255 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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, 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.98.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.98.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.98.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.98.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 };
|
package/dist/esm/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "module"
|
|
3
|
+
}
|