@injectivelabs/wallet-cosmostation 1.17.2-alpha.1 → 1.17.2-alpha.3
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 +140 -50
- package/dist/cjs/index.d.cts +142 -6
- package/dist/esm/index.d.ts +143 -7
- package/dist/esm/index.js +140 -51
- 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,19 @@
|
|
|
1
|
-
let __cosmostation_extension_client = require("@cosmostation/extension-client");
|
|
2
1
|
let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
|
|
3
|
-
let __cosmjs_proto_signing = require("@cosmjs/proto-signing");
|
|
4
2
|
let __injectivelabs_ts_types = require("@injectivelabs/ts-types");
|
|
5
3
|
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
4
|
let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
|
|
5
|
+
let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
|
|
9
6
|
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
10
7
|
|
|
8
|
+
//#region src/types.ts
|
|
9
|
+
const SEND_TRANSACTION_MODE = {
|
|
10
|
+
UNSPECIFIED: 0,
|
|
11
|
+
BLOCK: 1,
|
|
12
|
+
SYNC: 2,
|
|
13
|
+
ASYNC: 3
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
11
17
|
//#region src/utils/index.ts
|
|
12
18
|
const isCosmosStationWalletInstalled = () => {
|
|
13
19
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -57,6 +63,33 @@ function _defineProperty(e, r, t) {
|
|
|
57
63
|
|
|
58
64
|
//#endregion
|
|
59
65
|
//#region src/wallet.ts
|
|
66
|
+
/**
|
|
67
|
+
* Get the Cosmostation cosmos provider from window.
|
|
68
|
+
* Throws if the extension is not installed.
|
|
69
|
+
*/
|
|
70
|
+
function getCosmostationProvider() {
|
|
71
|
+
var _window$cosmostation;
|
|
72
|
+
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"), {
|
|
73
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
74
|
+
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
75
|
+
});
|
|
76
|
+
return window.cosmostation.cosmos;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Request an account from the Cosmostation extension.
|
|
80
|
+
*/
|
|
81
|
+
async function requestAccount(chainName) {
|
|
82
|
+
return getCosmostationProvider().request({
|
|
83
|
+
method: "cos_requestAccount",
|
|
84
|
+
params: { chainName }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get supported chain IDs from the extension.
|
|
89
|
+
*/
|
|
90
|
+
async function getSupportedChainIds() {
|
|
91
|
+
return getCosmostationProvider().request({ method: "cos_supportedChainIds" });
|
|
92
|
+
}
|
|
60
93
|
var CosmostationWallet = class CosmostationWallet {
|
|
61
94
|
constructor(chainId) {
|
|
62
95
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -67,39 +100,41 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
67
100
|
}
|
|
68
101
|
async checkChainIdSupport() {
|
|
69
102
|
const { chainId: actualChainId } = this;
|
|
70
|
-
const provider = await this.getCosmostationWallet();
|
|
71
103
|
const chainName = actualChainId.split("-");
|
|
104
|
+
getCosmostationProvider();
|
|
72
105
|
try {
|
|
73
|
-
return !!(await
|
|
106
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
74
107
|
} catch (_unused) {
|
|
75
108
|
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
76
109
|
}
|
|
77
110
|
}
|
|
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
|
-
}
|
|
111
|
+
async getCosmostationProvider() {
|
|
112
|
+
return getCosmostationProvider();
|
|
88
113
|
}
|
|
89
114
|
};
|
|
90
115
|
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/strategy/lib.ts
|
|
118
|
+
let cachedMakeSignDoc = null;
|
|
119
|
+
const loadMakeSignDoc = async () => {
|
|
120
|
+
if (!cachedMakeSignDoc) cachedMakeSignDoc = (await import("@cosmjs/proto-signing")).makeSignDoc;
|
|
121
|
+
return cachedMakeSignDoc;
|
|
122
|
+
};
|
|
123
|
+
|
|
91
124
|
//#endregion
|
|
92
125
|
//#region src/strategy/strategy.ts
|
|
93
126
|
/**
|
|
94
127
|
* Get an offline signer from the Cosmostation extension.
|
|
95
|
-
* This
|
|
96
|
-
* WalletConnect v1 dependencies that cause ESM bundling issues.
|
|
128
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
97
129
|
*/
|
|
98
130
|
async function getExtensionOfflineSigner(chainId) {
|
|
99
|
-
const provider =
|
|
131
|
+
const provider = getCosmostationProvider();
|
|
100
132
|
return {
|
|
101
133
|
getAccounts: async () => {
|
|
102
|
-
const response = await provider.
|
|
134
|
+
const response = await provider.request({
|
|
135
|
+
method: "cos_account",
|
|
136
|
+
params: { chainName: chainId }
|
|
137
|
+
});
|
|
103
138
|
return [{
|
|
104
139
|
address: response.address,
|
|
105
140
|
pubkey: response.publicKey,
|
|
@@ -107,7 +142,15 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
107
142
|
}];
|
|
108
143
|
},
|
|
109
144
|
signAmino: async (_signerAddress, signDoc) => {
|
|
110
|
-
const response = await provider.
|
|
145
|
+
const response = await provider.request({
|
|
146
|
+
method: "cos_signAmino",
|
|
147
|
+
params: {
|
|
148
|
+
chainName: chainId,
|
|
149
|
+
doc: signDoc,
|
|
150
|
+
isEditFee: true,
|
|
151
|
+
isEditMemo: true
|
|
152
|
+
}
|
|
153
|
+
});
|
|
111
154
|
return {
|
|
112
155
|
signed: response.signed_doc,
|
|
113
156
|
signature: {
|
|
@@ -117,11 +160,20 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
117
160
|
};
|
|
118
161
|
},
|
|
119
162
|
signDirect: async (_signerAddress, signDoc) => {
|
|
120
|
-
const
|
|
163
|
+
const doc = {
|
|
121
164
|
account_number: String(signDoc.accountNumber),
|
|
122
165
|
auth_info_bytes: signDoc.authInfoBytes,
|
|
123
166
|
body_bytes: signDoc.bodyBytes,
|
|
124
167
|
chain_id: signDoc.chainId
|
|
168
|
+
};
|
|
169
|
+
const response = await provider.request({
|
|
170
|
+
method: "cos_signDirect",
|
|
171
|
+
params: {
|
|
172
|
+
chainName: chainId,
|
|
173
|
+
doc,
|
|
174
|
+
isEditFee: true,
|
|
175
|
+
isEditMemo: true
|
|
176
|
+
}
|
|
125
177
|
});
|
|
126
178
|
return {
|
|
127
179
|
signed: {
|
|
@@ -149,7 +201,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
149
201
|
var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
150
202
|
constructor(args) {
|
|
151
203
|
super(args);
|
|
152
|
-
_defineProperty(this, "
|
|
204
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
153
205
|
_defineProperty(this, "chainName", void 0);
|
|
154
206
|
this.chainId = args.chainId || __injectivelabs_ts_types.CosmosChainId.Injective;
|
|
155
207
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -161,9 +213,9 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
161
213
|
return Promise.resolve(true);
|
|
162
214
|
}
|
|
163
215
|
async getAddresses() {
|
|
164
|
-
|
|
216
|
+
this.getProvider();
|
|
165
217
|
try {
|
|
166
|
-
return [(await
|
|
218
|
+
return [(await requestAccount(this.chainName)).address];
|
|
167
219
|
} catch (e) {
|
|
168
220
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
169
221
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -191,17 +243,26 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
191
243
|
});
|
|
192
244
|
}
|
|
193
245
|
async sendTransaction(transaction, _options) {
|
|
194
|
-
const
|
|
246
|
+
const provider = this.getProvider();
|
|
195
247
|
const txRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(transaction);
|
|
248
|
+
const txBytes = (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)(__injectivelabs_sdk_ts.CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw));
|
|
196
249
|
try {
|
|
197
|
-
const response = await
|
|
250
|
+
const response = await provider.request({
|
|
251
|
+
method: "cos_sendTransaction",
|
|
252
|
+
params: {
|
|
253
|
+
chainName: this.chainName,
|
|
254
|
+
txBytes,
|
|
255
|
+
mode: SEND_TRANSACTION_MODE.SYNC
|
|
256
|
+
}
|
|
257
|
+
});
|
|
198
258
|
return {
|
|
199
259
|
...response.tx_response,
|
|
200
260
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
201
261
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
202
262
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
203
263
|
txHash: response.tx_response.txhash,
|
|
204
|
-
rawLog: response.tx_response.raw_log
|
|
264
|
+
rawLog: response.tx_response.raw_log,
|
|
265
|
+
timestamp: ""
|
|
205
266
|
};
|
|
206
267
|
} catch (e) {
|
|
207
268
|
if (e instanceof __injectivelabs_exceptions.TransactionException) throw e;
|
|
@@ -219,20 +280,26 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
219
280
|
}
|
|
220
281
|
async signCosmosTransaction(transaction) {
|
|
221
282
|
const { chainId } = this;
|
|
222
|
-
const
|
|
283
|
+
const provider = this.getProvider();
|
|
223
284
|
const signDoc = (0, __injectivelabs_sdk_ts_core_tx.createSignDocFromTransaction)(transaction);
|
|
285
|
+
const doc = {
|
|
286
|
+
chain_id: chainId,
|
|
287
|
+
body_bytes: signDoc.bodyBytes,
|
|
288
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
289
|
+
account_number: signDoc.accountNumber.toString()
|
|
290
|
+
};
|
|
224
291
|
try {
|
|
225
|
-
const signDirectResponse = await
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
292
|
+
const signDirectResponse = await provider.request({
|
|
293
|
+
method: "cos_signDirect",
|
|
294
|
+
params: {
|
|
295
|
+
chainName: this.chainName,
|
|
296
|
+
doc,
|
|
297
|
+
isEditFee: true,
|
|
298
|
+
isEditMemo: true
|
|
299
|
+
}
|
|
233
300
|
});
|
|
234
301
|
return {
|
|
235
|
-
signed: (
|
|
302
|
+
signed: (await loadMakeSignDoc())(signDirectResponse.signed_doc.body_bytes, signDirectResponse.signed_doc.auth_info_bytes, signDirectResponse.signed_doc.chain_id, parseInt(signDirectResponse.signed_doc.account_number, 10)),
|
|
236
303
|
signature: { signature: signDirectResponse.signature }
|
|
237
304
|
};
|
|
238
305
|
} catch (e) {
|
|
@@ -243,9 +310,8 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
243
310
|
}
|
|
244
311
|
}
|
|
245
312
|
async getPubKey() {
|
|
246
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
247
313
|
try {
|
|
248
|
-
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await
|
|
314
|
+
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await requestAccount(this.chainName)).publicKey);
|
|
249
315
|
} catch (e) {
|
|
250
316
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
251
317
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -265,7 +331,16 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
265
331
|
}
|
|
266
332
|
async signArbitrary(signer, data) {
|
|
267
333
|
try {
|
|
268
|
-
|
|
334
|
+
const provider = this.getProvider();
|
|
335
|
+
const message = data instanceof Uint8Array ? new TextDecoder().decode(data) : data;
|
|
336
|
+
return (await provider.request({
|
|
337
|
+
method: "cos_signMessage",
|
|
338
|
+
params: {
|
|
339
|
+
chainName: this.chainName,
|
|
340
|
+
signer,
|
|
341
|
+
message
|
|
342
|
+
}
|
|
343
|
+
})).signature;
|
|
269
344
|
} catch (e) {
|
|
270
345
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
|
|
271
346
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -289,18 +364,32 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
289
364
|
async getOfflineSigner(chainId) {
|
|
290
365
|
return await getExtensionOfflineSigner(chainId);
|
|
291
366
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Subscribe to account change events.
|
|
369
|
+
*/
|
|
370
|
+
onAccountChange(callback) {
|
|
371
|
+
const provider = this.getProvider();
|
|
372
|
+
const handler = async () => {
|
|
373
|
+
try {
|
|
374
|
+
callback((await requestAccount(this.chainName)).address);
|
|
375
|
+
} catch (_unused) {}
|
|
376
|
+
};
|
|
377
|
+
provider.on("cosmostation_keystorechange", handler);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Unsubscribe from account change events.
|
|
381
|
+
*/
|
|
382
|
+
offAccountChange(callback) {
|
|
383
|
+
this.getProvider().off("cosmostation_keystorechange", callback);
|
|
384
|
+
}
|
|
385
|
+
getProvider() {
|
|
386
|
+
if (this.cosmostationProvider) return this.cosmostationProvider;
|
|
295
387
|
try {
|
|
296
|
-
const provider =
|
|
297
|
-
this.
|
|
388
|
+
const provider = getCosmostationProvider();
|
|
389
|
+
this.cosmostationProvider = provider;
|
|
298
390
|
return provider;
|
|
299
391
|
} catch (e) {
|
|
300
|
-
if (e instanceof
|
|
301
|
-
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
302
|
-
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
303
|
-
});
|
|
392
|
+
if (e instanceof __injectivelabs_exceptions.CosmosWalletException && e.type === __injectivelabs_exceptions.ErrorType.WalletNotInstalledError) throw e;
|
|
304
393
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
|
|
305
394
|
}
|
|
306
395
|
}
|
|
@@ -309,4 +398,5 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
309
398
|
//#endregion
|
|
310
399
|
exports.CosmostationWallet = CosmostationWallet;
|
|
311
400
|
exports.CosmostationWalletStrategy = Cosmostation;
|
|
401
|
+
exports.SEND_TRANSACTION_MODE = SEND_TRANSACTION_MODE;
|
|
312
402
|
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
|
@@ -1,11 +1,139 @@
|
|
|
1
|
-
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
2
1
|
import { AccountAddress, ChainId, CosmosChainId, EvmChainId, TestnetCosmosChainId } from "@injectivelabs/ts-types";
|
|
3
2
|
import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
|
|
4
3
|
import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
5
|
-
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
6
|
-
import
|
|
4
|
+
import { BaseConcreteStrategy, ConcreteWalletStrategy, StdSignDoc, WalletDeviceType, onAccountChangeCallback } from "@injectivelabs/wallet-base";
|
|
5
|
+
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
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,19 @@
|
|
|
1
|
-
import { InstallError, cosmos } from "@cosmostation/extension-client";
|
|
2
1
|
import { CosmosWalletException, ErrorType, TransactionException, UnspecifiedErrorCode } from "@injectivelabs/exceptions";
|
|
3
|
-
import { makeSignDoc } from "@cosmjs/proto-signing";
|
|
4
2
|
import { CosmosChainId } from "@injectivelabs/ts-types";
|
|
5
3
|
import { CosmosTxV1Beta1TxPb } from "@injectivelabs/sdk-ts";
|
|
6
|
-
import {
|
|
4
|
+
import { stringToUint8Array, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
7
5
|
import { createSignDocFromTransaction, createTxRawFromSigResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
8
|
-
import { stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
9
6
|
import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
10
7
|
|
|
8
|
+
//#region src/types.ts
|
|
9
|
+
const SEND_TRANSACTION_MODE = {
|
|
10
|
+
UNSPECIFIED: 0,
|
|
11
|
+
BLOCK: 1,
|
|
12
|
+
SYNC: 2,
|
|
13
|
+
ASYNC: 3
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
11
17
|
//#region src/utils/index.ts
|
|
12
18
|
const isCosmosStationWalletInstalled = () => {
|
|
13
19
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -57,6 +63,33 @@ function _defineProperty(e, r, t) {
|
|
|
57
63
|
|
|
58
64
|
//#endregion
|
|
59
65
|
//#region src/wallet.ts
|
|
66
|
+
/**
|
|
67
|
+
* Get the Cosmostation cosmos provider from window.
|
|
68
|
+
* Throws if the extension is not installed.
|
|
69
|
+
*/
|
|
70
|
+
function getCosmostationProvider() {
|
|
71
|
+
var _window$cosmostation;
|
|
72
|
+
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"), {
|
|
73
|
+
code: UnspecifiedErrorCode,
|
|
74
|
+
type: ErrorType.WalletNotInstalledError
|
|
75
|
+
});
|
|
76
|
+
return window.cosmostation.cosmos;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Request an account from the Cosmostation extension.
|
|
80
|
+
*/
|
|
81
|
+
async function requestAccount(chainName) {
|
|
82
|
+
return getCosmostationProvider().request({
|
|
83
|
+
method: "cos_requestAccount",
|
|
84
|
+
params: { chainName }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get supported chain IDs from the extension.
|
|
89
|
+
*/
|
|
90
|
+
async function getSupportedChainIds() {
|
|
91
|
+
return getCosmostationProvider().request({ method: "cos_supportedChainIds" });
|
|
92
|
+
}
|
|
60
93
|
var CosmostationWallet = class CosmostationWallet {
|
|
61
94
|
constructor(chainId) {
|
|
62
95
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -67,39 +100,41 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
67
100
|
}
|
|
68
101
|
async checkChainIdSupport() {
|
|
69
102
|
const { chainId: actualChainId } = this;
|
|
70
|
-
const provider = await this.getCosmostationWallet();
|
|
71
103
|
const chainName = actualChainId.split("-");
|
|
104
|
+
getCosmostationProvider();
|
|
72
105
|
try {
|
|
73
|
-
return !!(await
|
|
106
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
74
107
|
} catch (_unused) {
|
|
75
108
|
throw new CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
76
109
|
}
|
|
77
110
|
}
|
|
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
|
-
}
|
|
111
|
+
async getCosmostationProvider() {
|
|
112
|
+
return getCosmostationProvider();
|
|
88
113
|
}
|
|
89
114
|
};
|
|
90
115
|
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/strategy/lib.ts
|
|
118
|
+
let cachedMakeSignDoc = null;
|
|
119
|
+
const loadMakeSignDoc = async () => {
|
|
120
|
+
if (!cachedMakeSignDoc) cachedMakeSignDoc = (await import("@cosmjs/proto-signing")).makeSignDoc;
|
|
121
|
+
return cachedMakeSignDoc;
|
|
122
|
+
};
|
|
123
|
+
|
|
91
124
|
//#endregion
|
|
92
125
|
//#region src/strategy/strategy.ts
|
|
93
126
|
/**
|
|
94
127
|
* Get an offline signer from the Cosmostation extension.
|
|
95
|
-
* This
|
|
96
|
-
* WalletConnect v1 dependencies that cause ESM bundling issues.
|
|
128
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
97
129
|
*/
|
|
98
130
|
async function getExtensionOfflineSigner(chainId) {
|
|
99
|
-
const provider =
|
|
131
|
+
const provider = getCosmostationProvider();
|
|
100
132
|
return {
|
|
101
133
|
getAccounts: async () => {
|
|
102
|
-
const response = await provider.
|
|
134
|
+
const response = await provider.request({
|
|
135
|
+
method: "cos_account",
|
|
136
|
+
params: { chainName: chainId }
|
|
137
|
+
});
|
|
103
138
|
return [{
|
|
104
139
|
address: response.address,
|
|
105
140
|
pubkey: response.publicKey,
|
|
@@ -107,7 +142,15 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
107
142
|
}];
|
|
108
143
|
},
|
|
109
144
|
signAmino: async (_signerAddress, signDoc) => {
|
|
110
|
-
const response = await provider.
|
|
145
|
+
const response = await provider.request({
|
|
146
|
+
method: "cos_signAmino",
|
|
147
|
+
params: {
|
|
148
|
+
chainName: chainId,
|
|
149
|
+
doc: signDoc,
|
|
150
|
+
isEditFee: true,
|
|
151
|
+
isEditMemo: true
|
|
152
|
+
}
|
|
153
|
+
});
|
|
111
154
|
return {
|
|
112
155
|
signed: response.signed_doc,
|
|
113
156
|
signature: {
|
|
@@ -117,11 +160,20 @@ async function getExtensionOfflineSigner(chainId) {
|
|
|
117
160
|
};
|
|
118
161
|
},
|
|
119
162
|
signDirect: async (_signerAddress, signDoc) => {
|
|
120
|
-
const
|
|
163
|
+
const doc = {
|
|
121
164
|
account_number: String(signDoc.accountNumber),
|
|
122
165
|
auth_info_bytes: signDoc.authInfoBytes,
|
|
123
166
|
body_bytes: signDoc.bodyBytes,
|
|
124
167
|
chain_id: signDoc.chainId
|
|
168
|
+
};
|
|
169
|
+
const response = await provider.request({
|
|
170
|
+
method: "cos_signDirect",
|
|
171
|
+
params: {
|
|
172
|
+
chainName: chainId,
|
|
173
|
+
doc,
|
|
174
|
+
isEditFee: true,
|
|
175
|
+
isEditMemo: true
|
|
176
|
+
}
|
|
125
177
|
});
|
|
126
178
|
return {
|
|
127
179
|
signed: {
|
|
@@ -149,7 +201,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
149
201
|
var Cosmostation = class extends BaseConcreteStrategy {
|
|
150
202
|
constructor(args) {
|
|
151
203
|
super(args);
|
|
152
|
-
_defineProperty(this, "
|
|
204
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
153
205
|
_defineProperty(this, "chainName", void 0);
|
|
154
206
|
this.chainId = args.chainId || CosmosChainId.Injective;
|
|
155
207
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -161,9 +213,9 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
161
213
|
return Promise.resolve(true);
|
|
162
214
|
}
|
|
163
215
|
async getAddresses() {
|
|
164
|
-
|
|
216
|
+
this.getProvider();
|
|
165
217
|
try {
|
|
166
|
-
return [(await
|
|
218
|
+
return [(await requestAccount(this.chainName)).address];
|
|
167
219
|
} catch (e) {
|
|
168
220
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
169
221
|
code: UnspecifiedErrorCode,
|
|
@@ -191,17 +243,26 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
191
243
|
});
|
|
192
244
|
}
|
|
193
245
|
async sendTransaction(transaction, _options) {
|
|
194
|
-
const
|
|
246
|
+
const provider = this.getProvider();
|
|
195
247
|
const txRaw = createTxRawFromSigResponse(transaction);
|
|
248
|
+
const txBytes = uint8ArrayToBase64(CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw));
|
|
196
249
|
try {
|
|
197
|
-
const response = await
|
|
250
|
+
const response = await provider.request({
|
|
251
|
+
method: "cos_sendTransaction",
|
|
252
|
+
params: {
|
|
253
|
+
chainName: this.chainName,
|
|
254
|
+
txBytes,
|
|
255
|
+
mode: SEND_TRANSACTION_MODE.SYNC
|
|
256
|
+
}
|
|
257
|
+
});
|
|
198
258
|
return {
|
|
199
259
|
...response.tx_response,
|
|
200
260
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
201
261
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
202
262
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
203
263
|
txHash: response.tx_response.txhash,
|
|
204
|
-
rawLog: response.tx_response.raw_log
|
|
264
|
+
rawLog: response.tx_response.raw_log,
|
|
265
|
+
timestamp: ""
|
|
205
266
|
};
|
|
206
267
|
} catch (e) {
|
|
207
268
|
if (e instanceof TransactionException) throw e;
|
|
@@ -219,20 +280,26 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
219
280
|
}
|
|
220
281
|
async signCosmosTransaction(transaction) {
|
|
221
282
|
const { chainId } = this;
|
|
222
|
-
const
|
|
283
|
+
const provider = this.getProvider();
|
|
223
284
|
const signDoc = createSignDocFromTransaction(transaction);
|
|
285
|
+
const doc = {
|
|
286
|
+
chain_id: chainId,
|
|
287
|
+
body_bytes: signDoc.bodyBytes,
|
|
288
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
289
|
+
account_number: signDoc.accountNumber.toString()
|
|
290
|
+
};
|
|
224
291
|
try {
|
|
225
|
-
const signDirectResponse = await
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
292
|
+
const signDirectResponse = await provider.request({
|
|
293
|
+
method: "cos_signDirect",
|
|
294
|
+
params: {
|
|
295
|
+
chainName: this.chainName,
|
|
296
|
+
doc,
|
|
297
|
+
isEditFee: true,
|
|
298
|
+
isEditMemo: true
|
|
299
|
+
}
|
|
233
300
|
});
|
|
234
301
|
return {
|
|
235
|
-
signed:
|
|
302
|
+
signed: (await loadMakeSignDoc())(signDirectResponse.signed_doc.body_bytes, signDirectResponse.signed_doc.auth_info_bytes, signDirectResponse.signed_doc.chain_id, parseInt(signDirectResponse.signed_doc.account_number, 10)),
|
|
236
303
|
signature: { signature: signDirectResponse.signature }
|
|
237
304
|
};
|
|
238
305
|
} catch (e) {
|
|
@@ -243,9 +310,8 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
243
310
|
}
|
|
244
311
|
}
|
|
245
312
|
async getPubKey() {
|
|
246
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
247
313
|
try {
|
|
248
|
-
return uint8ArrayToBase64((await
|
|
314
|
+
return uint8ArrayToBase64((await requestAccount(this.chainName)).publicKey);
|
|
249
315
|
} catch (e) {
|
|
250
316
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
251
317
|
code: UnspecifiedErrorCode,
|
|
@@ -265,7 +331,16 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
265
331
|
}
|
|
266
332
|
async signArbitrary(signer, data) {
|
|
267
333
|
try {
|
|
268
|
-
|
|
334
|
+
const provider = this.getProvider();
|
|
335
|
+
const message = data instanceof Uint8Array ? new TextDecoder().decode(data) : data;
|
|
336
|
+
return (await provider.request({
|
|
337
|
+
method: "cos_signMessage",
|
|
338
|
+
params: {
|
|
339
|
+
chainName: this.chainName,
|
|
340
|
+
signer,
|
|
341
|
+
message
|
|
342
|
+
}
|
|
343
|
+
})).signature;
|
|
269
344
|
} catch (e) {
|
|
270
345
|
throw new CosmosWalletException(new Error(e.message), {
|
|
271
346
|
code: UnspecifiedErrorCode,
|
|
@@ -289,22 +364,36 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
289
364
|
async getOfflineSigner(chainId) {
|
|
290
365
|
return await getExtensionOfflineSigner(chainId);
|
|
291
366
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Subscribe to account change events.
|
|
369
|
+
*/
|
|
370
|
+
onAccountChange(callback) {
|
|
371
|
+
const provider = this.getProvider();
|
|
372
|
+
const handler = async () => {
|
|
373
|
+
try {
|
|
374
|
+
callback((await requestAccount(this.chainName)).address);
|
|
375
|
+
} catch (_unused) {}
|
|
376
|
+
};
|
|
377
|
+
provider.on("cosmostation_keystorechange", handler);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Unsubscribe from account change events.
|
|
381
|
+
*/
|
|
382
|
+
offAccountChange(callback) {
|
|
383
|
+
this.getProvider().off("cosmostation_keystorechange", callback);
|
|
384
|
+
}
|
|
385
|
+
getProvider() {
|
|
386
|
+
if (this.cosmostationProvider) return this.cosmostationProvider;
|
|
295
387
|
try {
|
|
296
|
-
const provider =
|
|
297
|
-
this.
|
|
388
|
+
const provider = getCosmostationProvider();
|
|
389
|
+
this.cosmostationProvider = provider;
|
|
298
390
|
return provider;
|
|
299
391
|
} catch (e) {
|
|
300
|
-
if (e instanceof
|
|
301
|
-
code: UnspecifiedErrorCode,
|
|
302
|
-
type: ErrorType.WalletNotInstalledError
|
|
303
|
-
});
|
|
392
|
+
if (e instanceof CosmosWalletException && e.type === ErrorType.WalletNotInstalledError) throw e;
|
|
304
393
|
throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
|
|
305
394
|
}
|
|
306
395
|
}
|
|
307
396
|
};
|
|
308
397
|
|
|
309
398
|
//#endregion
|
|
310
|
-
export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
|
|
399
|
+
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.3",
|
|
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/
|
|
45
|
-
"@injectivelabs/ts
|
|
46
|
-
"@injectivelabs/wallet-base": "1.17.2-alpha.1"
|
|
43
|
+
"@injectivelabs/exceptions": "1.17.2-alpha.3",
|
|
44
|
+
"@injectivelabs/ts-types": "1.17.2-alpha.3",
|
|
45
|
+
"@injectivelabs/wallet-base": "1.17.2-alpha.3",
|
|
46
|
+
"@injectivelabs/sdk-ts": "1.17.2-alpha.3"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|