@injectivelabs/wallet-cosmostation 1.17.2-alpha.0 → 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 +174 -44
- package/dist/cjs/index.d.cts +142 -6
- package/dist/esm/index.d.ts +142 -6
- package/dist/esm/index.js +174 -45
- package/package.json +6 -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,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_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
5
|
let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
|
|
6
|
+
let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
|
|
10
7
|
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
11
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
|
|
12
18
|
//#region src/utils/index.ts
|
|
13
19
|
const isCosmosStationWalletInstalled = () => {
|
|
14
20
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -58,6 +64,33 @@ function _defineProperty(e, r, t) {
|
|
|
58
64
|
|
|
59
65
|
//#endregion
|
|
60
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
|
+
}
|
|
61
94
|
var CosmostationWallet = class CosmostationWallet {
|
|
62
95
|
constructor(chainId) {
|
|
63
96
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -68,29 +101,88 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
68
101
|
}
|
|
69
102
|
async checkChainIdSupport() {
|
|
70
103
|
const { chainId: actualChainId } = this;
|
|
71
|
-
const provider = await this.getCosmostationWallet();
|
|
72
104
|
const chainName = actualChainId.split("-");
|
|
105
|
+
getCosmostationProvider();
|
|
73
106
|
try {
|
|
74
|
-
return !!(await
|
|
107
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
75
108
|
} catch (_unused) {
|
|
76
109
|
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
77
110
|
}
|
|
78
111
|
}
|
|
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
|
-
}
|
|
112
|
+
async getCosmostationProvider() {
|
|
113
|
+
return getCosmostationProvider();
|
|
89
114
|
}
|
|
90
115
|
};
|
|
91
116
|
|
|
92
117
|
//#endregion
|
|
93
118
|
//#region src/strategy/strategy.ts
|
|
119
|
+
/**
|
|
120
|
+
* Get an offline signer from the Cosmostation extension.
|
|
121
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
122
|
+
*/
|
|
123
|
+
async function getExtensionOfflineSigner(chainId) {
|
|
124
|
+
const provider = getCosmostationProvider();
|
|
125
|
+
return {
|
|
126
|
+
getAccounts: async () => {
|
|
127
|
+
const response = await provider.request({
|
|
128
|
+
method: "cos_account",
|
|
129
|
+
params: { chainName: chainId }
|
|
130
|
+
});
|
|
131
|
+
return [{
|
|
132
|
+
address: response.address,
|
|
133
|
+
pubkey: response.publicKey,
|
|
134
|
+
algo: "secp256k1"
|
|
135
|
+
}];
|
|
136
|
+
},
|
|
137
|
+
signAmino: async (_signerAddress, signDoc) => {
|
|
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
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
signed: response.signed_doc,
|
|
149
|
+
signature: {
|
|
150
|
+
pub_key: response.pub_key,
|
|
151
|
+
signature: response.signature
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
signDirect: async (_signerAddress, signDoc) => {
|
|
156
|
+
const doc = {
|
|
157
|
+
account_number: String(signDoc.accountNumber),
|
|
158
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
159
|
+
body_bytes: signDoc.bodyBytes,
|
|
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
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
signed: {
|
|
173
|
+
accountNumber: response.signed_doc.account_number,
|
|
174
|
+
chainId: response.signed_doc.chain_id,
|
|
175
|
+
authInfoBytes: response.signed_doc.auth_info_bytes,
|
|
176
|
+
bodyBytes: response.signed_doc.body_bytes
|
|
177
|
+
},
|
|
178
|
+
signature: {
|
|
179
|
+
pub_key: response.pub_key,
|
|
180
|
+
signature: response.signature
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
94
186
|
const getChainNameFromChainId = (chainId) => {
|
|
95
187
|
const [chainName] = chainId.split("-");
|
|
96
188
|
if (chainName.includes("cosmoshub")) return "cosmos";
|
|
@@ -102,7 +194,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
102
194
|
var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
103
195
|
constructor(args) {
|
|
104
196
|
super(args);
|
|
105
|
-
_defineProperty(this, "
|
|
197
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
106
198
|
_defineProperty(this, "chainName", void 0);
|
|
107
199
|
this.chainId = args.chainId || __injectivelabs_ts_types.CosmosChainId.Injective;
|
|
108
200
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -114,9 +206,9 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
114
206
|
return Promise.resolve(true);
|
|
115
207
|
}
|
|
116
208
|
async getAddresses() {
|
|
117
|
-
|
|
209
|
+
this.getProvider();
|
|
118
210
|
try {
|
|
119
|
-
return [(await
|
|
211
|
+
return [(await requestAccount(this.chainName)).address];
|
|
120
212
|
} catch (e) {
|
|
121
213
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
122
214
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -144,17 +236,26 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
144
236
|
});
|
|
145
237
|
}
|
|
146
238
|
async sendTransaction(transaction, _options) {
|
|
147
|
-
const
|
|
239
|
+
const provider = this.getProvider();
|
|
148
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));
|
|
149
242
|
try {
|
|
150
|
-
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
|
+
});
|
|
151
251
|
return {
|
|
152
252
|
...response.tx_response,
|
|
153
253
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
154
254
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
155
255
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
156
256
|
txHash: response.tx_response.txhash,
|
|
157
|
-
rawLog: response.tx_response.raw_log
|
|
257
|
+
rawLog: response.tx_response.raw_log,
|
|
258
|
+
timestamp: ""
|
|
158
259
|
};
|
|
159
260
|
} catch (e) {
|
|
160
261
|
if (e instanceof __injectivelabs_exceptions.TransactionException) throw e;
|
|
@@ -172,17 +273,23 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
172
273
|
}
|
|
173
274
|
async signCosmosTransaction(transaction) {
|
|
174
275
|
const { chainId } = this;
|
|
175
|
-
const
|
|
276
|
+
const provider = this.getProvider();
|
|
176
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
|
+
};
|
|
177
284
|
try {
|
|
178
|
-
const signDirectResponse = await
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
}
|
|
186
293
|
});
|
|
187
294
|
return {
|
|
188
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)),
|
|
@@ -196,9 +303,8 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
196
303
|
}
|
|
197
304
|
}
|
|
198
305
|
async getPubKey() {
|
|
199
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
200
306
|
try {
|
|
201
|
-
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await
|
|
307
|
+
return (0, __injectivelabs_sdk_ts_utils.uint8ArrayToBase64)((await requestAccount(this.chainName)).publicKey);
|
|
202
308
|
} catch (e) {
|
|
203
309
|
if (e.code === 4001) throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
204
310
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -218,7 +324,16 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
218
324
|
}
|
|
219
325
|
async signArbitrary(signer, data) {
|
|
220
326
|
try {
|
|
221
|
-
|
|
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;
|
|
222
337
|
} catch (e) {
|
|
223
338
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), {
|
|
224
339
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
@@ -240,20 +355,34 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
240
355
|
});
|
|
241
356
|
}
|
|
242
357
|
async getOfflineSigner(chainId) {
|
|
243
|
-
return await (
|
|
358
|
+
return await getExtensionOfflineSigner(chainId);
|
|
244
359
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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;
|
|
248
380
|
try {
|
|
249
|
-
const provider =
|
|
250
|
-
this.
|
|
381
|
+
const provider = getCosmostationProvider();
|
|
382
|
+
this.cosmostationProvider = provider;
|
|
251
383
|
return provider;
|
|
252
384
|
} catch (e) {
|
|
253
|
-
if (e instanceof
|
|
254
|
-
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
255
|
-
type: __injectivelabs_exceptions.ErrorType.WalletNotInstalledError
|
|
256
|
-
});
|
|
385
|
+
if (e instanceof __injectivelabs_exceptions.CosmosWalletException && e.type === __injectivelabs_exceptions.ErrorType.WalletNotInstalledError) throw e;
|
|
257
386
|
throw new __injectivelabs_exceptions.CosmosWalletException(new Error(e.message), { code: __injectivelabs_exceptions.UnspecifiedErrorCode });
|
|
258
387
|
}
|
|
259
388
|
}
|
|
@@ -262,4 +391,5 @@ var Cosmostation = class extends __injectivelabs_wallet_base.BaseConcreteStrateg
|
|
|
262
391
|
//#endregion
|
|
263
392
|
exports.CosmostationWallet = CosmostationWallet;
|
|
264
393
|
exports.CosmostationWalletStrategy = Cosmostation;
|
|
394
|
+
exports.SEND_TRANSACTION_MODE = SEND_TRANSACTION_MODE;
|
|
265
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,14 +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 {
|
|
7
|
-
import { SEND_TRANSACTION_MODE } from "@cosmostation/extension-client/cosmos.js";
|
|
5
|
+
import { stringToUint8Array, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
8
6
|
import { createSignDocFromTransaction, createTxRawFromSigResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
9
|
-
import { stringToUint8Array, toUtf8, uint8ArrayToBase64, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
10
7
|
import { BaseConcreteStrategy, WalletAction, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
11
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
|
|
12
18
|
//#region src/utils/index.ts
|
|
13
19
|
const isCosmosStationWalletInstalled = () => {
|
|
14
20
|
return (typeof window !== "undefined" ? window : {}).cosmostation !== void 0;
|
|
@@ -58,6 +64,33 @@ function _defineProperty(e, r, t) {
|
|
|
58
64
|
|
|
59
65
|
//#endregion
|
|
60
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
|
+
}
|
|
61
94
|
var CosmostationWallet = class CosmostationWallet {
|
|
62
95
|
constructor(chainId) {
|
|
63
96
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -68,29 +101,88 @@ var CosmostationWallet = class CosmostationWallet {
|
|
|
68
101
|
}
|
|
69
102
|
async checkChainIdSupport() {
|
|
70
103
|
const { chainId: actualChainId } = this;
|
|
71
|
-
const provider = await this.getCosmostationWallet();
|
|
72
104
|
const chainName = actualChainId.split("-");
|
|
105
|
+
getCosmostationProvider();
|
|
73
106
|
try {
|
|
74
|
-
return !!(await
|
|
107
|
+
return !!(await getSupportedChainIds()).official.find((chainId) => chainId === actualChainId);
|
|
75
108
|
} catch (_unused) {
|
|
76
109
|
throw new CosmosWalletException(/* @__PURE__ */ new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
77
110
|
}
|
|
78
111
|
}
|
|
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
|
-
}
|
|
112
|
+
async getCosmostationProvider() {
|
|
113
|
+
return getCosmostationProvider();
|
|
89
114
|
}
|
|
90
115
|
};
|
|
91
116
|
|
|
92
117
|
//#endregion
|
|
93
118
|
//#region src/strategy/strategy.ts
|
|
119
|
+
/**
|
|
120
|
+
* Get an offline signer from the Cosmostation extension.
|
|
121
|
+
* This uses the vanilla window.cosmostation API directly.
|
|
122
|
+
*/
|
|
123
|
+
async function getExtensionOfflineSigner(chainId) {
|
|
124
|
+
const provider = getCosmostationProvider();
|
|
125
|
+
return {
|
|
126
|
+
getAccounts: async () => {
|
|
127
|
+
const response = await provider.request({
|
|
128
|
+
method: "cos_account",
|
|
129
|
+
params: { chainName: chainId }
|
|
130
|
+
});
|
|
131
|
+
return [{
|
|
132
|
+
address: response.address,
|
|
133
|
+
pubkey: response.publicKey,
|
|
134
|
+
algo: "secp256k1"
|
|
135
|
+
}];
|
|
136
|
+
},
|
|
137
|
+
signAmino: async (_signerAddress, signDoc) => {
|
|
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
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
signed: response.signed_doc,
|
|
149
|
+
signature: {
|
|
150
|
+
pub_key: response.pub_key,
|
|
151
|
+
signature: response.signature
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
signDirect: async (_signerAddress, signDoc) => {
|
|
156
|
+
const doc = {
|
|
157
|
+
account_number: String(signDoc.accountNumber),
|
|
158
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
159
|
+
body_bytes: signDoc.bodyBytes,
|
|
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
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
signed: {
|
|
173
|
+
accountNumber: response.signed_doc.account_number,
|
|
174
|
+
chainId: response.signed_doc.chain_id,
|
|
175
|
+
authInfoBytes: response.signed_doc.auth_info_bytes,
|
|
176
|
+
bodyBytes: response.signed_doc.body_bytes
|
|
177
|
+
},
|
|
178
|
+
signature: {
|
|
179
|
+
pub_key: response.pub_key,
|
|
180
|
+
signature: response.signature
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
94
186
|
const getChainNameFromChainId = (chainId) => {
|
|
95
187
|
const [chainName] = chainId.split("-");
|
|
96
188
|
if (chainName.includes("cosmoshub")) return "cosmos";
|
|
@@ -102,7 +194,7 @@ const getChainNameFromChainId = (chainId) => {
|
|
|
102
194
|
var Cosmostation = class extends BaseConcreteStrategy {
|
|
103
195
|
constructor(args) {
|
|
104
196
|
super(args);
|
|
105
|
-
_defineProperty(this, "
|
|
197
|
+
_defineProperty(this, "cosmostationProvider", void 0);
|
|
106
198
|
_defineProperty(this, "chainName", void 0);
|
|
107
199
|
this.chainId = args.chainId || CosmosChainId.Injective;
|
|
108
200
|
this.chainName = getChainNameFromChainId(this.chainId);
|
|
@@ -114,9 +206,9 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
114
206
|
return Promise.resolve(true);
|
|
115
207
|
}
|
|
116
208
|
async getAddresses() {
|
|
117
|
-
|
|
209
|
+
this.getProvider();
|
|
118
210
|
try {
|
|
119
|
-
return [(await
|
|
211
|
+
return [(await requestAccount(this.chainName)).address];
|
|
120
212
|
} catch (e) {
|
|
121
213
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
122
214
|
code: UnspecifiedErrorCode,
|
|
@@ -144,17 +236,26 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
144
236
|
});
|
|
145
237
|
}
|
|
146
238
|
async sendTransaction(transaction, _options) {
|
|
147
|
-
const
|
|
239
|
+
const provider = this.getProvider();
|
|
148
240
|
const txRaw = createTxRawFromSigResponse(transaction);
|
|
241
|
+
const txBytes = uint8ArrayToBase64(CosmosTxV1Beta1TxPb.TxRaw.toBinary(txRaw));
|
|
149
242
|
try {
|
|
150
|
-
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
|
+
});
|
|
151
251
|
return {
|
|
152
252
|
...response.tx_response,
|
|
153
253
|
gasUsed: parseInt(response.tx_response.gas_used || "0", 10),
|
|
154
254
|
gasWanted: parseInt(response.tx_response.gas_wanted || "0", 10),
|
|
155
255
|
height: parseInt(response.tx_response.height || "0", 10),
|
|
156
256
|
txHash: response.tx_response.txhash,
|
|
157
|
-
rawLog: response.tx_response.raw_log
|
|
257
|
+
rawLog: response.tx_response.raw_log,
|
|
258
|
+
timestamp: ""
|
|
158
259
|
};
|
|
159
260
|
} catch (e) {
|
|
160
261
|
if (e instanceof TransactionException) throw e;
|
|
@@ -172,17 +273,23 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
172
273
|
}
|
|
173
274
|
async signCosmosTransaction(transaction) {
|
|
174
275
|
const { chainId } = this;
|
|
175
|
-
const
|
|
276
|
+
const provider = this.getProvider();
|
|
176
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
|
+
};
|
|
177
284
|
try {
|
|
178
|
-
const signDirectResponse = await
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
}
|
|
186
293
|
});
|
|
187
294
|
return {
|
|
188
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)),
|
|
@@ -196,9 +303,8 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
196
303
|
}
|
|
197
304
|
}
|
|
198
305
|
async getPubKey() {
|
|
199
|
-
const cosmostationWallet = await this.getCosmostationWallet();
|
|
200
306
|
try {
|
|
201
|
-
return uint8ArrayToBase64((await
|
|
307
|
+
return uint8ArrayToBase64((await requestAccount(this.chainName)).publicKey);
|
|
202
308
|
} catch (e) {
|
|
203
309
|
if (e.code === 4001) throw new CosmosWalletException(/* @__PURE__ */ new Error("The user rejected the request"), {
|
|
204
310
|
code: UnspecifiedErrorCode,
|
|
@@ -218,7 +324,16 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
218
324
|
}
|
|
219
325
|
async signArbitrary(signer, data) {
|
|
220
326
|
try {
|
|
221
|
-
|
|
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;
|
|
222
337
|
} catch (e) {
|
|
223
338
|
throw new CosmosWalletException(new Error(e.message), {
|
|
224
339
|
code: UnspecifiedErrorCode,
|
|
@@ -240,24 +355,38 @@ var Cosmostation = class extends BaseConcreteStrategy {
|
|
|
240
355
|
});
|
|
241
356
|
}
|
|
242
357
|
async getOfflineSigner(chainId) {
|
|
243
|
-
return await
|
|
358
|
+
return await getExtensionOfflineSigner(chainId);
|
|
359
|
+
}
|
|
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);
|
|
244
371
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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;
|
|
248
380
|
try {
|
|
249
|
-
const provider =
|
|
250
|
-
this.
|
|
381
|
+
const provider = getCosmostationProvider();
|
|
382
|
+
this.cosmostationProvider = provider;
|
|
251
383
|
return provider;
|
|
252
384
|
} catch (e) {
|
|
253
|
-
if (e instanceof
|
|
254
|
-
code: UnspecifiedErrorCode,
|
|
255
|
-
type: ErrorType.WalletNotInstalledError
|
|
256
|
-
});
|
|
385
|
+
if (e instanceof CosmosWalletException && e.type === ErrorType.WalletNotInstalledError) throw e;
|
|
257
386
|
throw new CosmosWalletException(new Error(e.message), { code: UnspecifiedErrorCode });
|
|
258
387
|
}
|
|
259
388
|
}
|
|
260
389
|
};
|
|
261
390
|
|
|
262
391
|
//#endregion
|
|
263
|
-
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,12 +40,10 @@
|
|
|
39
40
|
],
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@cosmjs/proto-signing": "0.33.0",
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@injectivelabs/
|
|
45
|
-
"@injectivelabs/
|
|
46
|
-
"@injectivelabs/ts-types": "1.17.2-alpha.0",
|
|
47
|
-
"@injectivelabs/wallet-base": "1.17.2-alpha.0"
|
|
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"
|
|
48
47
|
},
|
|
49
48
|
"publishConfig": {
|
|
50
49
|
"access": "public"
|