@injectivelabs/wallet-cosmostation 1.17.2-alpha.1 → 1.17.2-alpha.2
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/README.md +12 -0
- package/dist/cjs/index.cjs +131 -48
- package/dist/cjs/index.d.cts +142 -6
- package/dist/esm/index.d.ts +142 -6
- package/dist/esm/index.js +131 -49
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# 🌟 Injective Protocol - Wallet Cosmostation
|
|
2
2
|
|
|
3
|
+
> **DEPRECATED**: This package is deprecated. Please use `@injectivelabs/wallet-cosmos` with `Wallet.Cosmostation` instead.
|
|
4
|
+
>
|
|
5
|
+
> ```typescript
|
|
6
|
+
> import { Wallet } from '@injectivelabs/wallet-base'
|
|
7
|
+
> import { CosmosWalletStrategy } from '@injectivelabs/wallet-cosmos'
|
|
8
|
+
>
|
|
9
|
+
> const strategy = new CosmosWalletStrategy({
|
|
10
|
+
> chainId: ChainId.Mainnet,
|
|
11
|
+
> wallet: Wallet.Cosmostation,
|
|
12
|
+
> })
|
|
13
|
+
> ```
|
|
14
|
+
|
|
3
15
|
<!-- TODO -->
|
|
4
16
|
|
|
5
17
|
[](https://www.npmjs.com/package/@injectivelabs/wallet-cosmostation)
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
let __cosmostation_extension_client = require("@cosmostation/extension-client");
|
|
2
1
|
let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
|
|
3
2
|
let __cosmjs_proto_signing = require("@cosmjs/proto-signing");
|
|
4
3
|
let __injectivelabs_ts_types = require("@injectivelabs/ts-types");
|
|
5
4
|
let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
|
|
6
|
-
let __cosmostation_extension_client_cosmos_js = require("@cosmostation/extension-client/cosmos.js");
|
|
7
|
-
let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
|
|
8
5
|
let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
|
|
6
|
+
let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
|
|
9
7
|
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
10
8
|
|
|
9
|
+
//#region src/types.ts
|
|
10
|
+
const SEND_TRANSACTION_MODE = {
|
|
11
|
+
UNSPECIFIED: 0,
|
|
12
|
+
BLOCK: 1,
|
|
13
|
+
SYNC: 2,
|
|
14
|
+
ASYNC: 3
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
11
18
|
//#region src/utils/index.ts
|
|
12
19
|
const isCosmosStationWalletInstalled = () => {
|
|
13
20
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -57,6 +64,33 @@ function _defineProperty(e, r, t) {
|
|
|
57
64
|
|
|
58
65
|
//#endregion
|
|
59
66
|
//#region src/wallet.ts
|
|
67
|
+
/**
|
|
68
|
+
* Get the Cosmostation cosmos provider from window.
|
|
69
|
+
* Throws if the extension is not installed.
|
|
70
|
+
*/
|
|
71
|
+
function getCosmostationProvider() {
|
|
72
|
+
var _window$cosmostation;
|
|
73
|
+
if (typeof window === "undefined" || !((_window$cosmostation = window.cosmostation) === null || _window$cosmostation === void 0 ? void 0 : _window$cosmostation.cosmos)) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
74
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
75
|
+
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
76
|
+
});
|
|
77
|
+
return window.cosmostation.cosmos;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Request an account from the Cosmostation extension.
|
|
81
|
+
*/
|
|
82
|
+
async function requestAccount(chainName) {
|
|
83
|
+
return getCosmostationProvider().request({
|
|
84
|
+
method: "cos_requestAccount",
|
|
85
|
+
params: { chainName }
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get supported chain IDs from the extension.
|
|
90
|
+
*/
|
|
91
|
+
async function getSupportedChainIds() {
|
|
92
|
+
return getCosmostationProvider().request({ method: "cos_supportedChainIds" });
|
|
93
|
+
}
|
|
60
94
|
var CosmostationWallet = class CosmostationWallet {
|
|
61
95
|
constructor(chainId) {
|
|
62
96
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -67,24 +101,16 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
67
101
|
}
|
|
68
102
|
async checkChainIdSupport() {
|
|
69
103
|
const { chainId: actualChainId } = this;
|
|
70
|
-
const provider = await this.getCosmostationWallet();
|
|
71
104
|
const chainName = actualChainId.split("-");
|
|
105
|
+
getCosmostationProvider();
|
|
72
106
|
try {
|
|
73
|
-
return !!(await
|
|
107
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
74
108
|
} catch (_unused) {
|
|
75
109
|
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
76
110
|
}
|
|
77
111
|
}
|
|
78
|
-
async
|
|
79
|
-
|
|
80
|
-
return await (0, __cosmostation_extension_client.cosmos)();
|
|
81
|
-
} catch (e) {
|
|
82
|
-
if (e instanceof __cosmostation_extension_client.InstallError) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
83
|
-
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
84
|
-
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
85
|
-
});
|
|
86
|
-
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
|
|
87
|
-
}
|
|
112
|
+
async getCosmostationProvider() {
|
|
113
|
+
return getCosmostationProvider();
|
|
88
114
|
}
|
|
89
115
|
};
|
|
90
116
|
|
|
@@ -92,14 +118,16 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
92
118
|
//#region src/strategy/strategy.ts
|
|
93
119
|
/**
|
|
94
120
|
* Get an offline signer from the Cosmostation extension.
|
|
95
|
-
* This
|
|
96
|
-
* WalletConnect v1 dependencies that cause ESM bundling issues.
|
|
121
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
97
122
|
*/
|
|
98
123
|
async function getExtensionOfflineSigner(chainId) {
|
|
99
|
-
const provider =
|
|
124
|
+
const provider = getCosmostationProvider();
|
|
100
125
|
return {
|
|
101
126
|
getAccounts: async () => {
|
|
102
|
-
const response = await provider.
|
|
127
|
+
const response = await provider.request({
|
|
128
|
+
method: "cos_account",
|
|
129
|
+
params: { chainName: chainId }
|
|
130
|
+
});
|
|
103
131
|
return [{
|
|
104
132
|
address: response.address,
|
|
105
133
|
pubkey: response.publicKey,
|
|
@@ -107,7 +135,15 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
107
135
|
}];
|
|
108
136
|
},
|
|
109
137
|
signAmino: async (_signerAddress, signDoc) => {
|
|
110
|
-
const response = await provider.
|
|
138
|
+
const response = await provider.request({
|
|
139
|
+
method: "cos_signAmino",
|
|
140
|
+
params: {
|
|
141
|
+
chainName: chainId,
|
|
142
|
+
doc: signDoc,
|
|
143
|
+
isEditFee: true,
|
|
144
|
+
isEditMemo: true
|
|
145
|
+
}
|
|
146
|
+
});
|
|
111
147
|
return {
|
|
112
148
|
signed: response.signed_doc,
|
|
113
149
|
signature: {
|
|
@@ -117,11 +153,20 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
117
153
|
};
|
|
118
154
|
},
|
|
119
155
|
signDirect: async (_signerAddress, signDoc) => {
|
|
120
|
-
const
|
|
156
|
+
const doc = {
|
|
121
157
|
account_number: String(signDoc.accountNumber),
|
|
122
158
|
auth_info_bytes: signDoc.authInfoBytes,
|
|
123
159
|
body_bytes: signDoc.bodyBytes,
|
|
124
160
|
chain_id: signDoc.chainId
|
|
161
|
+
};
|
|
162
|
+
const response = await provider.request({
|
|
163
|
+
method: "cos_signDirect",
|
|
164
|
+
params: {
|
|
165
|
+
chainName: chainId,
|
|
166
|
+
doc,
|
|
167
|
+
isEditFee: true,
|
|
168
|
+
isEditMemo: true
|
|
169
|
+
}
|
|
125
170
|
});
|
|
126
171
|
return {
|
|
127
172
|
signed: {
|
|
@@ -149,7 +194,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
149
194
|
var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
150
195
|
constructor(args) {
|
|
151
196
|
super(args);
|
|
152
|
-
_defineProperty(this, "
|
|
197
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
153
198
|
_defineProperty(this, "chainName", void 0);
|
|
154
199
|
this.chainId = args.chainId || __injectivelabs_ts_types.CosmosChainId.Injective;
|
|
155
200
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -161,9 +206,9 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
161
206
|
return Promise.resolve(true);
|
|
162
207
|
}
|
|
163
208
|
async getAddresses() {
|
|
164
|
-
|
|
209
|
+
this.getProvider();
|
|
165
210
|
try {
|
|
166
|
-
return [(await
|
|
211
|
+
return [(await requestAccount(this.chainName)).address];
|
|
167
212
|
} catch (e) {
|
|
168
213
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
169
214
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -191,17 +236,26 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
191
236
|
});
|
|
192
237
|
}
|
|
193
238
|
async sendTransaction(transaction, _options) {
|
|
194
|
-
const
|
|
239
|
+
const provider = this.getProvider();
|
|
195
240
|
const txRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(transaction);
|
|
241
|
+
const txBytes = (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)(__injectivelabs_sdk_ts.CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw));
|
|
196
242
|
try {
|
|
197
|
-
const response = await
|
|
243
|
+
const response = await provider.request({
|
|
244
|
+
method: "cos_sendTransaction",
|
|
245
|
+
params: {
|
|
246
|
+
chainName: this.chainName,
|
|
247
|
+
txBytes,
|
|
248
|
+
mode: SEND_TRANSACTION_MODE.SYNC
|
|
249
|
+
}
|
|
250
|
+
});
|
|
198
251
|
return {
|
|
199
252
|
...response.tx_response,
|
|
200
253
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
201
254
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
202
255
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
203
256
|
txHash: response.tx_response.txhash,
|
|
204
|
-
rawLog: response.tx_response.raw_log
|
|
257
|
+
rawLog: response.tx_response.raw_log,
|
|
258
|
+
timestamp: ""
|
|
205
259
|
};
|
|
206
260
|
} catch (e) {
|
|
207
261
|
if (e instanceof __injectivelabs_exceptions.TransactionException) throw e;
|
|
@@ -219,17 +273,23 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
219
273
|
}
|
|
220
274
|
async signCosmosTransaction(transaction) {
|
|
221
275
|
const { chainId } = this;
|
|
222
|
-
const
|
|
276
|
+
const provider = this.getProvider();
|
|
223
277
|
const signDoc = (0, __injectivelabs_sdk_ts_core_tx.createSignDocFromTransaction)(transaction);
|
|
278
|
+
const doc = {
|
|
279
|
+
chain_id: chainId,
|
|
280
|
+
body_bytes: signDoc.bodyBytes,
|
|
281
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
282
|
+
account_number: signDoc.accountNumber.toString()
|
|
283
|
+
};
|
|
224
284
|
try {
|
|
225
|
-
const signDirectResponse = await
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
285
|
+
const signDirectResponse = await provider.request({
|
|
286
|
+
method: "cos_signDirect",
|
|
287
|
+
params: {
|
|
288
|
+
chainName: this.chainName,
|
|
289
|
+
doc,
|
|
290
|
+
isEditFee: true,
|
|
291
|
+
isEditMemo: true
|
|
292
|
+
}
|
|
233
293
|
});
|
|
234
294
|
return {
|
|
235
295
|
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)),
|
|
@@ -243,9 +303,8 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
243
303
|
}
|
|
244
304
|
}
|
|
245
305
|
async getPubKey() {
|
|
246
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
247
306
|
try {
|
|
248
|
-
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await
|
|
307
|
+
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await requestAccount(this.chainName)).publicKey);
|
|
249
308
|
} catch (e) {
|
|
250
309
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
251
310
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -265,7 +324,16 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
265
324
|
}
|
|
266
325
|
async signArbitrary(signer, data) {
|
|
267
326
|
try {
|
|
268
|
-
|
|
327
|
+
const provider = this.getProvider();
|
|
328
|
+
const message = data instanceof Uint8Array ? new TextDecoder().decode(data) : data;
|
|
329
|
+
return (await provider.request({
|
|
330
|
+
method: "cos_signMessage",
|
|
331
|
+
params: {
|
|
332
|
+
chainName: this.chainName,
|
|
333
|
+
signer,
|
|
334
|
+
message
|
|
335
|
+
}
|
|
336
|
+
})).signature;
|
|
269
337
|
} catch (e) {
|
|
270
338
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
|
|
271
339
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -289,18 +357,32 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
289
357
|
async getOfflineSigner(chainId) {
|
|
290
358
|
return await getExtensionOfflineSigner(chainId);
|
|
291
359
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
360
|
+
/**
|
|
361
|
+
* Subscribe to account change events.
|
|
362
|
+
*/
|
|
363
|
+
onAccountChange(callback) {
|
|
364
|
+
const provider = this.getProvider();
|
|
365
|
+
const handler = async () => {
|
|
366
|
+
try {
|
|
367
|
+
callback((await requestAccount(this.chainName)).address);
|
|
368
|
+
} catch (_unused) {}
|
|
369
|
+
};
|
|
370
|
+
provider.on("cosmostation_keystorechange", handler);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Unsubscribe from account change events.
|
|
374
|
+
*/
|
|
375
|
+
offAccountChange(callback) {
|
|
376
|
+
this.getProvider().off("cosmostation_keystorechange", callback);
|
|
377
|
+
}
|
|
378
|
+
getProvider() {
|
|
379
|
+
if (this.cosmostationProvider) return this.cosmostationProvider;
|
|
295
380
|
try {
|
|
296
|
-
const provider =
|
|
297
|
-
this.
|
|
381
|
+
const provider = getCosmostationProvider();
|
|
382
|
+
this.cosmostationProvider = provider;
|
|
298
383
|
return provider;
|
|
299
384
|
} catch (e) {
|
|
300
|
-
if (e instanceof
|
|
301
|
-
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
302
|
-
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
303
|
-
});
|
|
385
|
+
if (e instanceof __injectivelabs_exceptions.CosmosWalletException && e.type === __injectivelabs_exceptions.ErrorType.WalletNotInstalledError) throw e;
|
|
304
386
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
|
|
305
387
|
}
|
|
306
388
|
}
|
|
@@ -309,4 +391,5 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
309
391
|
//#endregion
|
|
310
392
|
exports.CosmostationWallet = CosmostationWallet;
|
|
311
393
|
exports.CosmostationWalletStrategy = Cosmostation;
|
|
394
|
+
exports.SEND_TRANSACTION_MODE = SEND_TRANSACTION_MODE;
|
|
312
395
|
exports.isCosmosStationWalletInstalled = isCosmosStationWalletInstalled;
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,11 +1,139 @@
|
|
|
1
|
-
import * as _cosmostation_extension_client_cosmos0 from "@cosmostation/extension-client/cosmos";
|
|
2
1
|
import { AccountAddress, ChainId, CosmosChainId, EvmChainId, TestnetCosmosChainId } from "@injectivelabs/ts-types";
|
|
3
2
|
import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
|
|
4
|
-
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
3
|
+
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType, onAccountChangeCallback } from "@injectivelabs/wallet-base";
|
|
5
4
|
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
6
5
|
import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
7
6
|
import { AminoSignResponse, DirectSignResponse } from "@injectivelabs/sdk-ts/types";
|
|
8
7
|
|
|
8
|
+
//#region src/types.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* TypeScript interfaces for the vanilla Cosmostation browser extension API.
|
|
11
|
+
* These replace the @cosmostation/extension-client package types.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.cosmostation.io/extension/cosmos/integrate
|
|
14
|
+
*/
|
|
15
|
+
interface CosmostationAccount {
|
|
16
|
+
name: string;
|
|
17
|
+
address: string;
|
|
18
|
+
publicKey: Uint8Array;
|
|
19
|
+
isLedger: boolean;
|
|
20
|
+
isEthermint?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface CosmostationSignDirectDoc {
|
|
23
|
+
chain_id: string;
|
|
24
|
+
body_bytes: Uint8Array;
|
|
25
|
+
auth_info_bytes: Uint8Array;
|
|
26
|
+
account_number: string;
|
|
27
|
+
}
|
|
28
|
+
interface CosmostationSignDirectResponse {
|
|
29
|
+
signed_doc: CosmostationSignDirectDoc;
|
|
30
|
+
signature: string;
|
|
31
|
+
pub_key: {
|
|
32
|
+
type: string;
|
|
33
|
+
value: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface CosmostationSignAminoResponse {
|
|
37
|
+
signed_doc: Record<string, unknown>;
|
|
38
|
+
signature: string;
|
|
39
|
+
pub_key: {
|
|
40
|
+
type: string;
|
|
41
|
+
value: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface CosmostationSignMessageResponse {
|
|
45
|
+
signature: string;
|
|
46
|
+
pub_key: {
|
|
47
|
+
type: string;
|
|
48
|
+
value: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface CosmostationSupportedChainIdsResponse {
|
|
52
|
+
official: string[];
|
|
53
|
+
unofficial: string[];
|
|
54
|
+
}
|
|
55
|
+
interface CosmostationSendTransactionResponse {
|
|
56
|
+
tx_response: {
|
|
57
|
+
txhash: string;
|
|
58
|
+
code?: number;
|
|
59
|
+
codespace?: string;
|
|
60
|
+
raw_log?: string;
|
|
61
|
+
height?: string | number;
|
|
62
|
+
gas_used?: string | number;
|
|
63
|
+
gas_wanted?: string | number;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
interface CosRequestAccountParams {
|
|
68
|
+
chainName: string;
|
|
69
|
+
}
|
|
70
|
+
interface CosAccountParams {
|
|
71
|
+
chainName: string;
|
|
72
|
+
}
|
|
73
|
+
interface CosSignDirectParams {
|
|
74
|
+
chainName: string;
|
|
75
|
+
doc: CosmostationSignDirectDoc;
|
|
76
|
+
isEditFee?: boolean;
|
|
77
|
+
isEditMemo?: boolean;
|
|
78
|
+
}
|
|
79
|
+
interface CosSignAminoParams {
|
|
80
|
+
chainName: string;
|
|
81
|
+
doc: Record<string, unknown>;
|
|
82
|
+
isEditFee?: boolean;
|
|
83
|
+
isEditMemo?: boolean;
|
|
84
|
+
}
|
|
85
|
+
interface CosSignMessageParams {
|
|
86
|
+
chainName: string;
|
|
87
|
+
signer: string;
|
|
88
|
+
message: string;
|
|
89
|
+
}
|
|
90
|
+
interface CosSendTransactionParams {
|
|
91
|
+
chainName: string;
|
|
92
|
+
txBytes: string;
|
|
93
|
+
mode: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The cosmos namespace of the Cosmostation provider.
|
|
97
|
+
*/
|
|
98
|
+
interface CosmostationCosmos {
|
|
99
|
+
/**
|
|
100
|
+
* Make a request to the Cosmostation extension.
|
|
101
|
+
*/
|
|
102
|
+
request<T>(message: {
|
|
103
|
+
method: string;
|
|
104
|
+
params?: unknown;
|
|
105
|
+
}): Promise<T>;
|
|
106
|
+
/**
|
|
107
|
+
* Subscribe to wallet events.
|
|
108
|
+
*/
|
|
109
|
+
on(eventName: string, handler: () => void): void;
|
|
110
|
+
/**
|
|
111
|
+
* Unsubscribe from wallet events.
|
|
112
|
+
*/
|
|
113
|
+
off(eventName: string, handler: () => void): void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The Cosmostation provider interface available on window.cosmostation.
|
|
117
|
+
*/
|
|
118
|
+
interface CosmostationProvider {
|
|
119
|
+
cosmos: CosmostationCosmos;
|
|
120
|
+
providers?: {
|
|
121
|
+
keplr?: unknown;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
declare const SEND_TRANSACTION_MODE: {
|
|
125
|
+
readonly UNSPECIFIED: 0;
|
|
126
|
+
readonly BLOCK: 1;
|
|
127
|
+
readonly SYNC: 2;
|
|
128
|
+
readonly ASYNC: 3;
|
|
129
|
+
};
|
|
130
|
+
type SendTransactionMode = (typeof SEND_TRANSACTION_MODE)[keyof typeof SEND_TRANSACTION_MODE];
|
|
131
|
+
declare global {
|
|
132
|
+
interface Window {
|
|
133
|
+
cosmostation?: CosmostationProvider;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
9
137
|
//#region src/utils/index.d.ts
|
|
10
138
|
declare const isCosmosStationWalletInstalled: () => boolean;
|
|
11
139
|
//#endregion
|
|
@@ -15,12 +143,12 @@ declare class CosmostationWallet {
|
|
|
15
143
|
constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
|
|
16
144
|
static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
|
|
17
145
|
checkChainIdSupport(): Promise<boolean>;
|
|
18
|
-
|
|
146
|
+
getCosmostationProvider(): Promise<CosmostationCosmos>;
|
|
19
147
|
}
|
|
20
148
|
//#endregion
|
|
21
149
|
//#region src/strategy/strategy.d.ts
|
|
22
150
|
declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
23
|
-
private
|
|
151
|
+
private cosmostationProvider?;
|
|
24
152
|
chainName: string;
|
|
25
153
|
constructor(args: {
|
|
26
154
|
chainId: ChainId | CosmosChainId;
|
|
@@ -58,7 +186,15 @@ declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalle
|
|
|
58
186
|
getEthereumChainId(): Promise<string>;
|
|
59
187
|
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
60
188
|
getOfflineSigner(chainId: string): Promise<OfflineSigner>;
|
|
61
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Subscribe to account change events.
|
|
191
|
+
*/
|
|
192
|
+
onAccountChange(callback: onAccountChangeCallback): void;
|
|
193
|
+
/**
|
|
194
|
+
* Unsubscribe from account change events.
|
|
195
|
+
*/
|
|
196
|
+
offAccountChange(callback: onAccountChangeCallback): void;
|
|
197
|
+
private getProvider;
|
|
62
198
|
}
|
|
63
199
|
//#endregion
|
|
64
|
-
export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
|
|
200
|
+
export { CosAccountParams, CosRequestAccountParams, CosSendTransactionParams, CosSignAminoParams, CosSignDirectParams, CosSignMessageParams, CosmostationAccount, CosmostationCosmos, CosmostationProvider, CosmostationSendTransactionResponse, CosmostationSignAminoResponse, CosmostationSignDirectDoc, CosmostationSignDirectResponse, CosmostationSignMessageResponse, CosmostationSupportedChainIdsResponse, CosmostationWallet, Cosmostation as CosmostationWalletStrategy, SEND_TRANSACTION_MODE, SendTransactionMode, isCosmosStationWalletInstalled };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,10 +2,138 @@ import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
|
2
2
|
import { AccountAddress, ChainId, CosmosChainId, EvmChainId, TestnetCosmosChainId } from "@injectivelabs/ts-types";
|
|
3
3
|
import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
|
|
4
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";
|
|
5
|
+
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType, onAccountChangeCallback } from "@injectivelabs/wallet-base";
|
|
7
6
|
import { AminoSignResponse, DirectSignResponse } from "@injectivelabs/sdk-ts/types";
|
|
8
7
|
|
|
8
|
+
//#region src/types.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* TypeScript interfaces for the vanilla Cosmostation browser extension API.
|
|
11
|
+
* These replace the @cosmostation/extension-client package types.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.cosmostation.io/extension/cosmos/integrate
|
|
14
|
+
*/
|
|
15
|
+
interface CosmostationAccount {
|
|
16
|
+
name: string;
|
|
17
|
+
address: string;
|
|
18
|
+
publicKey: Uint8Array;
|
|
19
|
+
isLedger: boolean;
|
|
20
|
+
isEthermint?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface CosmostationSignDirectDoc {
|
|
23
|
+
chain_id: string;
|
|
24
|
+
body_bytes: Uint8Array;
|
|
25
|
+
auth_info_bytes: Uint8Array;
|
|
26
|
+
account_number: string;
|
|
27
|
+
}
|
|
28
|
+
interface CosmostationSignDirectResponse {
|
|
29
|
+
signed_doc: CosmostationSignDirectDoc;
|
|
30
|
+
signature: string;
|
|
31
|
+
pub_key: {
|
|
32
|
+
type: string;
|
|
33
|
+
value: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface CosmostationSignAminoResponse {
|
|
37
|
+
signed_doc: Record<string, unknown>;
|
|
38
|
+
signature: string;
|
|
39
|
+
pub_key: {
|
|
40
|
+
type: string;
|
|
41
|
+
value: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface CosmostationSignMessageResponse {
|
|
45
|
+
signature: string;
|
|
46
|
+
pub_key: {
|
|
47
|
+
type: string;
|
|
48
|
+
value: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface CosmostationSupportedChainIdsResponse {
|
|
52
|
+
official: string[];
|
|
53
|
+
unofficial: string[];
|
|
54
|
+
}
|
|
55
|
+
interface CosmostationSendTransactionResponse {
|
|
56
|
+
tx_response: {
|
|
57
|
+
txhash: string;
|
|
58
|
+
code?: number;
|
|
59
|
+
codespace?: string;
|
|
60
|
+
raw_log?: string;
|
|
61
|
+
height?: string | number;
|
|
62
|
+
gas_used?: string | number;
|
|
63
|
+
gas_wanted?: string | number;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
interface CosRequestAccountParams {
|
|
68
|
+
chainName: string;
|
|
69
|
+
}
|
|
70
|
+
interface CosAccountParams {
|
|
71
|
+
chainName: string;
|
|
72
|
+
}
|
|
73
|
+
interface CosSignDirectParams {
|
|
74
|
+
chainName: string;
|
|
75
|
+
doc: CosmostationSignDirectDoc;
|
|
76
|
+
isEditFee?: boolean;
|
|
77
|
+
isEditMemo?: boolean;
|
|
78
|
+
}
|
|
79
|
+
interface CosSignAminoParams {
|
|
80
|
+
chainName: string;
|
|
81
|
+
doc: Record<string, unknown>;
|
|
82
|
+
isEditFee?: boolean;
|
|
83
|
+
isEditMemo?: boolean;
|
|
84
|
+
}
|
|
85
|
+
interface CosSignMessageParams {
|
|
86
|
+
chainName: string;
|
|
87
|
+
signer: string;
|
|
88
|
+
message: string;
|
|
89
|
+
}
|
|
90
|
+
interface CosSendTransactionParams {
|
|
91
|
+
chainName: string;
|
|
92
|
+
txBytes: string;
|
|
93
|
+
mode: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The cosmos namespace of the Cosmostation provider.
|
|
97
|
+
*/
|
|
98
|
+
interface CosmostationCosmos {
|
|
99
|
+
/**
|
|
100
|
+
* Make a request to the Cosmostation extension.
|
|
101
|
+
*/
|
|
102
|
+
request<T>(message: {
|
|
103
|
+
method: string;
|
|
104
|
+
params?: unknown;
|
|
105
|
+
}): Promise<T>;
|
|
106
|
+
/**
|
|
107
|
+
* Subscribe to wallet events.
|
|
108
|
+
*/
|
|
109
|
+
on(eventName: string, handler: () => void): void;
|
|
110
|
+
/**
|
|
111
|
+
* Unsubscribe from wallet events.
|
|
112
|
+
*/
|
|
113
|
+
off(eventName: string, handler: () => void): void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The Cosmostation provider interface available on window.cosmostation.
|
|
117
|
+
*/
|
|
118
|
+
interface CosmostationProvider {
|
|
119
|
+
cosmos: CosmostationCosmos;
|
|
120
|
+
providers?: {
|
|
121
|
+
keplr?: unknown;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
declare const SEND_TRANSACTION_MODE: {
|
|
125
|
+
readonly UNSPECIFIED: 0;
|
|
126
|
+
readonly BLOCK: 1;
|
|
127
|
+
readonly SYNC: 2;
|
|
128
|
+
readonly ASYNC: 3;
|
|
129
|
+
};
|
|
130
|
+
type SendTransactionMode = (typeof SEND_TRANSACTION_MODE)[keyof typeof SEND_TRANSACTION_MODE];
|
|
131
|
+
declare global {
|
|
132
|
+
interface Window {
|
|
133
|
+
cosmostation?: CosmostationProvider;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
9
137
|
//#region src/utils/index.d.ts
|
|
10
138
|
declare const isCosmosStationWalletInstalled: () => boolean;
|
|
11
139
|
//#endregion
|
|
@@ -15,12 +143,12 @@ declare class CosmostationWallet {
|
|
|
15
143
|
constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
|
|
16
144
|
static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
|
|
17
145
|
checkChainIdSupport(): Promise<boolean>;
|
|
18
|
-
|
|
146
|
+
getCosmostationProvider(): Promise<CosmostationCosmos>;
|
|
19
147
|
}
|
|
20
148
|
//#endregion
|
|
21
149
|
//#region src/strategy/strategy.d.ts
|
|
22
150
|
declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
23
|
-
private
|
|
151
|
+
private cosmostationProvider?;
|
|
24
152
|
chainName: string;
|
|
25
153
|
constructor(args: {
|
|
26
154
|
chainId: ChainId | CosmosChainId;
|
|
@@ -58,7 +186,15 @@ declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalle
|
|
|
58
186
|
getEthereumChainId(): Promise<string>;
|
|
59
187
|
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
60
188
|
getOfflineSigner(chainId: string): Promise<OfflineSigner>;
|
|
61
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Subscribe to account change events.
|
|
191
|
+
*/
|
|
192
|
+
onAccountChange(callback: onAccountChangeCallback): void;
|
|
193
|
+
/**
|
|
194
|
+
* Unsubscribe from account change events.
|
|
195
|
+
*/
|
|
196
|
+
offAccountChange(callback: onAccountChangeCallback): void;
|
|
197
|
+
private getProvider;
|
|
62
198
|
}
|
|
63
199
|
//#endregion
|
|
64
|
-
export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
|
|
200
|
+
export { CosAccountParams, CosRequestAccountParams, CosSendTransactionParams, CosSignAminoParams, CosSignDirectParams, CosSignMessageParams, CosmostationAccount, CosmostationCosmos, CosmostationProvider, CosmostationSendTransactionResponse, CosmostationSignAminoResponse, CosmostationSignDirectDoc, CosmostationSignDirectResponse, CosmostationSignMessageResponse, CosmostationSupportedChainIdsResponse, CosmostationWallet, Cosmostation as CosmostationWalletStrategy, SEND_TRANSACTION_MODE, SendTransactionMode, isCosmosStationWalletInstalled };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { InstallError, cosmos } from "@cosmostation/extension-client";
|
|
2
1
|
import { CosmosWalletException, ErrorType, TransactionException, UnspecifiedErrorCode } from "@injectivelabs/exceptions";
|
|
3
2
|
import { makeSignDoc } from "@cosmjs/proto-signing";
|
|
4
3
|
import { CosmosChainId } from "@injectivelabs/ts-types";
|
|
5
4
|
import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
|
|
6
|
-
import {
|
|
5
|
+
import { stringToUint8Array, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
7
6
|
import { createSignDocFromTransaction, createTxRawFromSigResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
8
|
-
import { stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
9
7
|
import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
10
8
|
|
|
9
|
+
//#region src/types.ts
|
|
10
|
+
const SEND_TRANSACTION_MODE = {
|
|
11
|
+
UNSPECIFIED: 0,
|
|
12
|
+
BLOCK: 1,
|
|
13
|
+
SYNC: 2,
|
|
14
|
+
ASYNC: 3
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
11
18
|
//#region src/utils/index.ts
|
|
12
19
|
const isCosmosStationWalletInstalled = () => {
|
|
13
20
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -57,6 +64,33 @@ function _defineProperty(e, r, t) {
|
|
|
57
64
|
|
|
58
65
|
//#endregion
|
|
59
66
|
//#region src/wallet.ts
|
|
67
|
+
/**
|
|
68
|
+
* Get the Cosmostation cosmos provider from window.
|
|
69
|
+
* Throws if the extension is not installed.
|
|
70
|
+
*/
|
|
71
|
+
function getCosmostationProvider() {
|
|
72
|
+
var _window$cosmostation;
|
|
73
|
+
if (typeof window === "undefined" || !((_window$cosmostation = window.cosmostation) === null || _window$cosmostation === void 0 ? void 0 : _window$cosmostation.cosmos)) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
74
|
+
code: UnspecifiedErrorCode,
|
|
75
|
+
type: ErrorType.WalletNotInstalledError
|
|
76
|
+
});
|
|
77
|
+
return window.cosmostation.cosmos;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Request an account from the Cosmostation extension.
|
|
81
|
+
*/
|
|
82
|
+
async function requestAccount(chainName) {
|
|
83
|
+
return getCosmostationProvider().request({
|
|
84
|
+
method: "cos_requestAccount",
|
|
85
|
+
params: { chainName }
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get supported chain IDs from the extension.
|
|
90
|
+
*/
|
|
91
|
+
async function getSupportedChainIds() {
|
|
92
|
+
return getCosmostationProvider().request({ method: "cos_supportedChainIds" });
|
|
93
|
+
}
|
|
60
94
|
var CosmostationWallet = class CosmostationWallet {
|
|
61
95
|
constructor(chainId) {
|
|
62
96
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -67,24 +101,16 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
67
101
|
}
|
|
68
102
|
async checkChainIdSupport() {
|
|
69
103
|
const { chainId: actualChainId } = this;
|
|
70
|
-
const provider = await this.getCosmostationWallet();
|
|
71
104
|
const chainName = actualChainId.split("-");
|
|
105
|
+
getCosmostationProvider();
|
|
72
106
|
try {
|
|
73
|
-
return !!(await
|
|
107
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
74
108
|
} catch (_unused) {
|
|
75
109
|
throw new CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
76
110
|
}
|
|
77
111
|
}
|
|
78
|
-
async
|
|
79
|
-
|
|
80
|
-
return await cosmos();
|
|
81
|
-
} catch (e) {
|
|
82
|
-
if (e instanceof InstallError) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
83
|
-
code: UnspecifiedErrorCode,
|
|
84
|
-
type: ErrorType.WalletNotInstalledError
|
|
85
|
-
});
|
|
86
|
-
throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
|
|
87
|
-
}
|
|
112
|
+
async getCosmostationProvider() {
|
|
113
|
+
return getCosmostationProvider();
|
|
88
114
|
}
|
|
89
115
|
};
|
|
90
116
|
|
|
@@ -92,14 +118,16 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
92
118
|
//#region src/strategy/strategy.ts
|
|
93
119
|
/**
|
|
94
120
|
* Get an offline signer from the Cosmostation extension.
|
|
95
|
-
* This
|
|
96
|
-
* WalletConnect v1 dependencies that cause ESM bundling issues.
|
|
121
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
97
122
|
*/
|
|
98
123
|
async function getExtensionOfflineSigner(chainId) {
|
|
99
|
-
const provider =
|
|
124
|
+
const provider = getCosmostationProvider();
|
|
100
125
|
return {
|
|
101
126
|
getAccounts: async () => {
|
|
102
|
-
const response = await provider.
|
|
127
|
+
const response = await provider.request({
|
|
128
|
+
method: "cos_account",
|
|
129
|
+
params: { chainName: chainId }
|
|
130
|
+
});
|
|
103
131
|
return [{
|
|
104
132
|
address: response.address,
|
|
105
133
|
pubkey: response.publicKey,
|
|
@@ -107,7 +135,15 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
107
135
|
}];
|
|
108
136
|
},
|
|
109
137
|
signAmino: async (_signerAddress, signDoc) => {
|
|
110
|
-
const response = await provider.
|
|
138
|
+
const response = await provider.request({
|
|
139
|
+
method: "cos_signAmino",
|
|
140
|
+
params: {
|
|
141
|
+
chainName: chainId,
|
|
142
|
+
doc: signDoc,
|
|
143
|
+
isEditFee: true,
|
|
144
|
+
isEditMemo: true
|
|
145
|
+
}
|
|
146
|
+
});
|
|
111
147
|
return {
|
|
112
148
|
signed: response.signed_doc,
|
|
113
149
|
signature: {
|
|
@@ -117,11 +153,20 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
117
153
|
};
|
|
118
154
|
},
|
|
119
155
|
signDirect: async (_signerAddress, signDoc) => {
|
|
120
|
-
const
|
|
156
|
+
const doc = {
|
|
121
157
|
account_number: String(signDoc.accountNumber),
|
|
122
158
|
auth_info_bytes: signDoc.authInfoBytes,
|
|
123
159
|
body_bytes: signDoc.bodyBytes,
|
|
124
160
|
chain_id: signDoc.chainId
|
|
161
|
+
};
|
|
162
|
+
const response = await provider.request({
|
|
163
|
+
method: "cos_signDirect",
|
|
164
|
+
params: {
|
|
165
|
+
chainName: chainId,
|
|
166
|
+
doc,
|
|
167
|
+
isEditFee: true,
|
|
168
|
+
isEditMemo: true
|
|
169
|
+
}
|
|
125
170
|
});
|
|
126
171
|
return {
|
|
127
172
|
signed: {
|
|
@@ -149,7 +194,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
149
194
|
var Cosmostation = class extends BaseConcreteStrategy {
|
|
150
195
|
constructor(args) {
|
|
151
196
|
super(args);
|
|
152
|
-
_defineProperty(this, "
|
|
197
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
153
198
|
_defineProperty(this, "chainName", void 0);
|
|
154
199
|
this.chainId = args.chainId || CosmosChainId.Injective;
|
|
155
200
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -161,9 +206,9 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
161
206
|
return Promise.resolve(true);
|
|
162
207
|
}
|
|
163
208
|
async getAddresses() {
|
|
164
|
-
|
|
209
|
+
this.getProvider();
|
|
165
210
|
try {
|
|
166
|
-
return [(await
|
|
211
|
+
return [(await requestAccount(this.chainName)).address];
|
|
167
212
|
} catch (e) {
|
|
168
213
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
169
214
|
code: UnspecifiedErrorCode,
|
|
@@ -191,17 +236,26 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
191
236
|
});
|
|
192
237
|
}
|
|
193
238
|
async sendTransaction(transaction, _options) {
|
|
194
|
-
const
|
|
239
|
+
const provider = this.getProvider();
|
|
195
240
|
const txRaw = createTxRawFromSigResponse(transaction);
|
|
241
|
+
const txBytes = uint8ArrayToBase64(CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw));
|
|
196
242
|
try {
|
|
197
|
-
const response = await
|
|
243
|
+
const response = await provider.request({
|
|
244
|
+
method: "cos_sendTransaction",
|
|
245
|
+
params: {
|
|
246
|
+
chainName: this.chainName,
|
|
247
|
+
txBytes,
|
|
248
|
+
mode: SEND_TRANSACTION_MODE.SYNC
|
|
249
|
+
}
|
|
250
|
+
});
|
|
198
251
|
return {
|
|
199
252
|
...response.tx_response,
|
|
200
253
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
201
254
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
202
255
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
203
256
|
txHash: response.tx_response.txhash,
|
|
204
|
-
rawLog: response.tx_response.raw_log
|
|
257
|
+
rawLog: response.tx_response.raw_log,
|
|
258
|
+
timestamp: ""
|
|
205
259
|
};
|
|
206
260
|
} catch (e) {
|
|
207
261
|
if (e instanceof TransactionException) throw e;
|
|
@@ -219,17 +273,23 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
219
273
|
}
|
|
220
274
|
async signCosmosTransaction(transaction) {
|
|
221
275
|
const { chainId } = this;
|
|
222
|
-
const
|
|
276
|
+
const provider = this.getProvider();
|
|
223
277
|
const signDoc = createSignDocFromTransaction(transaction);
|
|
278
|
+
const doc = {
|
|
279
|
+
chain_id: chainId,
|
|
280
|
+
body_bytes: signDoc.bodyBytes,
|
|
281
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
282
|
+
account_number: signDoc.accountNumber.toString()
|
|
283
|
+
};
|
|
224
284
|
try {
|
|
225
|
-
const signDirectResponse = await
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
285
|
+
const signDirectResponse = await provider.request({
|
|
286
|
+
method: "cos_signDirect",
|
|
287
|
+
params: {
|
|
288
|
+
chainName: this.chainName,
|
|
289
|
+
doc,
|
|
290
|
+
isEditFee: true,
|
|
291
|
+
isEditMemo: true
|
|
292
|
+
}
|
|
233
293
|
});
|
|
234
294
|
return {
|
|
235
295
|
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)),
|
|
@@ -243,9 +303,8 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
243
303
|
}
|
|
244
304
|
}
|
|
245
305
|
async getPubKey() {
|
|
246
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
247
306
|
try {
|
|
248
|
-
return uint8ArrayToBase64((await
|
|
307
|
+
return uint8ArrayToBase64((await requestAccount(this.chainName)).publicKey);
|
|
249
308
|
} catch (e) {
|
|
250
309
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
251
310
|
code: UnspecifiedErrorCode,
|
|
@@ -265,7 +324,16 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
265
324
|
}
|
|
266
325
|
async signArbitrary(signer, data) {
|
|
267
326
|
try {
|
|
268
|
-
|
|
327
|
+
const provider = this.getProvider();
|
|
328
|
+
const message = data instanceof Uint8Array ? new TextDecoder().decode(data) : data;
|
|
329
|
+
return (await provider.request({
|
|
330
|
+
method: "cos_signMessage",
|
|
331
|
+
params: {
|
|
332
|
+
chainName: this.chainName,
|
|
333
|
+
signer,
|
|
334
|
+
message
|
|
335
|
+
}
|
|
336
|
+
})).signature;
|
|
269
337
|
} catch (e) {
|
|
270
338
|
throw new CosmosWalletException(new Error(e.message), {
|
|
271
339
|
code: UnspecifiedErrorCode,
|
|
@@ -289,22 +357,36 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
289
357
|
async getOfflineSigner(chainId) {
|
|
290
358
|
return await getExtensionOfflineSigner(chainId);
|
|
291
359
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
360
|
+
/**
|
|
361
|
+
* Subscribe to account change events.
|
|
362
|
+
*/
|
|
363
|
+
onAccountChange(callback) {
|
|
364
|
+
const provider = this.getProvider();
|
|
365
|
+
const handler = async () => {
|
|
366
|
+
try {
|
|
367
|
+
callback((await requestAccount(this.chainName)).address);
|
|
368
|
+
} catch (_unused) {}
|
|
369
|
+
};
|
|
370
|
+
provider.on("cosmostation_keystorechange", handler);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Unsubscribe from account change events.
|
|
374
|
+
*/
|
|
375
|
+
offAccountChange(callback) {
|
|
376
|
+
this.getProvider().off("cosmostation_keystorechange", callback);
|
|
377
|
+
}
|
|
378
|
+
getProvider() {
|
|
379
|
+
if (this.cosmostationProvider) return this.cosmostationProvider;
|
|
295
380
|
try {
|
|
296
|
-
const provider =
|
|
297
|
-
this.
|
|
381
|
+
const provider = getCosmostationProvider();
|
|
382
|
+
this.cosmostationProvider = provider;
|
|
298
383
|
return provider;
|
|
299
384
|
} catch (e) {
|
|
300
|
-
if (e instanceof
|
|
301
|
-
code: UnspecifiedErrorCode,
|
|
302
|
-
type: ErrorType.WalletNotInstalledError
|
|
303
|
-
});
|
|
385
|
+
if (e instanceof CosmosWalletException && e.type === ErrorType.WalletNotInstalledError) throw e;
|
|
304
386
|
throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
|
|
305
387
|
}
|
|
306
388
|
}
|
|
307
389
|
};
|
|
308
390
|
|
|
309
391
|
//#endregion
|
|
310
|
-
export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
|
|
392
|
+
export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, SEND_TRANSACTION_MODE, isCosmosStationWalletInstalled };
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-cosmostation",
|
|
3
|
-
"version": "1.17.2-alpha.
|
|
3
|
+
"version": "1.17.2-alpha.2",
|
|
4
4
|
"description": "Cosmostation strategy for use with @injectivelabs/wallet-core.",
|
|
5
|
+
"deprecated": "Use @injectivelabs/wallet-cosmos with Wallet.Cosmostation instead",
|
|
5
6
|
"license": "Apache-2.0",
|
|
6
7
|
"author": {
|
|
7
8
|
"name": "InjectiveLabs",
|
|
@@ -39,11 +40,10 @@
|
|
|
39
40
|
],
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@cosmjs/proto-signing": "0.33.0",
|
|
42
|
-
"@
|
|
43
|
-
"@injectivelabs/
|
|
44
|
-
"@injectivelabs/sdk-ts": "1.17.2-alpha.
|
|
45
|
-
"@injectivelabs/
|
|
46
|
-
"@injectivelabs/wallet-base": "1.17.2-alpha.1"
|
|
43
|
+
"@injectivelabs/exceptions": "1.17.2-alpha.2",
|
|
44
|
+
"@injectivelabs/ts-types": "1.17.2-alpha.2",
|
|
45
|
+
"@injectivelabs/sdk-ts": "1.17.2-alpha.2",
|
|
46
|
+
"@injectivelabs/wallet-base": "1.17.2-alpha.2"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|