@injectivelabs/wallet-cosmostation 0.0.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 +108 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/strategy/strategy.d.ts +39 -0
- package/dist/cjs/strategy/strategy.d.ts.map +1 -0
- package/dist/cjs/strategy/strategy.js +216 -0
- package/dist/cjs/strategy/strategy.js.map +1 -0
- package/dist/cjs/wallet.d.ts +9 -0
- package/dist/cjs/wallet.d.ts.map +1 -0
- package/dist/cjs/wallet.js +59 -0
- package/dist/cjs/wallet.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/strategy/strategy.d.ts +39 -0
- package/dist/esm/strategy/strategy.d.ts.map +1 -0
- package/dist/esm/strategy/strategy.js +183 -0
- package/dist/esm/strategy/strategy.js.map +1 -0
- package/dist/esm/wallet.d.ts +9 -0
- package/dist/esm/wallet.d.ts.map +1 -0
- package/dist/esm/wallet.js +41 -0
- package/dist/esm/wallet.js.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# 🌟 Injective Protocol - Wallet Cosmostation
|
|
2
|
+
|
|
3
|
+
<!-- TODO -->
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@injectivelabs/wallet-ts)
|
|
6
|
+
[](https://www.npmjs.com/package/@injectivelabs/wallet-ts)
|
|
7
|
+
[]()
|
|
8
|
+
|
|
9
|
+
_Package to use Magic Wallets on Injective via the wallet strategy._
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 📚 Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @injectivelabs/wallet-cosmostation
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📖 Documentation
|
|
22
|
+
|
|
23
|
+
Injective's wallet packages are intended to make it easy for developers to choose exactly what wallets - and subsequent dependencies - they
|
|
24
|
+
want to include in their projects.
|
|
25
|
+
|
|
26
|
+
Regardless of which wallet package(s) you choose to use you must also have `@injectivelabs/wallet-core` and `@injectivelabs/wallet-base`
|
|
27
|
+
installed. These contain all of the types and core wallet functionality, with the separate wallet packages only providing the necessary
|
|
28
|
+
dependencies and implementations for their specific wallets.
|
|
29
|
+
|
|
30
|
+
Here's a brief example of how to use this package to send 1 INJ.:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Wallet } from '@injectivelabs/wallet-base';
|
|
34
|
+
import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
35
|
+
import { CosmostationWalletStrategy } from '@injectivelabs/wallet-cosmostation';
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const strategyArgs: WalletStrategyArguments = {
|
|
39
|
+
chainId: ChainId.Mainnet,
|
|
40
|
+
wallet: Wallet.Cosmostation,
|
|
41
|
+
strategies: {
|
|
42
|
+
[Wallet.Cosmostation]: new CosmostationWalletStrategy({
|
|
43
|
+
chainId: ChainId.Mainnet,
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
const walletStrategy = new BaseWalletStrategy(strategyArgs)
|
|
48
|
+
|
|
49
|
+
const msgBroadcaster = new MsgBroadcaster({
|
|
50
|
+
walletStrategy,
|
|
51
|
+
simulateTx: true,
|
|
52
|
+
network: Network.Mainnet,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const sendTX = async () => {
|
|
56
|
+
const injectiveAddress = 'someInjectiveAddress'
|
|
57
|
+
|
|
58
|
+
const message = MsgSend.fromJSON({
|
|
59
|
+
srcInjectiveAddress: injectiveAddress,
|
|
60
|
+
dstInjectiveAddress: injectiveAddress,
|
|
61
|
+
amount: {
|
|
62
|
+
amount: '1',
|
|
63
|
+
denom: 'inj',
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return await msgBroadcaster.broadcast({ msgs: message })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const result = await sendTX()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 📜 Contribution
|
|
78
|
+
|
|
79
|
+
**Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.**
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## ⛑ Support
|
|
84
|
+
|
|
85
|
+
Reach out to us at one of the following places!
|
|
86
|
+
|
|
87
|
+
- Website at <a href="https://injective.com" target="_blank">`injective.com`</a>
|
|
88
|
+
- Twitter at <a href="https://twitter.com/Injective_" target="_blank">`@Injective`</a>
|
|
89
|
+
- Discord at <a href="https://discord.com/invite/NK4qdbv" target="_blank">`Discord`</a>
|
|
90
|
+
- Telegram at <a href="https://t.me/joininjective" target="_blank">`Telegram`</a>
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 🔓 License
|
|
95
|
+
|
|
96
|
+
Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
|
|
97
|
+
|
|
98
|
+
<a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" />
|
|
99
|
+
|
|
100
|
+
Originally released by Injective Labs Inc. under: <br />
|
|
101
|
+
Apache License <br />
|
|
102
|
+
Version 2.0, January 2004 <br />
|
|
103
|
+
http://www.apache.org/licenses/
|
|
104
|
+
|
|
105
|
+
<p> </p>
|
|
106
|
+
<div align="center">
|
|
107
|
+
<sub><em>Powering the future of decentralized finance.</em></sub>
|
|
108
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,YAAY,IAAI,0BAA0B,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmostationWalletStrategy = exports.CosmostationWallet = void 0;
|
|
4
|
+
var wallet_1 = require("./wallet");
|
|
5
|
+
Object.defineProperty(exports, "CosmostationWallet", { enumerable: true, get: function () { return wallet_1.CosmostationWallet; } });
|
|
6
|
+
var strategy_1 = require("./strategy/strategy");
|
|
7
|
+
Object.defineProperty(exports, "CosmostationWalletStrategy", { enumerable: true, get: function () { return strategy_1.Cosmostation; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6C;AAApC,4GAAA,kBAAkB,OAAA;AAC3B,gDAAgF;AAAvE,sHAAA,YAAY,OAA8B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { ChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
|
+
import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, ConcreteWalletStrategy } from '@injectivelabs/wallet-base';
|
|
4
|
+
import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
|
|
5
|
+
export declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
|
+
private cosmostationWallet?;
|
|
7
|
+
constructor(args: {
|
|
8
|
+
chainId: ChainId;
|
|
9
|
+
});
|
|
10
|
+
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
11
|
+
enable(): Promise<boolean>;
|
|
12
|
+
getAddresses(): Promise<string[]>;
|
|
13
|
+
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
14
|
+
sendEthereumTransaction(_transaction: unknown, _options: {
|
|
15
|
+
address: AccountAddress;
|
|
16
|
+
ethereumChainId: EthereumChainId;
|
|
17
|
+
}): Promise<string>;
|
|
18
|
+
sendTransaction(transaction: DirectSignResponse | CosmosTxV1Beta1Tx.TxRaw, _options: {
|
|
19
|
+
address: AccountAddress;
|
|
20
|
+
chainId: ChainId;
|
|
21
|
+
}): Promise<TxResponse>;
|
|
22
|
+
signAminoCosmosTransaction(_transaction: {
|
|
23
|
+
address: string;
|
|
24
|
+
signDoc: StdSignDoc;
|
|
25
|
+
}): Promise<AminoSignResponse>;
|
|
26
|
+
signCosmosTransaction(transaction: {
|
|
27
|
+
txRaw: CosmosTxV1Beta1Tx.TxRaw;
|
|
28
|
+
chainId: string;
|
|
29
|
+
address: string;
|
|
30
|
+
accountNumber: number;
|
|
31
|
+
}): Promise<DirectSignResponse>;
|
|
32
|
+
getPubKey(): Promise<string>;
|
|
33
|
+
signEip712TypedData(_eip712TypedData: string, _address: AccountAddress): Promise<string>;
|
|
34
|
+
signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
|
|
35
|
+
getEthereumChainId(): Promise<string>;
|
|
36
|
+
getEthereumTransactionReceipt(_txHash: string): Promise<string>;
|
|
37
|
+
private getCosmostationWallet;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,UAAU,EACV,iBAAiB,EACj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f,aAAa,EAAE,MAAM,CAAA;KACtB;IAqCK,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IA2B5B,mBAAmB,CACvB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC;IAUZ,aAAa,CACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GAAG,UAAU,GACxB,OAAO,CAAC,MAAM,CAAC;IAmBZ,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAUrC,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAavD,qBAAqB;CA6BpC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Cosmostation = void 0;
|
|
13
|
+
/* eslint-disable class-methods-use-this */
|
|
14
|
+
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
15
|
+
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
16
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
17
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
18
|
+
const sdk_ts_2 = require("@injectivelabs/sdk-ts");
|
|
19
|
+
const extension_client_1 = require("@cosmostation/extension-client");
|
|
20
|
+
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
21
|
+
const cosmos_1 = require("@cosmostation/extension-client/cosmos");
|
|
22
|
+
const wallet_1 = require("./../wallet");
|
|
23
|
+
const INJECTIVE_CHAIN_NAME = 'injective';
|
|
24
|
+
class Cosmostation extends wallet_base_1.BaseConcreteStrategy {
|
|
25
|
+
constructor(args) {
|
|
26
|
+
super(args);
|
|
27
|
+
this.chainId = args.chainId || ts_types_1.CosmosChainId.Injective;
|
|
28
|
+
}
|
|
29
|
+
getWalletDeviceType() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
enable() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return Promise.resolve(true);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getAddresses() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const cosmostationWallet = yield this.getCosmostationWallet();
|
|
42
|
+
try {
|
|
43
|
+
const accounts = yield cosmostationWallet.requestAccount(INJECTIVE_CHAIN_NAME);
|
|
44
|
+
return [accounts.address];
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e.code === 4001) {
|
|
48
|
+
throw new exceptions_1.CosmosWalletException(new Error('The user rejected the request'), {
|
|
49
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
50
|
+
context: wallet_base_1.WalletAction.GetAccounts,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
54
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
55
|
+
context: wallet_base_1.WalletAction.GetAccounts,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
getSessionOrConfirm(address) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// eslint-disable-next-line class-methods-use-this
|
|
66
|
+
sendEthereumTransaction(_transaction, _options) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
throw new exceptions_1.CosmosWalletException(new Error('sendEthereumTransaction is not supported. Cosmostation only supports sending cosmos transactions'), {
|
|
69
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
70
|
+
context: wallet_base_1.WalletAction.SendEthereumTransaction,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
sendTransaction(transaction, _options) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const cosmostationWallet = yield this.getCosmostationWallet();
|
|
77
|
+
const txRaw = (0, sdk_ts_1.createTxRawFromSigResponse)(transaction);
|
|
78
|
+
try {
|
|
79
|
+
const response = yield cosmostationWallet.sendTransaction(INJECTIVE_CHAIN_NAME, sdk_ts_2.CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(), cosmos_1.SEND_TRANSACTION_MODE.SYNC);
|
|
80
|
+
return Object.assign(Object.assign({}, response.tx_response), { gasUsed: parseInt((response.tx_response.gas_used || '0'), 10), gasWanted: parseInt((response.tx_response.gas_wanted || '0'), 10), height: parseInt((response.tx_response.height || '0'), 10), txHash: response.tx_response.txhash, rawLog: response.tx_response.raw_log });
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
if (e instanceof exceptions_1.TransactionException) {
|
|
84
|
+
throw e;
|
|
85
|
+
}
|
|
86
|
+
throw new exceptions_1.TransactionException(new Error(e.message), {
|
|
87
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
88
|
+
context: wallet_base_1.WalletAction.SendTransaction,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
signAminoCosmosTransaction(_transaction) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
throw new exceptions_1.CosmosWalletException(new Error('This wallet does not support signing using amino'), {
|
|
96
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
97
|
+
context: wallet_base_1.WalletAction.SendTransaction,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
signCosmosTransaction(transaction) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const { chainId } = this;
|
|
104
|
+
const cosmostationWallet = yield this.getCosmostationWallet();
|
|
105
|
+
const signDoc = (0, sdk_ts_1.createSignDocFromTransaction)(transaction);
|
|
106
|
+
try {
|
|
107
|
+
/* Sign the transaction */
|
|
108
|
+
const signDirectResponse = yield cosmostationWallet.signDirect(INJECTIVE_CHAIN_NAME, {
|
|
109
|
+
chain_id: chainId,
|
|
110
|
+
body_bytes: signDoc.bodyBytes,
|
|
111
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
112
|
+
account_number: signDoc.accountNumber.toString(),
|
|
113
|
+
}, { fee: true, memo: true });
|
|
114
|
+
return {
|
|
115
|
+
signed: (0, proto_signing_1.makeSignDoc)(signDirectResponse.signed_doc.body_bytes, signDirectResponse.signed_doc.auth_info_bytes, signDirectResponse.signed_doc.chain_id, parseInt(signDirectResponse.signed_doc.account_number, 10)),
|
|
116
|
+
signature: {
|
|
117
|
+
signature: signDirectResponse.signature,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
123
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
124
|
+
context: wallet_base_1.WalletAction.SendTransaction,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
getPubKey() {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const cosmostationWallet = yield this.getCosmostationWallet();
|
|
132
|
+
try {
|
|
133
|
+
const account = yield cosmostationWallet.requestAccount(INJECTIVE_CHAIN_NAME);
|
|
134
|
+
return Buffer.from(account.publicKey).toString('base64');
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
if (e.code === 4001) {
|
|
138
|
+
throw new exceptions_1.CosmosWalletException(new Error('The user rejected the request'), {
|
|
139
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
140
|
+
context: wallet_base_1.WalletAction.GetAccounts,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
144
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
145
|
+
context: wallet_base_1.WalletAction.GetAccounts,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
signEip712TypedData(_eip712TypedData, _address) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
throw new exceptions_1.CosmosWalletException(new Error('This wallet does not support signing Ethereum transactions'), {
|
|
153
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
154
|
+
context: wallet_base_1.WalletAction.SendTransaction,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
signArbitrary(signer, data) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
try {
|
|
161
|
+
const cosmostationWallet = yield this.getCosmostationWallet();
|
|
162
|
+
const signature = yield cosmostationWallet.signMessage(INJECTIVE_CHAIN_NAME, signer, (0, sdk_ts_1.toUtf8)(data));
|
|
163
|
+
return signature.signature;
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
167
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
168
|
+
context: wallet_base_1.WalletAction.SignArbitrary,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
getEthereumChainId() {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
throw new exceptions_1.CosmosWalletException(new Error('getEthereumChainId is not supported on Cosmostation'), {
|
|
176
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
177
|
+
context: wallet_base_1.WalletAction.GetChainId,
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
getEthereumTransactionReceipt(_txHash) {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
throw new exceptions_1.CosmosWalletException(new Error('getEthereumTransactionReceipt is not supported on Cosmostation'), {
|
|
184
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
185
|
+
type: exceptions_1.ErrorType.WalletError,
|
|
186
|
+
context: wallet_base_1.WalletAction.GetEthereumTransactionReceipt,
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
getCosmostationWallet() {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
if (this.cosmostationWallet) {
|
|
193
|
+
return this.cosmostationWallet;
|
|
194
|
+
}
|
|
195
|
+
const cosmostationWallet = new wallet_1.CosmostationWallet(this.chainId);
|
|
196
|
+
try {
|
|
197
|
+
const provider = yield cosmostationWallet.getCosmostationWallet();
|
|
198
|
+
this.cosmostationWallet = provider;
|
|
199
|
+
return provider;
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
if (e instanceof extension_client_1.InstallError) {
|
|
203
|
+
throw new exceptions_1.CosmosWalletException(new Error('Please install the Cosmostation extension'), {
|
|
204
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
205
|
+
type: exceptions_1.ErrorType.WalletNotInstalledError,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
209
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.Cosmostation = Cosmostation;
|
|
216
|
+
//# sourceMappingURL=strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA2C;AAC3C,kDAO8B;AAC9B,sDAKgC;AAChC,0DAKkC;AAClC,4DAMmC;AACnC,kDAAyD;AACzD,qEAAqE;AACrE,yDAAmD;AACnD,kEAA6E;AAC7E,wCAAgD;AAEhD,MAAM,oBAAoB,GAAG,WAAW,CAAA;AAExC,MAAa,YACX,SAAQ,kCAAoB;IAK5B,YAAY,IAA0B;QACpC,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,wBAAa,CAAC,SAAS,CAAA;IACxD,CAAC;IAEK,mBAAmB;;YACvB,OAAO,OAAO,CAAC,OAAO,CAAC,8BAAgB,CAAC,OAAO,CAAC,CAAA;QAClD,CAAC;KAAA;IAEK,MAAM;;YACV,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC;KAAA;IAEK,YAAY;;YAChB,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAA;YAE7D,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,cAAc,CACtD,oBAAoB,CACrB,CAAA;gBAED,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC3B,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACpB,IAAK,CAAS,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;oBAC7B,MAAM,IAAI,kCAAqB,CAC7B,I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CAAC,OAAe;;YACjD,MAAM,IAAI,kCAAqB,CAC7B,IAAI,KAAK,CACP,gEAAgE,CACjE,EACD;gBACE,IAAI,EAAE,iCAAoB;gBAC1B,IAAI,EAAE,sBAAS,CAAC,WAAW;gBAC3B,OAAO,EAAE,0BAAY,CAAC,6BAA6B;aACpD,CACF,CAAA;QACH,CAAC;KAAA;IAEa,qBAAqB;;YACjC,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAA;YAChC,CAAC;YAED,MAAM,kBAAkB,GAAG,IAAI,2BAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAE/D,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,qBAAqB,EAAE,CAAA;gBAEjE,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAA;gBAElC,OAAO,QAAQ,CAAA;YACjB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,YAAY,+BAAY,EAAE,CAAC;oBAC9B,MAAM,IAAI,kCAAqB,CAC7B,IAAI,KAAK,CAAC,2CAA2C,CAAC,EACtD;wBACE,IAAI,EAAE,iCAAoB;wBAC1B,IAAI,EAAE,sBAAS,CAAC,uBAAuB;qBACxC,CACF,CAAA;gBACH,CAAC;gBAED,MAAM,IAAI,kCAAqB,CAAC,IAAI,KAAK,CAAE,CAAS,CAAC,OAAO,CAAC,EAAE;oBAC7D,IAAI,EAAE,iCAAoB;iBAC3B,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;KAAA;CACF;AApRD,oCAoRC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChainId, CosmosChainId, TestnetCosmosChainId } from '@injectivelabs/ts-types';
|
|
2
|
+
export declare class CosmostationWallet {
|
|
3
|
+
private chainId;
|
|
4
|
+
constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
|
|
5
|
+
static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
|
|
6
|
+
checkChainIdSupport(): Promise<boolean>;
|
|
7
|
+
getCosmostationWallet(): Promise<typeof import("@cosmostation/extension-client/cosmos")>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EACb,oBAAoB,EACrB,MAAM,yBAAyB,CAAA;AAQhC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAgD;gBAEnD,OAAO,EAAE,aAAa,GAAG,oBAAoB,GAAG,OAAO;WAItD,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5D,mBAAmB;IAsB1B,qBAAqB;CAqB5B"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CosmostationWallet = void 0;
|
|
13
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
14
|
+
const extension_client_1 = require("@cosmostation/extension-client");
|
|
15
|
+
class CosmostationWallet {
|
|
16
|
+
constructor(chainId) {
|
|
17
|
+
this.chainId = chainId;
|
|
18
|
+
}
|
|
19
|
+
static isChainIdSupported(chainId) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return new CosmostationWallet(chainId).checkChainIdSupport();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
checkChainIdSupport() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { chainId: actualChainId } = this;
|
|
27
|
+
const provider = yield this.getCosmostationWallet();
|
|
28
|
+
const chainName = actualChainId.split('-');
|
|
29
|
+
try {
|
|
30
|
+
const supportedChainIds = yield provider.getSupportedChainIds();
|
|
31
|
+
return !!supportedChainIds.official.find((chainId) => chainId === actualChainId);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new exceptions_1.CosmosWalletException(new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getCosmostationWallet() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
const provider = yield (0, extension_client_1.cosmos)();
|
|
42
|
+
return provider;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
if (e instanceof extension_client_1.InstallError) {
|
|
46
|
+
throw new exceptions_1.CosmosWalletException(new Error('Please install the Cosmostation extension'), {
|
|
47
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
48
|
+
type: exceptions_1.ErrorType.WalletNotInstalledError,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
52
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.CosmostationWallet = CosmostationWallet;
|
|
59
|
+
//# sourceMappingURL=wallet.js.map
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AA2C,CAAC,EACtD;wBACE,IAAI,EAAE,iCAAoB;wBAC1B,IAAI,EAAE,sBAAS,CAAC,uBAAuB;qBACxC,CACF,CAAA;gBACH,CAAC;gBAED,MAAM,IAAI,kCAAqB,CAAC,IAAI,KAAK,CAAE,CAAS,CAAC,OAAO,CAAC,EAAE;oBAC7D,IAAI,EAAE,iCAAoB;iBAC3B,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;KAAA;CACF;AAtDD,gDAsDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,YAAY,IAAI,0BAA0B,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,YAAY,IAAI,0BAA0B,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { ChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
|
+
import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, ConcreteWalletStrategy } from '@injectivelabs/wallet-base';
|
|
4
|
+
import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
|
|
5
|
+
export declare class Cosmostation extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
|
+
private cosmostationWallet?;
|
|
7
|
+
constructor(args: {
|
|
8
|
+
chainId: ChainId;
|
|
9
|
+
});
|
|
10
|
+
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
11
|
+
enable(): Promise<boolean>;
|
|
12
|
+
getAddresses(): Promise<string[]>;
|
|
13
|
+
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
14
|
+
sendEthereumTransaction(_transaction: unknown, _options: {
|
|
15
|
+
address: AccountAddress;
|
|
16
|
+
ethereumChainId: EthereumChainId;
|
|
17
|
+
}): Promise<string>;
|
|
18
|
+
sendTransaction(transaction: DirectSignResponse | CosmosTxV1Beta1Tx.TxRaw, _options: {
|
|
19
|
+
address: AccountAddress;
|
|
20
|
+
chainId: ChainId;
|
|
21
|
+
}): Promise<TxResponse>;
|
|
22
|
+
signAminoCosmosTransaction(_transaction: {
|
|
23
|
+
address: string;
|
|
24
|
+
signDoc: StdSignDoc;
|
|
25
|
+
}): Promise<AminoSignResponse>;
|
|
26
|
+
signCosmosTransaction(transaction: {
|
|
27
|
+
txRaw: CosmosTxV1Beta1Tx.TxRaw;
|
|
28
|
+
chainId: string;
|
|
29
|
+
address: string;
|
|
30
|
+
accountNumber: number;
|
|
31
|
+
}): Promise<DirectSignResponse>;
|
|
32
|
+
getPubKey(): Promise<string>;
|
|
33
|
+
signEip712TypedData(_eip712TypedData: string, _address: AccountAddress): Promise<string>;
|
|
34
|
+
signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
|
|
35
|
+
getEthereumChainId(): Promise<string>;
|
|
36
|
+
getEthereumTransactionReceipt(_txHash: string): Promise<string>;
|
|
37
|
+
private getCosmostationWallet;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAGnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,OAAO,EAEP,cAAc,EACd,eAAe,EAChB,MAAM,yBAAyB,CAAA;AAOhC,OAAO,EACL,UAAU,EAEV,gBAAgB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,OAAO,CAAC,MAAM,CAAC;IAUZ,aAAa,CACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GAAG,UAAU,GACxB,OAAO,CAAC,MAAM,CAAC;IAmBZ,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAUrC,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAavD,qBAAqB;CA6BpC"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
import { toUtf8, createTxRawFromSigResponse, createSignDocFromTransaction, } from '@injectivelabs/sdk-ts';
|
|
3
|
+
import { CosmosChainId, } from '@injectivelabs/ts-types';
|
|
4
|
+
import { ErrorType, UnspecifiedErrorCode, CosmosWalletException, TransactionException, } from '@injectivelabs/exceptions';
|
|
5
|
+
import { WalletAction, WalletDeviceType, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
|
|
6
|
+
import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
|
|
7
|
+
import { InstallError } from '@cosmostation/extension-client';
|
|
8
|
+
import { makeSignDoc } from '@cosmjs/proto-signing';
|
|
9
|
+
import { SEND_TRANSACTION_MODE } from '@cosmostation/extension-client/cosmos';
|
|
10
|
+
import { CosmostationWallet } from './../wallet';
|
|
11
|
+
const INJECTIVE_CHAIN_NAME = 'injective';
|
|
12
|
+
export class Cosmostation extends BaseConcreteStrategy {
|
|
13
|
+
cosmostationWallet;
|
|
14
|
+
constructor(args) {
|
|
15
|
+
super(args);
|
|
16
|
+
this.chainId = args.chainId || CosmosChainId.Injective;
|
|
17
|
+
}
|
|
18
|
+
async getWalletDeviceType() {
|
|
19
|
+
return Promise.resolve(WalletDeviceType.Browser);
|
|
20
|
+
}
|
|
21
|
+
async enable() {
|
|
22
|
+
return Promise.resolve(true);
|
|
23
|
+
}
|
|
24
|
+
async getAddresses() {
|
|
25
|
+
const cosmostationWallet = await this.getCosmostationWallet();
|
|
26
|
+
try {
|
|
27
|
+
const accounts = await cosmostationWallet.requestAccount(INJECTIVE_CHAIN_NAME);
|
|
28
|
+
return [accounts.address];
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (e.code === 4001) {
|
|
32
|
+
throw new CosmosWalletException(new Error('The user rejected the request'), {
|
|
33
|
+
code: UnspecifiedErrorCode,
|
|
34
|
+
context: WalletAction.GetAccounts,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
throw new CosmosWalletException(new Error(e.message), {
|
|
38
|
+
code: UnspecifiedErrorCode,
|
|
39
|
+
context: WalletAction.GetAccounts,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async getSessionOrConfirm(address) {
|
|
44
|
+
return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
|
|
45
|
+
}
|
|
46
|
+
// eslint-disable-next-line class-methods-use-this
|
|
47
|
+
async sendEthereumTransaction(_transaction, _options) {
|
|
48
|
+
throw new CosmosWalletException(new Error('sendEthereumTransaction is not supported. Cosmostation only supports sending cosmos transactions'), {
|
|
49
|
+
code: UnspecifiedErrorCode,
|
|
50
|
+
context: WalletAction.SendEthereumTransaction,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async sendTransaction(transaction, _options) {
|
|
54
|
+
const cosmostationWallet = await this.getCosmostationWallet();
|
|
55
|
+
const txRaw = createTxRawFromSigResponse(transaction);
|
|
56
|
+
try {
|
|
57
|
+
const response = await cosmostationWallet.sendTransaction(INJECTIVE_CHAIN_NAME, CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(), SEND_TRANSACTION_MODE.SYNC);
|
|
58
|
+
return {
|
|
59
|
+
...response.tx_response,
|
|
60
|
+
gasUsed: parseInt((response.tx_response.gas_used || '0'), 10),
|
|
61
|
+
gasWanted: parseInt((response.tx_response.gas_wanted || '0'), 10),
|
|
62
|
+
height: parseInt((response.tx_response.height || '0'), 10),
|
|
63
|
+
txHash: response.tx_response.txhash,
|
|
64
|
+
rawLog: response.tx_response.raw_log,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
if (e instanceof TransactionException) {
|
|
69
|
+
throw e;
|
|
70
|
+
}
|
|
71
|
+
throw new TransactionException(new Error(e.message), {
|
|
72
|
+
code: UnspecifiedErrorCode,
|
|
73
|
+
context: WalletAction.SendTransaction,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async signAminoCosmosTransaction(_transaction) {
|
|
78
|
+
throw new CosmosWalletException(new Error('This wallet does not support signing using amino'), {
|
|
79
|
+
code: UnspecifiedErrorCode,
|
|
80
|
+
context: WalletAction.SendTransaction,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async signCosmosTransaction(transaction) {
|
|
84
|
+
const { chainId } = this;
|
|
85
|
+
const cosmostationWallet = await this.getCosmostationWallet();
|
|
86
|
+
const signDoc = createSignDocFromTransaction(transaction);
|
|
87
|
+
try {
|
|
88
|
+
/* Sign the transaction */
|
|
89
|
+
const signDirectResponse = await cosmostationWallet.signDirect(INJECTIVE_CHAIN_NAME, {
|
|
90
|
+
chain_id: chainId,
|
|
91
|
+
body_bytes: signDoc.bodyBytes,
|
|
92
|
+
auth_info_bytes: signDoc.authInfoBytes,
|
|
93
|
+
account_number: signDoc.accountNumber.toString(),
|
|
94
|
+
}, { fee: true, memo: true });
|
|
95
|
+
return {
|
|
96
|
+
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)),
|
|
97
|
+
signature: {
|
|
98
|
+
signature: signDirectResponse.signature,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
throw new CosmosWalletException(new Error(e.message), {
|
|
104
|
+
code: UnspecifiedErrorCode,
|
|
105
|
+
context: WalletAction.SendTransaction,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async getPubKey() {
|
|
110
|
+
const cosmostationWallet = await this.getCosmostationWallet();
|
|
111
|
+
try {
|
|
112
|
+
const account = await cosmostationWallet.requestAccount(INJECTIVE_CHAIN_NAME);
|
|
113
|
+
return Buffer.from(account.publicKey).toString('base64');
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (e.code === 4001) {
|
|
117
|
+
throw new CosmosWalletException(new Error('The user rejected the request'), {
|
|
118
|
+
code: UnspecifiedErrorCode,
|
|
119
|
+
context: WalletAction.GetAccounts,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
throw new CosmosWalletException(new Error(e.message), {
|
|
123
|
+
code: UnspecifiedErrorCode,
|
|
124
|
+
context: WalletAction.GetAccounts,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async signEip712TypedData(_eip712TypedData, _address) {
|
|
129
|
+
throw new CosmosWalletException(new Error('This wallet does not support signing Ethereum transactions'), {
|
|
130
|
+
code: UnspecifiedErrorCode,
|
|
131
|
+
context: WalletAction.SendTransaction,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async signArbitrary(signer, data) {
|
|
135
|
+
try {
|
|
136
|
+
const cosmostationWallet = await this.getCosmostationWallet();
|
|
137
|
+
const signature = await cosmostationWallet.signMessage(INJECTIVE_CHAIN_NAME, signer, toUtf8(data));
|
|
138
|
+
return signature.signature;
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
throw new CosmosWalletException(new Error(e.message), {
|
|
142
|
+
code: UnspecifiedErrorCode,
|
|
143
|
+
context: WalletAction.SignArbitrary,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async getEthereumChainId() {
|
|
148
|
+
throw new CosmosWalletException(new Error('getEthereumChainId is not supported on Cosmostation'), {
|
|
149
|
+
code: UnspecifiedErrorCode,
|
|
150
|
+
context: WalletAction.GetChainId,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async getEthereumTransactionReceipt(_txHash) {
|
|
154
|
+
throw new CosmosWalletException(new Error('getEthereumTransactionReceipt is not supported on Cosmostation'), {
|
|
155
|
+
code: UnspecifiedErrorCode,
|
|
156
|
+
type: ErrorType.WalletError,
|
|
157
|
+
context: WalletAction.GetEthereumTransactionReceipt,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async getCosmostationWallet() {
|
|
161
|
+
if (this.cosmostationWallet) {
|
|
162
|
+
return this.cosmostationWallet;
|
|
163
|
+
}
|
|
164
|
+
const cosmostationWallet = new CosmostationWallet(this.chainId);
|
|
165
|
+
try {
|
|
166
|
+
const provider = await cosmostationWallet.getCosmostationWallet();
|
|
167
|
+
this.cosmostationWallet = provider;
|
|
168
|
+
return provider;
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
if (e instanceof InstallError) {
|
|
172
|
+
throw new CosmosWalletException(new Error('Please install the Cosmostation extension'), {
|
|
173
|
+
code: UnspecifiedErrorCode,
|
|
174
|
+
type: ErrorType.WalletNotInstalledError,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
throw new CosmosWalletException(new Error(e.message), {
|
|
178
|
+
code: UnspecifiedErrorCode,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EACL,MAAM,EAIN,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAEL,aAAa,GAGd,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,SAAS,E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,KAAK,CACP,gEAAgE,CACjE,EACD;YACE,IAAI,EAAE,oBAAoB;YAC1B,IAAI,EAAE,SAAS,CAAC,WAAW;YAC3B,OAAO,EAAE,YAAY,CAAC,6BAA6B;SACpD,CACF,CAAA;IACH,CAAC;IAEO,KAAK,CAAC,qBAAqB;QACjC,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAA;QAChC,CAAC;QAED,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAE/D,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,qBAAqB,EAAE,CAAA;YAEjE,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAA;YAElC,OAAO,QAAQ,CAAA;QACjB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,YAAY,EAAE,CAAC;gBAC9B,MAAM,IAAI,qBAAqB,CAC7B,IAAI,KAAK,CAAC,2CAA2C,CAAC,EACtD;oBACE,IAAI,EAAE,oBAAoB;oBAC1B,IAAI,EAAE,SAAS,CAAC,uBAAuB;iBACxC,CACF,CAAA;YACH,CAAC;YAED,MAAM,IAAI,qBAAqB,CAAC,IAAI,KAAK,CAAE,CAAS,CAAC,OAAO,CAAC,EAAE;gBAC7D,IAAI,EAAE,oBAAoB;aAC3B,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChainId, CosmosChainId, TestnetCosmosChainId } from '@injectivelabs/ts-types';
|
|
2
|
+
export declare class CosmostationWallet {
|
|
3
|
+
private chainId;
|
|
4
|
+
constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId);
|
|
5
|
+
static isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
|
|
6
|
+
checkChainIdSupport(): Promise<boolean>;
|
|
7
|
+
getCosmostationWallet(): Promise<typeof import("@cosmostation/extension-client/cosmos")>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EACb,oBAAoB,EACrB,MAAM,yBAAyB,CAAA;AAQhC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAgD;gBAEnD,OAAO,EAAE,aAAa,GAAG,oBAAoB,GAAG,OAAO;WAItD,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5D,mBAAmB;IAsB1B,qBAAqB;CAqB5B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ErrorType, UnspecifiedErrorCode, CosmosWalletException, } from '@injectivelabs/exceptions';
|
|
2
|
+
import { cosmos, InstallError } from '@cosmostation/extension-client';
|
|
3
|
+
export class CosmostationWallet {
|
|
4
|
+
chainId;
|
|
5
|
+
constructor(chainId) {
|
|
6
|
+
this.chainId = chainId;
|
|
7
|
+
}
|
|
8
|
+
static async isChainIdSupported(chainId) {
|
|
9
|
+
return new CosmostationWallet(chainId).checkChainIdSupport();
|
|
10
|
+
}
|
|
11
|
+
async checkChainIdSupport() {
|
|
12
|
+
const { chainId: actualChainId } = this;
|
|
13
|
+
const provider = await this.getCosmostationWallet();
|
|
14
|
+
const chainName = actualChainId.split('-');
|
|
15
|
+
try {
|
|
16
|
+
const supportedChainIds = await provider.getSupportedChainIds();
|
|
17
|
+
return !!supportedChainIds.official.find((chainId) => chainId === actualChainId);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
throw new CosmosWalletException(new Error(`Cosmostation doesn't support ${chainName[0] || actualChainId} network. Please use another Cosmos wallet`));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async getCosmostationWallet() {
|
|
24
|
+
try {
|
|
25
|
+
const provider = await cosmos();
|
|
26
|
+
return provider;
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
if (e instanceof InstallError) {
|
|
30
|
+
throw new CosmosWalletException(new Error('Please install the Cosmostation extension'), {
|
|
31
|
+
code: UnspecifiedErrorCode,
|
|
32
|
+
type: ErrorType.WalletNotInstalledError,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
throw new CosmosWalletException(new Error(e.message), {
|
|
36
|
+
code: UnspecifiedErrorCode,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAErE,MAAM,OAAO,kBAAkB;IACrB,OAAO,CAAgD;IAE/D,YAAY,OAAuD;QACjE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,OAAsB;QACpD,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC,mBAAmB,EAAE,CAAA;IAC9D,CAAC;IAEM,KAAK,CAAC,mBAAmB;QAC9B,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;QACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAA;QACnD,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE1C,IAAI,CAAC;YACH,MAAM,iBAAiB,GAAG,MAAM,QAAQ,CAAC,oBAAoB,EAAE,CAAA;YAE/D,OAAO,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CACtC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,aAAa,CACvC,CAAA;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,qBAAqB,CAC7B,IAAI,KAAK,CACP,gCACE,SAAS,CAAC,CAAC,CAAC,IAAI,aAClB,4CAA4C,CAC7C,CACF,CAAA;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,MAAM,EAAE,CAAA;YAE/B,OAAO,QAAQ,CAAA;QACjB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,YAAY,EAAE,CAAC;gBAC9B,MAAM,IAAI,qBAAqB,CAC7B,IAAI,KAAK,CAAC,2CAA2C,CAAC,EACtD;oBACE,IAAI,EAAE,oBAAoB;oBAC1B,IAAI,EAAE,SAAS,CAAC,uBAAuB;iBACxC,CACF,CAAA;YACH,CAAC;YAED,MAAM,IAAI,qBAAqB,CAAC,IAAI,KAAK,CAAE,CAAS,CAAC,OAAO,CAAC,EAAE;gBAC7D,IAAI,EAAE,oBAAoB;aAC3B,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@injectivelabs/wallet-cosmostation",
|
|
3
|
+
"description": "Cosmostation strategy for use with @injectivelabs/wallet-core.",
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "InjectiveLabs",
|
|
8
|
+
"email": "admin@injectivelabs.org"
|
|
9
|
+
},
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"types": "dist/cjs/index.d.ts",
|
|
12
|
+
"main": "dist/cjs/index.js",
|
|
13
|
+
"module": "dist/esm/index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"_moduleAliases": {
|
|
18
|
+
"~wallet-cosmostation": "dist"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"postinstall": "link-module-alias",
|
|
22
|
+
"build:cjs": "BUILD_MODE=cjs tsc --build tsconfig.build.json",
|
|
23
|
+
"build:esm": "BUILD_MODE=esm tsc --build tsconfig.build.esm.json",
|
|
24
|
+
"build": "yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
|
|
25
|
+
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
|
|
26
|
+
"build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
|
|
27
|
+
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"test:watch": "jest --watch",
|
|
30
|
+
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
|
|
31
|
+
"coverage": "jest --coverage",
|
|
32
|
+
"coverage:show": "live-server coverage",
|
|
33
|
+
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
34
|
+
"start": "node dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@cosmjs/proto-signing": "^0.32.3",
|
|
38
|
+
"@cosmostation/extension-client": "^0.1.15",
|
|
39
|
+
"@injectivelabs/exceptions": "^1.14.14",
|
|
40
|
+
"@injectivelabs/sdk-ts": "^1.14.15",
|
|
41
|
+
"@injectivelabs/ts-types": "^1.14.14",
|
|
42
|
+
"@injectivelabs/utils": "^1.14.14",
|
|
43
|
+
"@injectivelabs/wallet-base": "^0.0.2",
|
|
44
|
+
"@walletconnect/ethereum-provider": "^2.12.2"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "6442ae377bbfb3459d2fb3a44c650630a5b7f445",
|
|
47
|
+
"typedoc": {
|
|
48
|
+
"entryPoint": "./src/index.ts",
|
|
49
|
+
"readmeFile": "./README.md",
|
|
50
|
+
"displayName": "wallet-cosmostation API Documentation"
|
|
51
|
+
},
|
|
52
|
+
"resolutions": {
|
|
53
|
+
"**/libsodium": "npm:@bangjelkoski/noop",
|
|
54
|
+
"**/libsodium-wrappers": "npm:@bangjelkoski/noop"
|
|
55
|
+
}
|
|
56
|
+
}
|