@metamask/connect-multichain 0.4.0 → 0.5.1
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/CHANGELOG.md +33 -1
- package/dist/browser/es/connect-multichain.d.mts +26 -9
- package/dist/browser/es/connect-multichain.mjs +370 -100
- package/dist/browser/es/connect-multichain.mjs.map +1 -1
- package/dist/browser/es/metafile-esm.json +1 -1
- package/dist/browser/iife/connect-multichain.d.ts +26 -9
- package/dist/browser/iife/connect-multichain.js +2829 -224
- package/dist/browser/iife/connect-multichain.js.map +1 -1
- package/dist/browser/iife/metafile-iife.json +1 -1
- package/dist/browser/umd/connect-multichain.d.ts +26 -9
- package/dist/browser/umd/connect-multichain.js +370 -100
- package/dist/browser/umd/connect-multichain.js.map +1 -1
- package/dist/browser/umd/metafile-cjs.json +1 -1
- package/dist/node/cjs/connect-multichain.d.ts +26 -9
- package/dist/node/cjs/connect-multichain.js +364 -101
- package/dist/node/cjs/connect-multichain.js.map +1 -1
- package/dist/node/cjs/metafile-cjs.json +1 -1
- package/dist/node/es/connect-multichain.d.mts +26 -9
- package/dist/node/es/connect-multichain.mjs +363 -100
- package/dist/node/es/connect-multichain.mjs.map +1 -1
- package/dist/node/es/metafile-esm.json +1 -1
- package/dist/react-native/es/connect-multichain.d.mts +26 -9
- package/dist/react-native/es/connect-multichain.mjs +357 -91
- package/dist/react-native/es/connect-multichain.mjs.map +1 -1
- package/dist/react-native/es/metafile-esm.json +1 -1
- package/dist/src/domain/multichain/index.d.ts +4 -4
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +4 -3
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/ui/types.d.ts +7 -0
- package/dist/src/domain/ui/types.d.ts.map +1 -1
- package/dist/src/domain/ui/types.js.map +1 -1
- package/dist/src/index.browser.d.ts +2 -1
- package/dist/src/index.browser.d.ts.map +1 -1
- package/dist/src/index.browser.js +5 -3
- package/dist/src/index.browser.js.map +1 -1
- package/dist/src/index.native.d.ts +2 -1
- package/dist/src/index.native.d.ts.map +1 -1
- package/dist/src/index.native.js +6 -4
- package/dist/src/index.native.js.map +1 -1
- package/dist/src/index.node.d.ts +1 -1
- package/dist/src/index.node.d.ts.map +1 -1
- package/dist/src/index.node.js +3 -3
- package/dist/src/index.node.js.map +1 -1
- package/dist/src/multichain/index.d.ts +8 -8
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +161 -101
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +2 -1
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +1 -0
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +21 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +159 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -0
- package/dist/src/multichain/transports/mwp/index.d.ts +4 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +54 -2
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/polyfills/buffer-shim.d.ts +2 -0
- package/dist/src/polyfills/buffer-shim.d.ts.map +1 -0
- package/dist/src/polyfills/buffer-shim.js +22 -0
- package/dist/src/polyfills/buffer-shim.js.map +1 -0
- package/dist/src/ui/ModalFactory.d.ts +54 -0
- package/dist/src/ui/ModalFactory.d.ts.map +1 -0
- package/dist/src/ui/ModalFactory.js +171 -0
- package/dist/src/ui/ModalFactory.js.map +1 -0
- package/dist/src/ui/index.d.ts +14 -38
- package/dist/src/ui/index.d.ts.map +1 -1
- package/dist/src/ui/index.js +24 -142
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/index.native.d.ts +13 -0
- package/dist/src/ui/index.native.d.ts.map +1 -0
- package/dist/src/ui/{preload.native.js → index.native.js} +12 -6
- package/dist/src/ui/index.native.js.map +1 -0
- package/dist/src/ui/modals/base/AbstractInstallModal.d.ts.map +1 -1
- package/dist/src/ui/modals/base/AbstractInstallModal.js +0 -4
- package/dist/src/ui/modals/base/AbstractInstallModal.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +26 -9
- package/package.json +9 -3
- package/dist/src/ui/preload.native.d.ts +0 -5
- package/dist/src/ui/preload.native.d.ts.map +0 -1
- package/dist/src/ui/preload.native.js.map +0 -1
- package/dist/src/ui/preload.web.d.ts +0 -5
- package/dist/src/ui/preload.web.d.ts.map +0 -1
- package/dist/src/ui/preload.web.js +0 -27
- package/dist/src/ui/preload.web.js.map +0 -1
|
@@ -18,7 +18,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
18
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
19
19
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20
20
|
};
|
|
21
|
-
var
|
|
21
|
+
var _MetaMaskConnectMultichain_instances, _MetaMaskConnectMultichain_provider, _MetaMaskConnectMultichain_providerTransportWrapper, _MetaMaskConnectMultichain_transport, _MetaMaskConnectMultichain_dappClient, _MetaMaskConnectMultichain_beforeUnloadListener, _MetaMaskConnectMultichain_listener, _MetaMaskConnectMultichain_sdkInfo, _MetaMaskConnectMultichain_setupAnalytics, _MetaMaskConnectMultichain_onTransportNotification, _MetaMaskConnectMultichain_getStoredTransport, _MetaMaskConnectMultichain_setupTransport, _MetaMaskConnectMultichain_init, _MetaMaskConnectMultichain_createDappClient, _MetaMaskConnectMultichain_setupMWP, _MetaMaskConnectMultichain_onBeforeUnload, _MetaMaskConnectMultichain_createBeforeUnloadListener, _MetaMaskConnectMultichain_renderInstallModalAsync, _MetaMaskConnectMultichain_showInstallModal, _MetaMaskConnectMultichain_headlessConnect, _MetaMaskConnectMultichain_setupDefaultTransport, _MetaMaskConnectMultichain_deeplinkConnect, _MetaMaskConnectMultichain_handleConnection;
|
|
22
22
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
23
23
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
24
24
|
/* eslint-disable no-restricted-globals */
|
|
@@ -38,48 +38,42 @@ import { DefaultTransport } from './transports/default';
|
|
|
38
38
|
import { MWPTransport } from './transports/mwp';
|
|
39
39
|
import { keymanager } from './transports/mwp/KeyManager';
|
|
40
40
|
import { getDappId, openDeeplink, setupDappMetadata } from './utils';
|
|
41
|
+
import { MultichainApiClientWrapperTransport } from './transports/multichainApiClientWrapper';
|
|
41
42
|
export { getInfuraRpcUrls } from '../domain/multichain/api/infura';
|
|
42
43
|
// ENFORCE NAMESPACE THAT CAN BE DISABLED
|
|
43
44
|
const logger = createLogger('metamask-sdk:core');
|
|
44
|
-
export class
|
|
45
|
-
get
|
|
46
|
-
return this.
|
|
45
|
+
export class MetaMaskConnectMultichain extends MultichainCore {
|
|
46
|
+
get status() {
|
|
47
|
+
return this._status;
|
|
47
48
|
}
|
|
48
|
-
set
|
|
49
|
+
set status(value) {
|
|
49
50
|
var _a, _b;
|
|
50
|
-
this.
|
|
51
|
+
this._status = value;
|
|
51
52
|
(_b = (_a = this.options.transport) === null || _a === void 0 ? void 0 : _a.onNotification) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
52
53
|
method: 'stateChanged',
|
|
53
54
|
params: value,
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
get provider() {
|
|
57
|
-
|
|
58
|
-
__classPrivateFieldSet(this, _MultichainSDK_provider, getMultichainClient({ transport: __classPrivateFieldGet(this, _MultichainSDK_transport, "f") }), "f");
|
|
59
|
-
return __classPrivateFieldGet(this, _MultichainSDK_provider, "f");
|
|
60
|
-
}
|
|
61
|
-
if (!__classPrivateFieldGet(this, _MultichainSDK_provider, "f")) {
|
|
62
|
-
throw new Error('Provider not initialized, establish connection first');
|
|
63
|
-
}
|
|
64
|
-
return __classPrivateFieldGet(this, _MultichainSDK_provider, "f");
|
|
58
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_provider, "f");
|
|
65
59
|
}
|
|
66
60
|
get transport() {
|
|
67
|
-
if (!__classPrivateFieldGet(this,
|
|
61
|
+
if (!__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) {
|
|
68
62
|
throw new Error('Transport not initialized, establish connection first');
|
|
69
63
|
}
|
|
70
|
-
return __classPrivateFieldGet(this,
|
|
64
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f");
|
|
71
65
|
}
|
|
72
66
|
get dappClient() {
|
|
73
|
-
if (!__classPrivateFieldGet(this,
|
|
67
|
+
if (!__classPrivateFieldGet(this, _MetaMaskConnectMultichain_dappClient, "f")) {
|
|
74
68
|
throw new Error('DappClient not initialized, establish connection first');
|
|
75
69
|
}
|
|
76
|
-
return __classPrivateFieldGet(this,
|
|
70
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_dappClient, "f");
|
|
77
71
|
}
|
|
78
72
|
get storage() {
|
|
79
73
|
return this.options.storage;
|
|
80
74
|
}
|
|
81
75
|
get transportType() {
|
|
82
|
-
return __classPrivateFieldGet(this,
|
|
76
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f") instanceof MWPTransport
|
|
83
77
|
? TransportType.MWP
|
|
84
78
|
: TransportType.Browser;
|
|
85
79
|
}
|
|
@@ -89,30 +83,34 @@ export class MultichainSDK extends MultichainCore {
|
|
|
89
83
|
const integrationType = (_b = (_a = options.analytics) === null || _a === void 0 ? void 0 : _a.integrationType) !== null && _b !== void 0 ? _b : 'direct';
|
|
90
84
|
const allOptions = Object.assign(Object.assign({}, withDappMetadata), { ui: Object.assign(Object.assign({}, withDappMetadata.ui), { preferExtension: (_c = withDappMetadata.ui.preferExtension) !== null && _c !== void 0 ? _c : true, showInstallModal: (_d = withDappMetadata.ui.showInstallModal) !== null && _d !== void 0 ? _d : false, headless: (_e = withDappMetadata.ui.headless) !== null && _e !== void 0 ? _e : false }), analytics: Object.assign(Object.assign({}, ((_f = options.analytics) !== null && _f !== void 0 ? _f : {})), { integrationType }) });
|
|
91
85
|
super(allOptions);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
_MetaMaskConnectMultichain_instances.add(this);
|
|
87
|
+
_MetaMaskConnectMultichain_provider.set(this, void 0);
|
|
88
|
+
_MetaMaskConnectMultichain_providerTransportWrapper.set(this, void 0);
|
|
89
|
+
_MetaMaskConnectMultichain_transport.set(this, undefined);
|
|
90
|
+
_MetaMaskConnectMultichain_dappClient.set(this, undefined);
|
|
91
|
+
_MetaMaskConnectMultichain_beforeUnloadListener.set(this, void 0);
|
|
92
|
+
this._status = 'pending';
|
|
93
|
+
_MetaMaskConnectMultichain_listener.set(this, void 0);
|
|
94
|
+
_MetaMaskConnectMultichain_sdkInfo.set(this, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_g = this.options.dapp.url) !== null && _g !== void 0 ? _g : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
|
|
95
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_providerTransportWrapper, new MultichainApiClientWrapperTransport(this), "f");
|
|
96
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_provider, getMultichainClient({ transport: __classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f") }), "f");
|
|
100
97
|
}
|
|
101
98
|
static create(options) {
|
|
102
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
const instance = new
|
|
100
|
+
const instance = new MetaMaskConnectMultichain(options);
|
|
104
101
|
const isEnabled = yield isLoggerEnabled('metamask-sdk:core', instance.options.storage);
|
|
105
102
|
if (isEnabled) {
|
|
106
103
|
enableDebug('metamask-sdk:core');
|
|
107
104
|
}
|
|
108
|
-
yield __classPrivateFieldGet(instance,
|
|
105
|
+
yield __classPrivateFieldGet(instance, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_init).call(instance);
|
|
109
106
|
return instance;
|
|
110
107
|
});
|
|
111
108
|
}
|
|
112
|
-
|
|
109
|
+
// TODO: make this into param object
|
|
110
|
+
connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
|
|
113
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
112
|
var _a;
|
|
115
|
-
if (this.
|
|
113
|
+
if (this.status !== 'connected') {
|
|
116
114
|
yield this.disconnect();
|
|
117
115
|
}
|
|
118
116
|
const { ui } = this.options;
|
|
@@ -138,11 +136,11 @@ export class MultichainSDK extends MultichainCore {
|
|
|
138
136
|
catch (error) {
|
|
139
137
|
logger('Error tracking connection_initiated event', error);
|
|
140
138
|
}
|
|
141
|
-
if (((_a = __classPrivateFieldGet(this,
|
|
142
|
-
return __classPrivateFieldGet(this,
|
|
143
|
-
.connect({ scopes, caipAccountIds, forceRequest })
|
|
139
|
+
if (((_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) === null || _a === void 0 ? void 0 : _a.isConnected()) && !secure) {
|
|
140
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_handleConnection).call(this, __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")
|
|
141
|
+
.connect({ scopes, caipAccountIds, sessionProperties, forceRequest })
|
|
144
142
|
.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
if (__classPrivateFieldGet(this,
|
|
143
|
+
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f") instanceof MWPTransport) {
|
|
146
144
|
return this.storage.setTransport(TransportType.MWP);
|
|
147
145
|
}
|
|
148
146
|
return this.storage.setTransport(TransportType.Browser);
|
|
@@ -150,27 +148,27 @@ export class MultichainSDK extends MultichainCore {
|
|
|
150
148
|
}
|
|
151
149
|
// In MetaMask Mobile In App Browser, window.ethereum is available directly
|
|
152
150
|
if (platformType === PlatformType.MetaMaskMobileWebview) {
|
|
153
|
-
const defaultTransport = yield __classPrivateFieldGet(this,
|
|
154
|
-
return __classPrivateFieldGet(this,
|
|
151
|
+
const defaultTransport = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupDefaultTransport).call(this);
|
|
152
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_handleConnection).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
155
153
|
}
|
|
156
154
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
157
155
|
// If metamask extension is available, connect to it
|
|
158
|
-
const defaultTransport = yield __classPrivateFieldGet(this,
|
|
156
|
+
const defaultTransport = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupDefaultTransport).call(this);
|
|
159
157
|
// Web transport has no initial payload
|
|
160
|
-
return __classPrivateFieldGet(this,
|
|
158
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_handleConnection).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
161
159
|
}
|
|
162
160
|
// Connection will now be InstallModal + QRCodes or Deeplinks, both require mwp
|
|
163
|
-
yield __classPrivateFieldGet(this,
|
|
161
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupMWP).call(this);
|
|
164
162
|
// Determine preferred option for install modal
|
|
165
163
|
const shouldShowInstallModal = hasExtensionInstalled
|
|
166
164
|
? showInstallModal
|
|
167
165
|
: !preferExtension || showInstallModal;
|
|
168
166
|
if (secure && !shouldShowInstallModal) {
|
|
169
167
|
// Desktop is not preferred option, so we use deeplinks (mobile web)
|
|
170
|
-
return __classPrivateFieldGet(this,
|
|
168
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_handleConnection).call(this, __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_deeplinkConnect).call(this, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
171
169
|
}
|
|
172
170
|
// Show install modal for RN, Web + Node
|
|
173
|
-
return __classPrivateFieldGet(this,
|
|
171
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_handleConnection).call(this, __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_showInstallModal).call(this, shouldShowInstallModal, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
174
172
|
});
|
|
175
173
|
}
|
|
176
174
|
emit(event, args) {
|
|
@@ -181,25 +179,24 @@ export class MultichainSDK extends MultichainCore {
|
|
|
181
179
|
disconnect() {
|
|
182
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
181
|
var _a, _b, _c;
|
|
184
|
-
yield ((_a = __classPrivateFieldGet(this,
|
|
185
|
-
(_b = __classPrivateFieldGet(this,
|
|
186
|
-
yield ((_c = __classPrivateFieldGet(this,
|
|
182
|
+
yield ((_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_listener, "f")) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
183
|
+
(_b = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_beforeUnloadListener, "f")) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
184
|
+
yield ((_c = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) === null || _c === void 0 ? void 0 : _c.disconnect());
|
|
187
185
|
yield this.storage.removeTransport();
|
|
188
186
|
this.emit('stateChanged', 'disconnected');
|
|
189
|
-
__classPrivateFieldSet(this,
|
|
190
|
-
__classPrivateFieldSet(this,
|
|
191
|
-
__classPrivateFieldSet(this,
|
|
192
|
-
|
|
193
|
-
__classPrivateFieldSet(this,
|
|
187
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, undefined, "f");
|
|
188
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_beforeUnloadListener, undefined, "f");
|
|
189
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transport, undefined, "f");
|
|
190
|
+
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f").clearNotificationCallbacks();
|
|
191
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_dappClient, undefined, "f");
|
|
194
192
|
});
|
|
195
193
|
}
|
|
196
194
|
invokeMethod(request) {
|
|
197
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
var _a;
|
|
199
196
|
const { transport, options } = this;
|
|
200
|
-
|
|
201
|
-
const rpcClient = new RpcClient(options, __classPrivateFieldGet(this, _MultichainSDK_sdkInfo, "f"));
|
|
197
|
+
const rpcClient = new RpcClient(options, __classPrivateFieldGet(this, _MetaMaskConnectMultichain_sdkInfo, "f"));
|
|
202
198
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
199
|
+
// TODO: need read only method support for solana
|
|
203
200
|
return requestRouter.invokeMethod(request);
|
|
204
201
|
});
|
|
205
202
|
}
|
|
@@ -226,7 +223,7 @@ export class MultichainSDK extends MultichainCore {
|
|
|
226
223
|
}
|
|
227
224
|
}
|
|
228
225
|
}
|
|
229
|
-
|
|
226
|
+
_MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_providerTransportWrapper = new WeakMap(), _MetaMaskConnectMultichain_transport = new WeakMap(), _MetaMaskConnectMultichain_dappClient = new WeakMap(), _MetaMaskConnectMultichain_beforeUnloadListener = new WeakMap(), _MetaMaskConnectMultichain_listener = new WeakMap(), _MetaMaskConnectMultichain_sdkInfo = new WeakMap(), _MetaMaskConnectMultichain_instances = new WeakSet(), _MetaMaskConnectMultichain_setupAnalytics = function _MetaMaskConnectMultichain_setupAnalytics() {
|
|
230
227
|
return __awaiter(this, void 0, void 0, function* () {
|
|
231
228
|
var _a;
|
|
232
229
|
const platform = getPlatformType();
|
|
@@ -250,7 +247,7 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
250
247
|
analytics.setGlobalProperty('integration_type', integrationType);
|
|
251
248
|
analytics.enable();
|
|
252
249
|
});
|
|
253
|
-
},
|
|
250
|
+
}, _MetaMaskConnectMultichain_onTransportNotification = function _MetaMaskConnectMultichain_onTransportNotification(payload) {
|
|
254
251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
255
252
|
var _a;
|
|
256
253
|
if (typeof payload === 'object' &&
|
|
@@ -259,7 +256,7 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
259
256
|
this.emit(payload.method, (_a = payload.params) !== null && _a !== void 0 ? _a : payload.result);
|
|
260
257
|
}
|
|
261
258
|
});
|
|
262
|
-
},
|
|
259
|
+
}, _MetaMaskConnectMultichain_getStoredTransport = function _MetaMaskConnectMultichain_getStoredTransport() {
|
|
263
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
264
261
|
const transportType = yield this.storage.getTransport();
|
|
265
262
|
const hasExtensionInstalled = yield hasExtension();
|
|
@@ -267,33 +264,35 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
267
264
|
if (transportType === TransportType.Browser) {
|
|
268
265
|
if (hasExtensionInstalled) {
|
|
269
266
|
const apiTransport = new DefaultTransport();
|
|
270
|
-
__classPrivateFieldSet(this,
|
|
271
|
-
|
|
267
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transport, apiTransport, "f");
|
|
268
|
+
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f").setupNotifcationListener();
|
|
269
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, apiTransport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
272
270
|
return apiTransport;
|
|
273
271
|
}
|
|
274
272
|
}
|
|
275
273
|
else if (transportType === TransportType.MWP) {
|
|
276
274
|
const { adapter: kvstore } = this.options.storage;
|
|
277
|
-
const dappClient = yield __classPrivateFieldGet(this,
|
|
275
|
+
const dappClient = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_createDappClient).call(this);
|
|
278
276
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
279
|
-
__classPrivateFieldSet(this,
|
|
280
|
-
__classPrivateFieldSet(this,
|
|
281
|
-
|
|
277
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_dappClient, dappClient, "f");
|
|
278
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transport, apiTransport, "f");
|
|
279
|
+
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f").setupNotifcationListener();
|
|
280
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, apiTransport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
282
281
|
return apiTransport;
|
|
283
282
|
}
|
|
284
283
|
yield this.storage.removeTransport();
|
|
285
284
|
}
|
|
286
285
|
return undefined;
|
|
287
286
|
});
|
|
288
|
-
},
|
|
287
|
+
}, _MetaMaskConnectMultichain_setupTransport = function _MetaMaskConnectMultichain_setupTransport() {
|
|
289
288
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
const transport = yield __classPrivateFieldGet(this,
|
|
289
|
+
const transport = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_getStoredTransport).call(this);
|
|
291
290
|
if (transport) {
|
|
292
291
|
if (!this.transport.isConnected()) {
|
|
293
|
-
this.
|
|
292
|
+
this.status = 'connecting';
|
|
294
293
|
yield this.transport.connect();
|
|
295
294
|
}
|
|
296
|
-
this.
|
|
295
|
+
this.status = 'connected';
|
|
297
296
|
if (this.transport instanceof MWPTransport) {
|
|
298
297
|
yield this.storage.setTransport(TransportType.MWP);
|
|
299
298
|
}
|
|
@@ -302,10 +301,10 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
302
301
|
}
|
|
303
302
|
}
|
|
304
303
|
else {
|
|
305
|
-
this.
|
|
304
|
+
this.status = 'loaded';
|
|
306
305
|
}
|
|
307
306
|
});
|
|
308
|
-
},
|
|
307
|
+
}, _MetaMaskConnectMultichain_init = function _MetaMaskConnectMultichain_init() {
|
|
309
308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
310
309
|
var _a;
|
|
311
310
|
try {
|
|
@@ -314,8 +313,8 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
314
313
|
logger('MetaMaskSDK: init already initialized');
|
|
315
314
|
}
|
|
316
315
|
else {
|
|
317
|
-
yield __classPrivateFieldGet(this,
|
|
318
|
-
yield __classPrivateFieldGet(this,
|
|
316
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupAnalytics).call(this);
|
|
317
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupTransport).call(this);
|
|
319
318
|
try {
|
|
320
319
|
const baseProps = yield getBaseAnalyticsProperties(this.options, this.storage);
|
|
321
320
|
analytics.track('mmconnect_initialized', baseProps);
|
|
@@ -331,11 +330,11 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
331
330
|
}
|
|
332
331
|
catch (error) {
|
|
333
332
|
yield this.storage.removeTransport();
|
|
334
|
-
this.
|
|
333
|
+
this.status = 'pending';
|
|
335
334
|
logger('MetaMaskSDK error during initialization', error);
|
|
336
335
|
}
|
|
337
336
|
});
|
|
338
|
-
},
|
|
337
|
+
}, _MetaMaskConnectMultichain_createDappClient = function _MetaMaskConnectMultichain_createDappClient() {
|
|
339
338
|
return __awaiter(this, void 0, void 0, function* () {
|
|
340
339
|
const { adapter: kvstore } = this.options.storage;
|
|
341
340
|
const sessionstore = new SessionStore(kvstore);
|
|
@@ -352,21 +351,22 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
352
351
|
const dappClient = new DappClient({ transport, sessionstore, keymanager });
|
|
353
352
|
return dappClient;
|
|
354
353
|
});
|
|
355
|
-
},
|
|
354
|
+
}, _MetaMaskConnectMultichain_setupMWP = function _MetaMaskConnectMultichain_setupMWP() {
|
|
356
355
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
-
if (__classPrivateFieldGet(this,
|
|
356
|
+
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f") instanceof MWPTransport) {
|
|
358
357
|
return;
|
|
359
358
|
}
|
|
360
359
|
// Only setup MWP if it is not already mwp
|
|
361
360
|
const { adapter: kvstore } = this.options.storage;
|
|
362
|
-
const dappClient = yield __classPrivateFieldGet(this,
|
|
363
|
-
__classPrivateFieldSet(this,
|
|
361
|
+
const dappClient = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_createDappClient).call(this);
|
|
362
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_dappClient, dappClient, "f");
|
|
364
363
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
365
|
-
__classPrivateFieldSet(this,
|
|
366
|
-
|
|
364
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transport, apiTransport, "f");
|
|
365
|
+
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f").setupNotifcationListener();
|
|
366
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, this.transport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
367
367
|
yield this.storage.setTransport(TransportType.MWP);
|
|
368
368
|
});
|
|
369
|
-
},
|
|
369
|
+
}, _MetaMaskConnectMultichain_onBeforeUnload = function _MetaMaskConnectMultichain_onBeforeUnload() {
|
|
370
370
|
return __awaiter(this, void 0, void 0, function* () {
|
|
371
371
|
var _a;
|
|
372
372
|
// Fixes glitch with "connecting" state when modal is still visible and we close screen or refresh
|
|
@@ -374,18 +374,18 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
374
374
|
yield this.storage.removeTransport();
|
|
375
375
|
}
|
|
376
376
|
});
|
|
377
|
-
},
|
|
377
|
+
}, _MetaMaskConnectMultichain_createBeforeUnloadListener = function _MetaMaskConnectMultichain_createBeforeUnloadListener() {
|
|
378
378
|
if (typeof window !== 'undefined' &&
|
|
379
379
|
typeof window.addEventListener !== 'undefined') {
|
|
380
|
-
window.addEventListener('beforeunload', __classPrivateFieldGet(this,
|
|
380
|
+
window.addEventListener('beforeunload', __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onBeforeUnload).bind(this));
|
|
381
381
|
}
|
|
382
382
|
return () => {
|
|
383
383
|
if (typeof window !== 'undefined' &&
|
|
384
384
|
typeof window.removeEventListener !== 'undefined') {
|
|
385
|
-
window.removeEventListener('beforeunload', __classPrivateFieldGet(this,
|
|
385
|
+
window.removeEventListener('beforeunload', __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onBeforeUnload).bind(this));
|
|
386
386
|
}
|
|
387
387
|
};
|
|
388
|
-
},
|
|
388
|
+
}, _MetaMaskConnectMultichain_renderInstallModalAsync = function _MetaMaskConnectMultichain_renderInstallModalAsync(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
389
389
|
return __awaiter(this, void 0, void 0, function* () {
|
|
390
390
|
return new Promise((resolve, reject) => {
|
|
391
391
|
// Use Connection Modal
|
|
@@ -411,23 +411,23 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
411
411
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
412
412
|
var _a;
|
|
413
413
|
try {
|
|
414
|
-
yield this.transport.connect({ scopes, caipAccountIds });
|
|
414
|
+
yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
|
|
415
415
|
yield this.options.ui.factory.unload();
|
|
416
416
|
(_a = this.options.ui.factory.modal) === null || _a === void 0 ? void 0 : _a.unmount();
|
|
417
|
-
this.
|
|
417
|
+
this.status = 'connected';
|
|
418
418
|
yield this.storage.setTransport(TransportType.MWP);
|
|
419
419
|
}
|
|
420
420
|
catch (error) {
|
|
421
421
|
if (error instanceof ProtocolError) {
|
|
422
422
|
// Ignore Request expired errors to allow modal to regenerate expired qr codes
|
|
423
423
|
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
424
|
-
this.
|
|
424
|
+
this.status = 'disconnected';
|
|
425
425
|
reject(error);
|
|
426
426
|
}
|
|
427
427
|
// If request is expires, the QRCode will automatically be regenerated we can ignore this case
|
|
428
428
|
}
|
|
429
429
|
else {
|
|
430
|
-
this.
|
|
430
|
+
this.status = 'disconnected';
|
|
431
431
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
432
432
|
}
|
|
433
433
|
}
|
|
@@ -444,29 +444,87 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
444
444
|
yield this.storage.setTransport(TransportType.MWP);
|
|
445
445
|
resolve();
|
|
446
446
|
}
|
|
447
|
-
}))
|
|
447
|
+
}), (uri) => {
|
|
448
|
+
this.emit('display_uri', uri);
|
|
449
|
+
})
|
|
448
450
|
.catch((error) => {
|
|
449
451
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
450
452
|
});
|
|
451
453
|
});
|
|
452
454
|
});
|
|
453
|
-
},
|
|
455
|
+
}, _MetaMaskConnectMultichain_showInstallModal = function _MetaMaskConnectMultichain_showInstallModal(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
454
456
|
return __awaiter(this, void 0, void 0, function* () {
|
|
455
457
|
var _a;
|
|
456
458
|
// create the listener only once to avoid memory leaks
|
|
457
|
-
__classPrivateFieldSet(this,
|
|
458
|
-
|
|
459
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_beforeUnloadListener, (_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_beforeUnloadListener, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_createBeforeUnloadListener).call(this), "f");
|
|
460
|
+
// In headless mode, don't render UI but still emit display_uri events
|
|
461
|
+
if (this.options.ui.headless) {
|
|
462
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_headlessConnect).call(this, scopes, caipAccountIds, sessionProperties);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_renderInstallModalAsync).call(this, desktopPreferred, scopes, caipAccountIds, sessionProperties);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}, _MetaMaskConnectMultichain_headlessConnect = function _MetaMaskConnectMultichain_headlessConnect(scopes, caipAccountIds, sessionProperties) {
|
|
469
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
470
|
+
return new Promise((resolve, reject) => {
|
|
471
|
+
if (this.dappClient.state === 'CONNECTED' ||
|
|
472
|
+
this.dappClient.state === 'CONNECTING') {
|
|
473
|
+
this.dappClient.disconnect().catch(() => {
|
|
474
|
+
// Ignore disconnect errors
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
// Listen for session_request to generate and emit the QR code link
|
|
478
|
+
this.dappClient.on('session_request', (sessionRequest) => {
|
|
479
|
+
const connectionRequest = {
|
|
480
|
+
sessionRequest,
|
|
481
|
+
metadata: {
|
|
482
|
+
dapp: this.options.dapp,
|
|
483
|
+
sdk: {
|
|
484
|
+
version: getVersion(),
|
|
485
|
+
platform: getPlatformType(),
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
};
|
|
489
|
+
// Generate and emit the QR code link
|
|
490
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
491
|
+
this.emit('display_uri', deeplink);
|
|
492
|
+
});
|
|
493
|
+
// Start the connection
|
|
494
|
+
this.transport
|
|
495
|
+
.connect({ scopes, caipAccountIds, sessionProperties })
|
|
496
|
+
.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
497
|
+
this.status = 'connected';
|
|
498
|
+
yield this.storage.setTransport(TransportType.MWP);
|
|
499
|
+
resolve();
|
|
500
|
+
}))
|
|
501
|
+
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
502
|
+
if (error instanceof ProtocolError) {
|
|
503
|
+
// In headless mode, we don't auto-regenerate QR codes
|
|
504
|
+
// since there's no modal to display them
|
|
505
|
+
this.status = 'disconnected';
|
|
506
|
+
yield this.storage.removeTransport();
|
|
507
|
+
reject(error);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
this.status = 'disconnected';
|
|
511
|
+
yield this.storage.removeTransport();
|
|
512
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
513
|
+
}
|
|
514
|
+
}));
|
|
515
|
+
});
|
|
459
516
|
});
|
|
460
|
-
},
|
|
517
|
+
}, _MetaMaskConnectMultichain_setupDefaultTransport = function _MetaMaskConnectMultichain_setupDefaultTransport() {
|
|
461
518
|
return __awaiter(this, void 0, void 0, function* () {
|
|
462
|
-
this.
|
|
519
|
+
this.status = 'connecting';
|
|
463
520
|
yield this.storage.setTransport(TransportType.Browser);
|
|
464
521
|
const transport = new DefaultTransport();
|
|
465
|
-
__classPrivateFieldSet(this,
|
|
466
|
-
__classPrivateFieldSet(this,
|
|
522
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, transport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
523
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transport, transport, "f");
|
|
524
|
+
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f").setupNotifcationListener();
|
|
467
525
|
return transport;
|
|
468
526
|
});
|
|
469
|
-
},
|
|
527
|
+
}, _MetaMaskConnectMultichain_deeplinkConnect = function _MetaMaskConnectMultichain_deeplinkConnect(scopes, caipAccountIds, sessionProperties) {
|
|
470
528
|
return __awaiter(this, void 0, void 0, function* () {
|
|
471
529
|
return new Promise((resolve, reject) => {
|
|
472
530
|
// Handle the response to the initial wallet_createSession request
|
|
@@ -510,6 +568,8 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
510
568
|
};
|
|
511
569
|
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
512
570
|
const universalLink = this.options.ui.factory.createConnectionUniversalLink(connectionRequest);
|
|
571
|
+
// Emit display_uri event for deeplink connections
|
|
572
|
+
this.emit('display_uri', deeplink);
|
|
513
573
|
if ((_a = this.options.mobile) === null || _a === void 0 ? void 0 : _a.preferredOpenLink) {
|
|
514
574
|
this.options.mobile.preferredOpenLink(deeplink, '_self');
|
|
515
575
|
}
|
|
@@ -519,7 +579,7 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
519
579
|
});
|
|
520
580
|
}
|
|
521
581
|
return this.transport
|
|
522
|
-
.connect({ scopes, caipAccountIds })
|
|
582
|
+
.connect({ scopes, caipAccountIds, sessionProperties })
|
|
523
583
|
.then(resolve)
|
|
524
584
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
525
585
|
yield this.storage.removeTransport();
|
|
@@ -533,12 +593,12 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
533
593
|
});
|
|
534
594
|
});
|
|
535
595
|
});
|
|
536
|
-
},
|
|
596
|
+
}, _MetaMaskConnectMultichain_handleConnection = function _MetaMaskConnectMultichain_handleConnection(promise, scopes, transportType) {
|
|
537
597
|
return __awaiter(this, void 0, void 0, function* () {
|
|
538
|
-
this.
|
|
598
|
+
this.status = 'connecting';
|
|
539
599
|
return promise
|
|
540
600
|
.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
541
|
-
this.
|
|
601
|
+
this.status = 'connected';
|
|
542
602
|
try {
|
|
543
603
|
const baseProps = yield getBaseAnalyticsProperties(this.options, this.storage);
|
|
544
604
|
analytics.track('mmconnect_connection_established', Object.assign(Object.assign({}, baseProps), { transport_type: transportType, user_permissioned_chains: scopes }));
|
|
@@ -549,7 +609,7 @@ _MultichainSDK_provider = new WeakMap(), _MultichainSDK_transport = new WeakMap(
|
|
|
549
609
|
return undefined; // explicitly return `undefined` to avoid eslintpromise/always-return
|
|
550
610
|
}))
|
|
551
611
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
552
|
-
this.
|
|
612
|
+
this.status = 'disconnected';
|
|
553
613
|
try {
|
|
554
614
|
const baseProps = yield getBaseAnalyticsProperties(this.options, this.storage);
|
|
555
615
|
const isRejection = isRejectionError(error);
|