@metamask/connect-multichain 0.1.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/CHANGELOG.md +17 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/browser/es/connect-multichain.d.mts +585 -0
- package/dist/browser/es/connect-multichain.mjs +2609 -0
- package/dist/browser/es/connect-multichain.mjs.map +1 -0
- package/dist/browser/es/metafile-esm.json +1 -0
- package/dist/browser/iife/connect-multichain.d.ts +585 -0
- package/dist/browser/iife/connect-multichain.js +30057 -0
- package/dist/browser/iife/connect-multichain.js.map +1 -0
- package/dist/browser/iife/metafile-iife.json +1 -0
- package/dist/browser/umd/connect-multichain.d.ts +585 -0
- package/dist/browser/umd/connect-multichain.js +2622 -0
- package/dist/browser/umd/connect-multichain.js.map +1 -0
- package/dist/browser/umd/metafile-cjs.json +1 -0
- package/dist/node/cjs/connect-multichain.d.ts +585 -0
- package/dist/node/cjs/connect-multichain.js +2603 -0
- package/dist/node/cjs/connect-multichain.js.map +1 -0
- package/dist/node/cjs/metafile-cjs.json +1 -0
- package/dist/node/es/connect-multichain.d.mts +585 -0
- package/dist/node/es/connect-multichain.mjs +2564 -0
- package/dist/node/es/connect-multichain.mjs.map +1 -0
- package/dist/node/es/metafile-esm.json +1 -0
- package/dist/react-native/es/connect-multichain.d.mts +585 -0
- package/dist/react-native/es/connect-multichain.mjs +2517 -0
- package/dist/react-native/es/connect-multichain.mjs.map +1 -0
- package/dist/react-native/es/metafile-esm.json +1 -0
- package/dist/src/config/index.d.ts +4 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +4 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/domain/errors/base.d.ts +7 -0
- package/dist/src/domain/errors/base.d.ts.map +1 -0
- package/dist/src/domain/errors/base.js +8 -0
- package/dist/src/domain/errors/base.js.map +1 -0
- package/dist/src/domain/errors/index.d.ts +3 -0
- package/dist/src/domain/errors/index.d.ts.map +1 -0
- package/dist/src/domain/errors/index.js +2 -0
- package/dist/src/domain/errors/index.js.map +1 -0
- package/dist/src/domain/errors/rpc.d.ts +25 -0
- package/dist/src/domain/errors/rpc.d.ts.map +1 -0
- package/dist/src/domain/errors/rpc.js +33 -0
- package/dist/src/domain/errors/rpc.js.map +1 -0
- package/dist/src/domain/errors/storage.d.ts +24 -0
- package/dist/src/domain/errors/storage.d.ts.map +1 -0
- package/dist/src/domain/errors/storage.js +30 -0
- package/dist/src/domain/errors/storage.js.map +1 -0
- package/dist/src/domain/errors/types.d.ts +7 -0
- package/dist/src/domain/errors/types.d.ts.map +1 -0
- package/dist/src/domain/errors/types.js +2 -0
- package/dist/src/domain/errors/types.js.map +1 -0
- package/dist/src/domain/events/index.d.ts +39 -0
- package/dist/src/domain/events/index.d.ts.map +1 -0
- package/dist/src/domain/events/index.js +58 -0
- package/dist/src/domain/events/index.js.map +1 -0
- package/dist/src/domain/events/types/index.d.ts +8 -0
- package/dist/src/domain/events/types/index.d.ts.map +1 -0
- package/dist/src/domain/events/types/index.js +2 -0
- package/dist/src/domain/events/types/index.js.map +1 -0
- package/dist/src/domain/index.d.ts +9 -0
- package/dist/src/domain/index.d.ts.map +1 -0
- package/dist/src/domain/index.js +9 -0
- package/dist/src/domain/index.js.map +1 -0
- package/dist/src/domain/logger/index.d.ts +41 -0
- package/dist/src/domain/logger/index.d.ts.map +1 -0
- package/dist/src/domain/logger/index.js +79 -0
- package/dist/src/domain/logger/index.js.map +1 -0
- package/dist/src/domain/multichain/api/constants.d.ts +5 -0
- package/dist/src/domain/multichain/api/constants.d.ts.map +1 -0
- package/dist/src/domain/multichain/api/constants.js +101 -0
- package/dist/src/domain/multichain/api/constants.js.map +1 -0
- package/dist/src/domain/multichain/api/eip155.d.ts +58 -0
- package/dist/src/domain/multichain/api/eip155.d.ts.map +1 -0
- package/dist/src/domain/multichain/api/eip155.js +2 -0
- package/dist/src/domain/multichain/api/eip155.js.map +1 -0
- package/dist/src/domain/multichain/api/infura.d.ts +3 -0
- package/dist/src/domain/multichain/api/infura.d.ts.map +1 -0
- package/dist/src/domain/multichain/api/infura.js +10 -0
- package/dist/src/domain/multichain/api/infura.js.map +1 -0
- package/dist/src/domain/multichain/api/types.d.ts +89 -0
- package/dist/src/domain/multichain/api/types.d.ts.map +1 -0
- package/dist/src/domain/multichain/api/types.js +2 -0
- package/dist/src/domain/multichain/api/types.js.map +1 -0
- package/dist/src/domain/multichain/index.d.ts +51 -0
- package/dist/src/domain/multichain/index.d.ts.map +1 -0
- package/dist/src/domain/multichain/index.js +33 -0
- package/dist/src/domain/multichain/index.js.map +1 -0
- package/dist/src/domain/multichain/types.d.ts +102 -0
- package/dist/src/domain/multichain/types.d.ts.map +1 -0
- package/dist/src/domain/multichain/types.js +2 -0
- package/dist/src/domain/multichain/types.js.map +1 -0
- package/dist/src/domain/platform/index.d.ts +17 -0
- package/dist/src/domain/platform/index.d.ts.map +1 -0
- package/dist/src/domain/platform/index.js +122 -0
- package/dist/src/domain/platform/index.js.map +1 -0
- package/dist/src/domain/store/adapter.d.ts +10 -0
- package/dist/src/domain/store/adapter.d.ts.map +1 -0
- package/dist/src/domain/store/adapter.js +6 -0
- package/dist/src/domain/store/adapter.js.map +1 -0
- package/dist/src/domain/store/client.d.ts +16 -0
- package/dist/src/domain/store/client.d.ts.map +1 -0
- package/dist/src/domain/store/client.js +3 -0
- package/dist/src/domain/store/client.js.map +1 -0
- package/dist/src/domain/store/index.d.ts +3 -0
- package/dist/src/domain/store/index.d.ts.map +1 -0
- package/dist/src/domain/store/index.js +3 -0
- package/dist/src/domain/store/index.js.map +1 -0
- package/dist/src/domain/ui/factory.d.ts +26 -0
- package/dist/src/domain/ui/factory.d.ts.map +1 -0
- package/dist/src/domain/ui/factory.js +2 -0
- package/dist/src/domain/ui/factory.js.map +1 -0
- package/dist/src/domain/ui/index.d.ts +3 -0
- package/dist/src/domain/ui/index.d.ts.map +1 -0
- package/dist/src/domain/ui/index.js +2 -0
- package/dist/src/domain/ui/index.js.map +1 -0
- package/dist/src/domain/ui/types.d.ts +34 -0
- package/dist/src/domain/ui/types.d.ts.map +1 -0
- package/dist/src/domain/ui/types.js +38 -0
- package/dist/src/domain/ui/types.js.map +1 -0
- package/dist/src/domain/utils/index.d.ts +7 -0
- package/dist/src/domain/utils/index.d.ts.map +1 -0
- package/dist/src/domain/utils/index.js +9 -0
- package/dist/src/domain/utils/index.js.map +1 -0
- package/dist/src/index.browser.d.ts +4 -0
- package/dist/src/index.browser.d.ts.map +1 -0
- package/dist/src/index.browser.js +28 -0
- package/dist/src/index.browser.js.map +1 -0
- package/dist/src/index.native.d.ts +4 -0
- package/dist/src/index.native.d.ts.map +1 -0
- package/dist/src/index.native.js +28 -0
- package/dist/src/index.native.js.map +1 -0
- package/dist/src/index.node.d.ts +4 -0
- package/dist/src/index.node.d.ts.map +1 -0
- package/dist/src/index.node.js +28 -0
- package/dist/src/index.node.js.map +1 -0
- package/dist/src/multichain/index.d.ts +41 -0
- package/dist/src/multichain/index.d.ts.map +1 -0
- package/dist/src/multichain/index.js +499 -0
- package/dist/src/multichain/index.js.map +1 -0
- package/dist/src/multichain/rpc/handlers/rpcClient.d.ts +19 -0
- package/dist/src/multichain/rpc/handlers/rpcClient.d.ts.map +1 -0
- package/dist/src/multichain/rpc/handlers/rpcClient.js +105 -0
- package/dist/src/multichain/rpc/handlers/rpcClient.js.map +1 -0
- package/dist/src/multichain/rpc/requestRouter.d.ts +29 -0
- package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -0
- package/dist/src/multichain/rpc/requestRouter.js +104 -0
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -0
- package/dist/src/multichain/transports/default/index.d.ts +17 -0
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -0
- package/dist/src/multichain/transports/default/index.js +101 -0
- package/dist/src/multichain/transports/default/index.js.map +1 -0
- package/dist/src/multichain/transports/mwp/KeyManager.d.ts +9 -0
- package/dist/src/multichain/transports/mwp/KeyManager.d.ts.map +1 -0
- package/dist/src/multichain/transports/mwp/KeyManager.js +35 -0
- package/dist/src/multichain/transports/mwp/KeyManager.js.map +1 -0
- package/dist/src/multichain/transports/mwp/index.d.ts +65 -0
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -0
- package/dist/src/multichain/transports/mwp/index.js +323 -0
- package/dist/src/multichain/transports/mwp/index.js.map +1 -0
- package/dist/src/multichain/utils/index.d.ts +41 -0
- package/dist/src/multichain/utils/index.d.ts.map +1 -0
- package/dist/src/multichain/utils/index.js +239 -0
- package/dist/src/multichain/utils/index.js.map +1 -0
- package/dist/src/store/adapters/node.d.ts +9 -0
- package/dist/src/store/adapters/node.d.ts.map +1 -0
- package/dist/src/store/adapters/node.js +34 -0
- package/dist/src/store/adapters/node.js.map +1 -0
- package/dist/src/store/adapters/rn.d.ts +8 -0
- package/dist/src/store/adapters/rn.d.ts.map +1 -0
- package/dist/src/store/adapters/rn.js +33 -0
- package/dist/src/store/adapters/rn.js.map +1 -0
- package/dist/src/store/adapters/web.d.ts +16 -0
- package/dist/src/store/adapters/web.d.ts.map +1 -0
- package/dist/src/store/adapters/web.js +99 -0
- package/dist/src/store/adapters/web.js.map +1 -0
- package/dist/src/store/index.d.ts +17 -0
- package/dist/src/store/index.d.ts.map +1 -0
- package/dist/src/store/index.js +130 -0
- package/dist/src/store/index.js.map +1 -0
- package/dist/src/ui/index.d.ts +45 -0
- package/dist/src/ui/index.d.ts.map +1 -0
- package/dist/src/ui/index.js +185 -0
- package/dist/src/ui/index.js.map +1 -0
- package/dist/src/ui/modals/base/AbstractInstallModal.d.ts +16 -0
- package/dist/src/ui/modals/base/AbstractInstallModal.d.ts.map +1 -0
- package/dist/src/ui/modals/base/AbstractInstallModal.js +90 -0
- package/dist/src/ui/modals/base/AbstractInstallModal.js.map +1 -0
- package/dist/src/ui/modals/base/AbstractOTPModal.d.ts +8 -0
- package/dist/src/ui/modals/base/AbstractOTPModal.d.ts.map +1 -0
- package/dist/src/ui/modals/base/AbstractOTPModal.js +16 -0
- package/dist/src/ui/modals/base/AbstractOTPModal.js.map +1 -0
- package/dist/src/ui/modals/base/utils.d.ts +3 -0
- package/dist/src/ui/modals/base/utils.d.ts.map +1 -0
- package/dist/src/ui/modals/base/utils.js +30 -0
- package/dist/src/ui/modals/base/utils.js.map +1 -0
- package/dist/src/ui/modals/node/index.d.ts +3 -0
- package/dist/src/ui/modals/node/index.d.ts.map +1 -0
- package/dist/src/ui/modals/node/index.js +3 -0
- package/dist/src/ui/modals/node/index.js.map +1 -0
- package/dist/src/ui/modals/node/install.d.ts +9 -0
- package/dist/src/ui/modals/node/install.d.ts.map +1 -0
- package/dist/src/ui/modals/node/install.js +47 -0
- package/dist/src/ui/modals/node/install.js.map +1 -0
- package/dist/src/ui/modals/node/otp.d.ts +10 -0
- package/dist/src/ui/modals/node/otp.d.ts.map +1 -0
- package/dist/src/ui/modals/node/otp.js +10 -0
- package/dist/src/ui/modals/node/otp.js.map +1 -0
- package/dist/src/ui/modals/rn/index.d.ts +3 -0
- package/dist/src/ui/modals/rn/index.d.ts.map +1 -0
- package/dist/src/ui/modals/rn/index.js +3 -0
- package/dist/src/ui/modals/rn/index.js.map +1 -0
- package/dist/src/ui/modals/rn/install.d.ts +7 -0
- package/dist/src/ui/modals/rn/install.d.ts.map +1 -0
- package/dist/src/ui/modals/rn/install.js +9 -0
- package/dist/src/ui/modals/rn/install.js.map +1 -0
- package/dist/src/ui/modals/rn/otp.d.ts +10 -0
- package/dist/src/ui/modals/rn/otp.d.ts.map +1 -0
- package/dist/src/ui/modals/rn/otp.js +10 -0
- package/dist/src/ui/modals/rn/otp.js.map +1 -0
- package/dist/src/ui/modals/types.d.ts +13 -0
- package/dist/src/ui/modals/types.d.ts.map +1 -0
- package/dist/src/ui/modals/types.js +2 -0
- package/dist/src/ui/modals/types.js.map +1 -0
- package/dist/src/ui/modals/web/index.d.ts +3 -0
- package/dist/src/ui/modals/web/index.d.ts.map +1 -0
- package/dist/src/ui/modals/web/index.js +3 -0
- package/dist/src/ui/modals/web/index.js.map +1 -0
- package/dist/src/ui/modals/web/install.d.ts +7 -0
- package/dist/src/ui/modals/web/install.d.ts.map +1 -0
- package/dist/src/ui/modals/web/install.js +32 -0
- package/dist/src/ui/modals/web/install.js.map +1 -0
- package/dist/src/ui/modals/web/otp.d.ts +10 -0
- package/dist/src/ui/modals/web/otp.d.ts.map +1 -0
- package/dist/src/ui/modals/web/otp.js +10 -0
- package/dist/src/ui/modals/web/otp.js.map +1 -0
- package/dist/src/ui/qr.d.ts +3 -0
- package/dist/src/ui/qr.d.ts.map +1 -0
- package/dist/src/ui/qr.js +32 -0
- package/dist/src/ui/qr.js.map +1 -0
- package/dist/types/connect-multichain.d.ts +585 -0
- package/package.json +111 -0
|
@@ -0,0 +1,2609 @@
|
|
|
1
|
+
/* Browser ES build */
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __typeError = (msg) => {
|
|
10
|
+
throw TypeError(msg);
|
|
11
|
+
};
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __esm = (fn, res) => function __init() {
|
|
26
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
27
|
+
};
|
|
28
|
+
var __export = (target, all) => {
|
|
29
|
+
for (var name in all)
|
|
30
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
31
|
+
};
|
|
32
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
33
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
34
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
35
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
36
|
+
var __async = (__this, __arguments, generator) => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var fulfilled = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.next(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var rejected = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.throw(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/domain/errors/base.ts
|
|
58
|
+
var BaseErr;
|
|
59
|
+
var init_base = __esm({
|
|
60
|
+
"src/domain/errors/base.ts"() {
|
|
61
|
+
"use strict";
|
|
62
|
+
BaseErr = class extends Error {
|
|
63
|
+
constructor(message, code) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.message = message;
|
|
66
|
+
this.code = code;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// src/domain/errors/rpc.ts
|
|
73
|
+
var _RPCHttpErr, RPCHttpErr, _RPCReadonlyResponseErr, RPCReadonlyResponseErr, _RPCReadonlyRequestErr, RPCReadonlyRequestErr, _RPCInvokeMethodErr, RPCInvokeMethodErr;
|
|
74
|
+
var init_rpc = __esm({
|
|
75
|
+
"src/domain/errors/rpc.ts"() {
|
|
76
|
+
"use strict";
|
|
77
|
+
init_base();
|
|
78
|
+
_RPCHttpErr = class _RPCHttpErr extends BaseErr {
|
|
79
|
+
constructor(rpcEndpoint, method, httpStatus) {
|
|
80
|
+
super(
|
|
81
|
+
`RPCErr${_RPCHttpErr.code}: ${httpStatus} on ${rpcEndpoint} for method ${method}`,
|
|
82
|
+
_RPCHttpErr.code
|
|
83
|
+
);
|
|
84
|
+
this.rpcEndpoint = rpcEndpoint;
|
|
85
|
+
this.method = method;
|
|
86
|
+
this.httpStatus = httpStatus;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
_RPCHttpErr.code = 50;
|
|
90
|
+
RPCHttpErr = _RPCHttpErr;
|
|
91
|
+
_RPCReadonlyResponseErr = class _RPCReadonlyResponseErr extends BaseErr {
|
|
92
|
+
constructor(reason) {
|
|
93
|
+
super(
|
|
94
|
+
`RPCErr${_RPCReadonlyResponseErr.code}: RPC Client response reason ${reason}`,
|
|
95
|
+
_RPCReadonlyResponseErr.code
|
|
96
|
+
);
|
|
97
|
+
this.reason = reason;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
_RPCReadonlyResponseErr.code = 51;
|
|
101
|
+
RPCReadonlyResponseErr = _RPCReadonlyResponseErr;
|
|
102
|
+
_RPCReadonlyRequestErr = class _RPCReadonlyRequestErr extends BaseErr {
|
|
103
|
+
constructor(reason) {
|
|
104
|
+
super(
|
|
105
|
+
`RPCErr${_RPCReadonlyRequestErr.code}: RPC Client fetch reason ${reason}`,
|
|
106
|
+
_RPCReadonlyRequestErr.code
|
|
107
|
+
);
|
|
108
|
+
this.reason = reason;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
_RPCReadonlyRequestErr.code = 52;
|
|
112
|
+
RPCReadonlyRequestErr = _RPCReadonlyRequestErr;
|
|
113
|
+
_RPCInvokeMethodErr = class _RPCInvokeMethodErr extends BaseErr {
|
|
114
|
+
constructor(reason) {
|
|
115
|
+
super(
|
|
116
|
+
`RPCErr${_RPCInvokeMethodErr.code}: RPC Client invoke method reason (${reason})`,
|
|
117
|
+
_RPCInvokeMethodErr.code
|
|
118
|
+
);
|
|
119
|
+
this.reason = reason;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
_RPCInvokeMethodErr.code = 53;
|
|
123
|
+
RPCInvokeMethodErr = _RPCInvokeMethodErr;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// src/domain/errors/index.ts
|
|
128
|
+
var init_errors = __esm({
|
|
129
|
+
"src/domain/errors/index.ts"() {
|
|
130
|
+
"use strict";
|
|
131
|
+
init_rpc();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// src/domain/events/index.ts
|
|
136
|
+
import { EventEmitter as EventEmitter3 } from "eventemitter3";
|
|
137
|
+
var _emitter, EventEmitter;
|
|
138
|
+
var init_events = __esm({
|
|
139
|
+
"src/domain/events/index.ts"() {
|
|
140
|
+
"use strict";
|
|
141
|
+
EventEmitter = class {
|
|
142
|
+
constructor() {
|
|
143
|
+
__privateAdd(this, _emitter, new EventEmitter3());
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Emits an event with the specified name and arguments.
|
|
147
|
+
*
|
|
148
|
+
* @template TEventName - The name of the event to emit (must be a key of TEvents)
|
|
149
|
+
* @param eventName - The name of the event to emit
|
|
150
|
+
* @param eventArg - The arguments to pass to the event handlers
|
|
151
|
+
*/
|
|
152
|
+
emit(eventName, ...eventArg) {
|
|
153
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Registers an event handler for the specified event.
|
|
157
|
+
*
|
|
158
|
+
* @template TEventName - The name of the event to listen for (must be a key of TEvents)
|
|
159
|
+
* @param eventName - The name of the event to listen for
|
|
160
|
+
* @param handler - The function to call when the event is emitted
|
|
161
|
+
* @returns Nothing
|
|
162
|
+
*/
|
|
163
|
+
on(eventName, handler) {
|
|
164
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
165
|
+
return () => {
|
|
166
|
+
this.off(eventName, handler);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Removes a specific event handler for the specified event.
|
|
171
|
+
*
|
|
172
|
+
* @template TEventName - The name of the event to remove the handler from (must be a key of TEvents)
|
|
173
|
+
* @param eventName - The name of the event to remove the handler from
|
|
174
|
+
* @param handler - The specific handler function to remove
|
|
175
|
+
*/
|
|
176
|
+
off(eventName, handler) {
|
|
177
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
_emitter = new WeakMap();
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// src/domain/logger/index.ts
|
|
185
|
+
import debug from "debug";
|
|
186
|
+
function isNamespaceEnabled(debugValue, namespace) {
|
|
187
|
+
return debugValue.includes(namespace) || debugValue.includes("metamask-sdk:*") || debugValue.includes("*");
|
|
188
|
+
}
|
|
189
|
+
var createLogger, enableDebug, isEnabled;
|
|
190
|
+
var init_logger = __esm({
|
|
191
|
+
"src/domain/logger/index.ts"() {
|
|
192
|
+
"use strict";
|
|
193
|
+
createLogger = (namespace = "metamask-sdk", color = "214") => {
|
|
194
|
+
const logger4 = debug(namespace);
|
|
195
|
+
logger4.color = color;
|
|
196
|
+
return logger4;
|
|
197
|
+
};
|
|
198
|
+
enableDebug = (namespace = "metamask-sdk") => {
|
|
199
|
+
debug.enable(namespace);
|
|
200
|
+
};
|
|
201
|
+
isEnabled = (namespace, storage) => __async(null, null, function* () {
|
|
202
|
+
var _a;
|
|
203
|
+
if ("process" in globalThis && ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.DEBUG)) {
|
|
204
|
+
const { DEBUG } = process.env;
|
|
205
|
+
return isNamespaceEnabled(DEBUG, namespace);
|
|
206
|
+
}
|
|
207
|
+
const storageDebug = yield storage.getDebug();
|
|
208
|
+
if (storageDebug) {
|
|
209
|
+
return isNamespaceEnabled(storageDebug, namespace);
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// src/domain/multichain/api/constants.ts
|
|
217
|
+
var infuraRpcUrls, RPC_HANDLED_METHODS, SDK_HANDLED_METHODS;
|
|
218
|
+
var init_constants = __esm({
|
|
219
|
+
"src/domain/multichain/api/constants.ts"() {
|
|
220
|
+
"use strict";
|
|
221
|
+
infuraRpcUrls = {
|
|
222
|
+
// ###### Ethereum ######
|
|
223
|
+
// Mainnet
|
|
224
|
+
"eip155:1": "https://mainnet.infura.io/v3/",
|
|
225
|
+
// Goerli
|
|
226
|
+
"eip155:5": "https://goerli.infura.io/v3/",
|
|
227
|
+
// Sepolia 11155111
|
|
228
|
+
"eip155:11155111": "https://sepolia.infura.io/v3/",
|
|
229
|
+
// ###### Linea ######
|
|
230
|
+
// Mainnet Alpha
|
|
231
|
+
"eip155:59144": "https://linea-mainnet.infura.io/v3/",
|
|
232
|
+
// Testnet ( linea goerli )
|
|
233
|
+
"eip155:59140": "https://linea-goerli.infura.io/v3/",
|
|
234
|
+
// ###### Polygon ######
|
|
235
|
+
// Mainnet
|
|
236
|
+
"eip155:137": "https://polygon-mainnet.infura.io/v3/",
|
|
237
|
+
// Mumbai
|
|
238
|
+
"eip155:80001": "https://polygon-mumbai.infura.io/v3/",
|
|
239
|
+
// ###### Optimism ######
|
|
240
|
+
// Mainnet
|
|
241
|
+
"eip155:10": "https://optimism-mainnet.infura.io/v3/",
|
|
242
|
+
// Goerli
|
|
243
|
+
"eip155:420": "https://optimism-goerli.infura.io/v3/",
|
|
244
|
+
// ###### Arbitrum ######
|
|
245
|
+
// Mainnet
|
|
246
|
+
"eip155:42161": "https://arbitrum-mainnet.infura.io/v3/",
|
|
247
|
+
// Goerli
|
|
248
|
+
"eip155:421613": "https://arbitrum-goerli.infura.io/v3/",
|
|
249
|
+
// ###### Palm ######
|
|
250
|
+
// Mainnet
|
|
251
|
+
"eip155:11297108109": "https://palm-mainnet.infura.io/v3/",
|
|
252
|
+
// Testnet
|
|
253
|
+
"eip155:11297108099": "https://palm-testnet.infura.io/v3/",
|
|
254
|
+
// ###### Avalanche C-Chain ######
|
|
255
|
+
// Mainnet
|
|
256
|
+
"eip155:43114": "https://avalanche-mainnet.infura.io/v3/",
|
|
257
|
+
// Fuji
|
|
258
|
+
"eip155:43113": "https://avalanche-fuji.infura.io/v3/",
|
|
259
|
+
// // ###### NEAR ######
|
|
260
|
+
// // Mainnet
|
|
261
|
+
// 'near:mainnet': `https://near-mainnet.infura.io/v3/`,
|
|
262
|
+
// // Testnet
|
|
263
|
+
// 'near:testnet': `https://near-testnet.infura.io/v3/`,
|
|
264
|
+
// ###### Aurora ######
|
|
265
|
+
// Mainnet
|
|
266
|
+
"eip155:1313161554": "https://aurora-mainnet.infura.io/v3/",
|
|
267
|
+
// Testnet
|
|
268
|
+
"eip155:1313161555": "https://aurora-testnet.infura.io/v3/",
|
|
269
|
+
// ###### StarkNet ######
|
|
270
|
+
// Mainnet
|
|
271
|
+
//
|
|
272
|
+
// 'starknet:SN_MAIN': `https://starknet-mainnet.infura.io/v3/`,
|
|
273
|
+
// // Goerli
|
|
274
|
+
// 'starknet:SN_GOERLI': `https://starknet-goerli.infura.io/v3/`,
|
|
275
|
+
// // Goerli 2
|
|
276
|
+
// 'starknet:SN_GOERLI2': `https://starknet-goerli2.infura.io/v3/`,
|
|
277
|
+
// ###### Celo ######
|
|
278
|
+
// Mainnet
|
|
279
|
+
"eip155:42220": "https://celo-mainnet.infura.io/v3/",
|
|
280
|
+
// Alfajores Testnet
|
|
281
|
+
"eip155:44787": "https://celo-alfajores.infura.io/v3/"
|
|
282
|
+
};
|
|
283
|
+
RPC_HANDLED_METHODS = /* @__PURE__ */ new Set([
|
|
284
|
+
"eth_blockNumber",
|
|
285
|
+
"eth_gasPrice",
|
|
286
|
+
"eth_maxPriorityFeePerGas",
|
|
287
|
+
"eth_blobBaseFee",
|
|
288
|
+
"eth_feeHistory",
|
|
289
|
+
"eth_getBalance",
|
|
290
|
+
"eth_getCode",
|
|
291
|
+
"eth_getStorageAt",
|
|
292
|
+
"eth_call",
|
|
293
|
+
"eth_estimateGas",
|
|
294
|
+
"eth_getLogs",
|
|
295
|
+
"eth_getProof",
|
|
296
|
+
"eth_getTransactionCount",
|
|
297
|
+
"eth_getBlockByNumber",
|
|
298
|
+
"eth_getBlockByHash",
|
|
299
|
+
"eth_getBlockTransactionCountByNumber",
|
|
300
|
+
"eth_getBlockTransactionCountByHash",
|
|
301
|
+
"eth_getUncleCountByBlockNumber",
|
|
302
|
+
"eth_getUncleCountByBlockHash",
|
|
303
|
+
"eth_getTransactionByHash",
|
|
304
|
+
"eth_getTransactionByBlockNumberAndIndex",
|
|
305
|
+
"eth_getTransactionByBlockHashAndIndex",
|
|
306
|
+
"eth_getTransactionReceipt",
|
|
307
|
+
"eth_getUncleByBlockNumberAndIndex",
|
|
308
|
+
"eth_getUncleByBlockHashAndIndex",
|
|
309
|
+
"eth_getFilterChanges",
|
|
310
|
+
"eth_getFilterLogs",
|
|
311
|
+
"eth_newBlockFilter",
|
|
312
|
+
"eth_newFilter",
|
|
313
|
+
"eth_newPendingTransactionFilter",
|
|
314
|
+
"eth_sendRawTransaction",
|
|
315
|
+
"eth_syncing",
|
|
316
|
+
"eth_uninstallFilter"
|
|
317
|
+
]);
|
|
318
|
+
SDK_HANDLED_METHODS = /* @__PURE__ */ new Set(["eth_accounts", "eth_chainId"]);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// src/domain/multichain/api/infura.ts
|
|
323
|
+
function getInfuraRpcUrls(infuraAPIKey) {
|
|
324
|
+
return Object.keys(infuraRpcUrls).reduce((acc, key) => {
|
|
325
|
+
const typedKey = key;
|
|
326
|
+
acc[typedKey] = `${infuraRpcUrls[typedKey]}${infuraAPIKey}`;
|
|
327
|
+
return acc;
|
|
328
|
+
}, {});
|
|
329
|
+
}
|
|
330
|
+
var init_infura = __esm({
|
|
331
|
+
"src/domain/multichain/api/infura.ts"() {
|
|
332
|
+
"use strict";
|
|
333
|
+
init_constants();
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// src/domain/multichain/index.ts
|
|
338
|
+
function getTransportType(type) {
|
|
339
|
+
switch (type) {
|
|
340
|
+
case "browser":
|
|
341
|
+
return "browser" /* Browser */;
|
|
342
|
+
case "mwp":
|
|
343
|
+
return "mwp" /* MPW */;
|
|
344
|
+
default:
|
|
345
|
+
return "unknown" /* UNKNOWN */;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
var TransportType, MultichainCore;
|
|
349
|
+
var init_multichain = __esm({
|
|
350
|
+
"src/domain/multichain/index.ts"() {
|
|
351
|
+
"use strict";
|
|
352
|
+
init_events();
|
|
353
|
+
init_constants();
|
|
354
|
+
init_infura();
|
|
355
|
+
TransportType = /* @__PURE__ */ ((TransportType2) => {
|
|
356
|
+
TransportType2["Browser"] = "browser";
|
|
357
|
+
TransportType2["MPW"] = "mwp";
|
|
358
|
+
TransportType2["UNKNOWN"] = "unknown";
|
|
359
|
+
return TransportType2;
|
|
360
|
+
})(TransportType || {});
|
|
361
|
+
MultichainCore = class extends EventEmitter {
|
|
362
|
+
constructor(options) {
|
|
363
|
+
super();
|
|
364
|
+
this.options = options;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// src/domain/platform/index.ts
|
|
371
|
+
import { parse } from "bowser";
|
|
372
|
+
function isNotBrowser() {
|
|
373
|
+
var _a;
|
|
374
|
+
if (typeof window === "undefined") {
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
if (!(window == null ? void 0 : window.navigator)) {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
if (typeof global !== "undefined" && ((_a = global == null ? void 0 : global.navigator) == null ? void 0 : _a.product) === "ReactNative") {
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
return (navigator == null ? void 0 : navigator.product) === "ReactNative";
|
|
384
|
+
}
|
|
385
|
+
function isReactNative() {
|
|
386
|
+
var _a;
|
|
387
|
+
const hasWindowNavigator = typeof window !== "undefined" && window.navigator !== void 0;
|
|
388
|
+
const nav = hasWindowNavigator ? window.navigator : void 0;
|
|
389
|
+
if (!nav) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
return hasWindowNavigator && ((_a = window.navigator) == null ? void 0 : _a.product) === "ReactNative";
|
|
393
|
+
}
|
|
394
|
+
function isMetaMaskMobileWebView() {
|
|
395
|
+
return typeof window !== "undefined" && // @ts-expect-error ReactNativeWebView should be defined
|
|
396
|
+
Boolean(window.ReactNativeWebView) && Boolean(window.navigator.userAgent.endsWith("MetaMaskMobile"));
|
|
397
|
+
}
|
|
398
|
+
function isMobile() {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
const browser = parse(window.navigator.userAgent);
|
|
401
|
+
return ((_a = browser == null ? void 0 : browser.platform) == null ? void 0 : _a.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
|
|
402
|
+
}
|
|
403
|
+
function getPlatformType() {
|
|
404
|
+
if (isReactNative()) {
|
|
405
|
+
return "react-native" /* ReactNative */;
|
|
406
|
+
}
|
|
407
|
+
if (isNotBrowser()) {
|
|
408
|
+
return "nodejs" /* NonBrowser */;
|
|
409
|
+
}
|
|
410
|
+
if (isMetaMaskMobileWebView()) {
|
|
411
|
+
return "in-app-browser" /* MetaMaskMobileWebview */;
|
|
412
|
+
}
|
|
413
|
+
if (isMobile()) {
|
|
414
|
+
return "web-mobile" /* MobileWeb */;
|
|
415
|
+
}
|
|
416
|
+
return "web-desktop" /* DesktopWeb */;
|
|
417
|
+
}
|
|
418
|
+
function isMetamaskExtensionInstalled() {
|
|
419
|
+
var _a;
|
|
420
|
+
if (typeof window === "undefined") {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
return Boolean((_a = window.ethereum) == null ? void 0 : _a.isMetaMask);
|
|
424
|
+
}
|
|
425
|
+
function isSecure() {
|
|
426
|
+
const platformType = getPlatformType();
|
|
427
|
+
return isReactNative() || platformType === "web-mobile" /* MobileWeb */;
|
|
428
|
+
}
|
|
429
|
+
function hasExtension() {
|
|
430
|
+
return __async(this, null, function* () {
|
|
431
|
+
return detectionPromise;
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
var PlatformType, detectionPromise;
|
|
435
|
+
var init_platform = __esm({
|
|
436
|
+
"src/domain/platform/index.ts"() {
|
|
437
|
+
"use strict";
|
|
438
|
+
PlatformType = /* @__PURE__ */ ((PlatformType2) => {
|
|
439
|
+
PlatformType2["NonBrowser"] = "nodejs";
|
|
440
|
+
PlatformType2["MetaMaskMobileWebview"] = "in-app-browser";
|
|
441
|
+
PlatformType2["DesktopWeb"] = "web-desktop";
|
|
442
|
+
PlatformType2["MobileWeb"] = "web-mobile";
|
|
443
|
+
PlatformType2["ReactNative"] = "react-native";
|
|
444
|
+
return PlatformType2;
|
|
445
|
+
})(PlatformType || {});
|
|
446
|
+
detectionPromise = (() => __async(null, null, function* () {
|
|
447
|
+
const pt = getPlatformType();
|
|
448
|
+
if (pt === "nodejs" /* NonBrowser */ || pt === "react-native" /* ReactNative */) {
|
|
449
|
+
return Promise.resolve(false);
|
|
450
|
+
}
|
|
451
|
+
return new Promise((resolve) => {
|
|
452
|
+
const providers = [];
|
|
453
|
+
const handler = (event) => {
|
|
454
|
+
var _a, _b;
|
|
455
|
+
if ((_b = (_a = event == null ? void 0 : event.detail) == null ? void 0 : _a.info) == null ? void 0 : _b.rdns) {
|
|
456
|
+
providers.push(event.detail);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
window.addEventListener("eip6963:announceProvider", handler);
|
|
460
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
461
|
+
setTimeout(() => {
|
|
462
|
+
window.removeEventListener("eip6963:announceProvider", handler);
|
|
463
|
+
const hasMetaMask = providers.some(
|
|
464
|
+
(provider) => {
|
|
465
|
+
var _a;
|
|
466
|
+
return ((_a = provider == null ? void 0 : provider.info) == null ? void 0 : _a.rdns) === "io.metamask";
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
resolve(hasMetaMask);
|
|
470
|
+
}, 300);
|
|
471
|
+
});
|
|
472
|
+
}))();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// src/domain/store/adapter.ts
|
|
477
|
+
var StoreAdapter;
|
|
478
|
+
var init_adapter = __esm({
|
|
479
|
+
"src/domain/store/adapter.ts"() {
|
|
480
|
+
"use strict";
|
|
481
|
+
StoreAdapter = class {
|
|
482
|
+
constructor(options) {
|
|
483
|
+
this.options = options;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
// src/domain/store/client.ts
|
|
490
|
+
var StoreClient;
|
|
491
|
+
var init_client = __esm({
|
|
492
|
+
"src/domain/store/client.ts"() {
|
|
493
|
+
"use strict";
|
|
494
|
+
StoreClient = class {
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// src/domain/store/index.ts
|
|
500
|
+
var init_store = __esm({
|
|
501
|
+
"src/domain/store/index.ts"() {
|
|
502
|
+
"use strict";
|
|
503
|
+
init_adapter();
|
|
504
|
+
init_client();
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// src/domain/ui/types.ts
|
|
509
|
+
var Modal;
|
|
510
|
+
var init_types = __esm({
|
|
511
|
+
"src/domain/ui/types.ts"() {
|
|
512
|
+
"use strict";
|
|
513
|
+
Modal = class {
|
|
514
|
+
// eslint-disable-next-line @typescript-eslint/parameter-properties
|
|
515
|
+
constructor(options) {
|
|
516
|
+
this.options = options;
|
|
517
|
+
}
|
|
518
|
+
get isMounted() {
|
|
519
|
+
return this.instance !== void 0;
|
|
520
|
+
}
|
|
521
|
+
get data() {
|
|
522
|
+
if (typeof this.options === "object" && this.options && "link" in this.options) {
|
|
523
|
+
return this.options.link;
|
|
524
|
+
}
|
|
525
|
+
if (typeof this.options === "object" && this.options && "otpCode" in this.options) {
|
|
526
|
+
return this.options.otpCode;
|
|
527
|
+
}
|
|
528
|
+
throw new Error("Invalid options");
|
|
529
|
+
}
|
|
530
|
+
set data(data) {
|
|
531
|
+
if (typeof this.options === "object" && this.options && "link" in this.options) {
|
|
532
|
+
this.options.link = data;
|
|
533
|
+
}
|
|
534
|
+
if (typeof this.options === "object" && this.options && "otpCode" in this.options) {
|
|
535
|
+
this.options.otpCode = data;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// src/domain/ui/index.ts
|
|
543
|
+
var init_ui = __esm({
|
|
544
|
+
"src/domain/ui/index.ts"() {
|
|
545
|
+
"use strict";
|
|
546
|
+
init_types();
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
// src/domain/utils/index.ts
|
|
551
|
+
function getVersion() {
|
|
552
|
+
return "0.0.0";
|
|
553
|
+
}
|
|
554
|
+
var init_utils = __esm({
|
|
555
|
+
"src/domain/utils/index.ts"() {
|
|
556
|
+
"use strict";
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
// src/domain/index.ts
|
|
561
|
+
var init_domain = __esm({
|
|
562
|
+
"src/domain/index.ts"() {
|
|
563
|
+
"use strict";
|
|
564
|
+
init_errors();
|
|
565
|
+
init_events();
|
|
566
|
+
init_logger();
|
|
567
|
+
init_multichain();
|
|
568
|
+
init_platform();
|
|
569
|
+
init_store();
|
|
570
|
+
init_ui();
|
|
571
|
+
init_utils();
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
// src/ui/modals/base/utils.ts
|
|
576
|
+
function formatRemainingTime(milliseconds) {
|
|
577
|
+
if (milliseconds <= 0) return "EXPIRED";
|
|
578
|
+
const seconds = Math.floor(milliseconds / 1e3);
|
|
579
|
+
return `${seconds}s`;
|
|
580
|
+
}
|
|
581
|
+
function shouldLogCountdown(remainingSeconds) {
|
|
582
|
+
if (remainingSeconds <= 10) {
|
|
583
|
+
return true;
|
|
584
|
+
} else if (remainingSeconds <= 30) {
|
|
585
|
+
return remainingSeconds % 5 === 0;
|
|
586
|
+
} else if (remainingSeconds <= 60) {
|
|
587
|
+
return remainingSeconds % 10 === 0;
|
|
588
|
+
} else if (remainingSeconds <= 300) {
|
|
589
|
+
return remainingSeconds % 30 === 0;
|
|
590
|
+
} else {
|
|
591
|
+
return remainingSeconds % 60 === 0;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
var init_utils2 = __esm({
|
|
595
|
+
"src/ui/modals/base/utils.ts"() {
|
|
596
|
+
"use strict";
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// src/ui/modals/base/AbstractInstallModal.ts
|
|
601
|
+
var logger3, AbstractInstallModal;
|
|
602
|
+
var init_AbstractInstallModal = __esm({
|
|
603
|
+
"src/ui/modals/base/AbstractInstallModal.ts"() {
|
|
604
|
+
"use strict";
|
|
605
|
+
init_domain();
|
|
606
|
+
init_utils2();
|
|
607
|
+
logger3 = createLogger("metamask-sdk:ui");
|
|
608
|
+
AbstractInstallModal = class extends Modal {
|
|
609
|
+
constructor() {
|
|
610
|
+
super(...arguments);
|
|
611
|
+
this.expirationInterval = null;
|
|
612
|
+
this.lastLoggedCountdown = -1;
|
|
613
|
+
}
|
|
614
|
+
get link() {
|
|
615
|
+
return this.data;
|
|
616
|
+
}
|
|
617
|
+
set link(link) {
|
|
618
|
+
this.data = link;
|
|
619
|
+
}
|
|
620
|
+
get connectionRequest() {
|
|
621
|
+
return this.options.connectionRequest;
|
|
622
|
+
}
|
|
623
|
+
set connectionRequest(connectionRequest) {
|
|
624
|
+
this.options.connectionRequest = connectionRequest;
|
|
625
|
+
}
|
|
626
|
+
updateLink(link) {
|
|
627
|
+
this.link = link;
|
|
628
|
+
if (this.instance) {
|
|
629
|
+
this.instance.link = link;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
updateExpiresIn(expiresIn) {
|
|
633
|
+
if (expiresIn >= 0 && this.instance) {
|
|
634
|
+
this.instance.expiresIn = expiresIn;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
startExpirationCheck(connectionRequest) {
|
|
638
|
+
this.stopExpirationCheck();
|
|
639
|
+
let currentConnectionRequest = connectionRequest;
|
|
640
|
+
this.expirationInterval = setInterval(() => __async(this, null, function* () {
|
|
641
|
+
const { sessionRequest } = currentConnectionRequest;
|
|
642
|
+
const now = Date.now();
|
|
643
|
+
const remainingMs = sessionRequest.expiresAt - now;
|
|
644
|
+
const remainingSeconds = Math.floor(remainingMs / 1e3);
|
|
645
|
+
if (remainingMs > 0 && shouldLogCountdown(remainingSeconds) && this.lastLoggedCountdown !== remainingSeconds) {
|
|
646
|
+
const formattedTime = formatRemainingTime(remainingMs);
|
|
647
|
+
logger3(
|
|
648
|
+
`[UI: InstallModal-nodejs()] QR code expires in: ${formattedTime} (${remainingSeconds}s)`
|
|
649
|
+
);
|
|
650
|
+
this.lastLoggedCountdown = remainingSeconds;
|
|
651
|
+
}
|
|
652
|
+
if (now >= sessionRequest.expiresAt) {
|
|
653
|
+
this.stopExpirationCheck();
|
|
654
|
+
logger3(
|
|
655
|
+
"[UI: InstallModal-nodejs()] \u23F0 QR code EXPIRED! Generating new one..."
|
|
656
|
+
);
|
|
657
|
+
try {
|
|
658
|
+
currentConnectionRequest = yield this.options.createConnectionRequest();
|
|
659
|
+
const generateQRCode = yield this.options.generateQRCode(
|
|
660
|
+
currentConnectionRequest
|
|
661
|
+
);
|
|
662
|
+
this.lastLoggedCountdown = -1;
|
|
663
|
+
this.updateLink(generateQRCode);
|
|
664
|
+
this.updateExpiresIn(remainingSeconds);
|
|
665
|
+
this.renderQRCode(generateQRCode, currentConnectionRequest);
|
|
666
|
+
} catch (error) {
|
|
667
|
+
logger3(
|
|
668
|
+
`[UI: InstallModal-nodejs()] \u274C Error generating new QR code: ${error}`
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
} else {
|
|
672
|
+
const generateQRCode = yield this.options.generateQRCode(
|
|
673
|
+
currentConnectionRequest
|
|
674
|
+
);
|
|
675
|
+
this.renderQRCode(generateQRCode, currentConnectionRequest);
|
|
676
|
+
}
|
|
677
|
+
}), 1e3);
|
|
678
|
+
}
|
|
679
|
+
stopExpirationCheck() {
|
|
680
|
+
if (this.expirationInterval) {
|
|
681
|
+
clearInterval(this.expirationInterval);
|
|
682
|
+
this.expirationInterval = null;
|
|
683
|
+
logger3(
|
|
684
|
+
"[UI: InstallModal-nodejs()] \u{1F6D1} Stopped QR code expiration checking"
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
// src/ui/modals/web/install.ts
|
|
693
|
+
var InstallModal;
|
|
694
|
+
var init_install = __esm({
|
|
695
|
+
"src/ui/modals/web/install.ts"() {
|
|
696
|
+
"use strict";
|
|
697
|
+
init_AbstractInstallModal();
|
|
698
|
+
InstallModal = class extends AbstractInstallModal {
|
|
699
|
+
renderQRCode() {
|
|
700
|
+
}
|
|
701
|
+
mount() {
|
|
702
|
+
var _a;
|
|
703
|
+
const { options } = this;
|
|
704
|
+
const modal = document.createElement(
|
|
705
|
+
"mm-install-modal"
|
|
706
|
+
);
|
|
707
|
+
modal.preferDesktop = options.preferDesktop;
|
|
708
|
+
modal.sdkVersion = options.sdkVersion;
|
|
709
|
+
modal.addEventListener("close", (ev) => {
|
|
710
|
+
const { detail } = ev;
|
|
711
|
+
options.onClose(detail == null ? void 0 : detail.shouldTerminate);
|
|
712
|
+
});
|
|
713
|
+
modal.addEventListener(
|
|
714
|
+
"startDesktopOnboarding",
|
|
715
|
+
options.startDesktopOnboarding
|
|
716
|
+
);
|
|
717
|
+
modal.link = options.link;
|
|
718
|
+
this.instance = modal;
|
|
719
|
+
(_a = options.parentElement) == null ? void 0 : _a.appendChild(modal);
|
|
720
|
+
this.startExpirationCheck(options.connectionRequest);
|
|
721
|
+
}
|
|
722
|
+
unmount() {
|
|
723
|
+
var _a;
|
|
724
|
+
const { options, instance: modal } = this;
|
|
725
|
+
this.stopExpirationCheck();
|
|
726
|
+
if (modal && ((_a = options.parentElement) == null ? void 0 : _a.contains(modal))) {
|
|
727
|
+
options.parentElement.removeChild(modal);
|
|
728
|
+
this.instance = void 0;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
// src/ui/modals/base/AbstractOTPModal.ts
|
|
736
|
+
var AbstractOTPCodeModal;
|
|
737
|
+
var init_AbstractOTPModal = __esm({
|
|
738
|
+
"src/ui/modals/base/AbstractOTPModal.ts"() {
|
|
739
|
+
"use strict";
|
|
740
|
+
init_domain();
|
|
741
|
+
AbstractOTPCodeModal = class extends Modal {
|
|
742
|
+
get otpCode() {
|
|
743
|
+
return this.data;
|
|
744
|
+
}
|
|
745
|
+
set otpCode(code) {
|
|
746
|
+
this.data = code;
|
|
747
|
+
}
|
|
748
|
+
updateOTPCode(code) {
|
|
749
|
+
this.otpCode = code;
|
|
750
|
+
if (this.instance) {
|
|
751
|
+
this.instance.otpCode = code;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// src/ui/modals/web/otp.ts
|
|
759
|
+
var OTPCodeModal;
|
|
760
|
+
var init_otp = __esm({
|
|
761
|
+
"src/ui/modals/web/otp.ts"() {
|
|
762
|
+
"use strict";
|
|
763
|
+
init_AbstractOTPModal();
|
|
764
|
+
OTPCodeModal = class extends AbstractOTPCodeModal {
|
|
765
|
+
mount() {
|
|
766
|
+
}
|
|
767
|
+
unmount() {
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
// src/ui/modals/web/index.ts
|
|
774
|
+
var web_exports = {};
|
|
775
|
+
__export(web_exports, {
|
|
776
|
+
InstallModal: () => InstallModal,
|
|
777
|
+
OTPCodeModal: () => OTPCodeModal
|
|
778
|
+
});
|
|
779
|
+
var init_web = __esm({
|
|
780
|
+
"src/ui/modals/web/index.ts"() {
|
|
781
|
+
"use strict";
|
|
782
|
+
init_install();
|
|
783
|
+
init_otp();
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
// src/store/adapters/web.ts
|
|
788
|
+
var web_exports2 = {};
|
|
789
|
+
__export(web_exports2, {
|
|
790
|
+
StoreAdapterWeb: () => StoreAdapterWeb
|
|
791
|
+
});
|
|
792
|
+
var _StoreAdapterWeb, StoreAdapterWeb;
|
|
793
|
+
var init_web2 = __esm({
|
|
794
|
+
"src/store/adapters/web.ts"() {
|
|
795
|
+
"use strict";
|
|
796
|
+
init_domain();
|
|
797
|
+
_StoreAdapterWeb = class _StoreAdapterWeb extends StoreAdapter {
|
|
798
|
+
constructor(dbNameSuffix = "-kv-store", storeName = _StoreAdapterWeb.stores[0]) {
|
|
799
|
+
super();
|
|
800
|
+
this.storeName = storeName;
|
|
801
|
+
this.platform = "web";
|
|
802
|
+
const dbName = `${_StoreAdapterWeb.DB_NAME}${dbNameSuffix}`;
|
|
803
|
+
this.dbPromise = new Promise((resolve, reject) => {
|
|
804
|
+
try {
|
|
805
|
+
const request = this.internal.open(dbName, 1);
|
|
806
|
+
request.onerror = () => reject(new Error("Failed to open IndexedDB."));
|
|
807
|
+
request.onsuccess = () => resolve(request.result);
|
|
808
|
+
request.onupgradeneeded = () => {
|
|
809
|
+
const db = request.result;
|
|
810
|
+
for (const name of _StoreAdapterWeb.stores) {
|
|
811
|
+
if (!db.objectStoreNames.contains(name)) {
|
|
812
|
+
db.createObjectStore(name);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
} catch (error) {
|
|
817
|
+
reject(error);
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
get internal() {
|
|
822
|
+
if (typeof window === "undefined" || !window.indexedDB) {
|
|
823
|
+
throw new Error("indexedDB is not available in this environment");
|
|
824
|
+
}
|
|
825
|
+
return window.indexedDB;
|
|
826
|
+
}
|
|
827
|
+
get(key) {
|
|
828
|
+
return __async(this, null, function* () {
|
|
829
|
+
const { storeName } = this;
|
|
830
|
+
const db = yield this.dbPromise;
|
|
831
|
+
return new Promise((resolve, reject) => {
|
|
832
|
+
try {
|
|
833
|
+
const tx = db.transaction(storeName, "readonly");
|
|
834
|
+
const store = tx.objectStore(storeName);
|
|
835
|
+
const request = store.get(key);
|
|
836
|
+
request.onerror = () => reject(new Error("Failed to get value from IndexedDB."));
|
|
837
|
+
request.onsuccess = () => {
|
|
838
|
+
var _a;
|
|
839
|
+
return resolve((_a = request.result) != null ? _a : null);
|
|
840
|
+
};
|
|
841
|
+
} catch (error) {
|
|
842
|
+
reject(error);
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
set(key, value) {
|
|
848
|
+
return __async(this, null, function* () {
|
|
849
|
+
const { storeName } = this;
|
|
850
|
+
const db = yield this.dbPromise;
|
|
851
|
+
return new Promise((resolve, reject) => {
|
|
852
|
+
try {
|
|
853
|
+
const tx = db.transaction(storeName, "readwrite");
|
|
854
|
+
const store = tx.objectStore(storeName);
|
|
855
|
+
const request = store.put(value, key);
|
|
856
|
+
request.onerror = () => reject(new Error("Failed to set value in IndexedDB."));
|
|
857
|
+
request.onsuccess = () => resolve();
|
|
858
|
+
} catch (error) {
|
|
859
|
+
reject(error);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
delete(key) {
|
|
865
|
+
return __async(this, null, function* () {
|
|
866
|
+
const { storeName } = this;
|
|
867
|
+
const db = yield this.dbPromise;
|
|
868
|
+
return new Promise((resolve, reject) => {
|
|
869
|
+
try {
|
|
870
|
+
const tx = db.transaction(storeName, "readwrite");
|
|
871
|
+
const store = tx.objectStore(storeName);
|
|
872
|
+
const request = store.delete(key);
|
|
873
|
+
request.onerror = () => reject(new Error("Failed to delete value from IndexedDB."));
|
|
874
|
+
request.onsuccess = () => resolve();
|
|
875
|
+
} catch (error) {
|
|
876
|
+
reject(error);
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
_StoreAdapterWeb.stores = ["sdk-kv-store", "key-value-pairs"];
|
|
883
|
+
_StoreAdapterWeb.DB_NAME = "mmsdk";
|
|
884
|
+
StoreAdapterWeb = _StoreAdapterWeb;
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
// src/multichain/index.ts
|
|
889
|
+
import { analytics } from "@metamask/analytics";
|
|
890
|
+
import {
|
|
891
|
+
ErrorCode,
|
|
892
|
+
ProtocolError,
|
|
893
|
+
SessionStore as SessionStore2,
|
|
894
|
+
WebSocketTransport
|
|
895
|
+
} from "@metamask/mobile-wallet-protocol-core";
|
|
896
|
+
import { DappClient } from "@metamask/mobile-wallet-protocol-dapp-client";
|
|
897
|
+
import {
|
|
898
|
+
getMultichainClient
|
|
899
|
+
} from "@metamask/multichain-api-client";
|
|
900
|
+
|
|
901
|
+
// src/config/index.ts
|
|
902
|
+
var MWP_RELAY_URL = "wss://mm-sdk-relay.api.cx.metamask.io/connection/websocket";
|
|
903
|
+
var METAMASK_CONNECT_BASE_URL = "https://metamask.app.link/connect";
|
|
904
|
+
var METAMASK_DEEPLINK_BASE = "metamask://connect";
|
|
905
|
+
|
|
906
|
+
// src/multichain/index.ts
|
|
907
|
+
init_domain();
|
|
908
|
+
init_logger();
|
|
909
|
+
init_multichain();
|
|
910
|
+
init_platform();
|
|
911
|
+
|
|
912
|
+
// src/multichain/rpc/requestRouter.ts
|
|
913
|
+
init_domain();
|
|
914
|
+
|
|
915
|
+
// src/multichain/utils/index.ts
|
|
916
|
+
init_domain();
|
|
917
|
+
import { deflate } from "pako";
|
|
918
|
+
import {
|
|
919
|
+
parseCaipAccountId,
|
|
920
|
+
parseCaipChainId
|
|
921
|
+
} from "@metamask/utils";
|
|
922
|
+
function base64Encode(str) {
|
|
923
|
+
if (typeof btoa !== "undefined") {
|
|
924
|
+
return btoa(str);
|
|
925
|
+
} else if (typeof Buffer !== "undefined") {
|
|
926
|
+
return Buffer.from(str).toString("base64");
|
|
927
|
+
}
|
|
928
|
+
throw new Error("No base64 encoding method available");
|
|
929
|
+
}
|
|
930
|
+
function compressString(str) {
|
|
931
|
+
const compressed = deflate(str);
|
|
932
|
+
const binaryString = String.fromCharCode.apply(null, Array.from(compressed));
|
|
933
|
+
return base64Encode(binaryString);
|
|
934
|
+
}
|
|
935
|
+
function getDappId(dapp) {
|
|
936
|
+
var _a, _b;
|
|
937
|
+
if (typeof window === "undefined" || typeof window.location === "undefined") {
|
|
938
|
+
return (_b = (_a = dapp == null ? void 0 : dapp.name) != null ? _a : dapp == null ? void 0 : dapp.url) != null ? _b : "N/A";
|
|
939
|
+
}
|
|
940
|
+
return window.location.hostname;
|
|
941
|
+
}
|
|
942
|
+
function openDeeplink(options, deeplink, universalLink) {
|
|
943
|
+
const { mobile } = options;
|
|
944
|
+
const useDeeplink = mobile && mobile.useDeeplink !== void 0 ? mobile.useDeeplink : true;
|
|
945
|
+
if (useDeeplink) {
|
|
946
|
+
if (typeof window !== "undefined") {
|
|
947
|
+
window.location.href = deeplink;
|
|
948
|
+
}
|
|
949
|
+
} else if (typeof document !== "undefined") {
|
|
950
|
+
const link = document.createElement("a");
|
|
951
|
+
link.href = universalLink;
|
|
952
|
+
link.target = "_self";
|
|
953
|
+
link.rel = "noreferrer noopener";
|
|
954
|
+
link.click();
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function getOptionalScopes(scopes) {
|
|
958
|
+
return scopes.reduce(
|
|
959
|
+
(prev, scope) => __spreadProps(__spreadValues({}, prev), {
|
|
960
|
+
[scope]: {
|
|
961
|
+
methods: [],
|
|
962
|
+
notifications: [],
|
|
963
|
+
accounts: []
|
|
964
|
+
}
|
|
965
|
+
}),
|
|
966
|
+
{}
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
var extractFavicon = () => {
|
|
970
|
+
var _a;
|
|
971
|
+
if (typeof document === "undefined") {
|
|
972
|
+
return void 0;
|
|
973
|
+
}
|
|
974
|
+
let favicon;
|
|
975
|
+
const nodeList = document.getElementsByTagName("link");
|
|
976
|
+
for (let i = 0; i < nodeList.length; i++) {
|
|
977
|
+
if (nodeList[i].getAttribute("rel") === "icon" || nodeList[i].getAttribute("rel") === "shortcut icon") {
|
|
978
|
+
favicon = (_a = nodeList[i].getAttribute("href")) != null ? _a : void 0;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
return favicon;
|
|
982
|
+
};
|
|
983
|
+
function setupInfuraProvider(options) {
|
|
984
|
+
var _a, _b;
|
|
985
|
+
const infuraAPIKey = (_a = options.api) == null ? void 0 : _a.infuraAPIKey;
|
|
986
|
+
if (!infuraAPIKey) {
|
|
987
|
+
return options;
|
|
988
|
+
}
|
|
989
|
+
const urlsWithToken = getInfuraRpcUrls(infuraAPIKey);
|
|
990
|
+
if ((_b = options.api) == null ? void 0 : _b.readonlyRPCMap) {
|
|
991
|
+
options.api.readonlyRPCMap = __spreadValues(__spreadValues({}, options.api.readonlyRPCMap), urlsWithToken);
|
|
992
|
+
} else if (options.api) {
|
|
993
|
+
options.api.readonlyRPCMap = urlsWithToken;
|
|
994
|
+
}
|
|
995
|
+
return options;
|
|
996
|
+
}
|
|
997
|
+
function setupDappMetadata(options) {
|
|
998
|
+
var _a;
|
|
999
|
+
const platform = getPlatformType();
|
|
1000
|
+
const isBrowser = platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */ || platform === "in-app-browser" /* MetaMaskMobileWebview */;
|
|
1001
|
+
if (!((_a = options.dapp) == null ? void 0 : _a.url)) {
|
|
1002
|
+
if (isBrowser) {
|
|
1003
|
+
options.dapp = __spreadProps(__spreadValues({}, options.dapp), {
|
|
1004
|
+
url: `${window.location.protocol}//${window.location.host}`
|
|
1005
|
+
});
|
|
1006
|
+
} else {
|
|
1007
|
+
throw new Error("You must provide dapp url");
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
const BASE_64_ICON_MAX_LENGTH = 163400;
|
|
1011
|
+
const urlPattern = /^(http|https):\/\/[^\s]*$/;
|
|
1012
|
+
if (options.dapp) {
|
|
1013
|
+
if ("iconUrl" in options.dapp) {
|
|
1014
|
+
if (options.dapp.iconUrl && !urlPattern.test(options.dapp.iconUrl)) {
|
|
1015
|
+
console.warn(
|
|
1016
|
+
"Invalid dappMetadata.iconUrl: URL must start with http:// or https://"
|
|
1017
|
+
);
|
|
1018
|
+
options.dapp.iconUrl = void 0;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if ("base64Icon" in options.dapp) {
|
|
1022
|
+
if (options.dapp.base64Icon && options.dapp.base64Icon.length > BASE_64_ICON_MAX_LENGTH) {
|
|
1023
|
+
console.warn(
|
|
1024
|
+
"Invalid dappMetadata.base64Icon: Base64-encoded icon string length must be less than 163400 characters"
|
|
1025
|
+
);
|
|
1026
|
+
options.dapp.base64Icon = void 0;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if (options.dapp.url && !urlPattern.test(options.dapp.url)) {
|
|
1030
|
+
console.warn(
|
|
1031
|
+
"Invalid dappMetadata.url: URL must start with http:// or https://"
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
const favicon = extractFavicon();
|
|
1035
|
+
if (favicon && !("iconUrl" in options.dapp) && !("base64Icon" in options.dapp)) {
|
|
1036
|
+
const faviconUrl = `${window.location.protocol}//${window.location.host}${favicon}`;
|
|
1037
|
+
options.dapp.iconUrl = faviconUrl;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
return options;
|
|
1041
|
+
}
|
|
1042
|
+
function isSameScopesAndAccounts(currentScopes, proposedScopes, walletSession, proposedCaipAccountIds) {
|
|
1043
|
+
const isSameScopes = currentScopes.every((scope) => proposedScopes.includes(scope)) && proposedScopes.every((scope) => currentScopes.includes(scope));
|
|
1044
|
+
if (!isSameScopes) {
|
|
1045
|
+
return false;
|
|
1046
|
+
}
|
|
1047
|
+
const existingAccountIds = Object.values(
|
|
1048
|
+
walletSession.sessionScopes
|
|
1049
|
+
).filter(({ accounts }) => Boolean(accounts)).flatMap(({ accounts }) => accounts != null ? accounts : []);
|
|
1050
|
+
const allProposedAccountsIncluded = proposedCaipAccountIds.every(
|
|
1051
|
+
(proposedAccountId) => existingAccountIds.includes(proposedAccountId)
|
|
1052
|
+
);
|
|
1053
|
+
return allProposedAccountsIncluded;
|
|
1054
|
+
}
|
|
1055
|
+
function getValidAccounts(caipAccountIds) {
|
|
1056
|
+
return caipAccountIds.reduce(
|
|
1057
|
+
(caipAccounts, caipAccountId) => {
|
|
1058
|
+
try {
|
|
1059
|
+
return [...caipAccounts, parseCaipAccountId(caipAccountId)];
|
|
1060
|
+
} catch (err) {
|
|
1061
|
+
const stringifiedAccountId = JSON.stringify(caipAccountId);
|
|
1062
|
+
console.error(`Invalid CAIP account ID: ${stringifiedAccountId}`, err);
|
|
1063
|
+
return caipAccounts;
|
|
1064
|
+
}
|
|
1065
|
+
},
|
|
1066
|
+
[]
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
function addValidAccounts(optionalScopes, validAccounts) {
|
|
1070
|
+
var _a;
|
|
1071
|
+
if (!optionalScopes || !(validAccounts == null ? void 0 : validAccounts.length)) {
|
|
1072
|
+
return optionalScopes;
|
|
1073
|
+
}
|
|
1074
|
+
const result = Object.fromEntries(
|
|
1075
|
+
Object.entries(optionalScopes).map(([scope, scopeData]) => {
|
|
1076
|
+
var _a2, _b, _c;
|
|
1077
|
+
return [
|
|
1078
|
+
scope,
|
|
1079
|
+
{
|
|
1080
|
+
methods: [...(_a2 = scopeData == null ? void 0 : scopeData.methods) != null ? _a2 : []],
|
|
1081
|
+
notifications: [...(_b = scopeData == null ? void 0 : scopeData.notifications) != null ? _b : []],
|
|
1082
|
+
accounts: [...(_c = scopeData == null ? void 0 : scopeData.accounts) != null ? _c : []]
|
|
1083
|
+
}
|
|
1084
|
+
];
|
|
1085
|
+
})
|
|
1086
|
+
);
|
|
1087
|
+
const accountsByChain = /* @__PURE__ */ new Map();
|
|
1088
|
+
for (const account of validAccounts) {
|
|
1089
|
+
const chainKey = `${account.chain.namespace}:${account.chain.reference}`;
|
|
1090
|
+
const accountId = `${account.chainId}:${account.address}`;
|
|
1091
|
+
if (!accountsByChain.has(chainKey)) {
|
|
1092
|
+
accountsByChain.set(chainKey, []);
|
|
1093
|
+
}
|
|
1094
|
+
(_a = accountsByChain.get(chainKey)) == null ? void 0 : _a.push(accountId);
|
|
1095
|
+
}
|
|
1096
|
+
for (const [scopeKey, scopeData] of Object.entries(result)) {
|
|
1097
|
+
if (!(scopeData == null ? void 0 : scopeData.accounts)) {
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
try {
|
|
1101
|
+
const scope = scopeKey;
|
|
1102
|
+
const scopeDetails = parseCaipChainId(scope);
|
|
1103
|
+
const chainKey = `${scopeDetails.namespace}:${scopeDetails.reference}`;
|
|
1104
|
+
const matchingAccounts = accountsByChain.get(chainKey);
|
|
1105
|
+
if (matchingAccounts) {
|
|
1106
|
+
const existingAccounts = new Set(scopeData.accounts);
|
|
1107
|
+
const newAccounts = matchingAccounts.filter(
|
|
1108
|
+
(account) => !existingAccounts.has(account)
|
|
1109
|
+
);
|
|
1110
|
+
scopeData.accounts.push(...newAccounts);
|
|
1111
|
+
}
|
|
1112
|
+
} catch (error) {
|
|
1113
|
+
console.error(`Invalid scope format: ${scopeKey}`, error);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return result;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/multichain/rpc/handlers/rpcClient.ts
|
|
1120
|
+
init_domain();
|
|
1121
|
+
import fetch from "cross-fetch";
|
|
1122
|
+
var rpcId = 1;
|
|
1123
|
+
function getNextRpcId() {
|
|
1124
|
+
rpcId += 1;
|
|
1125
|
+
return rpcId;
|
|
1126
|
+
}
|
|
1127
|
+
var MissingRpcEndpointErr = class extends Error {
|
|
1128
|
+
};
|
|
1129
|
+
var RpcClient = class {
|
|
1130
|
+
constructor(config, sdkInfo) {
|
|
1131
|
+
this.config = config;
|
|
1132
|
+
this.sdkInfo = sdkInfo;
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Routes the request to a configured RPC node.
|
|
1136
|
+
*/
|
|
1137
|
+
request(options) {
|
|
1138
|
+
return __async(this, null, function* () {
|
|
1139
|
+
const { request } = options;
|
|
1140
|
+
const body = JSON.stringify({
|
|
1141
|
+
jsonrpc: "2.0",
|
|
1142
|
+
method: request.method,
|
|
1143
|
+
params: request.params,
|
|
1144
|
+
id: getNextRpcId()
|
|
1145
|
+
});
|
|
1146
|
+
const rpcEndpoint = this.getRpcEndpoint(options.scope);
|
|
1147
|
+
const rpcRequest = yield this.fetch(rpcEndpoint, body, "POST", this.getHeaders(rpcEndpoint));
|
|
1148
|
+
const response = yield this.parseResponse(rpcRequest);
|
|
1149
|
+
return response;
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
getRpcEndpoint(scope) {
|
|
1153
|
+
var _a, _b, _c, _d, _e;
|
|
1154
|
+
let infuraAPIKey = (_b = (_a = this.config) == null ? void 0 : _a.api) == null ? void 0 : _b.infuraAPIKey;
|
|
1155
|
+
let readonlyRPCMap = (_e = (_d = (_c = this.config) == null ? void 0 : _c.api) == null ? void 0 : _d.readonlyRPCMap) != null ? _e : {};
|
|
1156
|
+
if (infuraAPIKey) {
|
|
1157
|
+
const urlsWithToken = getInfuraRpcUrls(infuraAPIKey);
|
|
1158
|
+
if (readonlyRPCMap) {
|
|
1159
|
+
readonlyRPCMap = __spreadValues(__spreadValues({}, urlsWithToken), readonlyRPCMap);
|
|
1160
|
+
} else {
|
|
1161
|
+
readonlyRPCMap = urlsWithToken;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
const rpcEndpoint = readonlyRPCMap[scope];
|
|
1165
|
+
if (!rpcEndpoint) {
|
|
1166
|
+
throw new MissingRpcEndpointErr(`No RPC endpoint found for scope ${scope}`);
|
|
1167
|
+
}
|
|
1168
|
+
return rpcEndpoint;
|
|
1169
|
+
}
|
|
1170
|
+
fetch(endpoint, body, method, headers) {
|
|
1171
|
+
return __async(this, null, function* () {
|
|
1172
|
+
try {
|
|
1173
|
+
const response = yield fetch(endpoint, {
|
|
1174
|
+
method,
|
|
1175
|
+
headers,
|
|
1176
|
+
body
|
|
1177
|
+
});
|
|
1178
|
+
if (!response.ok) {
|
|
1179
|
+
throw new RPCHttpErr(endpoint, method, response.status);
|
|
1180
|
+
}
|
|
1181
|
+
return response;
|
|
1182
|
+
} catch (error) {
|
|
1183
|
+
if (error instanceof RPCHttpErr) {
|
|
1184
|
+
throw error;
|
|
1185
|
+
}
|
|
1186
|
+
throw new RPCReadonlyRequestErr(error.message);
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
parseResponse(response) {
|
|
1191
|
+
return __async(this, null, function* () {
|
|
1192
|
+
try {
|
|
1193
|
+
const rpcResponse = yield response.json();
|
|
1194
|
+
return rpcResponse.result;
|
|
1195
|
+
} catch (error) {
|
|
1196
|
+
throw new RPCReadonlyResponseErr(error.message);
|
|
1197
|
+
}
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
getHeaders(rpcEndpoint) {
|
|
1201
|
+
const defaultHeaders = {
|
|
1202
|
+
Accept: "application/json",
|
|
1203
|
+
"Content-Type": "application/json"
|
|
1204
|
+
};
|
|
1205
|
+
if (rpcEndpoint.includes("infura")) {
|
|
1206
|
+
return __spreadProps(__spreadValues({}, defaultHeaders), {
|
|
1207
|
+
"Metamask-Sdk-Info": this.sdkInfo
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
return defaultHeaders;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// src/multichain/rpc/requestRouter.ts
|
|
1215
|
+
var RequestRouter = class {
|
|
1216
|
+
constructor(transport, rpcClient, config) {
|
|
1217
|
+
this.transport = transport;
|
|
1218
|
+
this.rpcClient = rpcClient;
|
|
1219
|
+
this.config = config;
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* The main entry point for invoking an RPC method.
|
|
1223
|
+
* This method acts as a router, determining the correct handling strategy
|
|
1224
|
+
* for the request and delegating to the appropriate private handler.
|
|
1225
|
+
*/
|
|
1226
|
+
invokeMethod(options) {
|
|
1227
|
+
return __async(this, null, function* () {
|
|
1228
|
+
const method = options.request.method;
|
|
1229
|
+
if (RPC_HANDLED_METHODS.has(method)) {
|
|
1230
|
+
return this.handleWithRpcNode(options);
|
|
1231
|
+
}
|
|
1232
|
+
if (SDK_HANDLED_METHODS.has(method)) {
|
|
1233
|
+
return this.handleWithSdkState(options);
|
|
1234
|
+
}
|
|
1235
|
+
return this.handleWithWallet(options);
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Forwards the request directly to the wallet via the transport.
|
|
1240
|
+
*/
|
|
1241
|
+
handleWithWallet(options) {
|
|
1242
|
+
return __async(this, null, function* () {
|
|
1243
|
+
try {
|
|
1244
|
+
const request = this.transport.request({
|
|
1245
|
+
method: "wallet_invokeMethod",
|
|
1246
|
+
params: options
|
|
1247
|
+
});
|
|
1248
|
+
const { ui, mobile } = this.config;
|
|
1249
|
+
const { preferDesktop = false } = ui != null ? ui : {};
|
|
1250
|
+
const secure = isSecure();
|
|
1251
|
+
const shouldOpenDeeplink = secure && !preferDesktop;
|
|
1252
|
+
if (shouldOpenDeeplink) {
|
|
1253
|
+
setTimeout(() => {
|
|
1254
|
+
if (mobile == null ? void 0 : mobile.preferredOpenLink) {
|
|
1255
|
+
mobile.preferredOpenLink(METAMASK_DEEPLINK_BASE, "_self");
|
|
1256
|
+
} else {
|
|
1257
|
+
openDeeplink(this.config, METAMASK_DEEPLINK_BASE, METAMASK_CONNECT_BASE_URL);
|
|
1258
|
+
}
|
|
1259
|
+
}, 10);
|
|
1260
|
+
}
|
|
1261
|
+
const response = yield request;
|
|
1262
|
+
if (response.error) {
|
|
1263
|
+
throw new RPCInvokeMethodErr(`RPC Request failed with code ${response.error.code}: ${response.error.message}`);
|
|
1264
|
+
}
|
|
1265
|
+
return response.result;
|
|
1266
|
+
} catch (error) {
|
|
1267
|
+
throw new RPCInvokeMethodErr(error.message);
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Routes the request to a configured RPC node.
|
|
1273
|
+
*/
|
|
1274
|
+
handleWithRpcNode(options) {
|
|
1275
|
+
return __async(this, null, function* () {
|
|
1276
|
+
try {
|
|
1277
|
+
return yield this.rpcClient.request(options);
|
|
1278
|
+
} catch (error) {
|
|
1279
|
+
if (error instanceof MissingRpcEndpointErr) {
|
|
1280
|
+
return this.handleWithWallet(options);
|
|
1281
|
+
}
|
|
1282
|
+
throw error;
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Responds directly from the SDK's session state.
|
|
1288
|
+
*/
|
|
1289
|
+
handleWithSdkState(options) {
|
|
1290
|
+
return __async(this, null, function* () {
|
|
1291
|
+
console.warn(`Method "${options.request.method}" is configured for SDK state handling, but this is not yet implemented. Falling back to wallet passthrough.`);
|
|
1292
|
+
return this.handleWithWallet(options);
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
// src/multichain/transports/default/index.ts
|
|
1298
|
+
import {
|
|
1299
|
+
getDefaultTransport
|
|
1300
|
+
} from "@metamask/multichain-api-client";
|
|
1301
|
+
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
1302
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _DefaultTransport_instances, notifyCallbacks_fn;
|
|
1303
|
+
var DefaultTransport = class {
|
|
1304
|
+
constructor() {
|
|
1305
|
+
__privateAdd(this, _DefaultTransport_instances);
|
|
1306
|
+
__privateAdd(this, _notificationCallbacks, /* @__PURE__ */ new Set());
|
|
1307
|
+
__privateAdd(this, _transport, getDefaultTransport());
|
|
1308
|
+
__privateAdd(this, _defaultRequestOptions, {
|
|
1309
|
+
timeout: DEFAULT_REQUEST_TIMEOUT
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
connect(options) {
|
|
1313
|
+
return __async(this, null, function* () {
|
|
1314
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1315
|
+
yield __privateGet(this, _transport).connect();
|
|
1316
|
+
const sessionRequest = yield this.request(
|
|
1317
|
+
{ method: "wallet_getSession" },
|
|
1318
|
+
__privateGet(this, _defaultRequestOptions)
|
|
1319
|
+
);
|
|
1320
|
+
if (sessionRequest.error) {
|
|
1321
|
+
throw new Error(sessionRequest.error.message);
|
|
1322
|
+
}
|
|
1323
|
+
let walletSession = sessionRequest.result;
|
|
1324
|
+
if (walletSession && options) {
|
|
1325
|
+
const currentScopes = Object.keys(
|
|
1326
|
+
(_a = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a : {}
|
|
1327
|
+
);
|
|
1328
|
+
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1329
|
+
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
1330
|
+
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
1331
|
+
currentScopes,
|
|
1332
|
+
proposedScopes,
|
|
1333
|
+
walletSession,
|
|
1334
|
+
proposedCaipAccountIds
|
|
1335
|
+
);
|
|
1336
|
+
if (!hasSameScopesAndAccounts) {
|
|
1337
|
+
yield this.request(
|
|
1338
|
+
{ method: "wallet_revokeSession", params: walletSession },
|
|
1339
|
+
__privateGet(this, _defaultRequestOptions)
|
|
1340
|
+
);
|
|
1341
|
+
const optionalScopes = addValidAccounts(
|
|
1342
|
+
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
1343
|
+
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
1344
|
+
);
|
|
1345
|
+
const sessionRequest2 = { optionalScopes };
|
|
1346
|
+
const response = yield this.request(
|
|
1347
|
+
{ method: "wallet_createSession", params: sessionRequest2 },
|
|
1348
|
+
__privateGet(this, _defaultRequestOptions)
|
|
1349
|
+
);
|
|
1350
|
+
if (response.error) {
|
|
1351
|
+
throw new Error(response.error.message);
|
|
1352
|
+
}
|
|
1353
|
+
walletSession = response.result;
|
|
1354
|
+
}
|
|
1355
|
+
} else if (!walletSession) {
|
|
1356
|
+
const optionalScopes = addValidAccounts(
|
|
1357
|
+
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
1358
|
+
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1359
|
+
);
|
|
1360
|
+
const sessionRequest2 = { optionalScopes };
|
|
1361
|
+
const response = yield this.request(
|
|
1362
|
+
{ method: "wallet_createSession", params: sessionRequest2 },
|
|
1363
|
+
__privateGet(this, _defaultRequestOptions)
|
|
1364
|
+
);
|
|
1365
|
+
if (response.error) {
|
|
1366
|
+
throw new Error(response.error.message);
|
|
1367
|
+
}
|
|
1368
|
+
walletSession = response.result;
|
|
1369
|
+
}
|
|
1370
|
+
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, {
|
|
1371
|
+
method: "wallet_sessionChanged",
|
|
1372
|
+
params: walletSession
|
|
1373
|
+
});
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
disconnect() {
|
|
1377
|
+
return __async(this, null, function* () {
|
|
1378
|
+
__privateGet(this, _notificationCallbacks).clear();
|
|
1379
|
+
return __privateGet(this, _transport).disconnect();
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
isConnected() {
|
|
1383
|
+
return __privateGet(this, _transport).isConnected();
|
|
1384
|
+
}
|
|
1385
|
+
request(_0) {
|
|
1386
|
+
return __async(this, arguments, function* (request, options = __privateGet(this, _defaultRequestOptions)) {
|
|
1387
|
+
return __privateGet(this, _transport).request(request, options);
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
onNotification(callback) {
|
|
1391
|
+
__privateGet(this, _transport).onNotification(callback);
|
|
1392
|
+
__privateGet(this, _notificationCallbacks).add(callback);
|
|
1393
|
+
return () => {
|
|
1394
|
+
__privateGet(this, _notificationCallbacks).delete(callback);
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
_notificationCallbacks = new WeakMap();
|
|
1399
|
+
_transport = new WeakMap();
|
|
1400
|
+
_defaultRequestOptions = new WeakMap();
|
|
1401
|
+
_DefaultTransport_instances = new WeakSet();
|
|
1402
|
+
notifyCallbacks_fn = function(data) {
|
|
1403
|
+
for (const cb of __privateGet(this, _notificationCallbacks)) {
|
|
1404
|
+
try {
|
|
1405
|
+
cb(data);
|
|
1406
|
+
} catch (err) {
|
|
1407
|
+
console.log("[WindowPostMessageTransport] notifyCallbacks error:", err);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
|
|
1412
|
+
// src/multichain/transports/mwp/index.ts
|
|
1413
|
+
init_domain();
|
|
1414
|
+
import { SessionStore } from "@metamask/mobile-wallet-protocol-core";
|
|
1415
|
+
import {
|
|
1416
|
+
TransportTimeoutError
|
|
1417
|
+
} from "@metamask/multichain-api-client";
|
|
1418
|
+
var DEFAULT_REQUEST_TIMEOUT2 = 60 * 1e3;
|
|
1419
|
+
var CONNECTION_GRACE_PERIOD = 60 * 1e3;
|
|
1420
|
+
var DEFAULT_CONNECTION_TIMEOUT = DEFAULT_REQUEST_TIMEOUT2 + CONNECTION_GRACE_PERIOD;
|
|
1421
|
+
var SESSION_STORE_KEY = "cache_wallet_getSession";
|
|
1422
|
+
var CACHED_METHOD_LIST = [
|
|
1423
|
+
"wallet_getSession",
|
|
1424
|
+
"wallet_createSession",
|
|
1425
|
+
"wallet_sessionChanged"
|
|
1426
|
+
];
|
|
1427
|
+
var CACHED_RESET_METHOD_LIST = ["wallet_revokeSession"];
|
|
1428
|
+
var logger = createLogger("metamask-sdk:transport");
|
|
1429
|
+
var MWPTransport = class {
|
|
1430
|
+
constructor(dappClient, kvstore, options = {
|
|
1431
|
+
requestTimeout: DEFAULT_REQUEST_TIMEOUT2,
|
|
1432
|
+
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT
|
|
1433
|
+
}) {
|
|
1434
|
+
this.dappClient = dappClient;
|
|
1435
|
+
this.kvstore = kvstore;
|
|
1436
|
+
this.options = options;
|
|
1437
|
+
this.__reqId = 0;
|
|
1438
|
+
this.__pendingRequests = /* @__PURE__ */ new Map();
|
|
1439
|
+
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
1440
|
+
this.dappClient.on("message", this.handleMessage.bind(this));
|
|
1441
|
+
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
1442
|
+
this.windowFocusHandler = this.onWindowFocus.bind(this);
|
|
1443
|
+
window.addEventListener("focus", this.windowFocusHandler);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
get pendingRequests() {
|
|
1447
|
+
return this.__pendingRequests;
|
|
1448
|
+
}
|
|
1449
|
+
set pendingRequests(pendingRequests) {
|
|
1450
|
+
this.__pendingRequests = pendingRequests;
|
|
1451
|
+
}
|
|
1452
|
+
get sessionRequest() {
|
|
1453
|
+
return this.currentSessionRequest;
|
|
1454
|
+
}
|
|
1455
|
+
onWindowFocus() {
|
|
1456
|
+
if (!this.isConnected()) {
|
|
1457
|
+
this.dappClient.reconnect();
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
notifyCallbacks(data) {
|
|
1461
|
+
this.notificationCallbacks.forEach((callback) => callback(data));
|
|
1462
|
+
}
|
|
1463
|
+
rejectRequest(id, error = new Error("Request rejected")) {
|
|
1464
|
+
const request = this.pendingRequests.get(id);
|
|
1465
|
+
if (request) {
|
|
1466
|
+
this.pendingRequests.delete(id);
|
|
1467
|
+
clearTimeout(request.timeout);
|
|
1468
|
+
request.reject(error);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
handleMessage(message) {
|
|
1472
|
+
if (typeof message === "object" && message !== null) {
|
|
1473
|
+
if ("data" in message) {
|
|
1474
|
+
const messagePayload = message.data;
|
|
1475
|
+
if ("id" in messagePayload && typeof messagePayload.id === "string") {
|
|
1476
|
+
const request = this.pendingRequests.get(messagePayload.id);
|
|
1477
|
+
if (request) {
|
|
1478
|
+
const requestWithName = __spreadProps(__spreadValues({}, messagePayload), {
|
|
1479
|
+
method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method
|
|
1480
|
+
});
|
|
1481
|
+
const notification = __spreadProps(__spreadValues({}, messagePayload), {
|
|
1482
|
+
method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method,
|
|
1483
|
+
params: requestWithName.result
|
|
1484
|
+
});
|
|
1485
|
+
clearTimeout(request.timeout);
|
|
1486
|
+
this.notifyCallbacks(notification);
|
|
1487
|
+
request.resolve(requestWithName);
|
|
1488
|
+
this.pendingRequests.delete(messagePayload.id);
|
|
1489
|
+
}
|
|
1490
|
+
} else {
|
|
1491
|
+
this.notifyCallbacks(message.data);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
1497
|
+
return __async(this, null, function* () {
|
|
1498
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1499
|
+
try {
|
|
1500
|
+
const sessionRequest = yield this.request({
|
|
1501
|
+
method: "wallet_getSession"
|
|
1502
|
+
});
|
|
1503
|
+
if (sessionRequest.error) {
|
|
1504
|
+
return resumeReject(new Error(sessionRequest.error.message));
|
|
1505
|
+
}
|
|
1506
|
+
let walletSession = sessionRequest.result;
|
|
1507
|
+
if (walletSession && options) {
|
|
1508
|
+
const currentScopes = Object.keys(
|
|
1509
|
+
(_a = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a : {}
|
|
1510
|
+
);
|
|
1511
|
+
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1512
|
+
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
1513
|
+
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
1514
|
+
currentScopes,
|
|
1515
|
+
proposedScopes,
|
|
1516
|
+
walletSession,
|
|
1517
|
+
proposedCaipAccountIds
|
|
1518
|
+
);
|
|
1519
|
+
if (!hasSameScopesAndAccounts) {
|
|
1520
|
+
const optionalScopes = addValidAccounts(
|
|
1521
|
+
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
1522
|
+
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
1523
|
+
);
|
|
1524
|
+
const sessionRequest2 = {
|
|
1525
|
+
optionalScopes
|
|
1526
|
+
};
|
|
1527
|
+
const response = yield this.request({
|
|
1528
|
+
method: "wallet_createSession",
|
|
1529
|
+
params: sessionRequest2
|
|
1530
|
+
});
|
|
1531
|
+
if (response.error) {
|
|
1532
|
+
return resumeReject(new Error(response.error.message));
|
|
1533
|
+
}
|
|
1534
|
+
walletSession = response.result;
|
|
1535
|
+
}
|
|
1536
|
+
} else if (!walletSession) {
|
|
1537
|
+
const optionalScopes = addValidAccounts(
|
|
1538
|
+
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
1539
|
+
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1540
|
+
);
|
|
1541
|
+
const sessionRequest2 = { optionalScopes };
|
|
1542
|
+
const response = yield this.request({
|
|
1543
|
+
method: "wallet_createSession",
|
|
1544
|
+
params: sessionRequest2
|
|
1545
|
+
});
|
|
1546
|
+
if (response.error) {
|
|
1547
|
+
return resumeReject(new Error(response.error.message));
|
|
1548
|
+
}
|
|
1549
|
+
walletSession = response.result;
|
|
1550
|
+
}
|
|
1551
|
+
this.notifyCallbacks({
|
|
1552
|
+
method: "wallet_sessionChanged",
|
|
1553
|
+
params: walletSession
|
|
1554
|
+
});
|
|
1555
|
+
return resumeResolve();
|
|
1556
|
+
} catch (err) {
|
|
1557
|
+
return resumeReject(err);
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
connect(options) {
|
|
1562
|
+
return __async(this, null, function* () {
|
|
1563
|
+
const { dappClient, kvstore } = this;
|
|
1564
|
+
const sessionStore = new SessionStore(kvstore);
|
|
1565
|
+
let session;
|
|
1566
|
+
try {
|
|
1567
|
+
const [activeSession] = yield sessionStore.list();
|
|
1568
|
+
if (activeSession) {
|
|
1569
|
+
logger("active session found", activeSession);
|
|
1570
|
+
session = activeSession;
|
|
1571
|
+
}
|
|
1572
|
+
} catch (e) {
|
|
1573
|
+
}
|
|
1574
|
+
let timeout;
|
|
1575
|
+
const connectionPromise = new Promise((resolve, reject) => {
|
|
1576
|
+
let connection;
|
|
1577
|
+
if (session) {
|
|
1578
|
+
connection = new Promise((resumeResolve, resumeReject) => {
|
|
1579
|
+
var _a;
|
|
1580
|
+
if (this.dappClient.state === "CONNECTED") {
|
|
1581
|
+
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1582
|
+
} else {
|
|
1583
|
+
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
1584
|
+
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1585
|
+
}));
|
|
1586
|
+
dappClient.resume((_a = session == null ? void 0 : session.id) != null ? _a : "");
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
} else {
|
|
1590
|
+
connection = new Promise(
|
|
1591
|
+
(resolveConnection, rejectConnection) => {
|
|
1592
|
+
var _a, _b;
|
|
1593
|
+
const optionalScopes = addValidAccounts(
|
|
1594
|
+
getOptionalScopes((_a = options == null ? void 0 : options.scopes) != null ? _a : []),
|
|
1595
|
+
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1596
|
+
);
|
|
1597
|
+
const sessionRequest = {
|
|
1598
|
+
optionalScopes
|
|
1599
|
+
};
|
|
1600
|
+
const request = {
|
|
1601
|
+
jsonrpc: "2.0",
|
|
1602
|
+
id: `${this.__reqId++}`,
|
|
1603
|
+
method: "wallet_createSession",
|
|
1604
|
+
params: sessionRequest
|
|
1605
|
+
};
|
|
1606
|
+
this.dappClient.on("message", (message) => __async(this, null, function* () {
|
|
1607
|
+
if (typeof message === "object" && message !== null) {
|
|
1608
|
+
if ("data" in message) {
|
|
1609
|
+
const messagePayload = message.data;
|
|
1610
|
+
if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
1611
|
+
if (messagePayload.error) {
|
|
1612
|
+
return rejectConnection(messagePayload.error);
|
|
1613
|
+
}
|
|
1614
|
+
this.notifyCallbacks(message.data);
|
|
1615
|
+
yield this.storeWalletSession(
|
|
1616
|
+
request,
|
|
1617
|
+
messagePayload
|
|
1618
|
+
);
|
|
1619
|
+
return resolveConnection();
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}));
|
|
1624
|
+
dappClient.connect({ mode: "trusted", initialPayload: request }).catch(rejectConnection);
|
|
1625
|
+
}
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
timeout = setTimeout(() => {
|
|
1629
|
+
reject(new TransportTimeoutError());
|
|
1630
|
+
}, this.options.connectionTimeout);
|
|
1631
|
+
connection.then(resolve).catch(reject);
|
|
1632
|
+
});
|
|
1633
|
+
return connectionPromise.finally(() => {
|
|
1634
|
+
if (timeout) {
|
|
1635
|
+
clearTimeout(timeout);
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Disconnects from the Mobile Wallet Protocol
|
|
1642
|
+
*
|
|
1643
|
+
* @returns Nothing
|
|
1644
|
+
*/
|
|
1645
|
+
disconnect() {
|
|
1646
|
+
return __async(this, null, function* () {
|
|
1647
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined" && this.windowFocusHandler) {
|
|
1648
|
+
window.removeEventListener("focus", this.windowFocusHandler);
|
|
1649
|
+
this.windowFocusHandler = void 0;
|
|
1650
|
+
}
|
|
1651
|
+
return this.dappClient.disconnect();
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Checks if the transport is connected
|
|
1656
|
+
*
|
|
1657
|
+
* @returns True if transport is connected, false otherwise
|
|
1658
|
+
*/
|
|
1659
|
+
isConnected() {
|
|
1660
|
+
return this.dappClient.state === "CONNECTED";
|
|
1661
|
+
}
|
|
1662
|
+
fetchCachedWalletSession(request) {
|
|
1663
|
+
return __async(this, null, function* () {
|
|
1664
|
+
var _a;
|
|
1665
|
+
if (request.method === "wallet_getSession") {
|
|
1666
|
+
const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
1667
|
+
if (walletGetSession) {
|
|
1668
|
+
const walletSession = JSON.parse(walletGetSession);
|
|
1669
|
+
return {
|
|
1670
|
+
id: request.id,
|
|
1671
|
+
jsonrpc: "2.0",
|
|
1672
|
+
result: (_a = walletSession.params) != null ? _a : walletSession.result,
|
|
1673
|
+
method: request.method
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
storeWalletSession(request, response) {
|
|
1680
|
+
return __async(this, null, function* () {
|
|
1681
|
+
if (CACHED_METHOD_LIST.includes(request.method)) {
|
|
1682
|
+
yield this.kvstore.set(SESSION_STORE_KEY, JSON.stringify(response));
|
|
1683
|
+
} else if (CACHED_RESET_METHOD_LIST.includes(request.method)) {
|
|
1684
|
+
yield this.kvstore.delete(SESSION_STORE_KEY);
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
request(payload, options) {
|
|
1689
|
+
return __async(this, null, function* () {
|
|
1690
|
+
const request = __spreadValues({
|
|
1691
|
+
jsonrpc: "2.0",
|
|
1692
|
+
id: `${this.__reqId++}`
|
|
1693
|
+
}, payload);
|
|
1694
|
+
const cachedWalletSession = yield this.fetchCachedWalletSession(request);
|
|
1695
|
+
if (cachedWalletSession) {
|
|
1696
|
+
this.notifyCallbacks(cachedWalletSession);
|
|
1697
|
+
return cachedWalletSession;
|
|
1698
|
+
}
|
|
1699
|
+
return new Promise((resolve, reject) => {
|
|
1700
|
+
var _a;
|
|
1701
|
+
const timeout = setTimeout(() => {
|
|
1702
|
+
this.rejectRequest(request.id, new TransportTimeoutError());
|
|
1703
|
+
}, (_a = options == null ? void 0 : options.timeout) != null ? _a : this.options.requestTimeout);
|
|
1704
|
+
this.pendingRequests.set(request.id, {
|
|
1705
|
+
request,
|
|
1706
|
+
method: request.method,
|
|
1707
|
+
resolve: (response) => __async(this, null, function* () {
|
|
1708
|
+
if (CACHED_METHOD_LIST.includes(request.method)) {
|
|
1709
|
+
yield this.storeWalletSession(request, response);
|
|
1710
|
+
}
|
|
1711
|
+
return resolve(response);
|
|
1712
|
+
}),
|
|
1713
|
+
reject,
|
|
1714
|
+
timeout
|
|
1715
|
+
});
|
|
1716
|
+
this.dappClient.sendRequest(request).catch(reject);
|
|
1717
|
+
});
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
onNotification(callback) {
|
|
1721
|
+
this.notificationCallbacks.add(callback);
|
|
1722
|
+
return () => {
|
|
1723
|
+
this.notificationCallbacks.delete(callback);
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
|
|
1728
|
+
// src/multichain/transports/mwp/KeyManager.ts
|
|
1729
|
+
import { decrypt, encrypt, PrivateKey } from "eciesjs";
|
|
1730
|
+
var KeyManager = class {
|
|
1731
|
+
generateKeyPair() {
|
|
1732
|
+
const privateKey = new PrivateKey();
|
|
1733
|
+
return {
|
|
1734
|
+
privateKey: new Uint8Array(privateKey.secret),
|
|
1735
|
+
publicKey: privateKey.publicKey.toBytes(true)
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
encrypt(plaintext, theirPublicKey) {
|
|
1739
|
+
return __async(this, null, function* () {
|
|
1740
|
+
const plaintextBuffer = Buffer.from(plaintext, "utf8");
|
|
1741
|
+
const encryptedBuffer = encrypt(theirPublicKey, plaintextBuffer);
|
|
1742
|
+
return encryptedBuffer.toString("base64");
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
decrypt(encryptedB64, myPrivateKey) {
|
|
1746
|
+
return __async(this, null, function* () {
|
|
1747
|
+
const encryptedBuffer = Buffer.from(encryptedB64, "base64");
|
|
1748
|
+
const decryptedBuffer = yield decrypt(myPrivateKey, encryptedBuffer);
|
|
1749
|
+
return Buffer.from(decryptedBuffer).toString("utf8");
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
var keymanager = new KeyManager();
|
|
1754
|
+
|
|
1755
|
+
// src/multichain/index.ts
|
|
1756
|
+
var logger2 = createLogger("metamask-sdk:core");
|
|
1757
|
+
var MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
1758
|
+
constructor(options) {
|
|
1759
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1760
|
+
const withInfuraRPCMethods = setupInfuraProvider(options);
|
|
1761
|
+
const withDappMetadata = setupDappMetadata(withInfuraRPCMethods);
|
|
1762
|
+
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
1763
|
+
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
1764
|
+
preferExtension: (_a = withDappMetadata.ui.preferExtension) != null ? _a : true,
|
|
1765
|
+
preferDesktop: (_b = withDappMetadata.ui.preferDesktop) != null ? _b : false,
|
|
1766
|
+
headless: (_c = withDappMetadata.ui.headless) != null ? _c : false
|
|
1767
|
+
}),
|
|
1768
|
+
analytics: __spreadProps(__spreadValues({}, (_d = options.analytics) != null ? _d : {}), {
|
|
1769
|
+
enabled: (_f = (_e = options.analytics) == null ? void 0 : _e.enabled) != null ? _f : true,
|
|
1770
|
+
integrationType: "unknown"
|
|
1771
|
+
})
|
|
1772
|
+
});
|
|
1773
|
+
super(allOptions);
|
|
1774
|
+
this.__provider = void 0;
|
|
1775
|
+
this.__transport = void 0;
|
|
1776
|
+
this.__dappClient = void 0;
|
|
1777
|
+
this.__state = "pending";
|
|
1778
|
+
}
|
|
1779
|
+
get state() {
|
|
1780
|
+
return this.__state;
|
|
1781
|
+
}
|
|
1782
|
+
set state(value) {
|
|
1783
|
+
var _a, _b;
|
|
1784
|
+
this.__state = value;
|
|
1785
|
+
(_b = (_a = this.options.transport) == null ? void 0 : _a.onNotification) == null ? void 0 : _b.call(_a, {
|
|
1786
|
+
method: "stateChanged",
|
|
1787
|
+
params: value
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
get provider() {
|
|
1791
|
+
if (!this.__provider) {
|
|
1792
|
+
throw new Error("Provider not initialized, establish connection first");
|
|
1793
|
+
}
|
|
1794
|
+
return this.__provider;
|
|
1795
|
+
}
|
|
1796
|
+
get transport() {
|
|
1797
|
+
if (!this.__transport) {
|
|
1798
|
+
throw new Error("Transport not initialized, establish connection first");
|
|
1799
|
+
}
|
|
1800
|
+
return this.__transport;
|
|
1801
|
+
}
|
|
1802
|
+
get dappClient() {
|
|
1803
|
+
if (!this.__dappClient) {
|
|
1804
|
+
throw new Error("DappClient not initialized, establish connection first");
|
|
1805
|
+
}
|
|
1806
|
+
return this.__dappClient;
|
|
1807
|
+
}
|
|
1808
|
+
get storage() {
|
|
1809
|
+
return this.options.storage;
|
|
1810
|
+
}
|
|
1811
|
+
get sdkInfo() {
|
|
1812
|
+
var _a;
|
|
1813
|
+
return `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`;
|
|
1814
|
+
}
|
|
1815
|
+
static create(options) {
|
|
1816
|
+
return __async(this, null, function* () {
|
|
1817
|
+
const instance = new _MultichainSDK(options);
|
|
1818
|
+
const isEnabled2 = yield isEnabled(
|
|
1819
|
+
"metamask-sdk:core",
|
|
1820
|
+
instance.options.storage
|
|
1821
|
+
);
|
|
1822
|
+
if (isEnabled2) {
|
|
1823
|
+
enableDebug("metamask-sdk:core");
|
|
1824
|
+
}
|
|
1825
|
+
yield instance.init();
|
|
1826
|
+
return instance;
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
setupAnalytics() {
|
|
1830
|
+
return __async(this, null, function* () {
|
|
1831
|
+
var _a, _b;
|
|
1832
|
+
if (!((_a = this.options.analytics) == null ? void 0 : _a.enabled)) {
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
const platform = getPlatformType();
|
|
1836
|
+
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
1837
|
+
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
1838
|
+
if (!isBrowser && !isReactNative2) {
|
|
1839
|
+
return;
|
|
1840
|
+
}
|
|
1841
|
+
const version = getVersion();
|
|
1842
|
+
const dappId = getDappId(this.options.dapp);
|
|
1843
|
+
const anonId = yield this.storage.getAnonId();
|
|
1844
|
+
const { integrationType } = (_b = this.options.analytics) != null ? _b : {
|
|
1845
|
+
integrationType: ""
|
|
1846
|
+
};
|
|
1847
|
+
analytics.setGlobalProperty("sdk_version", version);
|
|
1848
|
+
analytics.setGlobalProperty("dapp_id", dappId);
|
|
1849
|
+
analytics.setGlobalProperty("anon_id", anonId);
|
|
1850
|
+
analytics.setGlobalProperty("platform", platform);
|
|
1851
|
+
analytics.setGlobalProperty("integration_type", integrationType);
|
|
1852
|
+
analytics.enable();
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
onTransportNotification(payload) {
|
|
1856
|
+
return __async(this, null, function* () {
|
|
1857
|
+
var _a;
|
|
1858
|
+
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
1859
|
+
this.emit(payload.method, (_a = payload.params) != null ? _a : payload.result);
|
|
1860
|
+
}
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
getStoredTransport() {
|
|
1864
|
+
return __async(this, null, function* () {
|
|
1865
|
+
const { ui } = this.options;
|
|
1866
|
+
const { preferExtension = true } = ui;
|
|
1867
|
+
const transportType = yield this.storage.getTransport();
|
|
1868
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
1869
|
+
if (transportType) {
|
|
1870
|
+
if (transportType === "browser" /* Browser */) {
|
|
1871
|
+
if (hasExtensionInstalled && preferExtension) {
|
|
1872
|
+
const apiTransport = new DefaultTransport();
|
|
1873
|
+
this.__transport = apiTransport;
|
|
1874
|
+
this.listener = apiTransport.onNotification(
|
|
1875
|
+
this.onTransportNotification.bind(this)
|
|
1876
|
+
);
|
|
1877
|
+
return apiTransport;
|
|
1878
|
+
}
|
|
1879
|
+
} else if (transportType === "mwp" /* MPW */) {
|
|
1880
|
+
const { adapter: kvstore } = this.options.storage;
|
|
1881
|
+
const dappClient = yield this.createDappClient();
|
|
1882
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
1883
|
+
this.__dappClient = dappClient;
|
|
1884
|
+
this.__transport = apiTransport;
|
|
1885
|
+
this.listener = apiTransport.onNotification(
|
|
1886
|
+
this.onTransportNotification.bind(this)
|
|
1887
|
+
);
|
|
1888
|
+
return apiTransport;
|
|
1889
|
+
}
|
|
1890
|
+
yield this.storage.removeTransport();
|
|
1891
|
+
}
|
|
1892
|
+
return void 0;
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
setupTransport() {
|
|
1896
|
+
return __async(this, null, function* () {
|
|
1897
|
+
const transport = yield this.getStoredTransport();
|
|
1898
|
+
if (transport) {
|
|
1899
|
+
if (!this.transport.isConnected()) {
|
|
1900
|
+
this.state = "connecting";
|
|
1901
|
+
yield this.transport.connect();
|
|
1902
|
+
}
|
|
1903
|
+
this.state = "connected";
|
|
1904
|
+
if (this.transport instanceof MWPTransport) {
|
|
1905
|
+
yield this.storage.setTransport("mwp" /* MPW */);
|
|
1906
|
+
} else {
|
|
1907
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
1908
|
+
}
|
|
1909
|
+
} else {
|
|
1910
|
+
this.state = "loaded";
|
|
1911
|
+
}
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
init() {
|
|
1915
|
+
return __async(this, null, function* () {
|
|
1916
|
+
var _a;
|
|
1917
|
+
try {
|
|
1918
|
+
if (typeof window !== "undefined" && ((_a = window.mmsdk) == null ? void 0 : _a.isInitialized)) {
|
|
1919
|
+
logger2("MetaMaskSDK: init already initialized");
|
|
1920
|
+
} else {
|
|
1921
|
+
yield this.setupAnalytics();
|
|
1922
|
+
yield this.setupTransport();
|
|
1923
|
+
analytics.track("sdk_initialized", {});
|
|
1924
|
+
if (typeof window !== "undefined") {
|
|
1925
|
+
window.mmsdk = this;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
} catch (error) {
|
|
1929
|
+
yield this.storage.removeTransport();
|
|
1930
|
+
this.state = "pending";
|
|
1931
|
+
logger2("MetaMaskSDK error during initialization", error);
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
createDappClient() {
|
|
1936
|
+
return __async(this, null, function* () {
|
|
1937
|
+
const { adapter: kvstore } = this.options.storage;
|
|
1938
|
+
const sessionstore = new SessionStore2(kvstore);
|
|
1939
|
+
const websocket = (
|
|
1940
|
+
// eslint-disable-next-line no-negated-condition
|
|
1941
|
+
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
1942
|
+
);
|
|
1943
|
+
const transport = yield WebSocketTransport.create({
|
|
1944
|
+
url: MWP_RELAY_URL,
|
|
1945
|
+
kvstore,
|
|
1946
|
+
websocket
|
|
1947
|
+
});
|
|
1948
|
+
const dappClient = new DappClient({ transport, sessionstore, keymanager });
|
|
1949
|
+
return dappClient;
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
setupMWP() {
|
|
1953
|
+
return __async(this, null, function* () {
|
|
1954
|
+
if (this.__transport instanceof MWPTransport) {
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
const { adapter: kvstore } = this.options.storage;
|
|
1958
|
+
const dappClient = yield this.createDappClient();
|
|
1959
|
+
this.__dappClient = dappClient;
|
|
1960
|
+
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
1961
|
+
this.__transport = apiTransport;
|
|
1962
|
+
this.listener = this.transport.onNotification(
|
|
1963
|
+
this.onTransportNotification.bind(this)
|
|
1964
|
+
);
|
|
1965
|
+
yield this.storage.setTransport("mwp" /* MPW */);
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
onBeforeUnload() {
|
|
1969
|
+
return __async(this, null, function* () {
|
|
1970
|
+
var _a;
|
|
1971
|
+
if ((_a = this.options.ui.factory.modal) == null ? void 0 : _a.isMounted) {
|
|
1972
|
+
yield this.storage.removeTransport();
|
|
1973
|
+
}
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
createBeforeUnloadListener() {
|
|
1977
|
+
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
1978
|
+
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this));
|
|
1979
|
+
}
|
|
1980
|
+
return () => {
|
|
1981
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
1982
|
+
window.removeEventListener(
|
|
1983
|
+
"beforeunload",
|
|
1984
|
+
this.onBeforeUnload.bind(this)
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
showInstallModal(desktopPreferred, scopes, caipAccountIds) {
|
|
1990
|
+
return __async(this, null, function* () {
|
|
1991
|
+
var _a;
|
|
1992
|
+
(_a = this.__beforeUnloadListener) != null ? _a : this.__beforeUnloadListener = this.createBeforeUnloadListener();
|
|
1993
|
+
return new Promise((resolve, reject) => {
|
|
1994
|
+
this.options.ui.factory.renderInstallModal(
|
|
1995
|
+
desktopPreferred,
|
|
1996
|
+
() => __async(this, null, function* () {
|
|
1997
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
1998
|
+
yield this.dappClient.disconnect();
|
|
1999
|
+
}
|
|
2000
|
+
return new Promise((resolveConnectionRequest) => {
|
|
2001
|
+
this.dappClient.on(
|
|
2002
|
+
"session_request",
|
|
2003
|
+
(sessionRequest) => {
|
|
2004
|
+
resolveConnectionRequest({
|
|
2005
|
+
sessionRequest,
|
|
2006
|
+
metadata: {
|
|
2007
|
+
dapp: this.options.dapp,
|
|
2008
|
+
sdk: {
|
|
2009
|
+
version: getVersion(),
|
|
2010
|
+
platform: getPlatformType()
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
);
|
|
2016
|
+
this.transport.connect({ scopes, caipAccountIds }).then(() => {
|
|
2017
|
+
var _a2;
|
|
2018
|
+
this.options.ui.factory.unload();
|
|
2019
|
+
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2020
|
+
this.state = "connected";
|
|
2021
|
+
return this.storage.setTransport("mwp" /* MPW */);
|
|
2022
|
+
}).catch((error) => {
|
|
2023
|
+
if (error instanceof ProtocolError) {
|
|
2024
|
+
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2025
|
+
this.state = "disconnected";
|
|
2026
|
+
reject(error);
|
|
2027
|
+
}
|
|
2028
|
+
} else {
|
|
2029
|
+
this.state = "disconnected";
|
|
2030
|
+
reject(error);
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
});
|
|
2034
|
+
}),
|
|
2035
|
+
(error) => __async(this, null, function* () {
|
|
2036
|
+
if (!error) {
|
|
2037
|
+
yield this.storage.setTransport("mwp" /* MPW */);
|
|
2038
|
+
resolve();
|
|
2039
|
+
} else {
|
|
2040
|
+
yield this.storage.removeTransport();
|
|
2041
|
+
reject(error);
|
|
2042
|
+
}
|
|
2043
|
+
})
|
|
2044
|
+
);
|
|
2045
|
+
});
|
|
2046
|
+
});
|
|
2047
|
+
}
|
|
2048
|
+
setupDefaultTransport() {
|
|
2049
|
+
return __async(this, null, function* () {
|
|
2050
|
+
this.state = "connecting";
|
|
2051
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
2052
|
+
const transport = new DefaultTransport();
|
|
2053
|
+
this.listener = transport.onNotification(
|
|
2054
|
+
this.onTransportNotification.bind(this)
|
|
2055
|
+
);
|
|
2056
|
+
this.__transport = transport;
|
|
2057
|
+
return transport;
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
deeplinkConnect(scopes, caipAccountIds) {
|
|
2061
|
+
return __async(this, null, function* () {
|
|
2062
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2063
|
+
this.dappClient.on("message", (payload) => {
|
|
2064
|
+
var _a, _b, _c;
|
|
2065
|
+
const data = payload.data;
|
|
2066
|
+
if (typeof data === "object" && data !== null) {
|
|
2067
|
+
if ("method" in data && data.method === "wallet_createSession") {
|
|
2068
|
+
if (data.error) {
|
|
2069
|
+
this.state = "loaded";
|
|
2070
|
+
return reject(data.error);
|
|
2071
|
+
}
|
|
2072
|
+
const session = (_a = data.params) != null ? _a : data.result;
|
|
2073
|
+
if (session) {
|
|
2074
|
+
(_c = (_b = this.options.transport) == null ? void 0 : _b.onNotification) == null ? void 0 : _c.call(_b, payload.data);
|
|
2075
|
+
this.emit("wallet_sessionChanged", session);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
});
|
|
2080
|
+
let timeout;
|
|
2081
|
+
if (!this.transport.isConnected()) {
|
|
2082
|
+
this.dappClient.once(
|
|
2083
|
+
"session_request",
|
|
2084
|
+
(sessionRequest) => {
|
|
2085
|
+
var _a;
|
|
2086
|
+
const connectionRequest = {
|
|
2087
|
+
sessionRequest,
|
|
2088
|
+
metadata: {
|
|
2089
|
+
dapp: this.options.dapp,
|
|
2090
|
+
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
2091
|
+
}
|
|
2092
|
+
};
|
|
2093
|
+
const deeplink = this.options.ui.factory.createDeeplink(connectionRequest);
|
|
2094
|
+
const universalLink = this.options.ui.factory.createUniversalLink(connectionRequest);
|
|
2095
|
+
if ((_a = this.options.mobile) == null ? void 0 : _a.preferredOpenLink) {
|
|
2096
|
+
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2097
|
+
} else {
|
|
2098
|
+
openDeeplink(this.options, deeplink, universalLink);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
);
|
|
2102
|
+
} else {
|
|
2103
|
+
timeout = setTimeout(() => {
|
|
2104
|
+
var _a;
|
|
2105
|
+
const deeplink = this.options.ui.factory.createDeeplink();
|
|
2106
|
+
const universalLink = this.options.ui.factory.createUniversalLink();
|
|
2107
|
+
if ((_a = this.options.mobile) == null ? void 0 : _a.preferredOpenLink) {
|
|
2108
|
+
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2109
|
+
} else {
|
|
2110
|
+
openDeeplink(this.options, deeplink, universalLink);
|
|
2111
|
+
}
|
|
2112
|
+
}, 250);
|
|
2113
|
+
}
|
|
2114
|
+
this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => {
|
|
2115
|
+
this.storage.removeTransport();
|
|
2116
|
+
reject(error);
|
|
2117
|
+
}).finally(() => {
|
|
2118
|
+
if (timeout) {
|
|
2119
|
+
clearTimeout(timeout);
|
|
2120
|
+
}
|
|
2121
|
+
});
|
|
2122
|
+
}));
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
handleConnection(promise) {
|
|
2126
|
+
return __async(this, null, function* () {
|
|
2127
|
+
this.state = "connecting";
|
|
2128
|
+
return promise.then(() => {
|
|
2129
|
+
this.state = "connected";
|
|
2130
|
+
}).catch((error) => {
|
|
2131
|
+
this.state = "disconnected";
|
|
2132
|
+
return Promise.reject(error);
|
|
2133
|
+
});
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
connect(scopes, caipAccountIds) {
|
|
2137
|
+
return __async(this, null, function* () {
|
|
2138
|
+
var _a;
|
|
2139
|
+
const { ui } = this.options;
|
|
2140
|
+
const platformType = getPlatformType();
|
|
2141
|
+
const isWeb = platformType === "in-app-browser" /* MetaMaskMobileWebview */ || platformType === "web-desktop" /* DesktopWeb */;
|
|
2142
|
+
const { preferExtension = true, preferDesktop = false } = ui;
|
|
2143
|
+
const secure = isSecure();
|
|
2144
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
2145
|
+
if (((_a = this.__transport) == null ? void 0 : _a.isConnected()) && !secure) {
|
|
2146
|
+
return this.handleConnection(
|
|
2147
|
+
this.__transport.connect({ scopes, caipAccountIds }).then(() => {
|
|
2148
|
+
if (this.__transport instanceof MWPTransport) {
|
|
2149
|
+
return this.storage.setTransport("mwp" /* MPW */);
|
|
2150
|
+
} else {
|
|
2151
|
+
return this.storage.setTransport("browser" /* Browser */);
|
|
2152
|
+
}
|
|
2153
|
+
})
|
|
2154
|
+
);
|
|
2155
|
+
}
|
|
2156
|
+
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2157
|
+
const defaultTransport = yield this.setupDefaultTransport();
|
|
2158
|
+
return this.handleConnection(
|
|
2159
|
+
defaultTransport.connect({ scopes, caipAccountIds })
|
|
2160
|
+
);
|
|
2161
|
+
}
|
|
2162
|
+
yield this.setupMWP();
|
|
2163
|
+
const isDesktopPreferred = hasExtensionInstalled ? preferDesktop : !preferExtension || preferDesktop;
|
|
2164
|
+
if (secure && !isDesktopPreferred) {
|
|
2165
|
+
return this.handleConnection(
|
|
2166
|
+
this.deeplinkConnect(scopes, caipAccountIds)
|
|
2167
|
+
);
|
|
2168
|
+
}
|
|
2169
|
+
return this.handleConnection(
|
|
2170
|
+
this.showInstallModal(isDesktopPreferred, scopes, caipAccountIds)
|
|
2171
|
+
);
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
emit(event, args) {
|
|
2175
|
+
var _a, _b;
|
|
2176
|
+
(_b = (_a = this.options.transport) == null ? void 0 : _a.onNotification) == null ? void 0 : _b.call(_a, { method: event, params: args });
|
|
2177
|
+
super.emit(event, args);
|
|
2178
|
+
}
|
|
2179
|
+
disconnect() {
|
|
2180
|
+
return __async(this, null, function* () {
|
|
2181
|
+
var _a, _b, _c;
|
|
2182
|
+
(_a = this.listener) == null ? void 0 : _a.call(this);
|
|
2183
|
+
(_b = this.__beforeUnloadListener) == null ? void 0 : _b.call(this);
|
|
2184
|
+
yield (_c = this.__transport) == null ? void 0 : _c.disconnect();
|
|
2185
|
+
yield this.storage.removeTransport();
|
|
2186
|
+
this.emit("wallet_sessionChanged", void 0);
|
|
2187
|
+
this.emit("stateChanged", "disconnected");
|
|
2188
|
+
this.listener = void 0;
|
|
2189
|
+
this.__beforeUnloadListener = void 0;
|
|
2190
|
+
this.__transport = void 0;
|
|
2191
|
+
this.__provider = void 0;
|
|
2192
|
+
this.__dappClient = void 0;
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
invokeMethod(request) {
|
|
2196
|
+
return __async(this, null, function* () {
|
|
2197
|
+
var _a;
|
|
2198
|
+
const { sdkInfo, transport, options } = this;
|
|
2199
|
+
(_a = this.__provider) != null ? _a : this.__provider = getMultichainClient({ transport });
|
|
2200
|
+
const rpcClient = new RpcClient(options, sdkInfo);
|
|
2201
|
+
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2202
|
+
return requestRouter.invokeMethod(request);
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
};
|
|
2206
|
+
|
|
2207
|
+
// src/store/index.ts
|
|
2208
|
+
import * as uuid from "uuid";
|
|
2209
|
+
|
|
2210
|
+
// src/domain/errors/storage.ts
|
|
2211
|
+
init_base();
|
|
2212
|
+
var _StorageGetErr = class _StorageGetErr extends BaseErr {
|
|
2213
|
+
constructor(platform, key, reason) {
|
|
2214
|
+
super(
|
|
2215
|
+
`StorageErr${_StorageGetErr.code}: ${platform} storage get error in key: ${key} - ${reason}`,
|
|
2216
|
+
_StorageGetErr.code
|
|
2217
|
+
);
|
|
2218
|
+
this.platform = platform;
|
|
2219
|
+
this.key = key;
|
|
2220
|
+
this.reason = reason;
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
_StorageGetErr.code = 60;
|
|
2224
|
+
var StorageGetErr = _StorageGetErr;
|
|
2225
|
+
var _StorageSetErr = class _StorageSetErr extends BaseErr {
|
|
2226
|
+
constructor(platform, key, reason) {
|
|
2227
|
+
super(
|
|
2228
|
+
`StorageErr${_StorageSetErr.code}: ${platform} storage set error in key: ${key} - ${reason}`,
|
|
2229
|
+
_StorageSetErr.code
|
|
2230
|
+
);
|
|
2231
|
+
this.platform = platform;
|
|
2232
|
+
this.key = key;
|
|
2233
|
+
this.reason = reason;
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
_StorageSetErr.code = 61;
|
|
2237
|
+
var StorageSetErr = _StorageSetErr;
|
|
2238
|
+
var _StorageDeleteErr = class _StorageDeleteErr extends BaseErr {
|
|
2239
|
+
constructor(platform, key, reason) {
|
|
2240
|
+
super(
|
|
2241
|
+
`StorageErr${_StorageDeleteErr.code}: ${platform} storage delete error in key: ${key} - ${reason}`,
|
|
2242
|
+
_StorageDeleteErr.code
|
|
2243
|
+
);
|
|
2244
|
+
this.platform = platform;
|
|
2245
|
+
this.key = key;
|
|
2246
|
+
this.reason = reason;
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
_StorageDeleteErr.code = 62;
|
|
2250
|
+
var StorageDeleteErr = _StorageDeleteErr;
|
|
2251
|
+
|
|
2252
|
+
// src/store/index.ts
|
|
2253
|
+
init_multichain();
|
|
2254
|
+
init_client();
|
|
2255
|
+
var Store = class extends StoreClient {
|
|
2256
|
+
constructor(adapter) {
|
|
2257
|
+
super();
|
|
2258
|
+
this.adapter = adapter;
|
|
2259
|
+
}
|
|
2260
|
+
getTransport() {
|
|
2261
|
+
return __async(this, null, function* () {
|
|
2262
|
+
try {
|
|
2263
|
+
const transport = yield this.adapter.get("multichain-transport");
|
|
2264
|
+
if (!transport) {
|
|
2265
|
+
return null;
|
|
2266
|
+
}
|
|
2267
|
+
return getTransportType(transport);
|
|
2268
|
+
} catch (err) {
|
|
2269
|
+
throw new StorageGetErr(
|
|
2270
|
+
this.adapter.platform,
|
|
2271
|
+
"multichain-transport",
|
|
2272
|
+
err.message
|
|
2273
|
+
);
|
|
2274
|
+
}
|
|
2275
|
+
});
|
|
2276
|
+
}
|
|
2277
|
+
setTransport(transport) {
|
|
2278
|
+
return __async(this, null, function* () {
|
|
2279
|
+
try {
|
|
2280
|
+
yield this.adapter.set("multichain-transport", transport);
|
|
2281
|
+
} catch (err) {
|
|
2282
|
+
throw new StorageSetErr(
|
|
2283
|
+
this.adapter.platform,
|
|
2284
|
+
"multichain-transport",
|
|
2285
|
+
err.message
|
|
2286
|
+
);
|
|
2287
|
+
}
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
removeTransport() {
|
|
2291
|
+
return __async(this, null, function* () {
|
|
2292
|
+
try {
|
|
2293
|
+
yield this.adapter.delete("multichain-transport");
|
|
2294
|
+
} catch (err) {
|
|
2295
|
+
throw new StorageDeleteErr(
|
|
2296
|
+
this.adapter.platform,
|
|
2297
|
+
"multichain-transport",
|
|
2298
|
+
err.message
|
|
2299
|
+
);
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
getAnonId() {
|
|
2304
|
+
return __async(this, null, function* () {
|
|
2305
|
+
try {
|
|
2306
|
+
const anonId = yield this.adapter.get("anonId");
|
|
2307
|
+
if (anonId) {
|
|
2308
|
+
return anonId;
|
|
2309
|
+
}
|
|
2310
|
+
const newAnonId = uuid.v4();
|
|
2311
|
+
yield this.adapter.set("anonId", newAnonId);
|
|
2312
|
+
return newAnonId;
|
|
2313
|
+
} catch (err) {
|
|
2314
|
+
throw new StorageGetErr(this.adapter.platform, "anonId", err.message);
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
getExtensionId() {
|
|
2319
|
+
return __async(this, null, function* () {
|
|
2320
|
+
try {
|
|
2321
|
+
return yield this.adapter.get("extensionId");
|
|
2322
|
+
} catch (err) {
|
|
2323
|
+
throw new StorageGetErr(
|
|
2324
|
+
this.adapter.platform,
|
|
2325
|
+
"extensionId",
|
|
2326
|
+
err.message
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2331
|
+
setAnonId(anonId) {
|
|
2332
|
+
return __async(this, null, function* () {
|
|
2333
|
+
try {
|
|
2334
|
+
return yield this.adapter.set("anonId", anonId);
|
|
2335
|
+
} catch (err) {
|
|
2336
|
+
throw new StorageSetErr(this.adapter.platform, "anonId", err.message);
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
setExtensionId(extensionId) {
|
|
2341
|
+
return __async(this, null, function* () {
|
|
2342
|
+
try {
|
|
2343
|
+
return yield this.adapter.set("extensionId", extensionId);
|
|
2344
|
+
} catch (err) {
|
|
2345
|
+
throw new StorageSetErr(
|
|
2346
|
+
this.adapter.platform,
|
|
2347
|
+
"extensionId",
|
|
2348
|
+
err.message
|
|
2349
|
+
);
|
|
2350
|
+
}
|
|
2351
|
+
});
|
|
2352
|
+
}
|
|
2353
|
+
removeExtensionId() {
|
|
2354
|
+
return __async(this, null, function* () {
|
|
2355
|
+
try {
|
|
2356
|
+
return yield this.adapter.delete("extensionId");
|
|
2357
|
+
} catch (err) {
|
|
2358
|
+
throw new StorageDeleteErr(
|
|
2359
|
+
this.adapter.platform,
|
|
2360
|
+
"extensionId",
|
|
2361
|
+
err.message
|
|
2362
|
+
);
|
|
2363
|
+
}
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
removeAnonId() {
|
|
2367
|
+
return __async(this, null, function* () {
|
|
2368
|
+
try {
|
|
2369
|
+
return yield this.adapter.delete("anonId");
|
|
2370
|
+
} catch (err) {
|
|
2371
|
+
throw new StorageDeleteErr(this.adapter.platform, "anonId", err.message);
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
getDebug() {
|
|
2376
|
+
return __async(this, null, function* () {
|
|
2377
|
+
try {
|
|
2378
|
+
return yield this.adapter.get("DEBUG");
|
|
2379
|
+
} catch (err) {
|
|
2380
|
+
throw new StorageGetErr(this.adapter.platform, "DEBUG", err.message);
|
|
2381
|
+
}
|
|
2382
|
+
});
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
|
|
2386
|
+
// src/ui/index.ts
|
|
2387
|
+
import MetaMaskOnboarding from "@metamask/onboarding";
|
|
2388
|
+
init_domain();
|
|
2389
|
+
|
|
2390
|
+
// src/ui/qr.ts
|
|
2391
|
+
var encodeQRImpl = null;
|
|
2392
|
+
function preloadQR() {
|
|
2393
|
+
return __async(this, null, function* () {
|
|
2394
|
+
if (encodeQRImpl) {
|
|
2395
|
+
return;
|
|
2396
|
+
}
|
|
2397
|
+
const mod = yield import("@paulmillr/qr");
|
|
2398
|
+
encodeQRImpl = mod.default;
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
// src/ui/index.ts
|
|
2403
|
+
var __instance;
|
|
2404
|
+
function preload() {
|
|
2405
|
+
return __async(this, null, function* () {
|
|
2406
|
+
__instance != null ? __instance : __instance = yield import(
|
|
2407
|
+
// Use a non-literal specifier to avoid Vite static analysis of deep imports
|
|
2408
|
+
// and gracefully handle absence of the Stencil loader in this package build.
|
|
2409
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2410
|
+
// @ts-ignore
|
|
2411
|
+
"@metamask/multichain-ui".concat("/dist/loader/index.js")
|
|
2412
|
+
// Prefer ESM loader in browsers
|
|
2413
|
+
).then((loader) => __async(null, null, function* () {
|
|
2414
|
+
if (typeof (loader == null ? void 0 : loader.defineCustomElements) === "function") {
|
|
2415
|
+
loader.defineCustomElements();
|
|
2416
|
+
}
|
|
2417
|
+
return Promise.resolve(loader);
|
|
2418
|
+
})).catch((error) => __async(null, null, function* () {
|
|
2419
|
+
console.error(`Gracefully Failed to load modal customElements:`, error);
|
|
2420
|
+
return Promise.resolve(void 0);
|
|
2421
|
+
}));
|
|
2422
|
+
});
|
|
2423
|
+
}
|
|
2424
|
+
var ModalFactory = class {
|
|
2425
|
+
/**
|
|
2426
|
+
* Creates a new modal factory instance.
|
|
2427
|
+
*
|
|
2428
|
+
* @param options - The modals configuration object
|
|
2429
|
+
*/
|
|
2430
|
+
constructor(options) {
|
|
2431
|
+
this.options = options;
|
|
2432
|
+
this.platform = getPlatformType();
|
|
2433
|
+
this.validateModals();
|
|
2434
|
+
}
|
|
2435
|
+
validateModals() {
|
|
2436
|
+
const requiredModals = ["InstallModal", "OTPCodeModal"];
|
|
2437
|
+
const missingModals = requiredModals.filter(
|
|
2438
|
+
(modal) => !this.options[modal]
|
|
2439
|
+
);
|
|
2440
|
+
if (missingModals.length > 0) {
|
|
2441
|
+
throw new Error(`Missing required modals: ${missingModals.join(", ")}`);
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
unload(error) {
|
|
2445
|
+
return __async(this, null, function* () {
|
|
2446
|
+
var _a, _b;
|
|
2447
|
+
(_a = this.modal) == null ? void 0 : _a.unmount();
|
|
2448
|
+
yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Determines if the current platform is a mobile native environment.
|
|
2453
|
+
* Currently only includes React Native.
|
|
2454
|
+
*/
|
|
2455
|
+
get isMobile() {
|
|
2456
|
+
return this.platform === "react-native" /* ReactNative */;
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* Determines if the current platform is a Node.js environment.
|
|
2460
|
+
* Used for server-side or non-browser environments.
|
|
2461
|
+
*/
|
|
2462
|
+
get isNode() {
|
|
2463
|
+
return this.platform === "nodejs" /* NonBrowser */;
|
|
2464
|
+
}
|
|
2465
|
+
/**
|
|
2466
|
+
* Determines if the current platform is a web environment.
|
|
2467
|
+
* Includes desktop web, MetaMask mobile webview, and mobile web.
|
|
2468
|
+
*/
|
|
2469
|
+
get isWeb() {
|
|
2470
|
+
return this.platform === "web-desktop" /* DesktopWeb */ || this.platform === "in-app-browser" /* MetaMaskMobileWebview */ || this.platform === "web-mobile" /* MobileWeb */;
|
|
2471
|
+
}
|
|
2472
|
+
getContainer() {
|
|
2473
|
+
return typeof document === "undefined" ? void 0 : document.createElement("div");
|
|
2474
|
+
}
|
|
2475
|
+
getMountedContainer() {
|
|
2476
|
+
if (typeof document === "undefined") {
|
|
2477
|
+
return void 0;
|
|
2478
|
+
}
|
|
2479
|
+
const container = this.getContainer();
|
|
2480
|
+
if (container) {
|
|
2481
|
+
document.body.appendChild(container);
|
|
2482
|
+
}
|
|
2483
|
+
return container;
|
|
2484
|
+
}
|
|
2485
|
+
createDeeplink(connectionRequest) {
|
|
2486
|
+
if (!connectionRequest) {
|
|
2487
|
+
return `${METAMASK_DEEPLINK_BASE}`;
|
|
2488
|
+
}
|
|
2489
|
+
const json = JSON.stringify(connectionRequest);
|
|
2490
|
+
const compressed = compressString(json);
|
|
2491
|
+
const urlEncoded = encodeURIComponent(compressed);
|
|
2492
|
+
return `${METAMASK_DEEPLINK_BASE}/mwp?p=${urlEncoded}&c=1`;
|
|
2493
|
+
}
|
|
2494
|
+
createUniversalLink(connectionRequest) {
|
|
2495
|
+
if (!connectionRequest) {
|
|
2496
|
+
return `${METAMASK_CONNECT_BASE_URL}`;
|
|
2497
|
+
}
|
|
2498
|
+
const json = JSON.stringify(connectionRequest);
|
|
2499
|
+
const compressed = compressString(json);
|
|
2500
|
+
const urlEncoded = encodeURIComponent(compressed);
|
|
2501
|
+
return `${METAMASK_CONNECT_BASE_URL}/mwp?p=${urlEncoded}&c=1`;
|
|
2502
|
+
}
|
|
2503
|
+
onCloseModal(shouldTerminate = true) {
|
|
2504
|
+
return __async(this, null, function* () {
|
|
2505
|
+
return this.unload(
|
|
2506
|
+
shouldTerminate ? new Error("User closed modal") : void 0
|
|
2507
|
+
);
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
onStartDesktopOnboarding() {
|
|
2511
|
+
new MetaMaskOnboarding().startOnboarding();
|
|
2512
|
+
}
|
|
2513
|
+
renderInstallModal(preferDesktop, createConnectionRequest, successCallback) {
|
|
2514
|
+
return __async(this, null, function* () {
|
|
2515
|
+
var _a;
|
|
2516
|
+
(_a = this.modal) == null ? void 0 : _a.unmount();
|
|
2517
|
+
yield Promise.all([preload(), preloadQR()]);
|
|
2518
|
+
this.successCallback = successCallback;
|
|
2519
|
+
const parentElement = this.getMountedContainer();
|
|
2520
|
+
const connectionRequest = yield createConnectionRequest();
|
|
2521
|
+
const qrCodeLink = this.createDeeplink(connectionRequest);
|
|
2522
|
+
const modal = new this.options.InstallModal({
|
|
2523
|
+
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
2524
|
+
connectionRequest,
|
|
2525
|
+
parentElement,
|
|
2526
|
+
preferDesktop,
|
|
2527
|
+
link: qrCodeLink,
|
|
2528
|
+
sdkVersion: getVersion(),
|
|
2529
|
+
generateQRCode: (request) => __async(this, null, function* () {
|
|
2530
|
+
return this.createDeeplink(request);
|
|
2531
|
+
}),
|
|
2532
|
+
onClose: this.onCloseModal.bind(this),
|
|
2533
|
+
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
2534
|
+
createConnectionRequest
|
|
2535
|
+
});
|
|
2536
|
+
this.modal = modal;
|
|
2537
|
+
modal.mount();
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
|
|
2541
|
+
return __async(this, null, function* () {
|
|
2542
|
+
var _a;
|
|
2543
|
+
(_a = this.modal) == null ? void 0 : _a.unmount();
|
|
2544
|
+
yield Promise.all([preload(), preloadQR()]);
|
|
2545
|
+
this.successCallback = successCallback;
|
|
2546
|
+
const container = this.getMountedContainer();
|
|
2547
|
+
const otpCode = yield createOTPCode();
|
|
2548
|
+
const modal = new this.options.OTPCodeModal({
|
|
2549
|
+
parentElement: container,
|
|
2550
|
+
sdkVersion: getVersion(),
|
|
2551
|
+
otpCode,
|
|
2552
|
+
onClose: this.onCloseModal.bind(this),
|
|
2553
|
+
createOTPCode,
|
|
2554
|
+
updateOTPCode: (otpCode2) => updateOTPCode(otpCode2, modal)
|
|
2555
|
+
});
|
|
2556
|
+
this.modal = modal;
|
|
2557
|
+
modal.mount();
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
|
|
2562
|
+
// src/index.browser.ts
|
|
2563
|
+
init_domain();
|
|
2564
|
+
var createMetamaskConnect = (options) => __async(null, null, function* () {
|
|
2565
|
+
const uiModules = yield Promise.resolve().then(() => (init_web(), web_exports));
|
|
2566
|
+
let storage;
|
|
2567
|
+
if (!options.storage) {
|
|
2568
|
+
const { StoreAdapterWeb: StoreAdapterWeb2 } = yield Promise.resolve().then(() => (init_web2(), web_exports2));
|
|
2569
|
+
const adapter = new StoreAdapterWeb2();
|
|
2570
|
+
storage = new Store(adapter);
|
|
2571
|
+
} else {
|
|
2572
|
+
storage = options.storage;
|
|
2573
|
+
}
|
|
2574
|
+
const factory = new ModalFactory(uiModules);
|
|
2575
|
+
return MultichainSDK.create(__spreadProps(__spreadValues({}, options), {
|
|
2576
|
+
storage,
|
|
2577
|
+
ui: __spreadProps(__spreadValues({}, options.ui), {
|
|
2578
|
+
factory
|
|
2579
|
+
})
|
|
2580
|
+
}));
|
|
2581
|
+
});
|
|
2582
|
+
export {
|
|
2583
|
+
EventEmitter,
|
|
2584
|
+
Modal,
|
|
2585
|
+
MultichainCore,
|
|
2586
|
+
PlatformType,
|
|
2587
|
+
RPCHttpErr,
|
|
2588
|
+
RPCInvokeMethodErr,
|
|
2589
|
+
RPCReadonlyRequestErr,
|
|
2590
|
+
RPCReadonlyResponseErr,
|
|
2591
|
+
RPC_HANDLED_METHODS,
|
|
2592
|
+
SDK_HANDLED_METHODS,
|
|
2593
|
+
StoreAdapter,
|
|
2594
|
+
StoreClient,
|
|
2595
|
+
TransportType,
|
|
2596
|
+
createLogger,
|
|
2597
|
+
createMetamaskConnect,
|
|
2598
|
+
enableDebug,
|
|
2599
|
+
getInfuraRpcUrls,
|
|
2600
|
+
getPlatformType,
|
|
2601
|
+
getTransportType,
|
|
2602
|
+
getVersion,
|
|
2603
|
+
hasExtension,
|
|
2604
|
+
infuraRpcUrls,
|
|
2605
|
+
isEnabled,
|
|
2606
|
+
isMetamaskExtensionInstalled,
|
|
2607
|
+
isSecure
|
|
2608
|
+
};
|
|
2609
|
+
//# sourceMappingURL=connect-multichain.mjs.map
|