@injectivelabs/wallet-wallet-connect 1.15.0 → 1.15.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.
@@ -0,0 +1 @@
1
+ export { WalletConnect as WalletConnectStrategy } from './strategy/strategy.js';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletConnectStrategy = void 0;
4
+ var strategy_js_1 = require("./strategy/strategy.js");
5
+ Object.defineProperty(exports, "WalletConnectStrategy", { enumerable: true, get: function () { return strategy_js_1.WalletConnect; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,45 @@
1
+ import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, WalletConnectMetadata, ConcreteWalletStrategy, SendTransactionOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
+ import { Provider } from '@bangjelkoski/wc-ethereum-provider';
3
+ import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
4
+ import { TxRaw, TxResponse, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
5
+ interface WalletConnectArgs extends ConcreteEthereumWalletStrategyArgs {
6
+ metadata?: WalletConnectMetadata;
7
+ }
8
+ export declare class WalletConnect extends BaseConcreteStrategy implements ConcreteWalletStrategy {
9
+ provider: Provider | undefined;
10
+ metadata?: WalletConnectMetadata;
11
+ constructor(args: WalletConnectArgs);
12
+ getWalletDeviceType(): Promise<WalletDeviceType>;
13
+ enable(args?: {
14
+ topic: string;
15
+ }): Promise<boolean>;
16
+ disconnect(): Promise<void>;
17
+ getAddresses(): Promise<string[]>;
18
+ getSessionOrConfirm(_address: AccountAddress): Promise<string>;
19
+ sendEthereumTransaction(transaction: unknown, _options: {
20
+ address: AccountAddress;
21
+ ethereumChainId: EthereumChainId;
22
+ }): Promise<string>;
23
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
24
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
25
+ signAminoCosmosTransaction(_transaction: {
26
+ address: string;
27
+ signDoc: StdSignDoc;
28
+ }): Promise<AminoSignResponse>;
29
+ signCosmosTransaction(_transaction: {
30
+ txRaw: TxRaw;
31
+ accountNumber: number;
32
+ chainId: string;
33
+ address: string;
34
+ }): Promise<DirectSignResponse>;
35
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
36
+ getEthereumChainId(): Promise<string>;
37
+ getEthereumTransactionReceipt(_txHash: string): Promise<string>;
38
+ getPubKey(): Promise<string>;
39
+ onChainIdChanged(callback: (chain: string) => void): Promise<void>;
40
+ onAccountChange(callback: (account: AccountAddress | string[]) => void): Promise<void>;
41
+ private getWalletConnect;
42
+ private getConnectedWalletConnect;
43
+ private connectWalletConnect;
44
+ }
45
+ export {};
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletConnect = void 0;
4
+ /* eslint-disable class-methods-use-this */
5
+ const exceptions_1 = require("@injectivelabs/exceptions");
6
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
7
+ const wc_ethereum_provider_1 = require("@bangjelkoski/wc-ethereum-provider");
8
+ const ts_types_1 = require("@injectivelabs/ts-types");
9
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
10
+ const WalletConnectIds = {
11
+ FireBlocks: '5864e2ced7c293ed18ac35e0db085c09ed567d67346ccb6f58a0327a75137489',
12
+ };
13
+ class WalletConnect extends wallet_base_1.BaseConcreteStrategy {
14
+ provider;
15
+ metadata;
16
+ constructor(args) {
17
+ super(args);
18
+ this.metadata = args.metadata;
19
+ }
20
+ async getWalletDeviceType() {
21
+ return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
22
+ }
23
+ async enable(args) {
24
+ await this.connectWalletConnect(args?.topic);
25
+ return Promise.resolve(true);
26
+ }
27
+ async disconnect() {
28
+ if (this.listeners[wallet_base_1.WalletEventListener.AccountChange]) {
29
+ const wc = await this.getConnectedWalletConnect();
30
+ wc.removeListener('accountsChanged', this.listeners[wallet_base_1.WalletEventListener.AccountChange]);
31
+ }
32
+ if (this.listeners[wallet_base_1.WalletEventListener.ChainIdChange]) {
33
+ const wc = await this.getConnectedWalletConnect();
34
+ wc.removeListener('chainChanged', this.listeners[wallet_base_1.WalletEventListener.ChainIdChange]);
35
+ }
36
+ this.listeners = {};
37
+ if (this.provider) {
38
+ await this.provider.disconnect();
39
+ this.provider = undefined;
40
+ }
41
+ }
42
+ async getAddresses() {
43
+ const wc = await this.getConnectedWalletConnect();
44
+ try {
45
+ return await wc.request({
46
+ method: 'eth_requestAccounts',
47
+ });
48
+ }
49
+ catch (e) {
50
+ throw new exceptions_1.MetamaskException(new Error(e.message), {
51
+ code: exceptions_1.UnspecifiedErrorCode,
52
+ type: exceptions_1.ErrorType.WalletError,
53
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
54
+ });
55
+ }
56
+ }
57
+ async getSessionOrConfirm(_address) {
58
+ const wc = await this.getConnectedWalletConnect();
59
+ return wc.session?.topic || '';
60
+ }
61
+ async sendEthereumTransaction(transaction, _options) {
62
+ const wc = await this.getConnectedWalletConnect();
63
+ try {
64
+ return await wc.request({
65
+ method: 'eth_sendTransaction',
66
+ params: [transaction],
67
+ });
68
+ }
69
+ catch (e) {
70
+ throw new exceptions_1.MetamaskException(new Error(e.message), {
71
+ code: exceptions_1.UnspecifiedErrorCode,
72
+ type: exceptions_1.ErrorType.WalletError,
73
+ contextModule: wallet_base_1.WalletAction.SendEthereumTransaction,
74
+ });
75
+ }
76
+ }
77
+ async sendTransaction(transaction, options) {
78
+ const { endpoints, txTimeout } = options;
79
+ if (!endpoints) {
80
+ throw new exceptions_1.WalletException(new Error('You have to pass endpoints within the options for using Ethereum native wallets'));
81
+ }
82
+ const txApi = new sdk_ts_1.TxGrpcApi(endpoints.grpc);
83
+ const response = await txApi.broadcast(transaction, { txTimeout });
84
+ if (response.code !== 0) {
85
+ throw new exceptions_1.TransactionException(new Error(response.rawLog), {
86
+ code: exceptions_1.UnspecifiedErrorCode,
87
+ contextCode: response.code,
88
+ contextModule: response.codespace,
89
+ });
90
+ }
91
+ return response;
92
+ }
93
+ async signEip712TypedData(eip712json, address) {
94
+ const wc = await this.getConnectedWalletConnect();
95
+ try {
96
+ return await wc.request({
97
+ method: 'eth_signTypedData_v4',
98
+ params: [address, eip712json],
99
+ });
100
+ }
101
+ catch (e) {
102
+ throw new exceptions_1.MetamaskException(new Error(e.message), {
103
+ code: exceptions_1.UnspecifiedErrorCode,
104
+ type: exceptions_1.ErrorType.WalletError,
105
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
106
+ });
107
+ }
108
+ }
109
+ async signAminoCosmosTransaction(_transaction) {
110
+ throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
111
+ code: exceptions_1.UnspecifiedErrorCode,
112
+ type: exceptions_1.ErrorType.WalletError,
113
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
114
+ });
115
+ }
116
+ // eslint-disable-next-line class-methods-use-this
117
+ async signCosmosTransaction(_transaction) {
118
+ throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
119
+ code: exceptions_1.UnspecifiedErrorCode,
120
+ type: exceptions_1.ErrorType.WalletError,
121
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
122
+ });
123
+ }
124
+ async signArbitrary(signer, data) {
125
+ const wc = await this.getConnectedWalletConnect();
126
+ try {
127
+ const signature = await wc.request({
128
+ method: 'personal_sign',
129
+ params: [(0, sdk_ts_1.toUtf8)(data), signer],
130
+ });
131
+ return signature;
132
+ }
133
+ catch (e) {
134
+ throw new exceptions_1.MetamaskException(new Error(e.message), {
135
+ code: exceptions_1.UnspecifiedErrorCode,
136
+ type: exceptions_1.ErrorType.WalletError,
137
+ contextModule: wallet_base_1.WalletAction.SignArbitrary,
138
+ });
139
+ }
140
+ }
141
+ async getEthereumChainId() {
142
+ const wc = await this.getConnectedWalletConnect();
143
+ try {
144
+ return wc.request({ method: 'eth_chainId' });
145
+ }
146
+ catch (e) {
147
+ throw new exceptions_1.MetamaskException(new Error(e.message), {
148
+ code: exceptions_1.UnspecifiedErrorCode,
149
+ type: exceptions_1.ErrorType.WalletError,
150
+ contextModule: wallet_base_1.WalletAction.GetChainId,
151
+ });
152
+ }
153
+ }
154
+ async getEthereumTransactionReceipt(_txHash) {
155
+ throw new exceptions_1.WalletException(new Error('This wallet does not support awaiting Ethereum transactions'), {
156
+ code: exceptions_1.UnspecifiedErrorCode,
157
+ type: exceptions_1.ErrorType.WalletError,
158
+ contextModule: wallet_base_1.WalletAction.GetEthereumTransactionReceipt,
159
+ });
160
+ }
161
+ // eslint-disable-next-line class-methods-use-this
162
+ async getPubKey() {
163
+ throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
164
+ }
165
+ async onChainIdChanged(callback) {
166
+ const wc = await this.getConnectedWalletConnect();
167
+ this.listeners = {
168
+ [wallet_base_1.WalletEventListener.ChainIdChange]: callback,
169
+ };
170
+ wc.on('chainChanged', callback);
171
+ }
172
+ async onAccountChange(callback) {
173
+ const wc = await this.getConnectedWalletConnect();
174
+ this.listeners = {
175
+ [wallet_base_1.WalletEventListener.AccountChange]: callback,
176
+ };
177
+ wc.on('accountsChanged', (accounts) => callback(accounts[0]));
178
+ }
179
+ async getWalletConnect() {
180
+ if (this.provider) {
181
+ return this.provider;
182
+ }
183
+ if (!this.metadata) {
184
+ throw new exceptions_1.WalletException(new Error('Please provide metadata for WalletConnect'), {
185
+ code: exceptions_1.UnspecifiedErrorCode,
186
+ type: exceptions_1.ErrorType.WalletError,
187
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
188
+ });
189
+ }
190
+ if (!this.metadata.projectId) {
191
+ throw new exceptions_1.WalletException(new Error('Please provide projectId alongside the metadata for WalletConnect'), {
192
+ code: exceptions_1.UnspecifiedErrorCode,
193
+ type: exceptions_1.ErrorType.WalletError,
194
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
195
+ });
196
+ }
197
+ try {
198
+ this.provider = await wc_ethereum_provider_1.EthereumProvider.init({
199
+ projectId: this.metadata.projectId,
200
+ metadata: this.metadata
201
+ .metadata,
202
+ showQrModal: true,
203
+ optionalChains: this.ethereumChainId
204
+ ? [this.ethereumChainId]
205
+ : [ts_types_1.EthereumChainId.Mainnet, ts_types_1.EthereumChainId.Sepolia],
206
+ qrModalOptions: {
207
+ explorerRecommendedWalletIds: [WalletConnectIds.FireBlocks],
208
+ explorerExcludedWalletIds: 'ALL',
209
+ mobileWallets: [],
210
+ walletImages: {
211
+ [WalletConnectIds.FireBlocks]: '/wallet-connect/fireblocks.webp',
212
+ },
213
+ desktopWallets: [
214
+ {
215
+ id: WalletConnectIds.FireBlocks,
216
+ name: 'Fireblocks',
217
+ links: {
218
+ native: 'fireblocks-wc://',
219
+ universal: 'https://console.fireblocks.io/v2/',
220
+ },
221
+ },
222
+ ],
223
+ },
224
+ });
225
+ return this.provider;
226
+ }
227
+ catch (e) {
228
+ throw new exceptions_1.WalletException(new Error('WalletConnect not supported for this wallet'), {
229
+ code: exceptions_1.UnspecifiedErrorCode,
230
+ type: exceptions_1.ErrorType.WalletError,
231
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
232
+ });
233
+ }
234
+ }
235
+ async getConnectedWalletConnect() {
236
+ if (!this.provider) {
237
+ await this.getWalletConnect();
238
+ }
239
+ if (!this.provider?.connected) {
240
+ await this.enable();
241
+ }
242
+ return this.provider;
243
+ }
244
+ async connectWalletConnect(topic) {
245
+ if (this.provider && this.provider.connected) {
246
+ return;
247
+ }
248
+ const wc = await this.getWalletConnect();
249
+ await wc.connect({
250
+ ...(topic && { pairingTopic: topic }),
251
+ });
252
+ }
253
+ }
254
+ exports.WalletConnect = WalletConnect;
@@ -0,0 +1 @@
1
+ export { WalletConnect as WalletConnectStrategy } from './strategy/strategy.js';
@@ -0,0 +1 @@
1
+ export { WalletConnect as WalletConnectStrategy } from './strategy/strategy.js';
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,45 @@
1
+ import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, WalletConnectMetadata, ConcreteWalletStrategy, SendTransactionOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
2
+ import { Provider } from '@bangjelkoski/wc-ethereum-provider';
3
+ import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
4
+ import { TxRaw, TxResponse, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
5
+ interface WalletConnectArgs extends ConcreteEthereumWalletStrategyArgs {
6
+ metadata?: WalletConnectMetadata;
7
+ }
8
+ export declare class WalletConnect extends BaseConcreteStrategy implements ConcreteWalletStrategy {
9
+ provider: Provider | undefined;
10
+ metadata?: WalletConnectMetadata;
11
+ constructor(args: WalletConnectArgs);
12
+ getWalletDeviceType(): Promise<WalletDeviceType>;
13
+ enable(args?: {
14
+ topic: string;
15
+ }): Promise<boolean>;
16
+ disconnect(): Promise<void>;
17
+ getAddresses(): Promise<string[]>;
18
+ getSessionOrConfirm(_address: AccountAddress): Promise<string>;
19
+ sendEthereumTransaction(transaction: unknown, _options: {
20
+ address: AccountAddress;
21
+ ethereumChainId: EthereumChainId;
22
+ }): Promise<string>;
23
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
24
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
25
+ signAminoCosmosTransaction(_transaction: {
26
+ address: string;
27
+ signDoc: StdSignDoc;
28
+ }): Promise<AminoSignResponse>;
29
+ signCosmosTransaction(_transaction: {
30
+ txRaw: TxRaw;
31
+ accountNumber: number;
32
+ chainId: string;
33
+ address: string;
34
+ }): Promise<DirectSignResponse>;
35
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
36
+ getEthereumChainId(): Promise<string>;
37
+ getEthereumTransactionReceipt(_txHash: string): Promise<string>;
38
+ getPubKey(): Promise<string>;
39
+ onChainIdChanged(callback: (chain: string) => void): Promise<void>;
40
+ onAccountChange(callback: (account: AccountAddress | string[]) => void): Promise<void>;
41
+ private getWalletConnect;
42
+ private getConnectedWalletConnect;
43
+ private connectWalletConnect;
44
+ }
45
+ export {};
@@ -0,0 +1,250 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ import { ErrorType, WalletException, MetamaskException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
3
+ import { WalletAction, WalletDeviceType, WalletEventListener, BaseConcreteStrategy, } from '@injectivelabs/wallet-base';
4
+ import { EthereumProvider, } from '@bangjelkoski/wc-ethereum-provider';
5
+ import { EthereumChainId } from '@injectivelabs/ts-types';
6
+ import { toUtf8, TxGrpcApi, } from '@injectivelabs/sdk-ts';
7
+ const WalletConnectIds = {
8
+ FireBlocks: '5864e2ced7c293ed18ac35e0db085c09ed567d67346ccb6f58a0327a75137489',
9
+ };
10
+ export class WalletConnect extends BaseConcreteStrategy {
11
+ provider;
12
+ metadata;
13
+ constructor(args) {
14
+ super(args);
15
+ this.metadata = args.metadata;
16
+ }
17
+ async getWalletDeviceType() {
18
+ return Promise.resolve(WalletDeviceType.Browser);
19
+ }
20
+ async enable(args) {
21
+ await this.connectWalletConnect(args?.topic);
22
+ return Promise.resolve(true);
23
+ }
24
+ async disconnect() {
25
+ if (this.listeners[WalletEventListener.AccountChange]) {
26
+ const wc = await this.getConnectedWalletConnect();
27
+ wc.removeListener('accountsChanged', this.listeners[WalletEventListener.AccountChange]);
28
+ }
29
+ if (this.listeners[WalletEventListener.ChainIdChange]) {
30
+ const wc = await this.getConnectedWalletConnect();
31
+ wc.removeListener('chainChanged', this.listeners[WalletEventListener.ChainIdChange]);
32
+ }
33
+ this.listeners = {};
34
+ if (this.provider) {
35
+ await this.provider.disconnect();
36
+ this.provider = undefined;
37
+ }
38
+ }
39
+ async getAddresses() {
40
+ const wc = await this.getConnectedWalletConnect();
41
+ try {
42
+ return await wc.request({
43
+ method: 'eth_requestAccounts',
44
+ });
45
+ }
46
+ catch (e) {
47
+ throw new MetamaskException(new Error(e.message), {
48
+ code: UnspecifiedErrorCode,
49
+ type: ErrorType.WalletError,
50
+ contextModule: WalletAction.GetAccounts,
51
+ });
52
+ }
53
+ }
54
+ async getSessionOrConfirm(_address) {
55
+ const wc = await this.getConnectedWalletConnect();
56
+ return wc.session?.topic || '';
57
+ }
58
+ async sendEthereumTransaction(transaction, _options) {
59
+ const wc = await this.getConnectedWalletConnect();
60
+ try {
61
+ return await wc.request({
62
+ method: 'eth_sendTransaction',
63
+ params: [transaction],
64
+ });
65
+ }
66
+ catch (e) {
67
+ throw new MetamaskException(new Error(e.message), {
68
+ code: UnspecifiedErrorCode,
69
+ type: ErrorType.WalletError,
70
+ contextModule: WalletAction.SendEthereumTransaction,
71
+ });
72
+ }
73
+ }
74
+ async sendTransaction(transaction, options) {
75
+ const { endpoints, txTimeout } = options;
76
+ if (!endpoints) {
77
+ throw new WalletException(new Error('You have to pass endpoints within the options for using Ethereum native wallets'));
78
+ }
79
+ const txApi = new TxGrpcApi(endpoints.grpc);
80
+ const response = await txApi.broadcast(transaction, { txTimeout });
81
+ if (response.code !== 0) {
82
+ throw new TransactionException(new Error(response.rawLog), {
83
+ code: UnspecifiedErrorCode,
84
+ contextCode: response.code,
85
+ contextModule: response.codespace,
86
+ });
87
+ }
88
+ return response;
89
+ }
90
+ async signEip712TypedData(eip712json, address) {
91
+ const wc = await this.getConnectedWalletConnect();
92
+ try {
93
+ return await wc.request({
94
+ method: 'eth_signTypedData_v4',
95
+ params: [address, eip712json],
96
+ });
97
+ }
98
+ catch (e) {
99
+ throw new MetamaskException(new Error(e.message), {
100
+ code: UnspecifiedErrorCode,
101
+ type: ErrorType.WalletError,
102
+ contextModule: WalletAction.SignTransaction,
103
+ });
104
+ }
105
+ }
106
+ async signAminoCosmosTransaction(_transaction) {
107
+ throw new WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
108
+ code: UnspecifiedErrorCode,
109
+ type: ErrorType.WalletError,
110
+ contextModule: WalletAction.SignTransaction,
111
+ });
112
+ }
113
+ // eslint-disable-next-line class-methods-use-this
114
+ async signCosmosTransaction(_transaction) {
115
+ throw new WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
116
+ code: UnspecifiedErrorCode,
117
+ type: ErrorType.WalletError,
118
+ contextModule: WalletAction.SignTransaction,
119
+ });
120
+ }
121
+ async signArbitrary(signer, data) {
122
+ const wc = await this.getConnectedWalletConnect();
123
+ try {
124
+ const signature = await wc.request({
125
+ method: 'personal_sign',
126
+ params: [toUtf8(data), signer],
127
+ });
128
+ return signature;
129
+ }
130
+ catch (e) {
131
+ throw new MetamaskException(new Error(e.message), {
132
+ code: UnspecifiedErrorCode,
133
+ type: ErrorType.WalletError,
134
+ contextModule: WalletAction.SignArbitrary,
135
+ });
136
+ }
137
+ }
138
+ async getEthereumChainId() {
139
+ const wc = await this.getConnectedWalletConnect();
140
+ try {
141
+ return wc.request({ method: 'eth_chainId' });
142
+ }
143
+ catch (e) {
144
+ throw new MetamaskException(new Error(e.message), {
145
+ code: UnspecifiedErrorCode,
146
+ type: ErrorType.WalletError,
147
+ contextModule: WalletAction.GetChainId,
148
+ });
149
+ }
150
+ }
151
+ async getEthereumTransactionReceipt(_txHash) {
152
+ throw new WalletException(new Error('This wallet does not support awaiting Ethereum transactions'), {
153
+ code: UnspecifiedErrorCode,
154
+ type: ErrorType.WalletError,
155
+ contextModule: WalletAction.GetEthereumTransactionReceipt,
156
+ });
157
+ }
158
+ // eslint-disable-next-line class-methods-use-this
159
+ async getPubKey() {
160
+ throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
161
+ }
162
+ async onChainIdChanged(callback) {
163
+ const wc = await this.getConnectedWalletConnect();
164
+ this.listeners = {
165
+ [WalletEventListener.ChainIdChange]: callback,
166
+ };
167
+ wc.on('chainChanged', callback);
168
+ }
169
+ async onAccountChange(callback) {
170
+ const wc = await this.getConnectedWalletConnect();
171
+ this.listeners = {
172
+ [WalletEventListener.AccountChange]: callback,
173
+ };
174
+ wc.on('accountsChanged', (accounts) => callback(accounts[0]));
175
+ }
176
+ async getWalletConnect() {
177
+ if (this.provider) {
178
+ return this.provider;
179
+ }
180
+ if (!this.metadata) {
181
+ throw new WalletException(new Error('Please provide metadata for WalletConnect'), {
182
+ code: UnspecifiedErrorCode,
183
+ type: ErrorType.WalletError,
184
+ contextModule: WalletAction.GetAccounts,
185
+ });
186
+ }
187
+ if (!this.metadata.projectId) {
188
+ throw new WalletException(new Error('Please provide projectId alongside the metadata for WalletConnect'), {
189
+ code: UnspecifiedErrorCode,
190
+ type: ErrorType.WalletError,
191
+ contextModule: WalletAction.GetAccounts,
192
+ });
193
+ }
194
+ try {
195
+ this.provider = await EthereumProvider.init({
196
+ projectId: this.metadata.projectId,
197
+ metadata: this.metadata
198
+ .metadata,
199
+ showQrModal: true,
200
+ optionalChains: this.ethereumChainId
201
+ ? [this.ethereumChainId]
202
+ : [EthereumChainId.Mainnet, EthereumChainId.Sepolia],
203
+ qrModalOptions: {
204
+ explorerRecommendedWalletIds: [WalletConnectIds.FireBlocks],
205
+ explorerExcludedWalletIds: 'ALL',
206
+ mobileWallets: [],
207
+ walletImages: {
208
+ [WalletConnectIds.FireBlocks]: '/wallet-connect/fireblocks.webp',
209
+ },
210
+ desktopWallets: [
211
+ {
212
+ id: WalletConnectIds.FireBlocks,
213
+ name: 'Fireblocks',
214
+ links: {
215
+ native: 'fireblocks-wc://',
216
+ universal: 'https://console.fireblocks.io/v2/',
217
+ },
218
+ },
219
+ ],
220
+ },
221
+ });
222
+ return this.provider;
223
+ }
224
+ catch (e) {
225
+ throw new WalletException(new Error('WalletConnect not supported for this wallet'), {
226
+ code: UnspecifiedErrorCode,
227
+ type: ErrorType.WalletError,
228
+ contextModule: WalletAction.GetAccounts,
229
+ });
230
+ }
231
+ }
232
+ async getConnectedWalletConnect() {
233
+ if (!this.provider) {
234
+ await this.getWalletConnect();
235
+ }
236
+ if (!this.provider?.connected) {
237
+ await this.enable();
238
+ }
239
+ return this.provider;
240
+ }
241
+ async connectWalletConnect(topic) {
242
+ if (this.provider && this.provider.connected) {
243
+ return;
244
+ }
245
+ const wc = await this.getWalletConnect();
246
+ await wc.connect({
247
+ ...(topic && { pairingTopic: topic }),
248
+ });
249
+ }
250
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-wallet-connect",
3
3
  "description": "Wallet connect strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.15.0",
4
+ "version": "1.15.2",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -58,12 +58,12 @@
58
58
  "dependencies": {
59
59
  "@bangjelkoski/wallet-connect-ethereum-provider": "2.17.2",
60
60
  "@bangjelkoski/wc-ethereum-provider": "2.18.1",
61
- "@injectivelabs/exceptions": "^1.15.0",
62
- "@injectivelabs/sdk-ts": "^1.15.0",
63
- "@injectivelabs/ts-types": "^1.15.0",
64
- "@injectivelabs/wallet-base": "^1.15.0"
61
+ "@injectivelabs/exceptions": "^1.15.1",
62
+ "@injectivelabs/sdk-ts": "^1.15.2",
63
+ "@injectivelabs/ts-types": "^1.15.2",
64
+ "@injectivelabs/wallet-base": "^1.15.2"
65
65
  },
66
- "gitHead": "acae5b41a4c8a0ac4f137cce434b9db81800a1c5",
66
+ "gitHead": "64a57f3115b63114124d0d1fb61f75e520905499",
67
67
  "typedoc": {
68
68
  "entryPoint": "./src/index.ts",
69
69
  "readmeFile": "./README.md",