@injectivelabs/wallet-cosmostation 1.17.2-alpha.0 → 1.17.2-alpha.10
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 +183 -46
- package/dist/cjs/index.d.cts +142 -6
- package/dist/esm/index.d.ts +143 -7
- package/dist/esm/index.js +183 -47
- package/package.json +10 -7
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,14 +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_cosmos_client = require("@cosmostation/cosmos-client");
|
|
7
|
-
let __cosmostation_extension_client_cosmos_js = require("@cosmostation/extension-client/cosmos.js");
|
|
8
|
-
let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
|
|
9
4
|
let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
|
|
5
|
+
let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
|
|
10
6
|
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
11
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
|
|
12
17
|
//#region src/utils/index.ts
|
|
13
18
|
const isCosmosStationWalletInstalled = () => {
|
|
14
19
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -58,6 +63,33 @@ function _defineProperty(e, r, t) {
|
|
|
58
63
|
|
|
59
64
|
//#endregion
|
|
60
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
|
+
}
|
|
61
93
|
var CosmostationWallet = class CosmostationWallet {
|
|
62
94
|
constructor(chainId) {
|
|
63
95
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -68,29 +100,96 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
68
100
|
}
|
|
69
101
|
async checkChainIdSupport() {
|
|
70
102
|
const { chainId: actualChainId } = this;
|
|
71
|
-
const provider = await this.getCosmostationWallet();
|
|
72
103
|
const chainName = actualChainId.split("-");
|
|
104
|
+
getCosmostationProvider();
|
|
73
105
|
try {
|
|
74
|
-
return !!(await
|
|
106
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
75
107
|
} catch (_unused) {
|
|
76
108
|
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
77
109
|
}
|
|
78
110
|
}
|
|
79
|
-
async
|
|
80
|
-
|
|
81
|
-
return await (0, __cosmostation_extension_client.cosmos)();
|
|
82
|
-
} catch (e) {
|
|
83
|
-
if (e instanceof __cosmostation_extension_client.InstallError) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
84
|
-
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
85
|
-
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
86
|
-
});
|
|
87
|
-
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
|
|
88
|
-
}
|
|
111
|
+
async getCosmostationProvider() {
|
|
112
|
+
return getCosmostationProvider();
|
|
89
113
|
}
|
|
90
114
|
};
|
|
91
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
|
+
|
|
92
124
|
//#endregion
|
|
93
125
|
//#region src/strategy/strategy.ts
|
|
126
|
+
/**
|
|
127
|
+
* Get an offline signer from the Cosmostation extension.
|
|
128
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
129
|
+
*/
|
|
130
|
+
async function getExtensionOfflineSigner(chainId) {
|
|
131
|
+
const provider = getCosmostationProvider();
|
|
132
|
+
return {
|
|
133
|
+
getAccounts: async () => {
|
|
134
|
+
const response = await provider.request({
|
|
135
|
+
method: "cos_account",
|
|
136
|
+
params: { chainName: chainId }
|
|
137
|
+
});
|
|
138
|
+
return [{
|
|
139
|
+
address: response.address,
|
|
140
|
+
pubkey: response.publicKey,
|
|
141
|
+
algo: "secp256k1"
|
|
142
|
+
}];
|
|
143
|
+
},
|
|
144
|
+
signAmino: async (_signerAddress, signDoc) => {
|
|
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
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
signed: response.signed_doc,
|
|
156
|
+
signature: {
|
|
157
|
+
pub_key: response.pub_key,
|
|
158
|
+
signature: response.signature
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
signDirect: async (_signerAddress, signDoc) => {
|
|
163
|
+
const doc = {
|
|
164
|
+
account_number: String(signDoc.accountNumber),
|
|
165
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
166
|
+
body_bytes: signDoc.bodyBytes,
|
|
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
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
signed: {
|
|
180
|
+
accountNumber: response.signed_doc.account_number,
|
|
181
|
+
chainId: response.signed_doc.chain_id,
|
|
182
|
+
authInfoBytes: response.signed_doc.auth_info_bytes,
|
|
183
|
+
bodyBytes: response.signed_doc.body_bytes
|
|
184
|
+
},
|
|
185
|
+
signature: {
|
|
186
|
+
pub_key: response.pub_key,
|
|
187
|
+
signature: response.signature
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
94
193
|
const getChainNameFromChainId = (chainId) => {
|
|
95
194
|
const [chainName] = chainId.split("-");
|
|
96
195
|
if (chainName.includes("cosmoshub")) return "cosmos";
|
|
@@ -102,7 +201,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
102
201
|
var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
103
202
|
constructor(args) {
|
|
104
203
|
super(args);
|
|
105
|
-
_defineProperty(this, "
|
|
204
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
106
205
|
_defineProperty(this, "chainName", void 0);
|
|
107
206
|
this.chainId = args.chainId || __injectivelabs_ts_types.CosmosChainId.Injective;
|
|
108
207
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -114,9 +213,9 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
114
213
|
return Promise.resolve(true);
|
|
115
214
|
}
|
|
116
215
|
async getAddresses() {
|
|
117
|
-
|
|
216
|
+
this.getProvider();
|
|
118
217
|
try {
|
|
119
|
-
return [(await
|
|
218
|
+
return [(await requestAccount(this.chainName)).address];
|
|
120
219
|
} catch (e) {
|
|
121
220
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
122
221
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -144,17 +243,26 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
144
243
|
});
|
|
145
244
|
}
|
|
146
245
|
async sendTransaction(transaction, _options) {
|
|
147
|
-
const
|
|
246
|
+
const provider = this.getProvider();
|
|
148
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));
|
|
149
249
|
try {
|
|
150
|
-
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
|
+
});
|
|
151
258
|
return {
|
|
152
259
|
...response.tx_response,
|
|
153
260
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
154
261
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
155
262
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
156
263
|
txHash: response.tx_response.txhash,
|
|
157
|
-
rawLog: response.tx_response.raw_log
|
|
264
|
+
rawLog: response.tx_response.raw_log,
|
|
265
|
+
timestamp: ""
|
|
158
266
|
};
|
|
159
267
|
} catch (e) {
|
|
160
268
|
if (e instanceof __injectivelabs_exceptions.TransactionException) throw e;
|
|
@@ -172,20 +280,26 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
172
280
|
}
|
|
173
281
|
async signCosmosTransaction(transaction) {
|
|
174
282
|
const { chainId } = this;
|
|
175
|
-
const
|
|
283
|
+
const provider = this.getProvider();
|
|
176
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
|
+
};
|
|
177
291
|
try {
|
|
178
|
-
const signDirectResponse = await
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
}
|
|
186
300
|
});
|
|
187
301
|
return {
|
|
188
|
-
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)),
|
|
189
303
|
signature: { signature: signDirectResponse.signature }
|
|
190
304
|
};
|
|
191
305
|
} catch (e) {
|
|
@@ -196,9 +310,8 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
196
310
|
}
|
|
197
311
|
}
|
|
198
312
|
async getPubKey() {
|
|
199
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
200
313
|
try {
|
|
201
|
-
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await
|
|
314
|
+
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await requestAccount(this.chainName)).publicKey);
|
|
202
315
|
} catch (e) {
|
|
203
316
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
204
317
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -218,7 +331,16 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
218
331
|
}
|
|
219
332
|
async signArbitrary(signer, data) {
|
|
220
333
|
try {
|
|
221
|
-
|
|
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;
|
|
222
344
|
} catch (e) {
|
|
223
345
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
|
|
224
346
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -240,20 +362,34 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
240
362
|
});
|
|
241
363
|
}
|
|
242
364
|
async getOfflineSigner(chainId) {
|
|
243
|
-
return await (
|
|
365
|
+
return await getExtensionOfflineSigner(chainId);
|
|
244
366
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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;
|
|
248
387
|
try {
|
|
249
|
-
const provider =
|
|
250
|
-
this.
|
|
388
|
+
const provider = getCosmostationProvider();
|
|
389
|
+
this.cosmostationProvider = provider;
|
|
251
390
|
return provider;
|
|
252
391
|
} catch (e) {
|
|
253
|
-
if (e instanceof
|
|
254
|
-
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
255
|
-
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
256
|
-
});
|
|
392
|
+
if (e instanceof __injectivelabs_exceptions.CosmosWalletException && e.type === __injectivelabs_exceptions.ErrorType.WalletNotInstalledError) throw e;
|
|
257
393
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
|
|
258
394
|
}
|
|
259
395
|
}
|
|
@@ -262,4 +398,5 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
262
398
|
//#endregion
|
|
263
399
|
exports.CosmostationWallet = CosmostationWallet;
|
|
264
400
|
exports.CosmostationWalletStrategy = Cosmostation;
|
|
401
|
+
exports.SEND_TRANSACTION_MODE = SEND_TRANSACTION_MODE;
|
|
265
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,14 +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 {
|
|
7
|
-
import { SEND_TRANSACTION_MODE } from "@cosmostation/extension-client/cosmos.js";
|
|
4
|
+
import { stringToUint8Array, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
8
5
|
import { createSignDocFromTransaction, createTxRawFromSigResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
9
|
-
import { stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
10
6
|
import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
11
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
|
|
12
17
|
//#region src/utils/index.ts
|
|
13
18
|
const isCosmosStationWalletInstalled = () => {
|
|
14
19
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -58,6 +63,33 @@ function _defineProperty(e, r, t) {
|
|
|
58
63
|
|
|
59
64
|
//#endregion
|
|
60
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
|
+
}
|
|
61
93
|
var CosmostationWallet = class CosmostationWallet {
|
|
62
94
|
constructor(chainId) {
|
|
63
95
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -68,29 +100,96 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
68
100
|
}
|
|
69
101
|
async checkChainIdSupport() {
|
|
70
102
|
const { chainId: actualChainId } = this;
|
|
71
|
-
const provider = await this.getCosmostationWallet();
|
|
72
103
|
const chainName = actualChainId.split("-");
|
|
104
|
+
getCosmostationProvider();
|
|
73
105
|
try {
|
|
74
|
-
return !!(await
|
|
106
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
75
107
|
} catch (_unused) {
|
|
76
108
|
throw new CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
77
109
|
}
|
|
78
110
|
}
|
|
79
|
-
async
|
|
80
|
-
|
|
81
|
-
return await cosmos();
|
|
82
|
-
} catch (e) {
|
|
83
|
-
if (e instanceof InstallError) throw new CosmosWalletException(/* @__PURE__ */ new Error("Please install the Cosmostation extension"), {
|
|
84
|
-
code: UnspecifiedErrorCode,
|
|
85
|
-
type: ErrorType.WalletNotInstalledError
|
|
86
|
-
});
|
|
87
|
-
throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
|
|
88
|
-
}
|
|
111
|
+
async getCosmostationProvider() {
|
|
112
|
+
return getCosmostationProvider();
|
|
89
113
|
}
|
|
90
114
|
};
|
|
91
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
|
+
|
|
92
124
|
//#endregion
|
|
93
125
|
//#region src/strategy/strategy.ts
|
|
126
|
+
/**
|
|
127
|
+
* Get an offline signer from the Cosmostation extension.
|
|
128
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
129
|
+
*/
|
|
130
|
+
async function getExtensionOfflineSigner(chainId) {
|
|
131
|
+
const provider = getCosmostationProvider();
|
|
132
|
+
return {
|
|
133
|
+
getAccounts: async () => {
|
|
134
|
+
const response = await provider.request({
|
|
135
|
+
method: "cos_account",
|
|
136
|
+
params: { chainName: chainId }
|
|
137
|
+
});
|
|
138
|
+
return [{
|
|
139
|
+
address: response.address,
|
|
140
|
+
pubkey: response.publicKey,
|
|
141
|
+
algo: "secp256k1"
|
|
142
|
+
}];
|
|
143
|
+
},
|
|
144
|
+
signAmino: async (_signerAddress, signDoc) => {
|
|
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
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
signed: response.signed_doc,
|
|
156
|
+
signature: {
|
|
157
|
+
pub_key: response.pub_key,
|
|
158
|
+
signature: response.signature
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
signDirect: async (_signerAddress, signDoc) => {
|
|
163
|
+
const doc = {
|
|
164
|
+
account_number: String(signDoc.accountNumber),
|
|
165
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
166
|
+
body_bytes: signDoc.bodyBytes,
|
|
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
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
signed: {
|
|
180
|
+
accountNumber: response.signed_doc.account_number,
|
|
181
|
+
chainId: response.signed_doc.chain_id,
|
|
182
|
+
authInfoBytes: response.signed_doc.auth_info_bytes,
|
|
183
|
+
bodyBytes: response.signed_doc.body_bytes
|
|
184
|
+
},
|
|
185
|
+
signature: {
|
|
186
|
+
pub_key: response.pub_key,
|
|
187
|
+
signature: response.signature
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
94
193
|
const getChainNameFromChainId = (chainId) => {
|
|
95
194
|
const [chainName] = chainId.split("-");
|
|
96
195
|
if (chainName.includes("cosmoshub")) return "cosmos";
|
|
@@ -102,7 +201,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
102
201
|
var Cosmostation = class extends BaseConcreteStrategy {
|
|
103
202
|
constructor(args) {
|
|
104
203
|
super(args);
|
|
105
|
-
_defineProperty(this, "
|
|
204
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
106
205
|
_defineProperty(this, "chainName", void 0);
|
|
107
206
|
this.chainId = args.chainId || CosmosChainId.Injective;
|
|
108
207
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -114,9 +213,9 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
114
213
|
return Promise.resolve(true);
|
|
115
214
|
}
|
|
116
215
|
async getAddresses() {
|
|
117
|
-
|
|
216
|
+
this.getProvider();
|
|
118
217
|
try {
|
|
119
|
-
return [(await
|
|
218
|
+
return [(await requestAccount(this.chainName)).address];
|
|
120
219
|
} catch (e) {
|
|
121
220
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
122
221
|
code: UnspecifiedErrorCode,
|
|
@@ -144,17 +243,26 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
144
243
|
});
|
|
145
244
|
}
|
|
146
245
|
async sendTransaction(transaction, _options) {
|
|
147
|
-
const
|
|
246
|
+
const provider = this.getProvider();
|
|
148
247
|
const txRaw = createTxRawFromSigResponse(transaction);
|
|
248
|
+
const txBytes = uint8ArrayToBase64(CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw));
|
|
149
249
|
try {
|
|
150
|
-
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
|
+
});
|
|
151
258
|
return {
|
|
152
259
|
...response.tx_response,
|
|
153
260
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
154
261
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
155
262
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
156
263
|
txHash: response.tx_response.txhash,
|
|
157
|
-
rawLog: response.tx_response.raw_log
|
|
264
|
+
rawLog: response.tx_response.raw_log,
|
|
265
|
+
timestamp: ""
|
|
158
266
|
};
|
|
159
267
|
} catch (e) {
|
|
160
268
|
if (e instanceof TransactionException) throw e;
|
|
@@ -172,20 +280,26 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
172
280
|
}
|
|
173
281
|
async signCosmosTransaction(transaction) {
|
|
174
282
|
const { chainId } = this;
|
|
175
|
-
const
|
|
283
|
+
const provider = this.getProvider();
|
|
176
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
|
+
};
|
|
177
291
|
try {
|
|
178
|
-
const signDirectResponse = await
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
}
|
|
186
300
|
});
|
|
187
301
|
return {
|
|
188
|
-
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)),
|
|
189
303
|
signature: { signature: signDirectResponse.signature }
|
|
190
304
|
};
|
|
191
305
|
} catch (e) {
|
|
@@ -196,9 +310,8 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
196
310
|
}
|
|
197
311
|
}
|
|
198
312
|
async getPubKey() {
|
|
199
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
200
313
|
try {
|
|
201
|
-
return uint8ArrayToBase64((await
|
|
314
|
+
return uint8ArrayToBase64((await requestAccount(this.chainName)).publicKey);
|
|
202
315
|
} catch (e) {
|
|
203
316
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
204
317
|
code: UnspecifiedErrorCode,
|
|
@@ -218,7 +331,16 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
218
331
|
}
|
|
219
332
|
async signArbitrary(signer, data) {
|
|
220
333
|
try {
|
|
221
|
-
|
|
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;
|
|
222
344
|
} catch (e) {
|
|
223
345
|
throw new CosmosWalletException(new Error(e.message), {
|
|
224
346
|
code: UnspecifiedErrorCode,
|
|
@@ -240,24 +362,38 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
240
362
|
});
|
|
241
363
|
}
|
|
242
364
|
async getOfflineSigner(chainId) {
|
|
243
|
-
return await
|
|
365
|
+
return await getExtensionOfflineSigner(chainId);
|
|
244
366
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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;
|
|
248
387
|
try {
|
|
249
|
-
const provider =
|
|
250
|
-
this.
|
|
388
|
+
const provider = getCosmostationProvider();
|
|
389
|
+
this.cosmostationProvider = provider;
|
|
251
390
|
return provider;
|
|
252
391
|
} catch (e) {
|
|
253
|
-
if (e instanceof
|
|
254
|
-
code: UnspecifiedErrorCode,
|
|
255
|
-
type: ErrorType.WalletNotInstalledError
|
|
256
|
-
});
|
|
392
|
+
if (e instanceof CosmosWalletException && e.type === ErrorType.WalletNotInstalledError) throw e;
|
|
257
393
|
throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
|
|
258
394
|
}
|
|
259
395
|
}
|
|
260
396
|
};
|
|
261
397
|
|
|
262
398
|
//#endregion
|
|
263
|
-
export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, isCosmosStationWalletInstalled };
|
|
399
|
+
export { CosmostationWallet, Cosmostation as CosmostationWalletStrategy, SEND_TRANSACTION_MODE, isCosmosStationWalletInstalled };
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-cosmostation",
|
|
3
|
-
"version": "1.17.2-alpha.
|
|
3
|
+
"version": "1.17.2-alpha.10",
|
|
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",
|
|
8
9
|
"email": "admin@injectivelabs.org"
|
|
9
10
|
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/InjectiveLabs/injective-ts"
|
|
14
|
+
},
|
|
10
15
|
"type": "module",
|
|
11
16
|
"sideEffects": false,
|
|
12
17
|
"exports": {
|
|
@@ -39,12 +44,10 @@
|
|
|
39
44
|
],
|
|
40
45
|
"dependencies": {
|
|
41
46
|
"@cosmjs/proto-signing": "0.33.0",
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@injectivelabs/exceptions": "1.17.2-alpha.
|
|
45
|
-
"@injectivelabs/
|
|
46
|
-
"@injectivelabs/ts-types": "1.17.2-alpha.0",
|
|
47
|
-
"@injectivelabs/wallet-base": "1.17.2-alpha.0"
|
|
47
|
+
"@injectivelabs/sdk-ts": "1.17.2-alpha.10",
|
|
48
|
+
"@injectivelabs/wallet-base": "1.17.2-alpha.10",
|
|
49
|
+
"@injectivelabs/exceptions": "1.17.2-alpha.10",
|
|
50
|
+
"@injectivelabs/ts-types": "1.17.2-alpha.10"
|
|
48
51
|
},
|
|
49
52
|
"publishConfig": {
|
|
50
53
|
"access": "public"
|