@dynamic-labs/global-wallet 4.34.0 → 4.35.0
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/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +5 -5
- package/src/GlobalWalletConnector.cjs +25 -13
- package/src/GlobalWalletConnector.d.ts +1 -0
- package/src/GlobalWalletConnector.js +22 -10
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/global-wallet",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.35.0",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"@walletconnect/utils": "2.21.5",
|
|
23
23
|
"@reown/walletkit": "1.1.2",
|
|
24
24
|
"jsqr": "1.4.0",
|
|
25
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
26
|
-
"@dynamic-labs/ethereum-core": "4.
|
|
27
|
-
"@dynamic-labs/utils": "4.
|
|
28
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
25
|
+
"@dynamic-labs/assert-package-version": "4.35.0",
|
|
26
|
+
"@dynamic-labs/ethereum-core": "4.35.0",
|
|
27
|
+
"@dynamic-labs/utils": "4.35.0",
|
|
28
|
+
"@dynamic-labs/wallet-connector-core": "4.35.0"
|
|
29
29
|
},
|
|
30
30
|
"overrides": {
|
|
31
31
|
"elliptic": "6.6.1"
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
-
var utils = require('@walletconnect/utils');
|
|
7
|
+
var utils$1 = require('@walletconnect/utils');
|
|
8
8
|
var jsQR = require('jsqr');
|
|
9
9
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
10
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
11
|
+
var utils = require('@dynamic-labs/utils');
|
|
11
12
|
var getWalletKitSingleton = require('./getWalletKitSingleton/getWalletKitSingleton.cjs');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -42,7 +43,7 @@ const globalConnectorState = {
|
|
|
42
43
|
};
|
|
43
44
|
const GlobalWalletExtension = {
|
|
44
45
|
extend: (connector, settings) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
let
|
|
46
|
+
let web3walletOrUndefined;
|
|
46
47
|
let WCListenersOn = false;
|
|
47
48
|
let pendingSessionProposal;
|
|
48
49
|
let signer = (yield connector.getSigner());
|
|
@@ -65,18 +66,25 @@ const GlobalWalletExtension = {
|
|
|
65
66
|
},
|
|
66
67
|
});
|
|
67
68
|
const globalWallet = {
|
|
69
|
+
assertWeb3walletDefined: (scope) => {
|
|
70
|
+
if (!web3walletOrUndefined) {
|
|
71
|
+
throw new utils.DynamicError(`[${GlobalWalletExtension.name} ${connector.key}] (${scope}) Global Wallet's web3wallet was not initialized, please call pairWithWC first`, utils.ErrorCode.INTERNAL_ERROR);
|
|
72
|
+
}
|
|
73
|
+
return web3walletOrUndefined;
|
|
74
|
+
},
|
|
68
75
|
confirmPairing: (confirm) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('confirmPairing');
|
|
69
77
|
const { params, id } = pendingSessionProposal;
|
|
70
78
|
if (!confirm) {
|
|
71
79
|
yield web3wallet.rejectSession({
|
|
72
80
|
id,
|
|
73
|
-
reason: utils.getSdkError('USER_REJECTED'),
|
|
81
|
+
reason: utils$1.getSdkError('USER_REJECTED'),
|
|
74
82
|
});
|
|
75
83
|
return;
|
|
76
84
|
}
|
|
77
85
|
const { chains, events, methods } = buildCombinedNamespaces(params);
|
|
78
86
|
const address = yield connector.getAddress();
|
|
79
|
-
const approvedNamespaces = utils.buildApprovedNamespaces({
|
|
87
|
+
const approvedNamespaces = utils$1.buildApprovedNamespaces({
|
|
80
88
|
proposal: params,
|
|
81
89
|
supportedNamespaces: {
|
|
82
90
|
eip155: {
|
|
@@ -93,19 +101,20 @@ const GlobalWalletExtension = {
|
|
|
93
101
|
});
|
|
94
102
|
}),
|
|
95
103
|
disconnectWCSession: (topic) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
reason: utils.getSdkError('USER_DISCONNECTED'),
|
|
99
|
-
topic,
|
|
100
|
-
});
|
|
104
|
+
if (!web3walletOrUndefined) {
|
|
105
|
+
return;
|
|
101
106
|
}
|
|
107
|
+
yield web3walletOrUndefined.disconnectSession({
|
|
108
|
+
reason: utils$1.getSdkError('USER_DISCONNECTED'),
|
|
109
|
+
topic,
|
|
110
|
+
});
|
|
102
111
|
}),
|
|
103
112
|
// topic => session mapping, with peer metadata in the session
|
|
104
|
-
getConnectedWCSessions: () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return
|
|
113
|
+
getConnectedWCSessions: () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return web3walletOrUndefined === null || web3walletOrUndefined === void 0 ? void 0 : web3walletOrUndefined.getActiveSessions(); }),
|
|
105
114
|
getPendingPairing: () => pendingSessionProposal,
|
|
106
|
-
getWeb3Wallet: () =>
|
|
115
|
+
getWeb3Wallet: () => web3walletOrUndefined,
|
|
107
116
|
initWeb3Wallet: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
-
|
|
117
|
+
web3walletOrUndefined = yield getWalletKitSingleton.getWalletKitSingleton(settings.walletConnectDappProjectId);
|
|
109
118
|
}),
|
|
110
119
|
initializeListeners: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
111
120
|
if (WCListenersOn)
|
|
@@ -191,6 +200,7 @@ const GlobalWalletExtension = {
|
|
|
191
200
|
response = yield handleEthSendTransaction();
|
|
192
201
|
}
|
|
193
202
|
if (response) {
|
|
203
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('sessionMessageListener');
|
|
194
204
|
yield web3wallet.respondSessionRequest({
|
|
195
205
|
response,
|
|
196
206
|
topic,
|
|
@@ -198,6 +208,7 @@ const GlobalWalletExtension = {
|
|
|
198
208
|
}
|
|
199
209
|
});
|
|
200
210
|
yield globalWallet.initWeb3Wallet();
|
|
211
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('initializeListeners');
|
|
201
212
|
web3wallet.on('session_proposal', onSessionProposal);
|
|
202
213
|
web3wallet.on('session_request', sessionMessageListener);
|
|
203
214
|
connector.on('chainChange', (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ chain }) {
|
|
@@ -218,12 +229,13 @@ const GlobalWalletExtension = {
|
|
|
218
229
|
WCListenersOn = true;
|
|
219
230
|
}),
|
|
220
231
|
pairWithWC: (uri) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
232
|
+
yield globalWallet.initializeListeners();
|
|
233
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('pairWithWC');
|
|
221
234
|
yield web3wallet.pair({ uri });
|
|
222
235
|
}),
|
|
223
236
|
qrScanner: (data, width, height, providedOptions) => jsQR__default["default"](data, width, height, providedOptions),
|
|
224
237
|
};
|
|
225
238
|
connector.globalWallet = globalWallet;
|
|
226
|
-
yield globalWallet.initializeListeners();
|
|
227
239
|
}),
|
|
228
240
|
name: 'global-wallet-extension',
|
|
229
241
|
};
|
|
@@ -16,6 +16,7 @@ declare module '@dynamic-labs/wallet-connector-core' {
|
|
|
16
16
|
getPendingPairing: () => object;
|
|
17
17
|
qrScanner: (data: Uint8ClampedArray, width: number, height: number, providedOptions?: Options) => QRCode | null;
|
|
18
18
|
getWeb3Wallet: () => IWalletKit | undefined;
|
|
19
|
+
assertWeb3walletDefined: (scope: string) => IWalletKit;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -4,6 +4,7 @@ import { getSdkError, buildApprovedNamespaces } from '@walletconnect/utils';
|
|
|
4
4
|
import jsQR from 'jsqr';
|
|
5
5
|
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
6
6
|
import { unFormatTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
+
import { DynamicError, ErrorCode } from '@dynamic-labs/utils';
|
|
7
8
|
import { getWalletKitSingleton } from './getWalletKitSingleton/getWalletKitSingleton.js';
|
|
8
9
|
|
|
9
10
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
@@ -34,7 +35,7 @@ const globalConnectorState = {
|
|
|
34
35
|
};
|
|
35
36
|
const GlobalWalletExtension = {
|
|
36
37
|
extend: (connector, settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
let
|
|
38
|
+
let web3walletOrUndefined;
|
|
38
39
|
let WCListenersOn = false;
|
|
39
40
|
let pendingSessionProposal;
|
|
40
41
|
let signer = (yield connector.getSigner());
|
|
@@ -57,7 +58,14 @@ const GlobalWalletExtension = {
|
|
|
57
58
|
},
|
|
58
59
|
});
|
|
59
60
|
const globalWallet = {
|
|
61
|
+
assertWeb3walletDefined: (scope) => {
|
|
62
|
+
if (!web3walletOrUndefined) {
|
|
63
|
+
throw new DynamicError(`[${GlobalWalletExtension.name} ${connector.key}] (${scope}) Global Wallet's web3wallet was not initialized, please call pairWithWC first`, ErrorCode.INTERNAL_ERROR);
|
|
64
|
+
}
|
|
65
|
+
return web3walletOrUndefined;
|
|
66
|
+
},
|
|
60
67
|
confirmPairing: (confirm) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('confirmPairing');
|
|
61
69
|
const { params, id } = pendingSessionProposal;
|
|
62
70
|
if (!confirm) {
|
|
63
71
|
yield web3wallet.rejectSession({
|
|
@@ -85,19 +93,20 @@ const GlobalWalletExtension = {
|
|
|
85
93
|
});
|
|
86
94
|
}),
|
|
87
95
|
disconnectWCSession: (topic) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
reason: getSdkError('USER_DISCONNECTED'),
|
|
91
|
-
topic,
|
|
92
|
-
});
|
|
96
|
+
if (!web3walletOrUndefined) {
|
|
97
|
+
return;
|
|
93
98
|
}
|
|
99
|
+
yield web3walletOrUndefined.disconnectSession({
|
|
100
|
+
reason: getSdkError('USER_DISCONNECTED'),
|
|
101
|
+
topic,
|
|
102
|
+
});
|
|
94
103
|
}),
|
|
95
104
|
// topic => session mapping, with peer metadata in the session
|
|
96
|
-
getConnectedWCSessions: () => __awaiter(void 0, void 0, void 0, function* () { return
|
|
105
|
+
getConnectedWCSessions: () => __awaiter(void 0, void 0, void 0, function* () { return web3walletOrUndefined === null || web3walletOrUndefined === void 0 ? void 0 : web3walletOrUndefined.getActiveSessions(); }),
|
|
97
106
|
getPendingPairing: () => pendingSessionProposal,
|
|
98
|
-
getWeb3Wallet: () =>
|
|
107
|
+
getWeb3Wallet: () => web3walletOrUndefined,
|
|
99
108
|
initWeb3Wallet: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
-
|
|
109
|
+
web3walletOrUndefined = yield getWalletKitSingleton(settings.walletConnectDappProjectId);
|
|
101
110
|
}),
|
|
102
111
|
initializeListeners: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
112
|
if (WCListenersOn)
|
|
@@ -183,6 +192,7 @@ const GlobalWalletExtension = {
|
|
|
183
192
|
response = yield handleEthSendTransaction();
|
|
184
193
|
}
|
|
185
194
|
if (response) {
|
|
195
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('sessionMessageListener');
|
|
186
196
|
yield web3wallet.respondSessionRequest({
|
|
187
197
|
response,
|
|
188
198
|
topic,
|
|
@@ -190,6 +200,7 @@ const GlobalWalletExtension = {
|
|
|
190
200
|
}
|
|
191
201
|
});
|
|
192
202
|
yield globalWallet.initWeb3Wallet();
|
|
203
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('initializeListeners');
|
|
193
204
|
web3wallet.on('session_proposal', onSessionProposal);
|
|
194
205
|
web3wallet.on('session_request', sessionMessageListener);
|
|
195
206
|
connector.on('chainChange', (_c) => __awaiter(void 0, [_c], void 0, function* ({ chain }) {
|
|
@@ -210,12 +221,13 @@ const GlobalWalletExtension = {
|
|
|
210
221
|
WCListenersOn = true;
|
|
211
222
|
}),
|
|
212
223
|
pairWithWC: (uri) => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
+
yield globalWallet.initializeListeners();
|
|
225
|
+
const web3wallet = globalWallet.assertWeb3walletDefined('pairWithWC');
|
|
213
226
|
yield web3wallet.pair({ uri });
|
|
214
227
|
}),
|
|
215
228
|
qrScanner: (data, width, height, providedOptions) => jsQR(data, width, height, providedOptions),
|
|
216
229
|
};
|
|
217
230
|
connector.globalWallet = globalWallet;
|
|
218
|
-
yield globalWallet.initializeListeners();
|
|
219
231
|
}),
|
|
220
232
|
name: 'global-wallet-extension',
|
|
221
233
|
};
|