@metamask/connect-multichain 0.5.2 → 0.5.3
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 +12 -1
- package/README.md +409 -3
- package/dist/browser/es/connect-multichain.d.mts +6 -5
- package/dist/browser/es/connect-multichain.mjs +308 -224
- package/dist/browser/es/connect-multichain.mjs.map +1 -1
- package/dist/browser/es/metafile-esm.json +1 -1
- package/dist/browser/iife/connect-multichain.d.ts +6 -5
- package/dist/browser/iife/connect-multichain.js +24209 -24108
- package/dist/browser/iife/connect-multichain.js.map +1 -1
- package/dist/browser/iife/metafile-iife.json +1 -1
- package/dist/browser/umd/connect-multichain.d.ts +6 -5
- package/dist/browser/umd/connect-multichain.js +309 -225
- package/dist/browser/umd/connect-multichain.js.map +1 -1
- package/dist/browser/umd/metafile-cjs.json +1 -1
- package/dist/node/cjs/connect-multichain.d.ts +6 -5
- package/dist/node/cjs/connect-multichain.js +311 -228
- package/dist/node/cjs/connect-multichain.js.map +1 -1
- package/dist/node/cjs/metafile-cjs.json +1 -1
- package/dist/node/es/connect-multichain.d.mts +6 -5
- package/dist/node/es/connect-multichain.mjs +311 -226
- package/dist/node/es/connect-multichain.mjs.map +1 -1
- package/dist/node/es/metafile-esm.json +1 -1
- package/dist/react-native/es/connect-multichain.d.mts +6 -5
- package/dist/react-native/es/connect-multichain.mjs +308 -224
- package/dist/react-native/es/connect-multichain.mjs.map +1 -1
- package/dist/react-native/es/metafile-esm.json +1 -1
- package/dist/src/domain/logger/index.d.ts +1 -1
- package/dist/src/domain/logger/index.d.ts.map +1 -1
- package/dist/src/domain/logger/index.js.map +1 -1
- package/dist/src/domain/multichain/api/constants.js.map +1 -1
- package/dist/src/domain/multichain/api/types.d.ts +1 -1
- package/dist/src/domain/multichain/api/types.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +2 -0
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/platform/index.d.ts.map +1 -1
- package/dist/src/domain/platform/index.js +1 -0
- package/dist/src/domain/platform/index.js.map +1 -1
- package/dist/src/index.browser.d.ts.map +1 -1
- package/dist/src/index.browser.js +9 -4
- package/dist/src/index.browser.js.map +1 -1
- package/dist/src/index.native.d.ts.map +1 -1
- package/dist/src/index.native.js +9 -4
- package/dist/src/index.native.js.map +1 -1
- package/dist/src/index.node.d.ts.map +1 -1
- package/dist/src/index.node.js +8 -4
- package/dist/src/index.node.js.map +1 -1
- package/dist/src/multichain/index.d.ts +1 -1
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +34 -9
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/handlers/rpcClient.d.ts +9 -2
- package/dist/src/multichain/rpc/handlers/rpcClient.d.ts.map +1 -1
- package/dist/src/multichain/rpc/handlers/rpcClient.js +13 -3
- package/dist/src/multichain/rpc/handlers/rpcClient.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.d.ts +14 -1
- package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +27 -5
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +2 -2
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +14 -17
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +0 -2
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +18 -11
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/KeyManager.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/KeyManager.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +2 -1
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/multichain/utils/analytics.d.ts.map +1 -1
- package/dist/src/multichain/utils/analytics.js +1 -0
- package/dist/src/multichain/utils/analytics.js.map +1 -1
- package/dist/src/multichain/utils/index.d.ts +25 -0
- package/dist/src/multichain/utils/index.d.ts.map +1 -1
- package/dist/src/multichain/utils/index.js +38 -6
- package/dist/src/multichain/utils/index.js.map +1 -1
- package/dist/src/polyfills/buffer-shim.js +7 -3
- package/dist/src/polyfills/buffer-shim.js.map +1 -1
- package/dist/src/store/adapters/node.d.ts +1 -1
- package/dist/src/store/adapters/node.d.ts.map +1 -1
- package/dist/src/store/adapters/node.js +11 -4
- package/dist/src/store/adapters/node.js.map +1 -1
- package/dist/src/store/adapters/rn.d.ts.map +1 -1
- package/dist/src/store/adapters/rn.js +1 -0
- package/dist/src/store/adapters/rn.js.map +1 -1
- package/dist/src/store/adapters/web.d.ts +4 -4
- package/dist/src/store/adapters/web.d.ts.map +1 -1
- package/dist/src/store/adapters/web.js +6 -0
- package/dist/src/store/adapters/web.js.map +1 -1
- package/dist/src/store/index.d.ts.map +1 -1
- package/dist/src/store/index.js +2 -0
- package/dist/src/store/index.js.map +1 -1
- package/dist/src/ui/ModalFactory.d.ts.map +1 -1
- package/dist/src/ui/ModalFactory.js +1 -4
- package/dist/src/ui/ModalFactory.js.map +1 -1
- package/dist/src/ui/index.d.ts.map +1 -1
- package/dist/src/ui/index.js +2 -0
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/index.native.d.ts.map +1 -1
- package/dist/src/ui/index.native.js +4 -1
- package/dist/src/ui/index.native.js.map +1 -1
- package/dist/src/ui/modals/base/AbstractInstallModal.d.ts +2 -3
- package/dist/src/ui/modals/base/AbstractInstallModal.d.ts.map +1 -1
- package/dist/src/ui/modals/base/AbstractInstallModal.js +28 -12
- package/dist/src/ui/modals/base/AbstractInstallModal.js.map +1 -1
- package/dist/src/ui/modals/base/AbstractOTPModal.d.ts +2 -2
- package/dist/src/ui/modals/base/AbstractOTPModal.d.ts.map +1 -1
- package/dist/src/ui/modals/base/AbstractOTPModal.js.map +1 -1
- package/dist/src/ui/modals/base/utils.d.ts +12 -0
- package/dist/src/ui/modals/base/utils.d.ts.map +1 -1
- package/dist/src/ui/modals/base/utils.js +16 -5
- package/dist/src/ui/modals/base/utils.js.map +1 -1
- package/dist/src/ui/modals/node/install.d.ts.map +1 -1
- package/dist/src/ui/modals/node/install.js +1 -1
- package/dist/src/ui/modals/node/install.js.map +1 -1
- package/dist/src/ui/modals/node/otp.d.ts.map +1 -1
- package/dist/src/ui/modals/node/otp.js +6 -2
- package/dist/src/ui/modals/node/otp.js.map +1 -1
- package/dist/src/ui/modals/rn/install.d.ts.map +1 -1
- package/dist/src/ui/modals/rn/install.js +7 -3
- package/dist/src/ui/modals/rn/install.js.map +1 -1
- package/dist/src/ui/modals/rn/otp.d.ts.map +1 -1
- package/dist/src/ui/modals/rn/otp.js +6 -2
- package/dist/src/ui/modals/rn/otp.js.map +1 -1
- package/dist/src/ui/modals/web/install.d.ts.map +1 -1
- package/dist/src/ui/modals/web/install.js +1 -1
- package/dist/src/ui/modals/web/install.js.map +1 -1
- package/dist/src/ui/modals/web/otp.d.ts.map +1 -1
- package/dist/src/ui/modals/web/otp.js +6 -2
- package/dist/src/ui/modals/web/otp.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +6 -5
- package/package.json +3 -3
|
@@ -34,6 +34,14 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
34
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
35
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
36
36
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
37
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
38
|
+
set _(value) {
|
|
39
|
+
__privateSet(obj, member, value, setter);
|
|
40
|
+
},
|
|
41
|
+
get _() {
|
|
42
|
+
return __privateGet(obj, member, getter);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
37
45
|
var __async = (__this, __arguments, generator) => {
|
|
38
46
|
return new Promise((resolve, reject) => {
|
|
39
47
|
var fulfilled = (value) => {
|
|
@@ -584,11 +592,11 @@ var init_ui = __esm({
|
|
|
584
592
|
});
|
|
585
593
|
|
|
586
594
|
// src/multichain/utils/index.ts
|
|
587
|
-
import { deflate } from "pako";
|
|
588
595
|
import {
|
|
589
596
|
parseCaipAccountId,
|
|
590
597
|
parseCaipChainId
|
|
591
598
|
} from "@metamask/utils";
|
|
599
|
+
import { deflate } from "pako";
|
|
592
600
|
function base64Encode(str) {
|
|
593
601
|
if (typeof btoa !== "undefined") {
|
|
594
602
|
return btoa(str);
|
|
@@ -607,8 +615,9 @@ function getDappId(dapp) {
|
|
|
607
615
|
return (_a2 = dapp.url) != null ? _a2 : dapp.name;
|
|
608
616
|
}
|
|
609
617
|
function openDeeplink(options, deeplink, universalLink) {
|
|
618
|
+
var _a2;
|
|
610
619
|
const { mobile } = options;
|
|
611
|
-
const useDeeplink =
|
|
620
|
+
const useDeeplink = (_a2 = mobile == null ? void 0 : mobile.useDeeplink) != null ? _a2 : true;
|
|
612
621
|
if (useDeeplink) {
|
|
613
622
|
if (typeof window !== "undefined") {
|
|
614
623
|
window.location.href = deeplink;
|
|
@@ -649,7 +658,7 @@ function setupDappMetadata(options) {
|
|
|
649
658
|
throw new Error("You must provide dapp url");
|
|
650
659
|
}
|
|
651
660
|
const BASE_64_ICON_MAX_LENGTH = 163400;
|
|
652
|
-
const urlPattern = /^(http|https):\/\/[^\s]
|
|
661
|
+
const urlPattern = /^(http|https):\/\/[^\s]*$/u;
|
|
653
662
|
if (options.dapp) {
|
|
654
663
|
if ("iconUrl" in options.dapp) {
|
|
655
664
|
if (options.dapp.iconUrl && !urlPattern.test(options.dapp.iconUrl)) {
|
|
@@ -698,9 +707,12 @@ function getValidAccounts(caipAccountIds) {
|
|
|
698
707
|
(caipAccounts, caipAccountId) => {
|
|
699
708
|
try {
|
|
700
709
|
return [...caipAccounts, parseCaipAccountId(caipAccountId)];
|
|
701
|
-
} catch (
|
|
710
|
+
} catch (error) {
|
|
702
711
|
const stringifiedAccountId = JSON.stringify(caipAccountId);
|
|
703
|
-
console.error(
|
|
712
|
+
console.error(
|
|
713
|
+
`Invalid CAIP account ID: ${stringifiedAccountId}`,
|
|
714
|
+
error
|
|
715
|
+
);
|
|
704
716
|
return caipAccounts;
|
|
705
717
|
}
|
|
706
718
|
},
|
|
@@ -861,7 +873,9 @@ var init_domain = __esm({
|
|
|
861
873
|
|
|
862
874
|
// src/ui/modals/base/utils.ts
|
|
863
875
|
function formatRemainingTime(milliseconds) {
|
|
864
|
-
if (milliseconds <= 0)
|
|
876
|
+
if (milliseconds <= 0) {
|
|
877
|
+
return "EXPIRED";
|
|
878
|
+
}
|
|
865
879
|
const seconds = Math.floor(milliseconds / 1e3);
|
|
866
880
|
return `${seconds}s`;
|
|
867
881
|
}
|
|
@@ -874,9 +888,8 @@ function shouldLogCountdown(remainingSeconds) {
|
|
|
874
888
|
return remainingSeconds % 10 === 0;
|
|
875
889
|
} else if (remainingSeconds <= 300) {
|
|
876
890
|
return remainingSeconds % 30 === 0;
|
|
877
|
-
} else {
|
|
878
|
-
return remainingSeconds % 60 === 0;
|
|
879
891
|
}
|
|
892
|
+
return remainingSeconds % 60 === 0;
|
|
880
893
|
}
|
|
881
894
|
var init_utils3 = __esm({
|
|
882
895
|
"src/ui/modals/base/utils.ts"() {
|
|
@@ -885,18 +898,18 @@ var init_utils3 = __esm({
|
|
|
885
898
|
});
|
|
886
899
|
|
|
887
900
|
// src/ui/modals/base/AbstractInstallModal.ts
|
|
888
|
-
var logger3, AbstractInstallModal;
|
|
901
|
+
var logger3, _expirationInterval, _lastLoggedCountdown, AbstractInstallModal;
|
|
889
902
|
var init_AbstractInstallModal = __esm({
|
|
890
903
|
"src/ui/modals/base/AbstractInstallModal.ts"() {
|
|
891
904
|
"use strict";
|
|
892
|
-
init_domain();
|
|
893
905
|
init_utils3();
|
|
906
|
+
init_domain();
|
|
894
907
|
logger3 = createLogger("metamask-sdk:ui");
|
|
895
908
|
AbstractInstallModal = class extends Modal {
|
|
896
909
|
constructor() {
|
|
897
910
|
super(...arguments);
|
|
898
|
-
this
|
|
899
|
-
this
|
|
911
|
+
__privateAdd(this, _expirationInterval, null);
|
|
912
|
+
__privateAdd(this, _lastLoggedCountdown, -1);
|
|
900
913
|
}
|
|
901
914
|
get link() {
|
|
902
915
|
return this.data;
|
|
@@ -924,17 +937,17 @@ var init_AbstractInstallModal = __esm({
|
|
|
924
937
|
startExpirationCheck(connectionRequest) {
|
|
925
938
|
this.stopExpirationCheck();
|
|
926
939
|
let currentConnectionRequest = connectionRequest;
|
|
927
|
-
this
|
|
940
|
+
__privateSet(this, _expirationInterval, setInterval(() => __async(this, null, function* () {
|
|
928
941
|
const { sessionRequest } = currentConnectionRequest;
|
|
929
942
|
const now = Date.now();
|
|
930
943
|
const remainingMs = sessionRequest.expiresAt - now;
|
|
931
944
|
const remainingSeconds = Math.floor(remainingMs / 1e3);
|
|
932
|
-
if (remainingMs > 0 && shouldLogCountdown(remainingSeconds) && this
|
|
945
|
+
if (remainingMs > 0 && shouldLogCountdown(remainingSeconds) && __privateGet(this, _lastLoggedCountdown) !== remainingSeconds) {
|
|
933
946
|
const formattedTime = formatRemainingTime(remainingMs);
|
|
934
947
|
logger3(
|
|
935
948
|
`[UI: InstallModal-nodejs()] QR code expires in: ${formattedTime} (${remainingSeconds}s)`
|
|
936
949
|
);
|
|
937
|
-
this
|
|
950
|
+
__privateSet(this, _lastLoggedCountdown, remainingSeconds);
|
|
938
951
|
}
|
|
939
952
|
if (now >= sessionRequest.expiresAt) {
|
|
940
953
|
this.stopExpirationCheck();
|
|
@@ -946,7 +959,7 @@ var init_AbstractInstallModal = __esm({
|
|
|
946
959
|
const generateQRCode = yield this.options.generateQRCode(
|
|
947
960
|
currentConnectionRequest
|
|
948
961
|
);
|
|
949
|
-
this
|
|
962
|
+
__privateSet(this, _lastLoggedCountdown, -1);
|
|
950
963
|
this.updateLink(generateQRCode);
|
|
951
964
|
this.updateExpiresIn(remainingSeconds);
|
|
952
965
|
this.renderQRCode(generateQRCode, currentConnectionRequest);
|
|
@@ -956,18 +969,20 @@ var init_AbstractInstallModal = __esm({
|
|
|
956
969
|
);
|
|
957
970
|
}
|
|
958
971
|
}
|
|
959
|
-
}), 1e3);
|
|
972
|
+
}), 1e3));
|
|
960
973
|
}
|
|
961
974
|
stopExpirationCheck() {
|
|
962
|
-
if (this
|
|
963
|
-
clearInterval(this
|
|
964
|
-
this
|
|
975
|
+
if (__privateGet(this, _expirationInterval)) {
|
|
976
|
+
clearInterval(__privateGet(this, _expirationInterval));
|
|
977
|
+
__privateSet(this, _expirationInterval, null);
|
|
965
978
|
logger3(
|
|
966
979
|
"[UI: InstallModal-nodejs()] \u{1F6D1} Stopped QR code expiration checking"
|
|
967
980
|
);
|
|
968
981
|
}
|
|
969
982
|
}
|
|
970
983
|
};
|
|
984
|
+
_expirationInterval = new WeakMap();
|
|
985
|
+
_lastLoggedCountdown = new WeakMap();
|
|
971
986
|
}
|
|
972
987
|
});
|
|
973
988
|
|
|
@@ -1080,7 +1095,7 @@ var node_exports2 = {};
|
|
|
1080
1095
|
__export(node_exports2, {
|
|
1081
1096
|
StoreAdapterNode: () => StoreAdapterNode
|
|
1082
1097
|
});
|
|
1083
|
-
var StoreAdapterNode;
|
|
1098
|
+
var _storage, StoreAdapterNode;
|
|
1084
1099
|
var init_node2 = __esm({
|
|
1085
1100
|
"src/store/adapters/node.ts"() {
|
|
1086
1101
|
"use strict";
|
|
@@ -1089,28 +1104,32 @@ var init_node2 = __esm({
|
|
|
1089
1104
|
constructor() {
|
|
1090
1105
|
super(...arguments);
|
|
1091
1106
|
this.platform = "node";
|
|
1092
|
-
this
|
|
1107
|
+
__privateAdd(this, _storage, /* @__PURE__ */ new Map());
|
|
1093
1108
|
}
|
|
1094
1109
|
get(key) {
|
|
1095
1110
|
return __async(this, null, function* () {
|
|
1096
1111
|
var _a2;
|
|
1097
|
-
return (_a2 = this.
|
|
1112
|
+
return (_a2 = __privateGet(this, _storage).get(key)) != null ? _a2 : null;
|
|
1098
1113
|
});
|
|
1099
1114
|
}
|
|
1100
1115
|
set(key, value) {
|
|
1101
1116
|
return __async(this, null, function* () {
|
|
1102
|
-
this.
|
|
1117
|
+
__privateGet(this, _storage).set(key, value);
|
|
1103
1118
|
});
|
|
1104
1119
|
}
|
|
1105
1120
|
delete(key) {
|
|
1106
1121
|
return __async(this, null, function* () {
|
|
1107
|
-
this.
|
|
1122
|
+
__privateGet(this, _storage).delete(key);
|
|
1108
1123
|
});
|
|
1109
1124
|
}
|
|
1110
1125
|
};
|
|
1126
|
+
_storage = new WeakMap();
|
|
1111
1127
|
}
|
|
1112
1128
|
});
|
|
1113
1129
|
|
|
1130
|
+
// src/index.node.ts
|
|
1131
|
+
init_domain();
|
|
1132
|
+
|
|
1114
1133
|
// src/multichain/index.ts
|
|
1115
1134
|
import { analytics as analytics2 } from "@metamask/analytics";
|
|
1116
1135
|
import {
|
|
@@ -1153,7 +1172,9 @@ var RpcClient = class {
|
|
|
1153
1172
|
}
|
|
1154
1173
|
/**
|
|
1155
1174
|
* Routes the request to a configured RPC node.
|
|
1156
|
-
*
|
|
1175
|
+
*
|
|
1176
|
+
* @param options - The invoke method options.
|
|
1177
|
+
* @returns The JSON response from the RPC node.
|
|
1157
1178
|
*/
|
|
1158
1179
|
request(options) {
|
|
1159
1180
|
return __async(this, null, function* () {
|
|
@@ -1165,7 +1186,13 @@ var RpcClient = class {
|
|
|
1165
1186
|
id: getNextRpcId()
|
|
1166
1187
|
});
|
|
1167
1188
|
const rpcEndpoint = this.getRpcEndpoint(options.scope);
|
|
1168
|
-
const rpcRequest = yield this.fetchWithTimeout(
|
|
1189
|
+
const rpcRequest = yield this.fetchWithTimeout(
|
|
1190
|
+
rpcEndpoint,
|
|
1191
|
+
body,
|
|
1192
|
+
"POST",
|
|
1193
|
+
this.getHeaders(rpcEndpoint),
|
|
1194
|
+
3e4
|
|
1195
|
+
);
|
|
1169
1196
|
const response = yield this.parseResponse(rpcRequest);
|
|
1170
1197
|
return response;
|
|
1171
1198
|
});
|
|
@@ -1175,7 +1202,9 @@ var RpcClient = class {
|
|
|
1175
1202
|
const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
|
|
1176
1203
|
const rpcEndpoint = supportedNetworks[scope];
|
|
1177
1204
|
if (!rpcEndpoint) {
|
|
1178
|
-
throw new MissingRpcEndpointErr(
|
|
1205
|
+
throw new MissingRpcEndpointErr(
|
|
1206
|
+
`No RPC endpoint found for scope ${scope}`
|
|
1207
|
+
);
|
|
1179
1208
|
}
|
|
1180
1209
|
return rpcEndpoint;
|
|
1181
1210
|
}
|
|
@@ -1203,7 +1232,7 @@ var RpcClient = class {
|
|
|
1203
1232
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1204
1233
|
throw new RPCReadonlyRequestErr(`Request timeout after ${timeout}ms`);
|
|
1205
1234
|
}
|
|
1206
|
-
throw new RPCReadonlyRequestErr(error
|
|
1235
|
+
throw new RPCReadonlyRequestErr(error.message);
|
|
1207
1236
|
}
|
|
1208
1237
|
});
|
|
1209
1238
|
}
|
|
@@ -1248,10 +1277,12 @@ var RequestRouter = class {
|
|
|
1248
1277
|
* The main entry point for invoking an RPC method.
|
|
1249
1278
|
* This method acts as a router, determining the correct handling strategy
|
|
1250
1279
|
* for the request and delegating to the appropriate private handler.
|
|
1280
|
+
*
|
|
1281
|
+
* @param options
|
|
1251
1282
|
*/
|
|
1252
1283
|
invokeMethod(options) {
|
|
1253
1284
|
return __async(this, null, function* () {
|
|
1254
|
-
const method = options.request
|
|
1285
|
+
const { method } = options.request;
|
|
1255
1286
|
if (RPC_HANDLED_METHODS.has(method)) {
|
|
1256
1287
|
return this.handleWithRpcNode(options);
|
|
1257
1288
|
}
|
|
@@ -1263,6 +1294,8 @@ var RequestRouter = class {
|
|
|
1263
1294
|
}
|
|
1264
1295
|
/**
|
|
1265
1296
|
* Forwards the request directly to the wallet via the transport.
|
|
1297
|
+
*
|
|
1298
|
+
* @param options
|
|
1266
1299
|
*/
|
|
1267
1300
|
handleWithWallet(options) {
|
|
1268
1301
|
return __async(this, null, function* () {
|
|
@@ -1291,7 +1324,10 @@ var RequestRouter = class {
|
|
|
1291
1324
|
}
|
|
1292
1325
|
const response = yield request;
|
|
1293
1326
|
if (response.error) {
|
|
1294
|
-
|
|
1327
|
+
const { error } = response;
|
|
1328
|
+
throw new RPCInvokeMethodErr(
|
|
1329
|
+
`RPC Request failed with code ${error.code}: ${error.message}`
|
|
1330
|
+
);
|
|
1295
1331
|
}
|
|
1296
1332
|
return response.result;
|
|
1297
1333
|
}));
|
|
@@ -1299,6 +1335,8 @@ var RequestRouter = class {
|
|
|
1299
1335
|
}
|
|
1300
1336
|
/**
|
|
1301
1337
|
* Routes the request to a configured RPC node.
|
|
1338
|
+
*
|
|
1339
|
+
* @param options
|
|
1302
1340
|
*/
|
|
1303
1341
|
handleWithRpcNode(options) {
|
|
1304
1342
|
return __async(this, null, function* () {
|
|
@@ -1316,10 +1354,14 @@ var RequestRouter = class {
|
|
|
1316
1354
|
}
|
|
1317
1355
|
/**
|
|
1318
1356
|
* Responds directly from the SDK's session state.
|
|
1357
|
+
*
|
|
1358
|
+
* @param options
|
|
1319
1359
|
*/
|
|
1320
1360
|
handleWithSdkState(options) {
|
|
1321
1361
|
return __async(this, null, function* () {
|
|
1322
|
-
console.warn(
|
|
1362
|
+
console.warn(
|
|
1363
|
+
`Method "${options.request.method}" is configured for SDK state handling, but this is not yet implemented. Falling back to wallet passthrough.`
|
|
1364
|
+
);
|
|
1323
1365
|
return this.handleWithWallet(options);
|
|
1324
1366
|
});
|
|
1325
1367
|
}
|
|
@@ -1339,31 +1381,50 @@ withAnalyticsTracking_fn = function(options, execute) {
|
|
|
1339
1381
|
} else {
|
|
1340
1382
|
yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
|
|
1341
1383
|
}
|
|
1384
|
+
if (error instanceof RPCInvokeMethodErr) {
|
|
1385
|
+
throw error;
|
|
1386
|
+
}
|
|
1342
1387
|
throw new RPCInvokeMethodErr(error.message);
|
|
1343
1388
|
}
|
|
1344
1389
|
});
|
|
1345
1390
|
};
|
|
1346
1391
|
trackWalletActionRequested_fn = function(options) {
|
|
1347
1392
|
return __async(this, null, function* () {
|
|
1348
|
-
const props = yield getWalletActionAnalyticsProperties(
|
|
1393
|
+
const props = yield getWalletActionAnalyticsProperties(
|
|
1394
|
+
this.config,
|
|
1395
|
+
this.config.storage,
|
|
1396
|
+
options
|
|
1397
|
+
);
|
|
1349
1398
|
analytics.track("mmconnect_wallet_action_requested", props);
|
|
1350
1399
|
});
|
|
1351
1400
|
};
|
|
1352
1401
|
trackWalletActionSucceeded_fn = function(options) {
|
|
1353
1402
|
return __async(this, null, function* () {
|
|
1354
|
-
const props = yield getWalletActionAnalyticsProperties(
|
|
1403
|
+
const props = yield getWalletActionAnalyticsProperties(
|
|
1404
|
+
this.config,
|
|
1405
|
+
this.config.storage,
|
|
1406
|
+
options
|
|
1407
|
+
);
|
|
1355
1408
|
analytics.track("mmconnect_wallet_action_succeeded", props);
|
|
1356
1409
|
});
|
|
1357
1410
|
};
|
|
1358
1411
|
trackWalletActionFailed_fn = function(options) {
|
|
1359
1412
|
return __async(this, null, function* () {
|
|
1360
|
-
const props = yield getWalletActionAnalyticsProperties(
|
|
1413
|
+
const props = yield getWalletActionAnalyticsProperties(
|
|
1414
|
+
this.config,
|
|
1415
|
+
this.config.storage,
|
|
1416
|
+
options
|
|
1417
|
+
);
|
|
1361
1418
|
analytics.track("mmconnect_wallet_action_failed", props);
|
|
1362
1419
|
});
|
|
1363
1420
|
};
|
|
1364
1421
|
trackWalletActionRejected_fn = function(options) {
|
|
1365
1422
|
return __async(this, null, function* () {
|
|
1366
|
-
const props = yield getWalletActionAnalyticsProperties(
|
|
1423
|
+
const props = yield getWalletActionAnalyticsProperties(
|
|
1424
|
+
this.config,
|
|
1425
|
+
this.config.storage,
|
|
1426
|
+
options
|
|
1427
|
+
);
|
|
1367
1428
|
analytics.track("mmconnect_wallet_action_rejected", props);
|
|
1368
1429
|
});
|
|
1369
1430
|
};
|
|
@@ -1427,7 +1488,7 @@ var DefaultTransport = class {
|
|
|
1427
1488
|
}
|
|
1428
1489
|
connect(options) {
|
|
1429
1490
|
return __async(this, null, function* () {
|
|
1430
|
-
var _a2, _b, _c, _d, _e
|
|
1491
|
+
var _a2, _b, _c, _d, _e;
|
|
1431
1492
|
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1432
1493
|
yield __privateGet(this, _transport).connect();
|
|
1433
1494
|
const sessionRequest = yield this.request(
|
|
@@ -1438,12 +1499,19 @@ var DefaultTransport = class {
|
|
|
1438
1499
|
throw new Error(sessionRequest.error.message);
|
|
1439
1500
|
}
|
|
1440
1501
|
let walletSession = sessionRequest.result;
|
|
1502
|
+
const createSessionParams = {
|
|
1503
|
+
optionalScopes: addValidAccounts(
|
|
1504
|
+
getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
|
|
1505
|
+
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1506
|
+
),
|
|
1507
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1508
|
+
};
|
|
1441
1509
|
if (walletSession && options && !options.forceRequest) {
|
|
1442
1510
|
const currentScopes = Object.keys(
|
|
1443
|
-
(
|
|
1511
|
+
(_c = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _c : {}
|
|
1444
1512
|
);
|
|
1445
|
-
const proposedScopes = (
|
|
1446
|
-
const proposedCaipAccountIds = (
|
|
1513
|
+
const proposedScopes = (_d = options == null ? void 0 : options.scopes) != null ? _d : [];
|
|
1514
|
+
const proposedCaipAccountIds = (_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [];
|
|
1447
1515
|
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
1448
1516
|
currentScopes,
|
|
1449
1517
|
proposedScopes,
|
|
@@ -1455,13 +1523,6 @@ var DefaultTransport = class {
|
|
|
1455
1523
|
{ method: "wallet_revokeSession", params: walletSession },
|
|
1456
1524
|
__privateGet(this, _defaultRequestOptions)
|
|
1457
1525
|
);
|
|
1458
|
-
const optionalScopes = addValidAccounts(
|
|
1459
|
-
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
1460
|
-
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
1461
|
-
);
|
|
1462
|
-
const createSessionParams = {
|
|
1463
|
-
optionalScopes
|
|
1464
|
-
};
|
|
1465
1526
|
const response = yield this.request(
|
|
1466
1527
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
1467
1528
|
__privateGet(this, _defaultRequestOptions)
|
|
@@ -1472,14 +1533,6 @@ var DefaultTransport = class {
|
|
|
1472
1533
|
walletSession = response.result;
|
|
1473
1534
|
}
|
|
1474
1535
|
} else if (!walletSession || (options == null ? void 0 : options.forceRequest)) {
|
|
1475
|
-
const optionalScopes = addValidAccounts(
|
|
1476
|
-
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
1477
|
-
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1478
|
-
);
|
|
1479
|
-
const createSessionParams = {
|
|
1480
|
-
optionalScopes,
|
|
1481
|
-
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1482
|
-
};
|
|
1483
1536
|
const response = yield this.request(
|
|
1484
1537
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
1485
1538
|
__privateGet(this, _defaultRequestOptions)
|
|
@@ -1531,7 +1584,11 @@ var DefaultTransport = class {
|
|
|
1531
1584
|
};
|
|
1532
1585
|
}
|
|
1533
1586
|
getActiveSession() {
|
|
1534
|
-
|
|
1587
|
+
return __async(this, null, function* () {
|
|
1588
|
+
throw new Error(
|
|
1589
|
+
"getActiveSession is purposely not implemented for the DefaultTransport"
|
|
1590
|
+
);
|
|
1591
|
+
});
|
|
1535
1592
|
}
|
|
1536
1593
|
};
|
|
1537
1594
|
_notificationCallbacks = new WeakMap();
|
|
@@ -1605,6 +1662,164 @@ setupMessageListener_fn = function() {
|
|
|
1605
1662
|
window.addEventListener("message", __privateGet(this, _handleNotificationListener));
|
|
1606
1663
|
};
|
|
1607
1664
|
|
|
1665
|
+
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
1666
|
+
import { providerErrors } from "@metamask/rpc-errors";
|
|
1667
|
+
var MAX = 4294967295;
|
|
1668
|
+
var idCounter = Math.floor(Math.random() * MAX);
|
|
1669
|
+
var getUniqueId = () => {
|
|
1670
|
+
idCounter = (idCounter + 1) % MAX;
|
|
1671
|
+
return idCounter;
|
|
1672
|
+
};
|
|
1673
|
+
var _requestId, _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
1674
|
+
var MultichainApiClientWrapperTransport = class {
|
|
1675
|
+
constructor(metamaskConnectMultichain) {
|
|
1676
|
+
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
1677
|
+
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
1678
|
+
__privateAdd(this, _requestId, getUniqueId());
|
|
1679
|
+
__privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
|
|
1680
|
+
}
|
|
1681
|
+
isTransportDefined() {
|
|
1682
|
+
try {
|
|
1683
|
+
return Boolean(this.metamaskConnectMultichain.transport);
|
|
1684
|
+
} catch (_error) {
|
|
1685
|
+
return false;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
clearNotificationCallbacks() {
|
|
1689
|
+
__privateGet(this, _notificationCallbacks2).clear();
|
|
1690
|
+
}
|
|
1691
|
+
notifyCallbacks(data) {
|
|
1692
|
+
__privateGet(this, _notificationCallbacks2).forEach((callback) => {
|
|
1693
|
+
callback(data);
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
setupNotifcationListener() {
|
|
1697
|
+
this.metamaskConnectMultichain.transport.onNotification(
|
|
1698
|
+
this.notifyCallbacks.bind(this)
|
|
1699
|
+
);
|
|
1700
|
+
}
|
|
1701
|
+
connect() {
|
|
1702
|
+
return __async(this, null, function* () {
|
|
1703
|
+
console.log("\u{1F4DA} connect");
|
|
1704
|
+
return Promise.resolve();
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
disconnect() {
|
|
1708
|
+
return __async(this, null, function* () {
|
|
1709
|
+
return Promise.resolve();
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
isConnected() {
|
|
1713
|
+
return true;
|
|
1714
|
+
}
|
|
1715
|
+
request(_0) {
|
|
1716
|
+
return __async(this, arguments, function* (params, _options = {}) {
|
|
1717
|
+
const id = __privateWrapper(this, _requestId)._++;
|
|
1718
|
+
const requestPayload = __spreadValues({
|
|
1719
|
+
id,
|
|
1720
|
+
jsonrpc: "2.0"
|
|
1721
|
+
}, params);
|
|
1722
|
+
switch (requestPayload.method) {
|
|
1723
|
+
case "wallet_createSession":
|
|
1724
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
|
|
1725
|
+
case "wallet_getSession":
|
|
1726
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
|
|
1727
|
+
case "wallet_revokeSession":
|
|
1728
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
|
|
1729
|
+
case "wallet_invokeMethod":
|
|
1730
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
|
|
1731
|
+
default:
|
|
1732
|
+
throw new Error(`Unsupported method: ${requestPayload.method}`);
|
|
1733
|
+
}
|
|
1734
|
+
throw new Error(`Unknown method: ${requestPayload.method}`);
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
onNotification(callback) {
|
|
1738
|
+
if (!this.isTransportDefined()) {
|
|
1739
|
+
__privateGet(this, _notificationCallbacks2).add(callback);
|
|
1740
|
+
return () => {
|
|
1741
|
+
__privateGet(this, _notificationCallbacks2).delete(callback);
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
return this.metamaskConnectMultichain.transport.onNotification(callback);
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
_requestId = new WeakMap();
|
|
1748
|
+
_notificationCallbacks2 = new WeakMap();
|
|
1749
|
+
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
1750
|
+
walletCreateSession_fn = function(request) {
|
|
1751
|
+
return __async(this, null, function* () {
|
|
1752
|
+
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
1753
|
+
const createSessionParams = request.params;
|
|
1754
|
+
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
1755
|
+
const scopeAccounts = [];
|
|
1756
|
+
scopes.forEach((scope) => {
|
|
1757
|
+
var _a2, _b, _c, _d;
|
|
1758
|
+
const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
|
|
1759
|
+
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
1760
|
+
if (requiredScope) {
|
|
1761
|
+
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
1762
|
+
}
|
|
1763
|
+
if (optionalScope) {
|
|
1764
|
+
scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
|
|
1765
|
+
}
|
|
1766
|
+
});
|
|
1767
|
+
const accounts = [...new Set(scopeAccounts)];
|
|
1768
|
+
console.log("\u{1F4DA} SDK connect");
|
|
1769
|
+
yield this.metamaskConnectMultichain.connect(
|
|
1770
|
+
scopes,
|
|
1771
|
+
accounts,
|
|
1772
|
+
createSessionParams.sessionProperties
|
|
1773
|
+
);
|
|
1774
|
+
console.log("\u{1F4DA} SDK connected");
|
|
1775
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
1776
|
+
method: "wallet_getSession"
|
|
1777
|
+
});
|
|
1778
|
+
});
|
|
1779
|
+
};
|
|
1780
|
+
walletGetSession_fn = function(request) {
|
|
1781
|
+
return __async(this, null, function* () {
|
|
1782
|
+
if (!this.isTransportDefined()) {
|
|
1783
|
+
return {
|
|
1784
|
+
jsonrpc: "2.0",
|
|
1785
|
+
id: request.id,
|
|
1786
|
+
result: {
|
|
1787
|
+
sessionScopes: {}
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
1792
|
+
method: "wallet_getSession"
|
|
1793
|
+
});
|
|
1794
|
+
});
|
|
1795
|
+
};
|
|
1796
|
+
walletRevokeSession_fn = function(request) {
|
|
1797
|
+
return __async(this, null, function* () {
|
|
1798
|
+
if (!this.isTransportDefined()) {
|
|
1799
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
1800
|
+
}
|
|
1801
|
+
try {
|
|
1802
|
+
this.metamaskConnectMultichain.disconnect();
|
|
1803
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
1804
|
+
} catch (_error) {
|
|
1805
|
+
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
1806
|
+
}
|
|
1807
|
+
});
|
|
1808
|
+
};
|
|
1809
|
+
walletInvokeMethod_fn = function(request) {
|
|
1810
|
+
return __async(this, null, function* () {
|
|
1811
|
+
if (!this.isTransportDefined()) {
|
|
1812
|
+
return { error: providerErrors.unauthorized() };
|
|
1813
|
+
}
|
|
1814
|
+
const result = this.metamaskConnectMultichain.invokeMethod(
|
|
1815
|
+
request.params
|
|
1816
|
+
);
|
|
1817
|
+
return {
|
|
1818
|
+
result
|
|
1819
|
+
};
|
|
1820
|
+
});
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1608
1823
|
// src/multichain/transports/mwp/index.ts
|
|
1609
1824
|
init_domain();
|
|
1610
1825
|
init_utils();
|
|
@@ -2166,164 +2381,6 @@ var keymanager = new KeyManager();
|
|
|
2166
2381
|
|
|
2167
2382
|
// src/multichain/index.ts
|
|
2168
2383
|
init_utils();
|
|
2169
|
-
|
|
2170
|
-
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2171
|
-
import { providerErrors } from "@metamask/rpc-errors";
|
|
2172
|
-
var MAX = 4294967295;
|
|
2173
|
-
var idCounter = Math.floor(Math.random() * MAX);
|
|
2174
|
-
var getUniqueId = () => {
|
|
2175
|
-
idCounter = (idCounter + 1) % MAX;
|
|
2176
|
-
return idCounter;
|
|
2177
|
-
};
|
|
2178
|
-
var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2179
|
-
var MultichainApiClientWrapperTransport = class {
|
|
2180
|
-
constructor(metamaskConnectMultichain) {
|
|
2181
|
-
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
2182
|
-
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2183
|
-
this.requestId = getUniqueId();
|
|
2184
|
-
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
2185
|
-
}
|
|
2186
|
-
isTransportDefined() {
|
|
2187
|
-
try {
|
|
2188
|
-
return Boolean(this.metamaskConnectMultichain.transport);
|
|
2189
|
-
} catch (error) {
|
|
2190
|
-
return false;
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
clearNotificationCallbacks() {
|
|
2194
|
-
this.notificationCallbacks.clear();
|
|
2195
|
-
}
|
|
2196
|
-
notifyCallbacks(data) {
|
|
2197
|
-
this.notificationCallbacks.forEach((callback) => {
|
|
2198
|
-
callback(data);
|
|
2199
|
-
});
|
|
2200
|
-
}
|
|
2201
|
-
setupNotifcationListener() {
|
|
2202
|
-
this.metamaskConnectMultichain.transport.onNotification(
|
|
2203
|
-
this.notifyCallbacks.bind(this)
|
|
2204
|
-
);
|
|
2205
|
-
}
|
|
2206
|
-
connect() {
|
|
2207
|
-
return __async(this, null, function* () {
|
|
2208
|
-
console.log("\u{1F4DA} connect");
|
|
2209
|
-
return Promise.resolve();
|
|
2210
|
-
});
|
|
2211
|
-
}
|
|
2212
|
-
disconnect() {
|
|
2213
|
-
return __async(this, null, function* () {
|
|
2214
|
-
return Promise.resolve();
|
|
2215
|
-
});
|
|
2216
|
-
}
|
|
2217
|
-
isConnected() {
|
|
2218
|
-
return true;
|
|
2219
|
-
}
|
|
2220
|
-
request(_0) {
|
|
2221
|
-
return __async(this, arguments, function* (params, _options = {}) {
|
|
2222
|
-
const id = this.requestId++;
|
|
2223
|
-
const requestPayload = __spreadValues({
|
|
2224
|
-
id,
|
|
2225
|
-
jsonrpc: "2.0"
|
|
2226
|
-
}, params);
|
|
2227
|
-
switch (requestPayload.method) {
|
|
2228
|
-
case "wallet_createSession":
|
|
2229
|
-
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
|
|
2230
|
-
case "wallet_getSession":
|
|
2231
|
-
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
|
|
2232
|
-
case "wallet_revokeSession":
|
|
2233
|
-
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
|
|
2234
|
-
case "wallet_invokeMethod":
|
|
2235
|
-
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
|
|
2236
|
-
default:
|
|
2237
|
-
throw new Error(`Unsupported method: ${requestPayload.method}`);
|
|
2238
|
-
}
|
|
2239
|
-
throw new Error(`Unknown method: ${requestPayload.method}`);
|
|
2240
|
-
});
|
|
2241
|
-
}
|
|
2242
|
-
onNotification(callback) {
|
|
2243
|
-
if (!this.isTransportDefined()) {
|
|
2244
|
-
this.notificationCallbacks.add(callback);
|
|
2245
|
-
return () => {
|
|
2246
|
-
this.notificationCallbacks.delete(callback);
|
|
2247
|
-
};
|
|
2248
|
-
}
|
|
2249
|
-
return this.metamaskConnectMultichain.transport.onNotification(callback);
|
|
2250
|
-
}
|
|
2251
|
-
};
|
|
2252
|
-
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2253
|
-
walletCreateSession_fn = function(request) {
|
|
2254
|
-
return __async(this, null, function* () {
|
|
2255
|
-
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
2256
|
-
const createSessionParams = request.params;
|
|
2257
|
-
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
2258
|
-
const scopeAccounts = [];
|
|
2259
|
-
scopes.forEach((scope) => {
|
|
2260
|
-
var _a2, _b, _c, _d;
|
|
2261
|
-
const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
|
|
2262
|
-
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
2263
|
-
if (requiredScope) {
|
|
2264
|
-
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
2265
|
-
}
|
|
2266
|
-
if (optionalScope) {
|
|
2267
|
-
scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
|
|
2268
|
-
}
|
|
2269
|
-
});
|
|
2270
|
-
const accounts = [...new Set(scopeAccounts)];
|
|
2271
|
-
console.log("\u{1F4DA} SDK connect");
|
|
2272
|
-
yield this.metamaskConnectMultichain.connect(
|
|
2273
|
-
scopes,
|
|
2274
|
-
accounts,
|
|
2275
|
-
createSessionParams.sessionProperties
|
|
2276
|
-
);
|
|
2277
|
-
console.log("\u{1F4DA} SDK connected");
|
|
2278
|
-
return this.metamaskConnectMultichain.transport.request({
|
|
2279
|
-
method: "wallet_getSession"
|
|
2280
|
-
});
|
|
2281
|
-
});
|
|
2282
|
-
};
|
|
2283
|
-
walletGetSession_fn = function(request) {
|
|
2284
|
-
return __async(this, null, function* () {
|
|
2285
|
-
if (!this.isTransportDefined()) {
|
|
2286
|
-
return {
|
|
2287
|
-
jsonrpc: "2.0",
|
|
2288
|
-
id: request.id,
|
|
2289
|
-
result: {
|
|
2290
|
-
sessionScopes: {}
|
|
2291
|
-
}
|
|
2292
|
-
};
|
|
2293
|
-
}
|
|
2294
|
-
return this.metamaskConnectMultichain.transport.request({
|
|
2295
|
-
method: "wallet_getSession"
|
|
2296
|
-
});
|
|
2297
|
-
});
|
|
2298
|
-
};
|
|
2299
|
-
walletRevokeSession_fn = function(request) {
|
|
2300
|
-
return __async(this, null, function* () {
|
|
2301
|
-
if (!this.isTransportDefined()) {
|
|
2302
|
-
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2303
|
-
}
|
|
2304
|
-
try {
|
|
2305
|
-
this.metamaskConnectMultichain.disconnect();
|
|
2306
|
-
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2307
|
-
} catch (error) {
|
|
2308
|
-
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
2309
|
-
}
|
|
2310
|
-
});
|
|
2311
|
-
};
|
|
2312
|
-
walletInvokeMethod_fn = function(request) {
|
|
2313
|
-
return __async(this, null, function* () {
|
|
2314
|
-
if (!this.isTransportDefined()) {
|
|
2315
|
-
return { error: providerErrors.unauthorized() };
|
|
2316
|
-
}
|
|
2317
|
-
const result = this.metamaskConnectMultichain.invokeMethod(
|
|
2318
|
-
request.params
|
|
2319
|
-
);
|
|
2320
|
-
return {
|
|
2321
|
-
result
|
|
2322
|
-
};
|
|
2323
|
-
});
|
|
2324
|
-
};
|
|
2325
|
-
|
|
2326
|
-
// src/multichain/index.ts
|
|
2327
2384
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2328
2385
|
var _a, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
|
|
2329
2386
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
@@ -2351,8 +2408,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2351
2408
|
this._status = "pending";
|
|
2352
2409
|
__privateAdd(this, _listener);
|
|
2353
2410
|
__privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
|
|
2354
|
-
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
|
|
2355
|
-
|
|
2411
|
+
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
|
|
2412
|
+
this
|
|
2413
|
+
));
|
|
2414
|
+
__privateSet(this, _provider, getMultichainClient({
|
|
2415
|
+
transport: __privateGet(this, _providerTransportWrapper)
|
|
2416
|
+
}));
|
|
2356
2417
|
}
|
|
2357
2418
|
get status() {
|
|
2358
2419
|
return this._status;
|
|
@@ -2438,7 +2499,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2438
2499
|
}
|
|
2439
2500
|
const nonEmptySessionProperites = Object.keys(sessionProperties != null ? sessionProperties : {}).length > 0 ? sessionProperties : void 0;
|
|
2440
2501
|
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2441
|
-
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({
|
|
2502
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({
|
|
2503
|
+
scopes,
|
|
2504
|
+
caipAccountIds,
|
|
2505
|
+
sessionProperties: nonEmptySessionProperites,
|
|
2506
|
+
forceRequest
|
|
2507
|
+
}).then(() => __async(this, null, function* () {
|
|
2442
2508
|
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2443
2509
|
return this.storage.setTransport("mwp" /* MWP */);
|
|
2444
2510
|
}
|
|
@@ -2447,11 +2513,21 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2447
2513
|
}
|
|
2448
2514
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2449
2515
|
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2450
|
-
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
|
|
2516
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
|
|
2517
|
+
scopes,
|
|
2518
|
+
caipAccountIds,
|
|
2519
|
+
sessionProperties: nonEmptySessionProperites,
|
|
2520
|
+
forceRequest
|
|
2521
|
+
}), scopes, transportType);
|
|
2451
2522
|
}
|
|
2452
2523
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2453
2524
|
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2454
|
-
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
|
|
2525
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
|
|
2526
|
+
scopes,
|
|
2527
|
+
caipAccountIds,
|
|
2528
|
+
sessionProperties: nonEmptySessionProperites,
|
|
2529
|
+
forceRequest
|
|
2530
|
+
}), scopes, transportType);
|
|
2455
2531
|
}
|
|
2456
2532
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
|
|
2457
2533
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
@@ -2713,7 +2789,11 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
|
|
|
2713
2789
|
(() => __async(this, null, function* () {
|
|
2714
2790
|
var _a2;
|
|
2715
2791
|
try {
|
|
2716
|
-
yield this.transport.connect({
|
|
2792
|
+
yield this.transport.connect({
|
|
2793
|
+
scopes,
|
|
2794
|
+
caipAccountIds,
|
|
2795
|
+
sessionProperties
|
|
2796
|
+
});
|
|
2717
2797
|
yield this.options.ui.factory.unload();
|
|
2718
2798
|
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2719
2799
|
this.status = "connected";
|
|
@@ -2821,7 +2901,7 @@ setupDefaultTransport_fn = function() {
|
|
|
2821
2901
|
};
|
|
2822
2902
|
deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2823
2903
|
return __async(this, null, function* () {
|
|
2824
|
-
return new Promise((resolve, reject) => {
|
|
2904
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2825
2905
|
const dappClientMessageHandler = (payload) => {
|
|
2826
2906
|
var _a2;
|
|
2827
2907
|
if (typeof payload !== "object" || payload === null || !("data" in payload)) {
|
|
@@ -2880,7 +2960,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
2880
2960
|
clearTimeout(timeout);
|
|
2881
2961
|
}
|
|
2882
2962
|
});
|
|
2883
|
-
});
|
|
2963
|
+
}));
|
|
2884
2964
|
});
|
|
2885
2965
|
};
|
|
2886
2966
|
handleConnection_fn = function(promise, scopes, transportType) {
|
|
@@ -3173,7 +3253,9 @@ var BaseModalFactory = class {
|
|
|
3173
3253
|
}
|
|
3174
3254
|
createConnectionDeeplink(connectionRequest) {
|
|
3175
3255
|
if (!connectionRequest) {
|
|
3176
|
-
throw new Error(
|
|
3256
|
+
throw new Error(
|
|
3257
|
+
"createConnectionDeeplink can only be called with a connection request"
|
|
3258
|
+
);
|
|
3177
3259
|
}
|
|
3178
3260
|
const json = JSON.stringify(connectionRequest);
|
|
3179
3261
|
const compressed = compressString(json);
|
|
@@ -3279,14 +3361,17 @@ var ModalFactory = class extends BaseModalFactory {
|
|
|
3279
3361
|
// src/index.node.ts
|
|
3280
3362
|
init_domain();
|
|
3281
3363
|
var createMultichainClient = (options) => __async(null, null, function* () {
|
|
3364
|
+
if (options.debug) {
|
|
3365
|
+
enableDebug("metamask-sdk:*");
|
|
3366
|
+
}
|
|
3282
3367
|
const uiModules = yield Promise.resolve().then(() => (init_node(), node_exports));
|
|
3283
3368
|
let storage;
|
|
3284
|
-
if (
|
|
3369
|
+
if (options.storage) {
|
|
3370
|
+
storage = options.storage;
|
|
3371
|
+
} else {
|
|
3285
3372
|
const { StoreAdapterNode: StoreAdapterNode2 } = yield Promise.resolve().then(() => (init_node2(), node_exports2));
|
|
3286
3373
|
const adapter = new StoreAdapterNode2();
|
|
3287
3374
|
storage = new Store(adapter);
|
|
3288
|
-
} else {
|
|
3289
|
-
storage = options.storage;
|
|
3290
3375
|
}
|
|
3291
3376
|
const factory = new ModalFactory(uiModules);
|
|
3292
3377
|
return MetaMaskConnectMultichain.create(__spreadProps(__spreadValues({}, options), {
|