@injectivelabs/wallet-core 1.20.8 → 1.20.9

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.
@@ -0,0 +1,162 @@
1
+ import { t as _defineProperty } from "./defineProperty-D4YE9KXX.js";
2
+ import { GeneralException, WalletException } from "@injectivelabs/exceptions";
3
+ import { EventEmitter } from "eventemitter3";
4
+ import { Wallet, WalletStrategyEmitterEventType, isCosmosWallet, isEvmWallet } from "@injectivelabs/wallet-base/light";
5
+
6
+ //#region src/strategy/BaseWalletStrategy.ts
7
+ const getInitialWallet = (args) => {
8
+ if (args.wallet) return args.wallet;
9
+ const keys = Object.keys(args.strategies || {});
10
+ if (keys.length === 0) return Wallet.Metamask;
11
+ if (keys.includes(Wallet.Metamask) && args.evmOptions) return Wallet.Metamask;
12
+ if (keys.includes(Wallet.Keplr) && !args.evmOptions) return Wallet.Keplr;
13
+ return keys[0];
14
+ };
15
+ var BaseWalletStrategy = class {
16
+ constructor(args) {
17
+ _defineProperty(this, "strategies", void 0);
18
+ _defineProperty(this, "wallet", void 0);
19
+ _defineProperty(this, "args", void 0);
20
+ _defineProperty(this, "metadata", void 0);
21
+ _defineProperty(this, "wallets", void 0);
22
+ _defineProperty(this, "emitter", void 0);
23
+ _defineProperty(this, "on", void 0);
24
+ _defineProperty(this, "off", void 0);
25
+ _defineProperty(this, "emit", void 0);
26
+ this.args = args;
27
+ this.strategies = args.strategies;
28
+ this.wallet = getInitialWallet(args);
29
+ this.metadata = args.metadata;
30
+ this.emitter = new EventEmitter();
31
+ this.on = this.emitter.on.bind(this.emitter);
32
+ this.off = this.emitter.off.bind(this.emitter);
33
+ this.emit = this.emitter.emit.bind(this.emitter);
34
+ }
35
+ /**
36
+ * Get the emitter instance.
37
+ * Used to pass to strategies so they can emit events directly.
38
+ */
39
+ getEmitter() {
40
+ return this.emitter;
41
+ }
42
+ getWallet() {
43
+ return this.wallet;
44
+ }
45
+ async setWallet(wallet) {
46
+ var _strategy$initStrateg;
47
+ this.wallet = wallet;
48
+ const strategy = this.getStrategy();
49
+ await (strategy === null || strategy === void 0 || (_strategy$initStrateg = strategy.initStrategy) === null || _strategy$initStrateg === void 0 ? void 0 : _strategy$initStrateg.call(strategy));
50
+ }
51
+ setMetadata(metadata) {
52
+ var _this$getStrategy$set, _this$getStrategy;
53
+ this.metadata = metadata;
54
+ (_this$getStrategy$set = (_this$getStrategy = this.getStrategy()).setMetadata) === null || _this$getStrategy$set === void 0 || _this$getStrategy$set.call(_this$getStrategy, metadata);
55
+ }
56
+ getStrategy() {
57
+ if (!this.strategies[this.wallet]) throw new GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} is not enabled/available!`));
58
+ return this.strategies[this.wallet];
59
+ }
60
+ getAddresses(args) {
61
+ return this.getStrategy().getAddresses(args);
62
+ }
63
+ getAddressesInfo(args) {
64
+ return this.getStrategy().getAddressesInfo(args);
65
+ }
66
+ getWalletDeviceType() {
67
+ return this.getStrategy().getWalletDeviceType();
68
+ }
69
+ getPubKey(address) {
70
+ return this.getStrategy().getPubKey(address);
71
+ }
72
+ enable(args) {
73
+ return this.getStrategy().enable(args);
74
+ }
75
+ async enableAndGetAddresses(args) {
76
+ await this.getStrategy().enable(args);
77
+ return this.getStrategy().getAddresses(args);
78
+ }
79
+ getEthereumChainId() {
80
+ return this.getStrategy().getEthereumChainId();
81
+ }
82
+ async getEvmTransactionReceipt(txHash, evmChainId) {
83
+ return this.getStrategy().getEvmTransactionReceipt(txHash, evmChainId);
84
+ }
85
+ async getSessionOrConfirm(address) {
86
+ return this.getStrategy().getSessionOrConfirm(address);
87
+ }
88
+ async getWalletClient() {
89
+ var _this$getStrategy2;
90
+ if ((_this$getStrategy2 = this.getStrategy()) === null || _this$getStrategy2 === void 0 ? void 0 : _this$getStrategy2.getWalletClient) {
91
+ var _this$getStrategy3, _this$getStrategy3$ge;
92
+ const result = (_this$getStrategy3 = this.getStrategy()) === null || _this$getStrategy3 === void 0 || (_this$getStrategy3$ge = _this$getStrategy3.getWalletClient) === null || _this$getStrategy3$ge === void 0 ? void 0 : _this$getStrategy3$ge.call(_this$getStrategy3);
93
+ if (result) return result;
94
+ }
95
+ throw new WalletException(/* @__PURE__ */ new Error("Wallet client not found. Please check your wallet strategy."));
96
+ }
97
+ async sendTransaction(tx, options) {
98
+ return this.getStrategy().sendTransaction(tx, options);
99
+ }
100
+ async sendEvmTransaction(tx, options) {
101
+ return this.getStrategy().sendEvmTransaction(tx, options);
102
+ }
103
+ async signEip712TypedData(eip712TypedData, address, options = {}) {
104
+ if (isCosmosWallet(this.wallet)) throw new WalletException(/* @__PURE__ */ new Error(`You can't sign Ethereum Transaction using ${this.wallet}`));
105
+ /** Phantom wallet needs enabling before signing */
106
+ if (this.wallet === Wallet.Phantom) await this.enable();
107
+ this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
108
+ const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address, options);
109
+ this.emit(WalletStrategyEmitterEventType.TransactionSigned);
110
+ return response;
111
+ }
112
+ async signAminoCosmosTransaction(transaction) {
113
+ if (isEvmWallet(this.wallet)) throw new WalletException(/* @__PURE__ */ new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
114
+ this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
115
+ const response = await this.getStrategy().signAminoCosmosTransaction(transaction);
116
+ this.emit(WalletStrategyEmitterEventType.TransactionSigned);
117
+ return response;
118
+ }
119
+ async signCosmosTransaction(transaction) {
120
+ if (isEvmWallet(this.wallet)) throw new WalletException(/* @__PURE__ */ new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
121
+ this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
122
+ const response = await this.getStrategy().signCosmosTransaction(transaction);
123
+ this.emit(WalletStrategyEmitterEventType.TransactionSigned);
124
+ return response;
125
+ }
126
+ async signArbitrary(signer, data) {
127
+ if (this.getStrategy().signArbitrary) {
128
+ this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
129
+ const response = await this.getStrategy().signArbitrary(signer, data);
130
+ this.emit(WalletStrategyEmitterEventType.TransactionSigned);
131
+ return response;
132
+ }
133
+ }
134
+ async onAccountChange(callback) {
135
+ if (this.getStrategy().onAccountChange) return this.getStrategy().onAccountChange(callback);
136
+ }
137
+ async onChainIdChange(callback) {
138
+ if (this.getStrategy().onChainIdChange) return this.getStrategy().onChainIdChange(callback);
139
+ }
140
+ async disconnect() {
141
+ if (this.getStrategy().disconnect) {
142
+ await this.getStrategy().disconnect();
143
+ this.emit(WalletStrategyEmitterEventType.WalletStrategyDisconnect);
144
+ }
145
+ }
146
+ getCosmosWallet(chainId) {
147
+ const strategy = this.getStrategy();
148
+ if (strategy.getCosmosWallet == void 0) throw new WalletException(/* @__PURE__ */ new Error(`This method is not available for ${this.getWallet()} wallet`));
149
+ return strategy.getCosmosWallet(chainId);
150
+ }
151
+ async getEip1193Provider() {
152
+ if (this.getStrategy().getEip1193Provider) return this.getStrategy().getEip1193Provider();
153
+ throw new WalletException(/* @__PURE__ */ new Error("EIP1193 provider not found. Please check your wallet strategy."));
154
+ }
155
+ async getOfflineSigner(chainId) {
156
+ if (this.getStrategy().getOfflineSigner) return this.getStrategy().getOfflineSigner(chainId);
157
+ throw new WalletException(/* @__PURE__ */ new Error("Offline signer not found. Please check your wallet strategy."));
158
+ }
159
+ };
160
+
161
+ //#endregion
162
+ export { BaseWalletStrategy as t };
@@ -0,0 +1,3 @@
1
+ import { t as BaseWalletStrategy } from "./BaseWalletStrategy-D2xNJmzo.js";
2
+ import "./index-DRYular4.js";
3
+ export { BaseWalletStrategy };
@@ -0,0 +1,4 @@
1
+ import "./defineProperty-D4YE9KXX.js";
2
+ import { t as BaseWalletStrategy } from "./strategy-DU-V-GfI.js";
3
+
4
+ export { BaseWalletStrategy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-core",
3
- "version": "1.20.8",
3
+ "version": "1.20.9",
4
4
  "description": "Core wallet strategy",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -33,6 +33,46 @@
33
33
  "types": "./dist/cjs/index.d.cts",
34
34
  "default": "./dist/cjs/index.cjs"
35
35
  }
36
+ },
37
+ "./strategy": {
38
+ "react-native": {
39
+ "import": "./dist/esm/strategy.js",
40
+ "require": "./dist/cjs/strategy.cjs",
41
+ "types": "./dist/cjs/strategy.d.cts",
42
+ "default": "./dist/cjs/strategy.cjs"
43
+ },
44
+ "require": {
45
+ "types": "./dist/cjs/strategy.d.cts",
46
+ "default": "./dist/cjs/strategy.cjs"
47
+ },
48
+ "import": {
49
+ "types": "./dist/esm/strategy.d.ts",
50
+ "default": "./dist/esm/strategy.js"
51
+ },
52
+ "default": {
53
+ "types": "./dist/cjs/strategy.d.cts",
54
+ "default": "./dist/cjs/strategy.cjs"
55
+ }
56
+ },
57
+ "./broadcaster": {
58
+ "react-native": {
59
+ "import": "./dist/esm/broadcaster.js",
60
+ "require": "./dist/cjs/broadcaster.cjs",
61
+ "types": "./dist/cjs/broadcaster.d.cts",
62
+ "default": "./dist/cjs/broadcaster.cjs"
63
+ },
64
+ "require": {
65
+ "types": "./dist/cjs/broadcaster.d.cts",
66
+ "default": "./dist/cjs/broadcaster.cjs"
67
+ },
68
+ "import": {
69
+ "types": "./dist/esm/broadcaster.d.ts",
70
+ "default": "./dist/esm/broadcaster.js"
71
+ },
72
+ "default": {
73
+ "types": "./dist/cjs/broadcaster.d.cts",
74
+ "default": "./dist/cjs/broadcaster.cjs"
75
+ }
36
76
  }
37
77
  },
38
78
  "main": "dist/cjs/index.cjs",
@@ -44,12 +84,12 @@
44
84
  "dependencies": {
45
85
  "@keplr-wallet/types": "^0.12.296",
46
86
  "eventemitter3": "^5.0.1",
47
- "@injectivelabs/exceptions": "1.20.8",
48
- "@injectivelabs/networks": "1.20.8",
49
- "@injectivelabs/sdk-ts": "1.20.8",
50
- "@injectivelabs/ts-types": "1.20.8",
51
- "@injectivelabs/utils": "1.20.8",
52
- "@injectivelabs/wallet-base": "1.20.8"
87
+ "@injectivelabs/exceptions": "1.20.9",
88
+ "@injectivelabs/networks": "1.20.9",
89
+ "@injectivelabs/utils": "1.20.9",
90
+ "@injectivelabs/ts-types": "1.20.9",
91
+ "@injectivelabs/wallet-base": "1.20.9",
92
+ "@injectivelabs/sdk-ts": "1.20.9"
53
93
  },
54
94
  "publishConfig": {
55
95
  "access": "public"