@injectivelabs/wallet-core 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 +77 -0
- package/dist/cjs/broadcaster/MsgBroadcaster.d.ts +125 -0
- package/dist/cjs/broadcaster/MsgBroadcaster.d.ts.map +1 -0
- package/dist/cjs/broadcaster/MsgBroadcaster.js +703 -0
- package/dist/cjs/broadcaster/MsgBroadcaster.js.map +1 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.d.ts +30 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.d.ts.map +1 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.js +41 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.js.map +1 -0
- package/dist/cjs/broadcaster/index.d.ts +4 -0
- package/dist/cjs/broadcaster/index.d.ts.map +1 -0
- package/dist/cjs/broadcaster/index.js +20 -0
- package/dist/cjs/broadcaster/index.js.map +1 -0
- package/dist/cjs/broadcaster/types.d.ts +33 -0
- package/dist/cjs/broadcaster/types.d.ts.map +1 -0
- package/dist/cjs/broadcaster/types.js +3 -0
- package/dist/cjs/broadcaster/types.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/strategy/BaseWalletStrategy.d.ts +45 -0
- package/dist/cjs/strategy/BaseWalletStrategy.d.ts.map +1 -0
- package/dist/cjs/strategy/BaseWalletStrategy.js +154 -0
- package/dist/cjs/strategy/BaseWalletStrategy.js.map +1 -0
- package/dist/cjs/strategy/index.d.ts +3 -0
- package/dist/cjs/strategy/index.d.ts.map +1 -0
- package/dist/cjs/strategy/index.js +9 -0
- package/dist/cjs/strategy/index.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +2 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/index.js +18 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/tx.d.ts +2 -0
- package/dist/cjs/utils/tx.d.ts.map +1 -0
- package/dist/cjs/utils/tx.js +12 -0
- package/dist/cjs/utils/tx.js.map +1 -0
- package/dist/esm/broadcaster/MsgBroadcaster.d.ts +125 -0
- package/dist/esm/broadcaster/MsgBroadcaster.d.ts.map +1 -0
- package/dist/esm/broadcaster/MsgBroadcaster.js +704 -0
- package/dist/esm/broadcaster/MsgBroadcaster.js.map +1 -0
- package/dist/esm/broadcaster/Web3Broadcaster.d.ts +30 -0
- package/dist/esm/broadcaster/Web3Broadcaster.d.ts.map +1 -0
- package/dist/esm/broadcaster/Web3Broadcaster.js +28 -0
- package/dist/esm/broadcaster/Web3Broadcaster.js.map +1 -0
- package/dist/esm/broadcaster/index.d.ts +4 -0
- package/dist/esm/broadcaster/index.d.ts.map +1 -0
- package/dist/esm/broadcaster/index.js +4 -0
- package/dist/esm/broadcaster/index.js.map +1 -0
- package/dist/esm/broadcaster/types.d.ts +33 -0
- package/dist/esm/broadcaster/types.d.ts.map +1 -0
- package/dist/esm/broadcaster/types.js +2 -0
- package/dist/esm/broadcaster/types.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/strategy/BaseWalletStrategy.d.ts +45 -0
- package/dist/esm/strategy/BaseWalletStrategy.d.ts.map +1 -0
- package/dist/esm/strategy/BaseWalletStrategy.js +121 -0
- package/dist/esm/strategy/BaseWalletStrategy.js.map +1 -0
- package/dist/esm/strategy/index.d.ts +3 -0
- package/dist/esm/strategy/index.d.ts.map +1 -0
- package/dist/esm/strategy/index.js +3 -0
- package/dist/esm/strategy/index.js.map +1 -0
- package/dist/esm/utils/index.d.ts +2 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/tx.d.ts +2 -0
- package/dist/esm/utils/tx.d.ts.map +1 -0
- package/dist/esm/utils/tx.js +8 -0
- package/dist/esm/utils/tx.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# 🌟 Injective Protocol - Wallet Core
|
|
2
|
+
|
|
3
|
+
<!-- TODO -->
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@injectivelabs/wallet-core)
|
|
6
|
+
[](https://www.npmjs.com/package/@injectivelabs/wallet-core)
|
|
7
|
+
[]()
|
|
8
|
+
|
|
9
|
+
_Package to use Wallets on Injective via the wallet strategy._
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 📚 Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @injectivelabs/wallet-core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📖 Documentation
|
|
22
|
+
|
|
23
|
+
To instantiate your MsgBroadcaster, you need to pass it an instance of `BaseWalletStrategy`. You can specify any strategy you want in the `BaseWalletStrategy` constructor and pass it to the `MsgBroadcaster`.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Wallet } from '@injectivelabs/wallet-base'
|
|
27
|
+
import { BaseWalletStrategy } from '@injectivelabs/wallet-core'
|
|
28
|
+
import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key'
|
|
29
|
+
|
|
30
|
+
const strategyArgs: WalletStrategyArguments = {} /** define the args */
|
|
31
|
+
const strategyEthArgs: ConcreteEthereumWalletStrategyArgs = {} /** if the wallet is an Ethereum wallet */
|
|
32
|
+
const strategies = {
|
|
33
|
+
[Wallet.PrivateKey]: new PrivateKeyWalletStrategy(strategyEthArgs)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const walletStrategy = new BaseWalletStrategy({...strategyArgs, strategies})
|
|
37
|
+
|
|
38
|
+
const broadcasterArgs: MsgBroadcasterOptions = {} /** define the broadcaster args */
|
|
39
|
+
export const msgBroadcaster = new MsgBroadcaster({...broadcasterArgs, walletStrategy})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 📜 Contribution
|
|
47
|
+
|
|
48
|
+
**Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.**
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## ⛑ Support
|
|
53
|
+
|
|
54
|
+
Reach out to us at one of the following places!
|
|
55
|
+
|
|
56
|
+
- Website at <a href="https://injective.com" target="_blank">`injective.com`</a>
|
|
57
|
+
- Twitter at <a href="https://twitter.com/Injective_" target="_blank">`@Injective`</a>
|
|
58
|
+
- Discord at <a href="https://discord.com/invite/NK4qdbv" target="_blank">`Discord`</a>
|
|
59
|
+
- Telegram at <a href="https://t.me/joininjective" target="_blank">`Telegram`</a>
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 🔓 License
|
|
64
|
+
|
|
65
|
+
Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
|
|
66
|
+
|
|
67
|
+
<a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" />
|
|
68
|
+
|
|
69
|
+
Originally released by Injective Labs Inc. under: <br />
|
|
70
|
+
Apache License <br />
|
|
71
|
+
Version 2.0, January 2004 <br />
|
|
72
|
+
http://www.apache.org/licenses/
|
|
73
|
+
|
|
74
|
+
<p> </p>
|
|
75
|
+
<div align="center">
|
|
76
|
+
<sub><em>Powering the future of decentralized finance.</em></sub>
|
|
77
|
+
</div>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { TxResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { NetworkEndpoints } from '@injectivelabs/networks';
|
|
3
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
|
+
import { MsgBroadcasterOptions, MsgBroadcasterTxOptions } from './types';
|
|
5
|
+
import BaseWalletStrategy from '../strategy/BaseWalletStrategy';
|
|
6
|
+
/**
|
|
7
|
+
* This class is used to broadcast transactions
|
|
8
|
+
* using the WalletStrategy as a handler
|
|
9
|
+
* for the sign/broadcast flow of the transactions
|
|
10
|
+
*
|
|
11
|
+
* Mainly used for building UI products
|
|
12
|
+
*/
|
|
13
|
+
export declare class MsgBroadcaster {
|
|
14
|
+
options: MsgBroadcasterOptions;
|
|
15
|
+
walletStrategy: BaseWalletStrategy;
|
|
16
|
+
endpoints: NetworkEndpoints;
|
|
17
|
+
chainId: ChainId;
|
|
18
|
+
txTimeout: number;
|
|
19
|
+
simulateTx: boolean;
|
|
20
|
+
txTimeoutOnFeeDelegation: boolean;
|
|
21
|
+
ethereumChainId?: EthereumChainId;
|
|
22
|
+
gasBufferCoefficient: number;
|
|
23
|
+
constructor(options: MsgBroadcasterOptions);
|
|
24
|
+
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Broadcasting the transaction using the client
|
|
27
|
+
* side approach for both cosmos and ethereum native wallets
|
|
28
|
+
*
|
|
29
|
+
* @param tx
|
|
30
|
+
* @returns {string} transaction hash
|
|
31
|
+
*/
|
|
32
|
+
broadcast(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Broadcasting the transaction using the client
|
|
35
|
+
* side approach for both cosmos and ethereum native wallets
|
|
36
|
+
* Note: using EIP712_V2 for Ethereum wallets
|
|
37
|
+
*
|
|
38
|
+
* @param tx
|
|
39
|
+
* @returns {string} transaction hash
|
|
40
|
+
*/
|
|
41
|
+
broadcastV2(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Broadcasting the transaction using the feeDelegation
|
|
44
|
+
* support approach for both cosmos and ethereum native wallets
|
|
45
|
+
*
|
|
46
|
+
* @param tx
|
|
47
|
+
* @returns {string} transaction hash
|
|
48
|
+
*/
|
|
49
|
+
broadcastWithFeeDelegation(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Prepare/sign/broadcast transaction using
|
|
52
|
+
* Ethereum native wallets on the client side.
|
|
53
|
+
*
|
|
54
|
+
* Note: Gas estimation not available
|
|
55
|
+
*
|
|
56
|
+
* @param tx The transaction that needs to be broadcasted
|
|
57
|
+
* @returns transaction hash
|
|
58
|
+
*/
|
|
59
|
+
private broadcastWeb3;
|
|
60
|
+
/**
|
|
61
|
+
* Prepare/sign/broadcast transaction using
|
|
62
|
+
* Ethereum native wallets on the client side.
|
|
63
|
+
*
|
|
64
|
+
* Note: Gas estimation not available
|
|
65
|
+
*
|
|
66
|
+
* @param tx The transaction that needs to be broadcasted
|
|
67
|
+
* @returns transaction hash
|
|
68
|
+
*/
|
|
69
|
+
private broadcastWeb3V2;
|
|
70
|
+
/**
|
|
71
|
+
* Prepare/sign/broadcast transaction using
|
|
72
|
+
* Ethereum native wallets using the Web3Gateway.
|
|
73
|
+
*
|
|
74
|
+
* @param tx The transaction that needs to be broadcasted
|
|
75
|
+
* @returns transaction hash
|
|
76
|
+
*/
|
|
77
|
+
private broadcastWeb3WithFeeDelegation;
|
|
78
|
+
/**
|
|
79
|
+
* Prepare/sign/broadcast transaction using
|
|
80
|
+
* Cosmos native wallets on the client side.
|
|
81
|
+
*
|
|
82
|
+
* @param tx The transaction that needs to be broadcasted
|
|
83
|
+
* @returns transaction hash
|
|
84
|
+
*/
|
|
85
|
+
private broadcastCosmos;
|
|
86
|
+
/**
|
|
87
|
+
* We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
|
|
88
|
+
*
|
|
89
|
+
* Note: Gas estimation not available
|
|
90
|
+
* @param tx the transaction that needs to be broadcasted
|
|
91
|
+
*/
|
|
92
|
+
private experimentalBroadcastWalletThroughLedger;
|
|
93
|
+
/**
|
|
94
|
+
* Prepare/sign/broadcast transaction using
|
|
95
|
+
* Cosmos native wallets using the Web3Gateway.
|
|
96
|
+
*
|
|
97
|
+
* @param tx The transaction that needs to be broadcasted
|
|
98
|
+
* @returns transaction hash
|
|
99
|
+
*/
|
|
100
|
+
private broadcastCosmosWithFeeDelegation;
|
|
101
|
+
/**
|
|
102
|
+
* Fetch the fee payer's pub key from the web3 gateway
|
|
103
|
+
*
|
|
104
|
+
* Returns a base64 version of it
|
|
105
|
+
*/
|
|
106
|
+
private fetchFeePayerPubKey;
|
|
107
|
+
/**
|
|
108
|
+
* In case we don't want to simulate the transaction
|
|
109
|
+
* we get the gas limit based on the message type.
|
|
110
|
+
*
|
|
111
|
+
* If we want to simulate the transaction we set the
|
|
112
|
+
* gas limit based on the simulation and add a small multiplier
|
|
113
|
+
* to be safe (factor of 1.2 as default)
|
|
114
|
+
*/
|
|
115
|
+
private getTxWithSignersAndStdFee;
|
|
116
|
+
/**
|
|
117
|
+
* Create TxRaw and simulate it
|
|
118
|
+
*/
|
|
119
|
+
private simulateTxRaw;
|
|
120
|
+
/**
|
|
121
|
+
* Create TxRaw and simulate it
|
|
122
|
+
*/
|
|
123
|
+
private simulateTxWithSigners;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=MsgBroadcaster.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MsgBroadcaster.d.ts","sourceRoot":"","sources":["../../../src/broadcaster/MsgBroadcaster.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EAoBX,MAAM,uBAAuB,CAAA;AAY9B,OAAO,EAEL,gBAAgB,EAEjB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,EACL,qBA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