@mocanetwork/airkit 0.5.0 → 1.0.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/dist/airkit.cjs.js +1921 -2597
- package/dist/airkit.esm.js +1925 -2413
- package/dist/airkit.umd.js +2104 -0
- package/dist/types/airService.d.ts +17 -12
- package/dist/types/airWalletProvider.d.ts +13 -0
- package/dist/types/common/air/error.d.ts +8 -0
- package/dist/types/common/custom.d.ts +6 -0
- package/dist/types/common/provider/error.d.ts +16 -0
- package/dist/types/common/provider/types.d.ts +24 -0
- package/dist/types/common/realm/error.d.ts +0 -0
- package/dist/types/common/realm/messaging/auth.d.ts +18 -21
- package/dist/types/common/realm/messaging/provider.d.ts +32 -0
- package/dist/types/common/realm/messaging/types.d.ts +52 -63
- package/dist/types/common/realm/partner/config.d.ts +1 -32
- package/dist/types/common/realm/smart-session/types.d.ts +1 -1
- package/dist/types/common/realm/user/types.d.ts +2 -31
- package/dist/types/common/types.d.ts +3 -0
- package/dist/types/common/utils.d.ts +17 -0
- package/dist/types/error.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/interfaces.d.ts +26 -187
- package/dist/types/messageService.d.ts +23 -31
- package/dist/types/utils.d.ts +3 -21
- package/package.json +7 -15
- package/dist/airkit.umd.min.js +0 -2
- package/dist/airkit.umd.min.js.LICENSE.txt +0 -12
- package/dist/lib.cjs/common/src/error.js +0 -25
- package/dist/lib.cjs/common/src/realm/messaging/auth.js +0 -28
- package/dist/lib.cjs/common/src/realm/messaging/types.js +0 -21
- package/dist/lib.cjs/ws-embed/src/PopupHandler.js +0 -64
- package/dist/lib.cjs/ws-embed/src/airService.js +0 -398
- package/dist/lib.cjs/ws-embed/src/baseProvider.js +0 -178
- package/dist/lib.cjs/ws-embed/src/communicationProvider.js +0 -346
- package/dist/lib.cjs/ws-embed/src/embed.js +0 -750
- package/dist/lib.cjs/ws-embed/src/error.js +0 -21
- package/dist/lib.cjs/ws-embed/src/iframeController.js +0 -68
- package/dist/lib.cjs/ws-embed/src/inPageProvider.js +0 -307
- package/dist/lib.cjs/ws-embed/src/index.js +0 -20
- package/dist/lib.cjs/ws-embed/src/interfaces.js +0 -29
- package/dist/lib.cjs/ws-embed/src/isStream.js +0 -20
- package/dist/lib.cjs/ws-embed/src/loglevel.js +0 -7
- package/dist/lib.cjs/ws-embed/src/messageService.js +0 -269
- package/dist/lib.cjs/ws-embed/src/messages.js +0 -22
- package/dist/lib.cjs/ws-embed/src/siteMetadata.js +0 -77
- package/dist/lib.cjs/ws-embed/src/utils.js +0 -95
- package/dist/lib.esm/common/src/error.js +0 -23
- package/dist/lib.esm/common/src/realm/messaging/auth.js +0 -26
- package/dist/lib.esm/common/src/realm/messaging/types.js +0 -19
- package/dist/lib.esm/ws-embed/src/PopupHandler.js +0 -62
- package/dist/lib.esm/ws-embed/src/airService.js +0 -396
- package/dist/lib.esm/ws-embed/src/baseProvider.js +0 -176
- package/dist/lib.esm/ws-embed/src/communicationProvider.js +0 -344
- package/dist/lib.esm/ws-embed/src/embed.js +0 -745
- package/dist/lib.esm/ws-embed/src/error.js +0 -18
- package/dist/lib.esm/ws-embed/src/iframeController.js +0 -66
- package/dist/lib.esm/ws-embed/src/inPageProvider.js +0 -302
- package/dist/lib.esm/ws-embed/src/index.js +0 -5
- package/dist/lib.esm/ws-embed/src/interfaces.js +0 -21
- package/dist/lib.esm/ws-embed/src/isStream.js +0 -15
- package/dist/lib.esm/ws-embed/src/loglevel.js +0 -5
- package/dist/lib.esm/ws-embed/src/messageService.js +0 -267
- package/dist/lib.esm/ws-embed/src/messages.js +0 -20
- package/dist/lib.esm/ws-embed/src/siteMetadata.js +0 -75
- package/dist/lib.esm/ws-embed/src/utils.js +0 -88
- package/dist/types/PopupHandler.d.ts +0 -24
- package/dist/types/baseProvider.d.ts +0 -66
- package/dist/types/communicationProvider.d.ts +0 -82
- package/dist/types/embed.d.ts +0 -55
- package/dist/types/inPageProvider.d.ts +0 -106
- package/dist/types/isStream.d.ts +0 -4
- package/dist/types/messages.d.ts +0 -19
package/dist/airkit.cjs.js
CHANGED
|
@@ -1,92 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
18
|
+
|
|
19
|
+
var extendStatics = function (d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf || {
|
|
21
|
+
__proto__: []
|
|
22
|
+
} instanceof Array && function (d, b) {
|
|
23
|
+
d.__proto__ = b;
|
|
24
|
+
} || function (d, b) {
|
|
25
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
26
|
+
};
|
|
27
|
+
return extendStatics(d, b);
|
|
28
|
+
};
|
|
29
|
+
function __extends(d, b) {
|
|
30
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
function __() {
|
|
33
|
+
this.constructor = d;
|
|
34
|
+
}
|
|
35
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
+
}
|
|
37
|
+
function __values(o) {
|
|
38
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
39
|
+
m = s && o[s],
|
|
40
|
+
i = 0;
|
|
41
|
+
if (m) return m.call(o);
|
|
42
|
+
if (o && typeof o.length === "number") return {
|
|
43
|
+
next: function () {
|
|
44
|
+
if (o && i >= o.length) o = undefined;
|
|
45
|
+
return {
|
|
46
|
+
value: o && o[i++],
|
|
47
|
+
done: !o
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
+
}
|
|
53
|
+
function __read(o, n) {
|
|
54
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
|
+
if (!m) return o;
|
|
56
|
+
var i = m.call(o),
|
|
57
|
+
r,
|
|
58
|
+
ar = [],
|
|
59
|
+
e;
|
|
60
|
+
try {
|
|
61
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
e = {
|
|
64
|
+
error: error
|
|
65
|
+
};
|
|
66
|
+
} finally {
|
|
67
|
+
try {
|
|
68
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
69
|
+
} finally {
|
|
70
|
+
if (e) throw e.error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return ar;
|
|
74
|
+
}
|
|
75
|
+
function __spreadArray(to, from, pack) {
|
|
76
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
77
|
+
if (ar || !(i in from)) {
|
|
78
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
79
|
+
ar[i] = from[i];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
83
|
+
}
|
|
84
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
85
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
86
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
87
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
88
|
+
}
|
|
89
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
90
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
91
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
92
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
93
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
94
|
+
}
|
|
95
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
96
|
+
var e = new Error(message);
|
|
97
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
98
|
+
};
|
|
62
99
|
|
|
63
|
-
;// external "@babel/runtime/helpers/objectSpread2"
|
|
64
|
-
const objectSpread2_namespaceObject = require("@babel/runtime/helpers/objectSpread2");
|
|
65
|
-
var objectSpread2_default = /*#__PURE__*/__webpack_require__.n(objectSpread2_namespaceObject);
|
|
66
|
-
;// external "@babel/runtime/helpers/classPrivateMethodInitSpec"
|
|
67
|
-
const classPrivateMethodInitSpec_namespaceObject = require("@babel/runtime/helpers/classPrivateMethodInitSpec");
|
|
68
|
-
var classPrivateMethodInitSpec_default = /*#__PURE__*/__webpack_require__.n(classPrivateMethodInitSpec_namespaceObject);
|
|
69
|
-
;// external "@babel/runtime/helpers/classPrivateFieldInitSpec"
|
|
70
|
-
const classPrivateFieldInitSpec_namespaceObject = require("@babel/runtime/helpers/classPrivateFieldInitSpec");
|
|
71
|
-
var classPrivateFieldInitSpec_default = /*#__PURE__*/__webpack_require__.n(classPrivateFieldInitSpec_namespaceObject);
|
|
72
|
-
;// external "@toruslabs/base-controllers"
|
|
73
|
-
const base_controllers_namespaceObject = require("@toruslabs/base-controllers");
|
|
74
|
-
;// ../common/src/realm/messaging/auth.js
|
|
75
100
|
const AirAuthMessageTypes = {
|
|
76
|
-
|
|
101
|
+
AUTH_SETUP_COMPLETED: "air_auth_setup_completed",
|
|
102
|
+
INITIALIZATION_REQUEST: "air_auth_initialization_request",
|
|
103
|
+
INITIALIZATION_RESPONSE: "air_auth_initialization_response",
|
|
77
104
|
LOGIN_REQUEST: "air_auth_login_request",
|
|
78
105
|
LOGIN_RESPONSE: "air_auth_login_response",
|
|
79
106
|
LOGIN_WALLET_RESPONSE: "air_auth_login_wallet_response",
|
|
80
|
-
USER_INFO_REQUEST: "air_auth_user_info_request",
|
|
81
|
-
USER_INFO_RESPONSE: "air_auth_user_info_response",
|
|
82
107
|
PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
|
|
83
108
|
PARTNER_USER_INFO_RESPONSE: "air_auth_partner_user_info_response",
|
|
84
109
|
REFRESH_TOKEN_REQUEST: "air_auth_refresh_token_request",
|
|
85
110
|
REFRESH_TOKEN_RESPONSE: "air_auth_refresh_token_response",
|
|
86
111
|
WALLET_TOKEN_REQUEST: "air_auth_wallet_token_request",
|
|
87
112
|
WALLET_TOKEN_RESPONSE: "air_auth_wallet_token_response",
|
|
88
|
-
INITIALIZATION_REQUEST: "air_auth_initialization_request",
|
|
89
|
-
INITIALIZATION_RESPONSE: "air_auth_initialization_response",
|
|
90
113
|
INIT_WALLET_COMMUNICATION: "air_auth_init_wallet_communication",
|
|
91
114
|
IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
|
|
92
115
|
SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
|
|
@@ -96,19 +119,15 @@ const AirAuthMessageTypes = {
|
|
|
96
119
|
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
97
120
|
LOGOUT_RESPONSE: "air_auth_logout_response"
|
|
98
121
|
};
|
|
99
|
-
|
|
100
|
-
const ethereum_controllers_namespaceObject = require("@toruslabs/ethereum-controllers");
|
|
101
|
-
;// external "@web3auth/auth"
|
|
102
|
-
const external_web3auth_auth_namespaceObject = require("@web3auth/auth");
|
|
103
|
-
;// ../common/src/realm/messaging/types.js
|
|
122
|
+
|
|
104
123
|
const AirMessageTypes = {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
CLAIM_REQUEST: "air_claim_request",
|
|
109
|
-
LOGIN_CLAIM_STATE: "air_login_claim_state",
|
|
110
|
-
CLOSE_MODAL: "air_close_modal",
|
|
124
|
+
SERVICE_STARTED: "air_service_started",
|
|
125
|
+
INITIALIZATION_REQUEST: "air_initialization_request",
|
|
126
|
+
INITIALIZATION_RESPONSE: "air_initialization_response",
|
|
111
127
|
INIT_AUTH_COMMUNICATION: "air_init_auth_communication",
|
|
128
|
+
WALLET_INITIALIZED: "air_wallet_initialized",
|
|
129
|
+
CLAIM_ID_REQUEST: "air_claim_id_request",
|
|
130
|
+
CLAIM_ID_RESPONSE: "air_claim_id_response",
|
|
112
131
|
DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
|
|
113
132
|
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
|
|
114
133
|
GRANT_PERMISSIONS_REQUEST: "air_grant_permissions_request",
|
|
@@ -116,763 +135,750 @@ const AirMessageTypes = {
|
|
|
116
135
|
EXECUTE_ACTION_REQUEST: "air_execute_action_request",
|
|
117
136
|
EXECUTE_ACTION_RESPONSE: "air_execute_action_response",
|
|
118
137
|
REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request",
|
|
119
|
-
REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response"
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
CLAIM_FLOW_CANCELLED: "claim_flow_cancelled",
|
|
126
|
-
MINTING_STARTED: "minting_started",
|
|
127
|
-
MINTING_FAILED: "minting_failed"
|
|
128
|
-
};
|
|
129
|
-
;// external "@babel/runtime/helpers/defineProperty"
|
|
130
|
-
const defineProperty_namespaceObject = require("@babel/runtime/helpers/defineProperty");
|
|
131
|
-
var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty_namespaceObject);
|
|
132
|
-
;// external "pump"
|
|
133
|
-
const external_pump_namespaceObject = require("pump");
|
|
134
|
-
var external_pump_default = /*#__PURE__*/__webpack_require__.n(external_pump_namespaceObject);
|
|
135
|
-
;// ./src/isStream.ts
|
|
136
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
137
|
-
function isStream(stream) {
|
|
138
|
-
return stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
|
|
139
|
-
}
|
|
140
|
-
function isWritableStream(stream) {
|
|
141
|
-
return isStream(stream) && stream.writable !== false && typeof stream._write === "function" && typeof stream._writableState === "object";
|
|
142
|
-
}
|
|
143
|
-
function isReadableStream(stream) {
|
|
144
|
-
return isStream(stream) && stream.readable !== false && typeof stream._read === "function" && typeof stream._readableState === "object";
|
|
145
|
-
}
|
|
146
|
-
function isDuplexStream(stream) {
|
|
147
|
-
return isWritableStream(stream) && isReadableStream(stream);
|
|
148
|
-
}
|
|
149
|
-
;// ./src/messages.ts
|
|
150
|
-
/* harmony default export */ const messages = ({
|
|
151
|
-
errors: {
|
|
152
|
-
disconnected: () => "Web3Auth: Lost connection to Web3Auth.",
|
|
153
|
-
permanentlyDisconnected: () => "Web3Auth: Disconnected from iframe. Page reload required.",
|
|
154
|
-
unsupportedSync: method => `Web3Auth: The Web3Auth Ethereum provider does not support synchronous methods like ${method} without a callback parameter.`,
|
|
155
|
-
invalidDuplexStream: () => "Must provide a Node.js-style duplex stream.",
|
|
156
|
-
invalidOptions: maxEventListeners => `Invalid options. Received: { maxEventListeners: ${maxEventListeners}}`,
|
|
157
|
-
invalidRequestArgs: () => `Expected a single, non-array, object argument.`,
|
|
158
|
-
invalidRequestMethod: () => `'args.method' must be a non-empty string.`,
|
|
159
|
-
invalidRequestParams: () => `'args.params' must be an object or array if provided.`,
|
|
160
|
-
invalidLoggerObject: () => `'args.logger' must be an object if provided.`,
|
|
161
|
-
invalidLoggerMethod: method => `'args.logger' must include required method '${method}'.`
|
|
162
|
-
},
|
|
163
|
-
info: {
|
|
164
|
-
connected: chainId => `Web3Auth: Connected to chain with ID "${chainId}".`
|
|
165
|
-
},
|
|
166
|
-
warnings: {}
|
|
167
|
-
});
|
|
168
|
-
;// ./src/interfaces.ts
|
|
169
|
-
|
|
170
|
-
const EMBED_BUILD_ENV = {
|
|
171
|
-
PRODUCTION: "production",
|
|
172
|
-
STAGING: "staging",
|
|
173
|
-
DEVELOPMENT: "development",
|
|
174
|
-
TESTING: "testing"
|
|
138
|
+
REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response",
|
|
139
|
+
WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request",
|
|
140
|
+
IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
|
|
141
|
+
IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
|
|
142
|
+
LOGOUT_REQUEST: "air_logout_request",
|
|
143
|
+
LOGOUT_RESPONSE: "air_logout_response"
|
|
175
144
|
};
|
|
176
|
-
const BUTTON_POSITION = {
|
|
177
|
-
BOTTOM_LEFT: "bottom-left",
|
|
178
|
-
TOP_LEFT: "top-left",
|
|
179
|
-
BOTTOM_RIGHT: "bottom-right",
|
|
180
|
-
TOP_RIGHT: "top-right"
|
|
181
|
-
};
|
|
182
|
-
const EXTERNAL_LOGIN_PROVIDER = {
|
|
183
|
-
METAMASK: "metamask",
|
|
184
|
-
WALLET_CONNECT: "walletconnect",
|
|
185
|
-
WAGMI: "wagmi"
|
|
186
|
-
};
|
|
187
|
-
;// external "loglevel"
|
|
188
|
-
const external_loglevel_namespaceObject = require("loglevel");
|
|
189
|
-
var external_loglevel_default = /*#__PURE__*/__webpack_require__.n(external_loglevel_namespaceObject);
|
|
190
|
-
;// ./src/loglevel.ts
|
|
191
|
-
|
|
192
|
-
/* harmony default export */ const loglevel = (external_loglevel_default().getLogger("ws-embed"));
|
|
193
|
-
;// ./src/utils.ts
|
|
194
145
|
|
|
146
|
+
function isFunction(value) {
|
|
147
|
+
return typeof value === 'function';
|
|
148
|
+
}
|
|
195
149
|
|
|
150
|
+
function createErrorClass(createImpl) {
|
|
151
|
+
var _super = function (instance) {
|
|
152
|
+
Error.call(instance);
|
|
153
|
+
instance.stack = new Error().stack;
|
|
154
|
+
};
|
|
155
|
+
var ctorFunc = createImpl(_super);
|
|
156
|
+
ctorFunc.prototype = Object.create(Error.prototype);
|
|
157
|
+
ctorFunc.prototype.constructor = ctorFunc;
|
|
158
|
+
return ctorFunc;
|
|
159
|
+
}
|
|
196
160
|
|
|
161
|
+
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
162
|
+
return function UnsubscriptionErrorImpl(errors) {
|
|
163
|
+
_super(this);
|
|
164
|
+
this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
|
|
165
|
+
return i + 1 + ") " + err.toString();
|
|
166
|
+
}).join('\n ') : '';
|
|
167
|
+
this.name = 'UnsubscriptionError';
|
|
168
|
+
this.errors = errors;
|
|
169
|
+
};
|
|
170
|
+
});
|
|
197
171
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
logLevel: "debug"
|
|
203
|
-
},
|
|
204
|
-
[EMBED_BUILD_ENV.DEVELOPMENT]: {
|
|
205
|
-
authUrl: "http://localhost:8100",
|
|
206
|
-
walletUrl: "https://localhost:4050",
|
|
207
|
-
logLevel: "debug"
|
|
208
|
-
},
|
|
209
|
-
[EMBED_BUILD_ENV.STAGING]: {
|
|
210
|
-
authUrl: "https://auth.staging.air3.com",
|
|
211
|
-
walletUrl: "https://account.staging.realmnetwork.io",
|
|
212
|
-
logLevel: "info"
|
|
213
|
-
},
|
|
214
|
-
[EMBED_BUILD_ENV.PRODUCTION]: {
|
|
215
|
-
authUrl: "https://auth.air3.com",
|
|
216
|
-
walletUrl: "https://account.realmnetwork.io",
|
|
217
|
-
logLevel: "error"
|
|
172
|
+
function arrRemove(arr, item) {
|
|
173
|
+
if (arr) {
|
|
174
|
+
var index = arr.indexOf(item);
|
|
175
|
+
0 <= index && arr.splice(index, 1);
|
|
218
176
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var Subscription = function () {
|
|
180
|
+
function Subscription(initialTeardown) {
|
|
181
|
+
this.initialTeardown = initialTeardown;
|
|
182
|
+
this.closed = false;
|
|
183
|
+
this._parentage = null;
|
|
184
|
+
this._finalizers = null;
|
|
185
|
+
}
|
|
186
|
+
Subscription.prototype.unsubscribe = function () {
|
|
187
|
+
var e_1, _a, e_2, _b;
|
|
188
|
+
var errors;
|
|
189
|
+
if (!this.closed) {
|
|
190
|
+
this.closed = true;
|
|
191
|
+
var _parentage = this._parentage;
|
|
192
|
+
if (_parentage) {
|
|
193
|
+
this._parentage = null;
|
|
194
|
+
if (Array.isArray(_parentage)) {
|
|
195
|
+
try {
|
|
196
|
+
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
197
|
+
var parent_1 = _parentage_1_1.value;
|
|
198
|
+
parent_1.remove(this);
|
|
199
|
+
}
|
|
200
|
+
} catch (e_1_1) {
|
|
201
|
+
e_1 = {
|
|
202
|
+
error: e_1_1
|
|
203
|
+
};
|
|
204
|
+
} finally {
|
|
205
|
+
try {
|
|
206
|
+
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
207
|
+
} finally {
|
|
208
|
+
if (e_1) throw e_1.error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
_parentage.remove(this);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
var initialFinalizer = this.initialTeardown;
|
|
216
|
+
if (isFunction(initialFinalizer)) {
|
|
217
|
+
try {
|
|
218
|
+
initialFinalizer();
|
|
219
|
+
} catch (e) {
|
|
220
|
+
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
var _finalizers = this._finalizers;
|
|
224
|
+
if (_finalizers) {
|
|
225
|
+
this._finalizers = null;
|
|
226
|
+
try {
|
|
227
|
+
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
228
|
+
var finalizer = _finalizers_1_1.value;
|
|
229
|
+
try {
|
|
230
|
+
execFinalizer(finalizer);
|
|
231
|
+
} catch (err) {
|
|
232
|
+
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
233
|
+
if (err instanceof UnsubscriptionError) {
|
|
234
|
+
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
235
|
+
} else {
|
|
236
|
+
errors.push(err);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} catch (e_2_1) {
|
|
241
|
+
e_2 = {
|
|
242
|
+
error: e_2_1
|
|
243
|
+
};
|
|
244
|
+
} finally {
|
|
245
|
+
try {
|
|
246
|
+
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
247
|
+
} finally {
|
|
248
|
+
if (e_2) throw e_2.error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (errors) {
|
|
253
|
+
throw new UnsubscriptionError(errors);
|
|
254
|
+
}
|
|
251
255
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
|
|
256
|
+
};
|
|
257
|
+
Subscription.prototype.add = function (teardown) {
|
|
258
|
+
var _a;
|
|
259
|
+
if (teardown && teardown !== this) {
|
|
260
|
+
if (this.closed) {
|
|
261
|
+
execFinalizer(teardown);
|
|
262
|
+
} else {
|
|
263
|
+
if (teardown instanceof Subscription) {
|
|
264
|
+
if (teardown.closed || teardown._hasParent(this)) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
teardown._addParent(this);
|
|
268
|
+
}
|
|
269
|
+
(this._finalizers = (_a = this._finalizers) !== null && _a !== undefined ? _a : []).push(teardown);
|
|
258
270
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
Subscription.prototype._hasParent = function (parent) {
|
|
274
|
+
var _parentage = this._parentage;
|
|
275
|
+
return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
|
|
276
|
+
};
|
|
277
|
+
Subscription.prototype._addParent = function (parent) {
|
|
278
|
+
var _parentage = this._parentage;
|
|
279
|
+
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
280
|
+
};
|
|
281
|
+
Subscription.prototype._removeParent = function (parent) {
|
|
282
|
+
var _parentage = this._parentage;
|
|
283
|
+
if (_parentage === parent) {
|
|
284
|
+
this._parentage = null;
|
|
285
|
+
} else if (Array.isArray(_parentage)) {
|
|
286
|
+
arrRemove(_parentage, parent);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
Subscription.prototype.remove = function (teardown) {
|
|
290
|
+
var _finalizers = this._finalizers;
|
|
291
|
+
_finalizers && arrRemove(_finalizers, teardown);
|
|
292
|
+
if (teardown instanceof Subscription) {
|
|
293
|
+
teardown._removeParent(this);
|
|
294
|
+
}
|
|
262
295
|
};
|
|
296
|
+
Subscription.EMPTY = function () {
|
|
297
|
+
var empty = new Subscription();
|
|
298
|
+
empty.closed = true;
|
|
299
|
+
return empty;
|
|
300
|
+
}();
|
|
301
|
+
return Subscription;
|
|
302
|
+
}();
|
|
303
|
+
var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
|
|
304
|
+
function isSubscription(value) {
|
|
305
|
+
return value instanceof Subscription || value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
|
|
263
306
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
* @param log - The logging API to use.
|
|
270
|
-
* @param remoteLabel - The label of the disconnected stream.
|
|
271
|
-
* @param error - The associated error to log.
|
|
272
|
-
* @param emitter - The logging API to use.
|
|
273
|
-
*/
|
|
274
|
-
function logStreamDisconnectWarning(remoteLabel, error, emitter) {
|
|
275
|
-
let warningMsg = `Web3Auth: Lost connection to "${remoteLabel}".`;
|
|
276
|
-
if (error !== null && error !== void 0 && error.stack) {
|
|
277
|
-
warningMsg += `\n${error.stack}`;
|
|
278
|
-
}
|
|
279
|
-
loglevel.warn(warningMsg);
|
|
280
|
-
if (emitter && emitter.listenerCount("error") > 0) {
|
|
281
|
-
emitter.emit("error", warningMsg);
|
|
307
|
+
function execFinalizer(finalizer) {
|
|
308
|
+
if (isFunction(finalizer)) {
|
|
309
|
+
finalizer();
|
|
310
|
+
} else {
|
|
311
|
+
finalizer.unsubscribe();
|
|
282
312
|
}
|
|
283
313
|
}
|
|
284
|
-
const EMITTED_NOTIFICATIONS = ["eth_subscription" // per eth-json-rpc-filters/subscriptionManager
|
|
285
|
-
];
|
|
286
|
-
;// ./src/baseProvider.ts
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
314
|
|
|
315
|
+
var config = {
|
|
316
|
+
onUnhandledError: null,
|
|
317
|
+
onStoppedNotification: null,
|
|
318
|
+
Promise: undefined,
|
|
319
|
+
useDeprecatedSynchronousErrorHandling: false,
|
|
320
|
+
useDeprecatedNextContext: false
|
|
321
|
+
};
|
|
292
322
|
|
|
323
|
+
var timeoutProvider = {
|
|
324
|
+
setTimeout: function (handler, timeout) {
|
|
325
|
+
var args = [];
|
|
326
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
327
|
+
args[_i - 2] = arguments[_i];
|
|
328
|
+
}
|
|
329
|
+
return setTimeout.apply(undefined, __spreadArray([handler, timeout], __read(args)));
|
|
330
|
+
},
|
|
331
|
+
clearTimeout: function (handle) {
|
|
332
|
+
return (clearTimeout)(handle);
|
|
333
|
+
},
|
|
334
|
+
delegate: undefined
|
|
335
|
+
};
|
|
293
336
|
|
|
337
|
+
function reportUnhandledError(err) {
|
|
338
|
+
timeoutProvider.setTimeout(function () {
|
|
339
|
+
{
|
|
340
|
+
throw err;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
294
344
|
|
|
345
|
+
function noop() {}
|
|
295
346
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
*/
|
|
300
|
-
class BaseProvider extends external_web3auth_auth_namespaceObject.SafeEventEmitter {
|
|
301
|
-
constructor(connectionStream, {
|
|
302
|
-
maxEventListeners = 100,
|
|
303
|
-
jsonRpcStreamName = "provider"
|
|
304
|
-
}) {
|
|
305
|
-
super();
|
|
306
|
-
defineProperty_default()(this, "rpcEngine", void 0);
|
|
307
|
-
defineProperty_default()(this, "jsonRpcConnectionEvents", void 0);
|
|
308
|
-
/**
|
|
309
|
-
* Indicating that this provider is a Web3Auth provider.
|
|
310
|
-
*/
|
|
311
|
-
defineProperty_default()(this, "isWeb3Auth", void 0);
|
|
312
|
-
defineProperty_default()(this, "state", void 0);
|
|
313
|
-
if (!isDuplexStream(connectionStream)) {
|
|
314
|
-
throw new Error(messages.errors.invalidDuplexStream());
|
|
315
|
-
}
|
|
316
|
-
this.isWeb3Auth = true;
|
|
317
|
-
this.setMaxListeners(maxEventListeners);
|
|
318
|
-
this.handleConnect = this.handleConnect.bind(this);
|
|
319
|
-
this.handleDisconnect = this.handleDisconnect.bind(this);
|
|
320
|
-
this.handleStreamDisconnect = this.handleStreamDisconnect.bind(this);
|
|
321
|
-
this.rpcRequest = this.rpcRequest.bind(this);
|
|
322
|
-
this.initializeState = this.initializeState.bind(this);
|
|
323
|
-
this.request = this.request.bind(this);
|
|
324
|
-
this.sendAsync = this.sendAsync.bind(this);
|
|
325
|
-
this.send = this.send.bind(this);
|
|
326
|
-
// this.enable = this.enable.bind(this);
|
|
327
|
-
|
|
328
|
-
// setup connectionStream multiplexing
|
|
329
|
-
const mux = new external_web3auth_auth_namespaceObject.ObjectMultiplex();
|
|
330
|
-
external_pump_default()(connectionStream, mux, connectionStream, this.handleStreamDisconnect.bind(this, "Web3Auth"));
|
|
331
|
-
|
|
332
|
-
// ignore phishing warning message (handled elsewhere)
|
|
333
|
-
mux.ignoreStream("phishing");
|
|
334
|
-
|
|
335
|
-
// setup own event listeners
|
|
336
|
-
// connect to async provider
|
|
337
|
-
|
|
338
|
-
const jsonRpcConnection = (0,external_web3auth_auth_namespaceObject.createStreamMiddleware)();
|
|
339
|
-
external_pump_default()(jsonRpcConnection.stream, mux.createStream(jsonRpcStreamName), jsonRpcConnection.stream, this.handleStreamDisconnect.bind(this, "Web3Auth RpcProvider"));
|
|
340
|
-
|
|
341
|
-
// handle RPC requests via dapp-side rpc engine
|
|
342
|
-
const rpcEngine = new external_web3auth_auth_namespaceObject.JRPCEngine();
|
|
343
|
-
rpcEngine.push((0,external_web3auth_auth_namespaceObject.createIdRemapMiddleware)());
|
|
344
|
-
rpcEngine.push(createErrorMiddleware());
|
|
345
|
-
rpcEngine.push((0,base_controllers_namespaceObject.createLoggerMiddleware)({
|
|
346
|
-
origin: location.origin
|
|
347
|
-
}));
|
|
348
|
-
rpcEngine.push(jsonRpcConnection.middleware);
|
|
349
|
-
this.rpcEngine = rpcEngine;
|
|
350
|
-
this.jsonRpcConnectionEvents = jsonRpcConnection.events;
|
|
347
|
+
function errorContext(cb) {
|
|
348
|
+
{
|
|
349
|
+
cb();
|
|
351
350
|
}
|
|
351
|
+
}
|
|
352
352
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
data: objectSpread2_default()(objectSpread2_default()({}, args || {}), {}, {
|
|
366
|
-
cause: messages.errors.invalidRequestArgs()
|
|
367
|
-
})
|
|
368
|
-
});
|
|
353
|
+
var Subscriber = function (_super) {
|
|
354
|
+
__extends(Subscriber, _super);
|
|
355
|
+
function Subscriber(destination) {
|
|
356
|
+
var _this = _super.call(this) || this;
|
|
357
|
+
_this.isStopped = false;
|
|
358
|
+
if (destination) {
|
|
359
|
+
_this.destination = destination;
|
|
360
|
+
if (isSubscription(destination)) {
|
|
361
|
+
destination.add(_this);
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
_this.destination = EMPTY_OBSERVER;
|
|
369
365
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
cause: messages.errors.invalidRequestArgs()
|
|
379
|
-
})
|
|
380
|
-
});
|
|
366
|
+
return _this;
|
|
367
|
+
}
|
|
368
|
+
Subscriber.create = function (next, error, complete) {
|
|
369
|
+
return new SafeSubscriber(next, error, complete);
|
|
370
|
+
};
|
|
371
|
+
Subscriber.prototype.next = function (value) {
|
|
372
|
+
if (this.isStopped) ; else {
|
|
373
|
+
this._next(value);
|
|
381
374
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
})
|
|
388
|
-
});
|
|
375
|
+
};
|
|
376
|
+
Subscriber.prototype.error = function (err) {
|
|
377
|
+
if (this.isStopped) ; else {
|
|
378
|
+
this.isStopped = true;
|
|
379
|
+
this._error(err);
|
|
389
380
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
this.
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
*/
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Internal RPC method. Forwards requests to background via the RPC engine.
|
|
438
|
-
* Also remap ids inbound and outbound
|
|
439
|
-
*/
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* When the provider becomes connected, updates internal state and emits
|
|
443
|
-
* required events. Idempotent.
|
|
444
|
-
*
|
|
445
|
-
* @param chainId - The ID of the newly connected chain.
|
|
446
|
-
* emits InPageProvider#connect
|
|
447
|
-
*/
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* When the provider becomes disconnected, updates internal state and emits
|
|
451
|
-
* required events. Idempotent with respect to the isRecoverable parameter.
|
|
452
|
-
*
|
|
453
|
-
* Error codes per the CloseEvent status codes as required by EIP-1193:
|
|
454
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes
|
|
455
|
-
*
|
|
456
|
-
* @param isRecoverable - Whether the disconnection is recoverable.
|
|
457
|
-
* @param errorMessage - A custom error message.
|
|
458
|
-
* emits InpageProvider#disconnect
|
|
459
|
-
*/
|
|
460
|
-
}
|
|
461
|
-
/* harmony default export */ const baseProvider = (BaseProvider);
|
|
462
|
-
;// ./src/PopupHandler.ts
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
class PopupHandler extends external_web3auth_auth_namespaceObject.SafeEventEmitter {
|
|
467
|
-
constructor({
|
|
468
|
-
url,
|
|
469
|
-
target,
|
|
470
|
-
features,
|
|
471
|
-
timeout = 30000
|
|
472
|
-
}) {
|
|
473
|
-
super();
|
|
474
|
-
defineProperty_default()(this, "url", void 0);
|
|
475
|
-
defineProperty_default()(this, "target", void 0);
|
|
476
|
-
defineProperty_default()(this, "features", void 0);
|
|
477
|
-
defineProperty_default()(this, "window", void 0);
|
|
478
|
-
defineProperty_default()(this, "windowTimer", void 0);
|
|
479
|
-
defineProperty_default()(this, "iClosedWindow", void 0);
|
|
480
|
-
defineProperty_default()(this, "timeout", void 0);
|
|
481
|
-
this.url = url;
|
|
482
|
-
this.target = target || "_blank";
|
|
483
|
-
this.features = features || (0,base_controllers_namespaceObject.getPopupFeatures)(base_controllers_namespaceObject.FEATURES_DEFAULT_POPUP_WINDOW);
|
|
484
|
-
this.window = undefined;
|
|
485
|
-
this.windowTimer = undefined;
|
|
486
|
-
this.iClosedWindow = false;
|
|
487
|
-
this.timeout = timeout;
|
|
488
|
-
this._setupTimer();
|
|
489
|
-
}
|
|
490
|
-
_setupTimer() {
|
|
491
|
-
this.windowTimer = Number(setInterval(() => {
|
|
492
|
-
if (this.window && this.window.closed) {
|
|
493
|
-
clearInterval(this.windowTimer);
|
|
494
|
-
setTimeout(() => {
|
|
495
|
-
if (!this.iClosedWindow) {
|
|
496
|
-
this.emit("close");
|
|
497
|
-
}
|
|
498
|
-
this.iClosedWindow = false;
|
|
499
|
-
this.window = undefined;
|
|
500
|
-
}, this.timeout);
|
|
381
|
+
};
|
|
382
|
+
Subscriber.prototype.complete = function () {
|
|
383
|
+
if (this.isStopped) ; else {
|
|
384
|
+
this.isStopped = true;
|
|
385
|
+
this._complete();
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
Subscriber.prototype.unsubscribe = function () {
|
|
389
|
+
if (!this.closed) {
|
|
390
|
+
this.isStopped = true;
|
|
391
|
+
_super.prototype.unsubscribe.call(this);
|
|
392
|
+
this.destination = null;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
Subscriber.prototype._next = function (value) {
|
|
396
|
+
this.destination.next(value);
|
|
397
|
+
};
|
|
398
|
+
Subscriber.prototype._error = function (err) {
|
|
399
|
+
try {
|
|
400
|
+
this.destination.error(err);
|
|
401
|
+
} finally {
|
|
402
|
+
this.unsubscribe();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
Subscriber.prototype._complete = function () {
|
|
406
|
+
try {
|
|
407
|
+
this.destination.complete();
|
|
408
|
+
} finally {
|
|
409
|
+
this.unsubscribe();
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
return Subscriber;
|
|
413
|
+
}(Subscription);
|
|
414
|
+
var ConsumerObserver = function () {
|
|
415
|
+
function ConsumerObserver(partialObserver) {
|
|
416
|
+
this.partialObserver = partialObserver;
|
|
417
|
+
}
|
|
418
|
+
ConsumerObserver.prototype.next = function (value) {
|
|
419
|
+
var partialObserver = this.partialObserver;
|
|
420
|
+
if (partialObserver.next) {
|
|
421
|
+
try {
|
|
422
|
+
partialObserver.next(value);
|
|
423
|
+
} catch (error) {
|
|
424
|
+
handleUnhandledError(error);
|
|
501
425
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
ConsumerObserver.prototype.error = function (err) {
|
|
429
|
+
var partialObserver = this.partialObserver;
|
|
430
|
+
if (partialObserver.error) {
|
|
431
|
+
try {
|
|
432
|
+
partialObserver.error(err);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
handleUnhandledError(error);
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
handleUnhandledError(err);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
ConsumerObserver.prototype.complete = function () {
|
|
441
|
+
var partialObserver = this.partialObserver;
|
|
442
|
+
if (partialObserver.complete) {
|
|
443
|
+
try {
|
|
444
|
+
partialObserver.complete();
|
|
445
|
+
} catch (error) {
|
|
446
|
+
handleUnhandledError(error);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
return ConsumerObserver;
|
|
451
|
+
}();
|
|
452
|
+
var SafeSubscriber = function (_super) {
|
|
453
|
+
__extends(SafeSubscriber, _super);
|
|
454
|
+
function SafeSubscriber(observerOrNext, error, complete) {
|
|
455
|
+
var _this = _super.call(this) || this;
|
|
456
|
+
var partialObserver;
|
|
457
|
+
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
458
|
+
partialObserver = {
|
|
459
|
+
next: observerOrNext !== null && observerOrNext !== undefined ? observerOrNext : undefined,
|
|
460
|
+
error: error !== null && error !== undefined ? error : undefined,
|
|
461
|
+
complete: complete !== null && complete !== undefined ? complete : undefined
|
|
462
|
+
};
|
|
517
463
|
} else {
|
|
518
|
-
|
|
464
|
+
{
|
|
465
|
+
partialObserver = observerOrNext;
|
|
466
|
+
}
|
|
519
467
|
}
|
|
468
|
+
_this.destination = new ConsumerObserver(partialObserver);
|
|
469
|
+
return _this;
|
|
470
|
+
}
|
|
471
|
+
return SafeSubscriber;
|
|
472
|
+
}(Subscriber);
|
|
473
|
+
function handleUnhandledError(error) {
|
|
474
|
+
{
|
|
475
|
+
reportUnhandledError(error);
|
|
520
476
|
}
|
|
521
477
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* @param connectionStream - A Node.js duplex stream
|
|
535
|
-
* @param opts - An options bag
|
|
536
|
-
*/
|
|
537
|
-
class CommunicationProvider extends baseProvider {
|
|
538
|
-
constructor(connectionStream, {
|
|
539
|
-
maxEventListeners = 100,
|
|
540
|
-
jsonRpcStreamName = "provider"
|
|
541
|
-
}, state) {
|
|
542
|
-
super(connectionStream, {
|
|
543
|
-
maxEventListeners,
|
|
544
|
-
jsonRpcStreamName
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
// private state
|
|
548
|
-
defineProperty_default()(this, "tryWindowHandle", void 0);
|
|
549
|
-
defineProperty_default()(this, "onLoginStateHandle", void 0);
|
|
550
|
-
defineProperty_default()(this, "windowRefs", void 0);
|
|
551
|
-
defineProperty_default()(this, "iframeUrl", void 0);
|
|
552
|
-
defineProperty_default()(this, "iframeId", void 0);
|
|
553
|
-
this.state = objectSpread2_default()(objectSpread2_default()({}, CommunicationProvider.defaultState), state);
|
|
554
|
-
|
|
555
|
-
// public state
|
|
556
|
-
this.iframeUrl = "";
|
|
557
|
-
this.iframeId = "";
|
|
558
|
-
this.windowRefs = new Map();
|
|
478
|
+
function defaultErrorHandler(err) {
|
|
479
|
+
throw err;
|
|
480
|
+
}
|
|
481
|
+
var EMPTY_OBSERVER = {
|
|
482
|
+
closed: true,
|
|
483
|
+
next: noop,
|
|
484
|
+
error: defaultErrorHandler,
|
|
485
|
+
complete: noop
|
|
486
|
+
};
|
|
559
487
|
|
|
560
|
-
|
|
488
|
+
var observable = function () {
|
|
489
|
+
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
490
|
+
}();
|
|
561
491
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
});
|
|
566
|
-
const notificationHandler = payload => {
|
|
567
|
-
const {
|
|
568
|
-
method,
|
|
569
|
-
params
|
|
570
|
-
} = payload;
|
|
571
|
-
// create_window should never come here..
|
|
572
|
-
// we either pre-open from embed.
|
|
573
|
-
// if it's blocked, we communicate down that it's blocked and we show full screen iframe and open from iframe
|
|
574
|
-
if (method === base_controllers_namespaceObject.COMMUNICATION_NOTIFICATIONS.IFRAME_STATUS) {
|
|
575
|
-
const {
|
|
576
|
-
isFullScreen,
|
|
577
|
-
rid
|
|
578
|
-
} = params;
|
|
579
|
-
this.displayIframe({
|
|
580
|
-
isFull: isFullScreen,
|
|
581
|
-
rid: rid
|
|
582
|
-
}, true);
|
|
583
|
-
} else if (method === base_controllers_namespaceObject.COMMUNICATION_NOTIFICATIONS.CLOSE_WINDOW) {
|
|
584
|
-
this.handleCloseWindow(params);
|
|
585
|
-
} else if (method === base_controllers_namespaceObject.COMMUNICATION_NOTIFICATIONS.USER_LOGGED_IN) {
|
|
586
|
-
loglevel.info("[TEST METAMASK] User received notification ", base_controllers_namespaceObject.COMMUNICATION_NOTIFICATIONS.USER_LOGGED_IN);
|
|
587
|
-
const {
|
|
588
|
-
currentLoginProvider
|
|
589
|
-
} = params;
|
|
590
|
-
this.state.isLoggedIn = true;
|
|
591
|
-
this.state.currentLoginProvider = currentLoginProvider;
|
|
592
|
-
if (this.onLoginStateHandle) this.onLoginStateHandle(true);
|
|
593
|
-
} else if (method === base_controllers_namespaceObject.COMMUNICATION_NOTIFICATIONS.USER_LOGGED_OUT) {
|
|
594
|
-
this.state.isLoggedIn = false;
|
|
595
|
-
this.state.currentLoginProvider = null;
|
|
596
|
-
this.displayIframe();
|
|
597
|
-
if (this.onLoginStateHandle) this.onLoginStateHandle(false);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
this.jsonRpcConnectionEvents.on("notification", notificationHandler);
|
|
601
|
-
}
|
|
602
|
-
get isLoggedIn() {
|
|
603
|
-
return this.state.isLoggedIn;
|
|
604
|
-
}
|
|
492
|
+
function identity(x) {
|
|
493
|
+
return x;
|
|
494
|
+
}
|
|
605
495
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
return
|
|
496
|
+
function pipeFromArray(fns) {
|
|
497
|
+
if (fns.length === 0) {
|
|
498
|
+
return identity;
|
|
609
499
|
}
|
|
610
|
-
|
|
611
|
-
return
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* Returns whether the inPage provider is connected to Torus.
|
|
616
|
-
*/
|
|
617
|
-
isConnected() {
|
|
618
|
-
return this.state.isConnected;
|
|
500
|
+
if (fns.length === 1) {
|
|
501
|
+
return fns[0];
|
|
619
502
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
this.iframeUrl = torusUrl;
|
|
627
|
-
this.iframeId = torusIframeId;
|
|
628
|
-
const {
|
|
629
|
-
currentLoginProvider,
|
|
630
|
-
isLoggedIn
|
|
631
|
-
} = await this.request({
|
|
632
|
-
method: base_controllers_namespaceObject.COMMUNICATION_JRPC_METHODS.GET_PROVIDER_STATE,
|
|
633
|
-
params: []
|
|
634
|
-
});
|
|
503
|
+
return function piped(input) {
|
|
504
|
+
return fns.reduce(function (prev, fn) {
|
|
505
|
+
return fn(prev);
|
|
506
|
+
}, input);
|
|
507
|
+
};
|
|
508
|
+
}
|
|
635
509
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
} finally {
|
|
641
|
-
loglevel.info("initialized communication state");
|
|
642
|
-
this.state.initialized = true;
|
|
510
|
+
var Observable = function () {
|
|
511
|
+
function Observable(subscribe) {
|
|
512
|
+
if (subscribe) {
|
|
513
|
+
this._subscribe = subscribe;
|
|
643
514
|
}
|
|
644
515
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
this
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
moveToForeground() {
|
|
660
|
-
this.state.isBackground = false;
|
|
661
|
-
this.displayIframe({
|
|
662
|
-
isFull: this.state.isIFrameFullScreen
|
|
516
|
+
Observable.prototype.lift = function (operator) {
|
|
517
|
+
var observable = new Observable();
|
|
518
|
+
observable.source = this;
|
|
519
|
+
observable.operator = operator;
|
|
520
|
+
return observable;
|
|
521
|
+
};
|
|
522
|
+
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
523
|
+
var _this = this;
|
|
524
|
+
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
525
|
+
errorContext(function () {
|
|
526
|
+
var _a = _this,
|
|
527
|
+
operator = _a.operator,
|
|
528
|
+
source = _a.source;
|
|
529
|
+
subscriber.add(operator ? operator.call(subscriber, source) : source ? _this._subscribe(subscriber) : _this._trySubscribe(subscriber));
|
|
663
530
|
});
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
isFull = false,
|
|
672
|
-
rid = ""
|
|
673
|
-
} = {}, walletRequest = false) {
|
|
674
|
-
const style = {};
|
|
675
|
-
// set phase
|
|
676
|
-
if (!isFull) {
|
|
677
|
-
style.display = this.state.widgetVisibility && !this.state.isBackground ? "block" : "none";
|
|
678
|
-
style.height = "70px";
|
|
679
|
-
style.width = "70px";
|
|
680
|
-
switch (this.state.buttonPosition) {
|
|
681
|
-
case BUTTON_POSITION.TOP_LEFT:
|
|
682
|
-
style.top = "0px";
|
|
683
|
-
style.left = "0px";
|
|
684
|
-
style.right = "auto";
|
|
685
|
-
style.bottom = "auto";
|
|
686
|
-
break;
|
|
687
|
-
case BUTTON_POSITION.TOP_RIGHT:
|
|
688
|
-
style.top = "0px";
|
|
689
|
-
style.right = "0px";
|
|
690
|
-
style.left = "auto";
|
|
691
|
-
style.bottom = "auto";
|
|
692
|
-
break;
|
|
693
|
-
case BUTTON_POSITION.BOTTOM_RIGHT:
|
|
694
|
-
style.bottom = "0px";
|
|
695
|
-
style.right = "0px";
|
|
696
|
-
style.top = "auto";
|
|
697
|
-
style.left = "auto";
|
|
698
|
-
break;
|
|
699
|
-
case BUTTON_POSITION.BOTTOM_LEFT:
|
|
700
|
-
default:
|
|
701
|
-
style.bottom = "0px";
|
|
702
|
-
style.left = "0px";
|
|
703
|
-
style.top = "auto";
|
|
704
|
-
style.right = "auto";
|
|
705
|
-
break;
|
|
706
|
-
}
|
|
707
|
-
} else {
|
|
708
|
-
style.display = this.state.isBackground ? "none" : "block";
|
|
709
|
-
style.width = "100%";
|
|
710
|
-
style.height = "100%";
|
|
711
|
-
style.top = "0px";
|
|
712
|
-
style.right = "0px";
|
|
713
|
-
style.left = "0px";
|
|
714
|
-
style.bottom = "0px";
|
|
715
|
-
}
|
|
716
|
-
const iframe = document.getElementById(this.iframeId);
|
|
717
|
-
Object.assign(iframe.style, style);
|
|
718
|
-
this.state.isIFrameFullScreen = isFull;
|
|
719
|
-
if (!walletRequest) {
|
|
720
|
-
this.request({
|
|
721
|
-
method: base_controllers_namespaceObject.COMMUNICATION_JRPC_METHODS.IFRAME_STATUS,
|
|
722
|
-
params: {
|
|
723
|
-
isIFrameFullScreen: isFull,
|
|
724
|
-
rid
|
|
725
|
-
}
|
|
726
|
-
});
|
|
531
|
+
return subscriber;
|
|
532
|
+
};
|
|
533
|
+
Observable.prototype._trySubscribe = function (sink) {
|
|
534
|
+
try {
|
|
535
|
+
return this._subscribe(sink);
|
|
536
|
+
} catch (err) {
|
|
537
|
+
sink.error(err);
|
|
727
538
|
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
target,
|
|
745
|
-
features,
|
|
746
|
-
timeout
|
|
747
|
-
});
|
|
748
|
-
handledWindow.open();
|
|
749
|
-
if (!handledWindow.window) {
|
|
750
|
-
this.displayIframe({
|
|
751
|
-
isFull: true
|
|
752
|
-
});
|
|
753
|
-
this.request({
|
|
754
|
-
method: base_controllers_namespaceObject.COMMUNICATION_JRPC_METHODS.WINDOW_BLOCKED,
|
|
755
|
-
params: {
|
|
756
|
-
windowId,
|
|
757
|
-
finalUrl: finalUrl.href
|
|
758
|
-
}
|
|
759
|
-
});
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
// Add to collection only if window is opened
|
|
763
|
-
this.windowRefs.set(windowId, handledWindow);
|
|
764
|
-
handledWindow.once("close", () => {
|
|
765
|
-
// user closed the window
|
|
766
|
-
this.windowRefs.delete(windowId);
|
|
767
|
-
this.request({
|
|
768
|
-
method: base_controllers_namespaceObject.COMMUNICATION_JRPC_METHODS.CLOSED_WINDOW,
|
|
769
|
-
params: {
|
|
770
|
-
windowId
|
|
771
|
-
}
|
|
539
|
+
};
|
|
540
|
+
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
541
|
+
var _this = this;
|
|
542
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
543
|
+
return new promiseCtor(function (resolve, reject) {
|
|
544
|
+
var subscriber = new SafeSubscriber({
|
|
545
|
+
next: function (value) {
|
|
546
|
+
try {
|
|
547
|
+
next(value);
|
|
548
|
+
} catch (err) {
|
|
549
|
+
reject(err);
|
|
550
|
+
subscriber.unsubscribe();
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
error: reject,
|
|
554
|
+
complete: resolve
|
|
772
555
|
});
|
|
556
|
+
_this.subscribe(subscriber);
|
|
773
557
|
});
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
}
|
|
558
|
+
};
|
|
559
|
+
Observable.prototype._subscribe = function (subscriber) {
|
|
560
|
+
var _a;
|
|
561
|
+
return (_a = this.source) === null || _a === undefined ? undefined : _a.subscribe(subscriber);
|
|
562
|
+
};
|
|
563
|
+
Observable.prototype[observable] = function () {
|
|
564
|
+
return this;
|
|
565
|
+
};
|
|
566
|
+
Observable.prototype.pipe = function () {
|
|
567
|
+
var operations = [];
|
|
568
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
569
|
+
operations[_i] = arguments[_i];
|
|
787
570
|
}
|
|
788
|
-
|
|
789
|
-
}
|
|
571
|
+
return pipeFromArray(operations)(this);
|
|
572
|
+
};
|
|
573
|
+
Observable.prototype.toPromise = function (promiseCtor) {
|
|
574
|
+
var _this = this;
|
|
575
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
576
|
+
return new promiseCtor(function (resolve, reject) {
|
|
577
|
+
var value;
|
|
578
|
+
_this.subscribe(function (x) {
|
|
579
|
+
return value = x;
|
|
580
|
+
}, function (err) {
|
|
581
|
+
return reject(err);
|
|
582
|
+
}, function () {
|
|
583
|
+
return resolve(value);
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
};
|
|
587
|
+
Observable.create = function (subscribe) {
|
|
588
|
+
return new Observable(subscribe);
|
|
589
|
+
};
|
|
590
|
+
return Observable;
|
|
591
|
+
}();
|
|
592
|
+
function getPromiseCtor(promiseCtor) {
|
|
593
|
+
var _a;
|
|
594
|
+
return (_a = promiseCtor !== null && promiseCtor !== undefined ? promiseCtor : config.Promise) !== null && _a !== undefined ? _a : Promise;
|
|
595
|
+
}
|
|
596
|
+
function isObserver(value) {
|
|
597
|
+
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
598
|
+
}
|
|
599
|
+
function isSubscriber(value) {
|
|
600
|
+
return value && value instanceof Subscriber || isObserver(value) && isSubscription(value);
|
|
601
|
+
}
|
|
790
602
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
isLoggedIn
|
|
603
|
+
function hasLift(source) {
|
|
604
|
+
return isFunction(source === null || source === undefined ? undefined : source.lift);
|
|
605
|
+
}
|
|
606
|
+
function operate(init) {
|
|
607
|
+
return function (source) {
|
|
608
|
+
if (hasLift(source)) {
|
|
609
|
+
return source.lift(function (liftedSource) {
|
|
610
|
+
try {
|
|
611
|
+
return init(liftedSource, this);
|
|
612
|
+
} catch (err) {
|
|
613
|
+
this.error(err);
|
|
614
|
+
}
|
|
804
615
|
});
|
|
805
|
-
loglevel.debug(messages.info.connected(currentLoginProvider));
|
|
806
616
|
}
|
|
807
|
-
|
|
617
|
+
throw new TypeError('Unable to lift unknown Observable type');
|
|
618
|
+
};
|
|
619
|
+
}
|
|
808
620
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
let error;
|
|
824
|
-
if (isRecoverable) {
|
|
825
|
-
error = new external_web3auth_auth_namespaceObject.EthereumProviderError(1013,
|
|
826
|
-
// Try again later
|
|
827
|
-
errorMessage || messages.errors.disconnected());
|
|
828
|
-
loglevel.debug(error);
|
|
829
|
-
} else {
|
|
830
|
-
error = new external_web3auth_auth_namespaceObject.EthereumProviderError(1011,
|
|
831
|
-
// Internal error
|
|
832
|
-
errorMessage || messages.errors.permanentlyDisconnected());
|
|
833
|
-
loglevel.error(error);
|
|
834
|
-
this.state.currentLoginProvider = null;
|
|
835
|
-
this.state.isLoggedIn = false;
|
|
836
|
-
this.state.widgetVisibility = false;
|
|
837
|
-
this.state.isIFrameFullScreen = false;
|
|
838
|
-
this.state.isPermanentlyDisconnected = true;
|
|
621
|
+
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
622
|
+
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
623
|
+
}
|
|
624
|
+
var OperatorSubscriber = function (_super) {
|
|
625
|
+
__extends(OperatorSubscriber, _super);
|
|
626
|
+
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
627
|
+
var _this = _super.call(this, destination) || this;
|
|
628
|
+
_this.onFinalize = onFinalize;
|
|
629
|
+
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
630
|
+
_this._next = onNext ? function (value) {
|
|
631
|
+
try {
|
|
632
|
+
onNext(value);
|
|
633
|
+
} catch (err) {
|
|
634
|
+
destination.error(err);
|
|
839
635
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
636
|
+
} : _super.prototype._next;
|
|
637
|
+
_this._error = onError ? function (err) {
|
|
638
|
+
try {
|
|
639
|
+
onError(err);
|
|
640
|
+
} catch (err) {
|
|
641
|
+
destination.error(err);
|
|
642
|
+
} finally {
|
|
643
|
+
this.unsubscribe();
|
|
644
|
+
}
|
|
645
|
+
} : _super.prototype._error;
|
|
646
|
+
_this._complete = onComplete ? function () {
|
|
647
|
+
try {
|
|
648
|
+
onComplete();
|
|
649
|
+
} catch (err) {
|
|
650
|
+
destination.error(err);
|
|
651
|
+
} finally {
|
|
652
|
+
this.unsubscribe();
|
|
653
|
+
}
|
|
654
|
+
} : _super.prototype._complete;
|
|
655
|
+
return _this;
|
|
656
|
+
}
|
|
657
|
+
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
658
|
+
var _a;
|
|
659
|
+
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
660
|
+
var closed_1 = this.closed;
|
|
661
|
+
_super.prototype.unsubscribe.call(this);
|
|
662
|
+
!closed_1 && ((_a = this.onFinalize) === null || _a === undefined ? undefined : _a.call(this));
|
|
850
663
|
}
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
isPermanentlyDisconnected: false,
|
|
862
|
-
isConnected: false,
|
|
863
|
-
hasEmittedConnection: false
|
|
664
|
+
};
|
|
665
|
+
return OperatorSubscriber;
|
|
666
|
+
}(Subscriber);
|
|
667
|
+
|
|
668
|
+
var ObjectUnsubscribedError = createErrorClass(function (_super) {
|
|
669
|
+
return function ObjectUnsubscribedErrorImpl() {
|
|
670
|
+
_super(this);
|
|
671
|
+
this.name = 'ObjectUnsubscribedError';
|
|
672
|
+
this.message = 'object unsubscribed';
|
|
673
|
+
};
|
|
864
674
|
});
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
675
|
+
|
|
676
|
+
var Subject = function (_super) {
|
|
677
|
+
__extends(Subject, _super);
|
|
678
|
+
function Subject() {
|
|
679
|
+
var _this = _super.call(this) || this;
|
|
680
|
+
_this.closed = false;
|
|
681
|
+
_this.currentObservers = null;
|
|
682
|
+
_this.observers = [];
|
|
683
|
+
_this.isStopped = false;
|
|
684
|
+
_this.hasError = false;
|
|
685
|
+
_this.thrownError = null;
|
|
686
|
+
return _this;
|
|
687
|
+
}
|
|
688
|
+
Subject.prototype.lift = function (operator) {
|
|
689
|
+
var subject = new AnonymousSubject(this, this);
|
|
690
|
+
subject.operator = operator;
|
|
691
|
+
return subject;
|
|
692
|
+
};
|
|
693
|
+
Subject.prototype._throwIfClosed = function () {
|
|
694
|
+
if (this.closed) {
|
|
695
|
+
throw new ObjectUnsubscribedError();
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
Subject.prototype.next = function (value) {
|
|
699
|
+
var _this = this;
|
|
700
|
+
errorContext(function () {
|
|
701
|
+
var e_1, _a;
|
|
702
|
+
_this._throwIfClosed();
|
|
703
|
+
if (!_this.isStopped) {
|
|
704
|
+
if (!_this.currentObservers) {
|
|
705
|
+
_this.currentObservers = Array.from(_this.observers);
|
|
706
|
+
}
|
|
707
|
+
try {
|
|
708
|
+
for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
709
|
+
var observer = _c.value;
|
|
710
|
+
observer.next(value);
|
|
711
|
+
}
|
|
712
|
+
} catch (e_1_1) {
|
|
713
|
+
e_1 = {
|
|
714
|
+
error: e_1_1
|
|
715
|
+
};
|
|
716
|
+
} finally {
|
|
717
|
+
try {
|
|
718
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
719
|
+
} finally {
|
|
720
|
+
if (e_1) throw e_1.error;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
Subject.prototype.error = function (err) {
|
|
727
|
+
var _this = this;
|
|
728
|
+
errorContext(function () {
|
|
729
|
+
_this._throwIfClosed();
|
|
730
|
+
if (!_this.isStopped) {
|
|
731
|
+
_this.hasError = _this.isStopped = true;
|
|
732
|
+
_this.thrownError = err;
|
|
733
|
+
var observers = _this.observers;
|
|
734
|
+
while (observers.length) {
|
|
735
|
+
observers.shift().error(err);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
};
|
|
740
|
+
Subject.prototype.complete = function () {
|
|
741
|
+
var _this = this;
|
|
742
|
+
errorContext(function () {
|
|
743
|
+
_this._throwIfClosed();
|
|
744
|
+
if (!_this.isStopped) {
|
|
745
|
+
_this.isStopped = true;
|
|
746
|
+
var observers = _this.observers;
|
|
747
|
+
while (observers.length) {
|
|
748
|
+
observers.shift().complete();
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
};
|
|
753
|
+
Subject.prototype.unsubscribe = function () {
|
|
754
|
+
this.isStopped = this.closed = true;
|
|
755
|
+
this.observers = this.currentObservers = null;
|
|
756
|
+
};
|
|
757
|
+
Object.defineProperty(Subject.prototype, "observed", {
|
|
758
|
+
get: function () {
|
|
759
|
+
var _a;
|
|
760
|
+
return ((_a = this.observers) === null || _a === undefined ? undefined : _a.length) > 0;
|
|
761
|
+
},
|
|
762
|
+
enumerable: false,
|
|
763
|
+
configurable: true
|
|
764
|
+
});
|
|
765
|
+
Subject.prototype._trySubscribe = function (subscriber) {
|
|
766
|
+
this._throwIfClosed();
|
|
767
|
+
return _super.prototype._trySubscribe.call(this, subscriber);
|
|
768
|
+
};
|
|
769
|
+
Subject.prototype._subscribe = function (subscriber) {
|
|
770
|
+
this._throwIfClosed();
|
|
771
|
+
this._checkFinalizedStatuses(subscriber);
|
|
772
|
+
return this._innerSubscribe(subscriber);
|
|
773
|
+
};
|
|
774
|
+
Subject.prototype._innerSubscribe = function (subscriber) {
|
|
775
|
+
var _this = this;
|
|
776
|
+
var _a = this,
|
|
777
|
+
hasError = _a.hasError,
|
|
778
|
+
isStopped = _a.isStopped,
|
|
779
|
+
observers = _a.observers;
|
|
780
|
+
if (hasError || isStopped) {
|
|
781
|
+
return EMPTY_SUBSCRIPTION;
|
|
782
|
+
}
|
|
783
|
+
this.currentObservers = null;
|
|
784
|
+
observers.push(subscriber);
|
|
785
|
+
return new Subscription(function () {
|
|
786
|
+
_this.currentObservers = null;
|
|
787
|
+
arrRemove(observers, subscriber);
|
|
788
|
+
});
|
|
789
|
+
};
|
|
790
|
+
Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
|
791
|
+
var _a = this,
|
|
792
|
+
hasError = _a.hasError,
|
|
793
|
+
thrownError = _a.thrownError,
|
|
794
|
+
isStopped = _a.isStopped;
|
|
795
|
+
if (hasError) {
|
|
796
|
+
subscriber.error(thrownError);
|
|
797
|
+
} else if (isStopped) {
|
|
798
|
+
subscriber.complete();
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
Subject.prototype.asObservable = function () {
|
|
802
|
+
var observable = new Observable();
|
|
803
|
+
observable.source = this;
|
|
804
|
+
return observable;
|
|
805
|
+
};
|
|
806
|
+
Subject.create = function (destination, source) {
|
|
807
|
+
return new AnonymousSubject(destination, source);
|
|
808
|
+
};
|
|
809
|
+
return Subject;
|
|
810
|
+
}(Observable);
|
|
811
|
+
var AnonymousSubject = function (_super) {
|
|
812
|
+
__extends(AnonymousSubject, _super);
|
|
813
|
+
function AnonymousSubject(destination, source) {
|
|
814
|
+
var _this = _super.call(this) || this;
|
|
815
|
+
_this.destination = destination;
|
|
816
|
+
_this.source = source;
|
|
817
|
+
return _this;
|
|
818
|
+
}
|
|
819
|
+
AnonymousSubject.prototype.next = function (value) {
|
|
820
|
+
var _a, _b;
|
|
821
|
+
(_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.next) === null || _b === undefined ? undefined : _b.call(_a, value);
|
|
822
|
+
};
|
|
823
|
+
AnonymousSubject.prototype.error = function (err) {
|
|
824
|
+
var _a, _b;
|
|
825
|
+
(_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.error) === null || _b === undefined ? undefined : _b.call(_a, err);
|
|
826
|
+
};
|
|
827
|
+
AnonymousSubject.prototype.complete = function () {
|
|
828
|
+
var _a, _b;
|
|
829
|
+
(_b = (_a = this.destination) === null || _a === undefined ? undefined : _a.complete) === null || _b === undefined ? undefined : _b.call(_a);
|
|
830
|
+
};
|
|
831
|
+
AnonymousSubject.prototype._subscribe = function (subscriber) {
|
|
832
|
+
var _a, _b;
|
|
833
|
+
return (_b = (_a = this.source) === null || _a === undefined ? undefined : _a.subscribe(subscriber)) !== null && _b !== undefined ? _b : EMPTY_SUBSCRIPTION;
|
|
834
|
+
};
|
|
835
|
+
return AnonymousSubject;
|
|
836
|
+
}(Subject);
|
|
837
|
+
|
|
838
|
+
var EmptyError = createErrorClass(function (_super) {
|
|
839
|
+
return function EmptyErrorImpl() {
|
|
840
|
+
_super(this);
|
|
841
|
+
this.name = 'EmptyError';
|
|
842
|
+
this.message = 'no elements in sequence';
|
|
843
|
+
};
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
function firstValueFrom(source, config) {
|
|
847
|
+
return new Promise(function (resolve, reject) {
|
|
848
|
+
var subscriber = new SafeSubscriber({
|
|
849
|
+
next: function (value) {
|
|
850
|
+
resolve(value);
|
|
851
|
+
subscriber.unsubscribe();
|
|
852
|
+
},
|
|
853
|
+
error: reject,
|
|
854
|
+
complete: function () {
|
|
855
|
+
{
|
|
856
|
+
reject(new EmptyError());
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
source.subscribe(subscriber);
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function filter(predicate, thisArg) {
|
|
865
|
+
return operate(function (source, subscriber) {
|
|
866
|
+
var index = 0;
|
|
867
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
868
|
+
return predicate.call(thisArg, value, index++) && subscriber.next(value);
|
|
869
|
+
}));
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
class BaseError extends Error {
|
|
874
|
+
constructor(name, message, options = {}) {
|
|
875
|
+
const {
|
|
876
|
+
cause,
|
|
877
|
+
context
|
|
878
|
+
} = options;
|
|
879
|
+
super(message || name);
|
|
874
880
|
this.name = name;
|
|
875
|
-
this.stack = cause
|
|
881
|
+
this.stack = cause?.stack;
|
|
876
882
|
this.cause = cause;
|
|
877
883
|
this.context = context;
|
|
878
884
|
}
|
|
@@ -885,1890 +891,1208 @@ class BaseError extends Error {
|
|
|
885
891
|
};
|
|
886
892
|
}
|
|
887
893
|
}
|
|
888
|
-
function ensureError(value) {
|
|
889
|
-
if (value instanceof Error) return value;
|
|
890
|
-
let stringified = "[Unable to stringify the thrown value]";
|
|
891
|
-
try {
|
|
892
|
-
stringified = JSON.stringify(value);
|
|
893
|
-
} catch {
|
|
894
|
-
// ignoring failed stringify
|
|
895
|
-
}
|
|
896
|
-
return new Error(`This value was not thrown as type Error: ${stringified}`);
|
|
897
|
-
}
|
|
898
|
-
;// ./src/error.ts
|
|
899
894
|
|
|
900
895
|
class AirServiceError extends BaseError {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
896
|
+
static from(error) {
|
|
897
|
+
if (error instanceof AirServiceError) {
|
|
898
|
+
return error;
|
|
899
|
+
}
|
|
900
|
+
else if (error instanceof Object && "message" in error) {
|
|
901
|
+
if (error.message === "User cancelled login") {
|
|
902
|
+
return new AirServiceError("USER_CANCELLED", error.message);
|
|
903
|
+
}
|
|
904
|
+
return new AirServiceError("UNKNOWN_ERROR", error.message.toString());
|
|
905
|
+
}
|
|
906
|
+
return new AirServiceError("UNKNOWN_ERROR");
|
|
909
907
|
}
|
|
910
|
-
return new AirServiceError("UNKNOWN_ERROR");
|
|
911
|
-
}
|
|
912
908
|
}
|
|
913
|
-
class RealmEmbedError extends AirServiceError {
|
|
914
|
-
|
|
915
|
-
const external_fast_deep_equal_namespaceObject = require("fast-deep-equal");
|
|
916
|
-
var external_fast_deep_equal_default = /*#__PURE__*/__webpack_require__.n(external_fast_deep_equal_namespaceObject);
|
|
917
|
-
;// ./src/inPageProvider.ts
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
909
|
+
class RealmEmbedError extends AirServiceError {
|
|
910
|
+
}
|
|
924
911
|
|
|
912
|
+
function getDefaultExportFromCjs (x) {
|
|
913
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
914
|
+
}
|
|
925
915
|
|
|
916
|
+
var loglevel$2 = {exports: {}};
|
|
917
|
+
|
|
918
|
+
/*
|
|
919
|
+
* loglevel - https://github.com/pimterry/loglevel
|
|
920
|
+
*
|
|
921
|
+
* Copyright (c) 2013 Tim Perry
|
|
922
|
+
* Licensed under the MIT license.
|
|
923
|
+
*/
|
|
924
|
+
var loglevel$1 = loglevel$2.exports;
|
|
925
|
+
var hasRequiredLoglevel;
|
|
926
|
+
function requireLoglevel() {
|
|
927
|
+
if (hasRequiredLoglevel) return loglevel$2.exports;
|
|
928
|
+
hasRequiredLoglevel = 1;
|
|
929
|
+
(function (module) {
|
|
930
|
+
(function (root, definition) {
|
|
931
|
+
|
|
932
|
+
if (module.exports) {
|
|
933
|
+
module.exports = definition();
|
|
934
|
+
} else {
|
|
935
|
+
root.log = definition();
|
|
936
|
+
}
|
|
937
|
+
})(loglevel$1, function () {
|
|
938
|
+
|
|
939
|
+
// Slightly dubious tricks to cut down minimized file size
|
|
940
|
+
var noop = function () {};
|
|
941
|
+
var undefinedType = "undefined";
|
|
942
|
+
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
943
|
+
var logMethods = ["trace", "debug", "info", "warn", "error"];
|
|
944
|
+
var _loggersByName = {};
|
|
945
|
+
var defaultLogger = null;
|
|
946
|
+
|
|
947
|
+
// Cross-browser bind equivalent that works at least back to IE6
|
|
948
|
+
function bindMethod(obj, methodName) {
|
|
949
|
+
var method = obj[methodName];
|
|
950
|
+
if (typeof method.bind === 'function') {
|
|
951
|
+
return method.bind(obj);
|
|
952
|
+
} else {
|
|
953
|
+
try {
|
|
954
|
+
return Function.prototype.bind.call(method, obj);
|
|
955
|
+
} catch (e) {
|
|
956
|
+
// Missing bind shim or IE8 + Modernizr, fallback to wrapping
|
|
957
|
+
return function () {
|
|
958
|
+
return Function.prototype.apply.apply(method, [obj, arguments]);
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
926
963
|
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
});
|
|
964
|
+
// Trace() doesn't print the message in IE, so for that case we need to wrap it
|
|
965
|
+
function traceForIE() {
|
|
966
|
+
if (console.log) {
|
|
967
|
+
if (console.log.apply) {
|
|
968
|
+
console.log.apply(console, arguments);
|
|
969
|
+
} else {
|
|
970
|
+
// In old IE, native console methods themselves don't have apply().
|
|
971
|
+
Function.prototype.apply.apply(console.log, [console, arguments]);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (console.trace) console.trace();
|
|
975
|
+
}
|
|
940
976
|
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
this.chainId = null;
|
|
959
|
-
this.handleAccountsChanged = this.handleAccountsChanged.bind(this);
|
|
960
|
-
this.handleChainChanged = this.handleChainChanged.bind(this);
|
|
961
|
-
this.handleUnlockStateChanged = this.handleUnlockStateChanged.bind(this);
|
|
962
|
-
|
|
963
|
-
// setup own event listeners
|
|
964
|
-
|
|
965
|
-
// EIP-1193 connect
|
|
966
|
-
this.on("connect", () => {
|
|
967
|
-
this.state.isConnected = true;
|
|
968
|
-
});
|
|
969
|
-
const jsonRpcNotificationHandler = payload => {
|
|
970
|
-
const {
|
|
971
|
-
method,
|
|
972
|
-
params
|
|
973
|
-
} = payload;
|
|
974
|
-
if (method === base_controllers_namespaceObject.PROVIDER_NOTIFICATIONS.ACCOUNTS_CHANGED) {
|
|
975
|
-
this.handleAccountsChanged(params);
|
|
976
|
-
} else if (method === base_controllers_namespaceObject.PROVIDER_NOTIFICATIONS.UNLOCK_STATE_CHANGED) {
|
|
977
|
-
this.handleUnlockStateChanged(params);
|
|
978
|
-
} else if (method === base_controllers_namespaceObject.PROVIDER_NOTIFICATIONS.CHAIN_CHANGED) {
|
|
979
|
-
this.handleChainChanged(params);
|
|
980
|
-
} else if (EMITTED_NOTIFICATIONS.includes(method)) {
|
|
981
|
-
this.emit("data", payload);
|
|
982
|
-
this.emit("notification", params.result);
|
|
983
|
-
this.emit("message", {
|
|
984
|
-
type: method,
|
|
985
|
-
data: params
|
|
986
|
-
});
|
|
977
|
+
// Build the best logging method possible for this env
|
|
978
|
+
// Wherever possible we want to bind, not wrap, to preserve stack traces
|
|
979
|
+
function realMethod(methodName) {
|
|
980
|
+
if (methodName === 'debug') {
|
|
981
|
+
methodName = 'log';
|
|
982
|
+
}
|
|
983
|
+
if (typeof console === undefinedType) {
|
|
984
|
+
return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
|
|
985
|
+
} else if (methodName === 'trace' && isIE) {
|
|
986
|
+
return traceForIE;
|
|
987
|
+
} else if (console[methodName] !== undefined) {
|
|
988
|
+
return bindMethod(console, methodName);
|
|
989
|
+
} else if (console.log !== undefined) {
|
|
990
|
+
return bindMethod(console, 'log');
|
|
991
|
+
} else {
|
|
992
|
+
return noop;
|
|
993
|
+
}
|
|
987
994
|
}
|
|
988
|
-
};
|
|
989
995
|
|
|
990
|
-
|
|
991
|
-
this.jsonRpcConnectionEvents.on("notification", jsonRpcNotificationHandler);
|
|
992
|
-
}
|
|
996
|
+
// These private functions always need `this` to be set properly
|
|
993
997
|
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
isConnected() {
|
|
998
|
-
return this.state.isConnected;
|
|
999
|
-
}
|
|
998
|
+
function replaceLoggingMethods() {
|
|
999
|
+
/*jshint validthis:true */
|
|
1000
|
+
var level = this.getLevel();
|
|
1000
1001
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
* necessary events.
|
|
1007
|
-
*/
|
|
1008
|
-
async initializeState() {
|
|
1009
|
-
try {
|
|
1010
|
-
const {
|
|
1011
|
-
accounts,
|
|
1012
|
-
chainId,
|
|
1013
|
-
isUnlocked
|
|
1014
|
-
} = await this.request({
|
|
1015
|
-
method: base_controllers_namespaceObject.PROVIDER_JRPC_METHODS.GET_PROVIDER_STATE,
|
|
1016
|
-
params: []
|
|
1017
|
-
});
|
|
1002
|
+
// Replace the actual methods.
|
|
1003
|
+
for (var i = 0; i < logMethods.length; i++) {
|
|
1004
|
+
var methodName = logMethods[i];
|
|
1005
|
+
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, this.name);
|
|
1006
|
+
}
|
|
1018
1007
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
chainId
|
|
1022
|
-
});
|
|
1023
|
-
this.handleChainChanged({
|
|
1024
|
-
chainId
|
|
1025
|
-
});
|
|
1026
|
-
this.handleUnlockStateChanged({
|
|
1027
|
-
accounts,
|
|
1028
|
-
isUnlocked
|
|
1029
|
-
});
|
|
1030
|
-
this.handleAccountsChanged(accounts);
|
|
1031
|
-
} catch (error) {
|
|
1032
|
-
loglevel.error("WsEmbed: Failed to get initial state. Please report this bug.", error);
|
|
1033
|
-
} finally {
|
|
1034
|
-
loglevel.info("initialized provider state");
|
|
1035
|
-
this.state.initialized = true;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1008
|
+
// Define log.log as an alias for log.debug
|
|
1009
|
+
this.log = this.debug;
|
|
1038
1010
|
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
rpcRequest(payload, callback, isInternal = false) {
|
|
1044
|
-
let cb = callback;
|
|
1045
|
-
const _payload = payload;
|
|
1046
|
-
if (!Array.isArray(_payload)) {
|
|
1047
|
-
if (!_payload.jsonrpc) {
|
|
1048
|
-
_payload.jsonrpc = "2.0";
|
|
1011
|
+
// Return any important warnings.
|
|
1012
|
+
if (typeof console === undefinedType && level < this.levels.SILENT) {
|
|
1013
|
+
return "No console available for logging";
|
|
1014
|
+
}
|
|
1049
1015
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1016
|
+
|
|
1017
|
+
// In old IE versions, the console isn't present until you first open it.
|
|
1018
|
+
// We build realMethod() replacements here that regenerate logging methods
|
|
1019
|
+
function enableLoggingWhenConsoleArrives(methodName) {
|
|
1020
|
+
return function () {
|
|
1021
|
+
if (typeof console !== undefinedType) {
|
|
1022
|
+
replaceLoggingMethods.call(this);
|
|
1023
|
+
this[methodName].apply(this, arguments);
|
|
1024
|
+
}
|
|
1055
1025
|
};
|
|
1056
|
-
} else if (_payload.method === "wallet_getProviderState") {
|
|
1057
|
-
this.rpcEngine.handle(payload, cb);
|
|
1058
|
-
return;
|
|
1059
1026
|
}
|
|
1060
|
-
}
|
|
1061
|
-
this.tryWindowHandle(_payload, cb);
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
/**
|
|
1065
|
-
* When the provider becomes connected, updates internal state and emits
|
|
1066
|
-
* required events. Idempotent.
|
|
1067
|
-
*
|
|
1068
|
-
* @param chainId - The ID of the newly connected chain.
|
|
1069
|
-
* emits TorusInpageProvider#connect
|
|
1070
|
-
*/
|
|
1071
|
-
handleConnect(chainId) {
|
|
1072
|
-
if (!this.state.isConnected) {
|
|
1073
|
-
this.state.isConnected = true;
|
|
1074
|
-
this.emit("connect", {
|
|
1075
|
-
chainId
|
|
1076
|
-
});
|
|
1077
|
-
loglevel.debug(messages.info.connected(chainId));
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
1027
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes
|
|
1087
|
-
*
|
|
1088
|
-
* @param isRecoverable - Whether the disconnection is recoverable.
|
|
1089
|
-
* @param errorMessage - A custom error message.
|
|
1090
|
-
* emits TorusInpageProvider#disconnect
|
|
1091
|
-
*/
|
|
1092
|
-
handleDisconnect(isRecoverable, errorMessage) {
|
|
1093
|
-
if (this.state.isConnected || !this.state.isPermanentlyDisconnected && !isRecoverable) {
|
|
1094
|
-
this.state.isConnected = false;
|
|
1095
|
-
let error;
|
|
1096
|
-
if (isRecoverable) {
|
|
1097
|
-
error = new external_web3auth_auth_namespaceObject.EthereumProviderError(1013,
|
|
1098
|
-
// Try again later
|
|
1099
|
-
errorMessage || messages.errors.disconnected());
|
|
1100
|
-
loglevel.debug(error);
|
|
1101
|
-
} else {
|
|
1102
|
-
error = new external_web3auth_auth_namespaceObject.EthereumProviderError(1011,
|
|
1103
|
-
// Internal error
|
|
1104
|
-
errorMessage || messages.errors.permanentlyDisconnected());
|
|
1105
|
-
loglevel.error(error);
|
|
1106
|
-
this.chainId = null;
|
|
1107
|
-
this.state.accounts = null;
|
|
1108
|
-
this.selectedAddress = null;
|
|
1109
|
-
this.state.isUnlocked = false;
|
|
1110
|
-
this.state.isPermanentlyDisconnected = true;
|
|
1028
|
+
// By default, we use closely bound real methods wherever possible, and
|
|
1029
|
+
// otherwise we wait for a console to appear, and then try again.
|
|
1030
|
+
function defaultMethodFactory(methodName, _level, _loggerName) {
|
|
1031
|
+
/*jshint validthis:true */
|
|
1032
|
+
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
1111
1033
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1034
|
+
function Logger(name, factory) {
|
|
1035
|
+
// Private instance variables.
|
|
1036
|
+
var self = this;
|
|
1037
|
+
/**
|
|
1038
|
+
* The level inherited from a parent logger (or a global default). We
|
|
1039
|
+
* cache this here rather than delegating to the parent so that it stays
|
|
1040
|
+
* in sync with the actual logging methods that we have installed (the
|
|
1041
|
+
* parent could change levels but we might not have rebuilt the loggers
|
|
1042
|
+
* in this child yet).
|
|
1043
|
+
* @type {number}
|
|
1044
|
+
*/
|
|
1045
|
+
var inheritedLevel;
|
|
1046
|
+
/**
|
|
1047
|
+
* The default level for this logger, if any. If set, this overrides
|
|
1048
|
+
* `inheritedLevel`.
|
|
1049
|
+
* @type {number|null}
|
|
1050
|
+
*/
|
|
1051
|
+
var defaultLevel;
|
|
1052
|
+
/**
|
|
1053
|
+
* A user-specific level for this logger. If set, this overrides
|
|
1054
|
+
* `defaultLevel`.
|
|
1055
|
+
* @type {number|null}
|
|
1056
|
+
*/
|
|
1057
|
+
var userLevel;
|
|
1058
|
+
var storageKey = "loglevel";
|
|
1059
|
+
if (typeof name === "string") {
|
|
1060
|
+
storageKey += ":" + name;
|
|
1061
|
+
} else if (typeof name === "symbol") {
|
|
1062
|
+
storageKey = undefined;
|
|
1063
|
+
}
|
|
1064
|
+
function persistLevelIfPossible(levelNum) {
|
|
1065
|
+
var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
|
|
1066
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
1115
1067
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
let finalAccounts = accounts;
|
|
1122
|
-
if (!Array.isArray(finalAccounts)) {
|
|
1123
|
-
loglevel.error("WsEmbed: Received non-array accounts parameter. Please report this bug.", finalAccounts);
|
|
1124
|
-
finalAccounts = [];
|
|
1125
|
-
}
|
|
1126
|
-
for (const account of accounts) {
|
|
1127
|
-
if (typeof account !== "string") {
|
|
1128
|
-
loglevel.error("WsEmbed: Received non-string account. Please report this bug.", accounts);
|
|
1129
|
-
finalAccounts = [];
|
|
1130
|
-
break;
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1068
|
+
// Use localStorage if available
|
|
1069
|
+
try {
|
|
1070
|
+
window.localStorage[storageKey] = levelName;
|
|
1071
|
+
return;
|
|
1072
|
+
} catch (ignore) {}
|
|
1133
1073
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1074
|
+
// Use session cookie as fallback
|
|
1075
|
+
try {
|
|
1076
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
|
|
1077
|
+
} catch (ignore) {}
|
|
1078
|
+
}
|
|
1079
|
+
function getPersistedLevel() {
|
|
1080
|
+
var storedLevel;
|
|
1081
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
1082
|
+
try {
|
|
1083
|
+
storedLevel = window.localStorage[storageKey];
|
|
1084
|
+
} catch (ignore) {}
|
|
1085
|
+
|
|
1086
|
+
// Fallback to cookies if local storage gives us nothing
|
|
1087
|
+
if (typeof storedLevel === undefinedType) {
|
|
1088
|
+
try {
|
|
1089
|
+
var cookie = window.document.cookie;
|
|
1090
|
+
var cookieName = encodeURIComponent(storageKey);
|
|
1091
|
+
var location = cookie.indexOf(cookieName + "=");
|
|
1092
|
+
if (location !== -1) {
|
|
1093
|
+
storedLevel = /^([^;]+)/.exec(cookie.slice(location + cookieName.length + 1))[1];
|
|
1094
|
+
}
|
|
1095
|
+
} catch (ignore) {}
|
|
1096
|
+
}
|
|
1144
1097
|
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1098
|
+
// If the stored level is not valid, treat it as if nothing was stored.
|
|
1099
|
+
if (self.levels[storedLevel] === undefined) {
|
|
1100
|
+
storedLevel = undefined;
|
|
1101
|
+
}
|
|
1102
|
+
return storedLevel;
|
|
1103
|
+
}
|
|
1104
|
+
function clearPersistedLevel() {
|
|
1105
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
1150
1106
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
} else {
|
|
1172
|
-
this.handleConnect(chainId);
|
|
1173
|
-
if (chainId !== this.chainId) {
|
|
1174
|
-
this.chainId = chainId;
|
|
1175
|
-
if (this.state.initialized) {
|
|
1176
|
-
this.emit("chainChanged", this.chainId);
|
|
1107
|
+
// Use localStorage if available
|
|
1108
|
+
try {
|
|
1109
|
+
window.localStorage.removeItem(storageKey);
|
|
1110
|
+
} catch (ignore) {}
|
|
1111
|
+
|
|
1112
|
+
// Use session cookie as fallback
|
|
1113
|
+
try {
|
|
1114
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
1115
|
+
} catch (ignore) {}
|
|
1116
|
+
}
|
|
1117
|
+
function normalizeLevel(input) {
|
|
1118
|
+
var level = input;
|
|
1119
|
+
if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
|
|
1120
|
+
level = self.levels[level.toUpperCase()];
|
|
1121
|
+
}
|
|
1122
|
+
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
1123
|
+
return level;
|
|
1124
|
+
} else {
|
|
1125
|
+
throw new TypeError("log.setLevel() called with invalid level: " + input);
|
|
1126
|
+
}
|
|
1177
1127
|
}
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
1128
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
isPermanentlyDisconnected: false,
|
|
1214
|
-
hasEmittedConnection: false
|
|
1215
|
-
});
|
|
1216
|
-
/* harmony default export */ const inPageProvider = (AirInPageProvider);
|
|
1217
|
-
class TorusInPageProvider extends AirInPageProvider {}
|
|
1218
|
-
;// external "rxjs"
|
|
1219
|
-
const external_rxjs_namespaceObject = require("rxjs");
|
|
1220
|
-
;// ./src/messageService.ts
|
|
1129
|
+
/*
|
|
1130
|
+
*
|
|
1131
|
+
* Public logger API - see https://github.com/pimterry/loglevel for details
|
|
1132
|
+
*
|
|
1133
|
+
*/
|
|
1134
|
+
|
|
1135
|
+
self.name = name;
|
|
1136
|
+
self.levels = {
|
|
1137
|
+
"TRACE": 0,
|
|
1138
|
+
"DEBUG": 1,
|
|
1139
|
+
"INFO": 2,
|
|
1140
|
+
"WARN": 3,
|
|
1141
|
+
"ERROR": 4,
|
|
1142
|
+
"SILENT": 5
|
|
1143
|
+
};
|
|
1144
|
+
self.methodFactory = factory || defaultMethodFactory;
|
|
1145
|
+
self.getLevel = function () {
|
|
1146
|
+
if (userLevel != null) {
|
|
1147
|
+
return userLevel;
|
|
1148
|
+
} else if (defaultLevel != null) {
|
|
1149
|
+
return defaultLevel;
|
|
1150
|
+
} else {
|
|
1151
|
+
return inheritedLevel;
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
self.setLevel = function (level, persist) {
|
|
1155
|
+
userLevel = normalizeLevel(level);
|
|
1156
|
+
if (persist !== false) {
|
|
1157
|
+
// defaults to true
|
|
1158
|
+
persistLevelIfPossible(userLevel);
|
|
1159
|
+
}
|
|
1221
1160
|
|
|
1222
|
-
|
|
1161
|
+
// NOTE: in v2, this should call rebuild(), which updates children.
|
|
1162
|
+
return replaceLoggingMethods.call(self);
|
|
1163
|
+
};
|
|
1164
|
+
self.setDefaultLevel = function (level) {
|
|
1165
|
+
defaultLevel = normalizeLevel(level);
|
|
1166
|
+
if (!getPersistedLevel()) {
|
|
1167
|
+
self.setLevel(level, false);
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
self.resetLevel = function () {
|
|
1171
|
+
userLevel = null;
|
|
1172
|
+
clearPersistedLevel();
|
|
1173
|
+
replaceLoggingMethods.call(self);
|
|
1174
|
+
};
|
|
1175
|
+
self.enableAll = function (persist) {
|
|
1176
|
+
self.setLevel(self.levels.TRACE, persist);
|
|
1177
|
+
};
|
|
1178
|
+
self.disableAll = function (persist) {
|
|
1179
|
+
self.setLevel(self.levels.SILENT, persist);
|
|
1180
|
+
};
|
|
1181
|
+
self.rebuild = function () {
|
|
1182
|
+
if (defaultLogger !== self) {
|
|
1183
|
+
inheritedLevel = normalizeLevel(defaultLogger.getLevel());
|
|
1184
|
+
}
|
|
1185
|
+
replaceLoggingMethods.call(self);
|
|
1186
|
+
if (defaultLogger === self) {
|
|
1187
|
+
for (var childName in _loggersByName) {
|
|
1188
|
+
_loggersByName[childName].rebuild();
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1223
1192
|
|
|
1193
|
+
// Initialize all the internal levels.
|
|
1194
|
+
inheritedLevel = normalizeLevel(defaultLogger ? defaultLogger.getLevel() : "WARN");
|
|
1195
|
+
var initialLevel = getPersistedLevel();
|
|
1196
|
+
if (initialLevel != null) {
|
|
1197
|
+
userLevel = normalizeLevel(initialLevel);
|
|
1198
|
+
}
|
|
1199
|
+
replaceLoggingMethods.call(self);
|
|
1200
|
+
}
|
|
1224
1201
|
|
|
1202
|
+
/*
|
|
1203
|
+
*
|
|
1204
|
+
* Top-level API
|
|
1205
|
+
*
|
|
1206
|
+
*/
|
|
1225
1207
|
|
|
1208
|
+
defaultLogger = new Logger();
|
|
1209
|
+
defaultLogger.getLogger = function getLogger(name) {
|
|
1210
|
+
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
1211
|
+
throw new TypeError("You must supply a name when creating a logger.");
|
|
1212
|
+
}
|
|
1213
|
+
var logger = _loggersByName[name];
|
|
1214
|
+
if (!logger) {
|
|
1215
|
+
logger = _loggersByName[name] = new Logger(name, defaultLogger.methodFactory);
|
|
1216
|
+
}
|
|
1217
|
+
return logger;
|
|
1218
|
+
};
|
|
1226
1219
|
|
|
1220
|
+
// Grab the current global log variable in case of overwrite
|
|
1221
|
+
var _log = typeof window !== undefinedType ? window.log : undefined;
|
|
1222
|
+
defaultLogger.noConflict = function () {
|
|
1223
|
+
if (typeof window !== undefinedType && window.log === defaultLogger) {
|
|
1224
|
+
window.log = _log;
|
|
1225
|
+
}
|
|
1226
|
+
return defaultLogger;
|
|
1227
|
+
};
|
|
1228
|
+
defaultLogger.getLoggers = function getLoggers() {
|
|
1229
|
+
return _loggersByName;
|
|
1230
|
+
};
|
|
1227
1231
|
|
|
1232
|
+
// ES6 default export, for compatibility
|
|
1233
|
+
defaultLogger['default'] = defaultLogger;
|
|
1234
|
+
return defaultLogger;
|
|
1235
|
+
});
|
|
1236
|
+
})(loglevel$2);
|
|
1237
|
+
return loglevel$2.exports;
|
|
1238
|
+
}
|
|
1228
1239
|
|
|
1229
|
-
|
|
1230
|
-
|
|
1240
|
+
var loglevelExports = requireLoglevel();
|
|
1241
|
+
var loglevel = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
|
|
1242
|
+
|
|
1243
|
+
var log = loglevel.getLogger("airkit");
|
|
1244
|
+
|
|
1245
|
+
var AirWalletProviderMessageTypes;
|
|
1246
|
+
(function (AirWalletProviderMessageTypes) {
|
|
1247
|
+
AirWalletProviderMessageTypes["REQUEST"] = "JRPC_REQUEST";
|
|
1248
|
+
AirWalletProviderMessageTypes["RESPONSE"] = "JRPC_RESPONSE";
|
|
1249
|
+
})(AirWalletProviderMessageTypes || (AirWalletProviderMessageTypes = {}));
|
|
1250
|
+
|
|
1251
|
+
const ACCOUNT_MESSAGES = [
|
|
1252
|
+
AirMessageTypes.INITIALIZATION_RESPONSE,
|
|
1253
|
+
AirMessageTypes.WALLET_INITIALIZED,
|
|
1254
|
+
AirMessageTypes.CLAIM_ID_RESPONSE,
|
|
1255
|
+
AirMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE,
|
|
1256
|
+
AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE,
|
|
1257
|
+
AirMessageTypes.EXECUTE_ACTION_RESPONSE,
|
|
1258
|
+
AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE,
|
|
1259
|
+
AirMessageTypes.GRANT_PERMISSIONS_RESPONSE,
|
|
1260
|
+
AirMessageTypes.WALLET_INITIALIZED,
|
|
1261
|
+
AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
|
|
1262
|
+
AirMessageTypes.LOGOUT_RESPONSE,
|
|
1263
|
+
];
|
|
1264
|
+
const AUTH_MESSAGES = [
|
|
1265
|
+
AirAuthMessageTypes.INITIALIZATION_RESPONSE,
|
|
1266
|
+
AirAuthMessageTypes.LOGIN_RESPONSE,
|
|
1267
|
+
AirAuthMessageTypes.REFRESH_TOKEN_RESPONSE,
|
|
1268
|
+
AirAuthMessageTypes.SETUP_WALLET_REQUEST,
|
|
1269
|
+
AirAuthMessageTypes.LOGOUT_RESPONSE,
|
|
1270
|
+
AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
|
|
1271
|
+
AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
|
|
1272
|
+
];
|
|
1231
1273
|
class AirMessageService {
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
defineProperty_default()(this, "_authIframe", null);
|
|
1237
|
-
defineProperty_default()(this, "closeAuthMessageListeners", null);
|
|
1238
|
-
defineProperty_default()(this, "closeRealmMessageListeners", null);
|
|
1239
|
-
}
|
|
1240
|
-
static get instance() {
|
|
1241
|
-
if (!AirMessageService._instance) {
|
|
1242
|
-
AirMessageService._instance = new AirMessageService();
|
|
1274
|
+
constructor() {
|
|
1275
|
+
this.closeAuthMessageListeners = null;
|
|
1276
|
+
this.closeRealmMessageListeners = null;
|
|
1277
|
+
this.closeWalletMessageListeners = null;
|
|
1243
1278
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
get loginState$() {
|
|
1250
|
-
return this._loginState$;
|
|
1251
|
-
}
|
|
1252
|
-
get authMessage$() {
|
|
1253
|
-
return this._authMessage$.asObservable();
|
|
1254
|
-
}
|
|
1255
|
-
async openAuthObservables({
|
|
1256
|
-
authIframeOrigin
|
|
1257
|
-
}) {
|
|
1258
|
-
this.closeAuthObservables();
|
|
1259
|
-
this.setupAuthObservables();
|
|
1260
|
-
const handleAuthMessage = async ev => {
|
|
1261
|
-
if (ev.origin !== authIframeOrigin || !ev.data || !(ev.data instanceof Object)) return;
|
|
1262
|
-
loglevel.debug("Embed auth message received from auth", ev.data);
|
|
1263
|
-
if (AUTH_EMBED_MESSAGES.includes(ev.data.type)) {
|
|
1264
|
-
this._authMessage$.next(ev.data);
|
|
1265
|
-
}
|
|
1266
|
-
};
|
|
1267
|
-
window.addEventListener("message", handleAuthMessage);
|
|
1268
|
-
this.closeAuthMessageListeners = () => {
|
|
1269
|
-
window.removeEventListener("message", handleAuthMessage);
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
|
-
async openRealmObservables({
|
|
1273
|
-
walletIframeOrigin
|
|
1274
|
-
}) {
|
|
1275
|
-
this.closeRealmObservables();
|
|
1276
|
-
this.setupRealmObservables();
|
|
1277
|
-
const handleMessage = async ev => {
|
|
1278
|
-
if (ev.origin !== walletIframeOrigin || !ev.data || !(ev.data instanceof Object)) return;
|
|
1279
|
-
// filter out torus and communication provider messages
|
|
1280
|
-
if ("target" in ev.data && (ev.data.target === "embed_torus" || ev.data.target === "embed_communication")) return;
|
|
1281
|
-
loglevel.debug("Embed realm message received from wallet", ev.data);
|
|
1282
|
-
if (REALM_EMBED_MESSAGES.includes(ev.data.type)) {
|
|
1283
|
-
this.airMessages$.next(ev.data);
|
|
1284
|
-
}
|
|
1285
|
-
};
|
|
1286
|
-
window.addEventListener("message", handleMessage);
|
|
1287
|
-
this.closeRealmMessageListeners = () => {
|
|
1288
|
-
window.removeEventListener("message", handleMessage);
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
// Note: Only use when embed is needed in airAuth
|
|
1293
|
-
setupAuthIframe(authIframe) {
|
|
1294
|
-
this._authIframe = authIframe;
|
|
1295
|
-
}
|
|
1296
|
-
setupIframeCommunication(walletIframe) {
|
|
1297
|
-
if (!this._authIframe) return;
|
|
1298
|
-
const channel = new MessageChannel();
|
|
1299
|
-
const authOrigin = new URL(this._authIframe.src).origin;
|
|
1300
|
-
this._authIframe.contentWindow.postMessage({
|
|
1301
|
-
type: AirAuthMessageTypes.INIT_WALLET_COMMUNICATION
|
|
1302
|
-
}, authOrigin, [channel.port1]);
|
|
1303
|
-
const walletOrigin = new URL(walletIframe.src).origin;
|
|
1304
|
-
walletIframe.contentWindow.postMessage({
|
|
1305
|
-
type: AirMessageTypes.INIT_AUTH_COMMUNICATION
|
|
1306
|
-
}, walletOrigin, [channel.port2]);
|
|
1307
|
-
this._authIframe = undefined;
|
|
1308
|
-
}
|
|
1309
|
-
onInitialized() {
|
|
1310
|
-
return (0,external_rxjs_namespaceObject.firstValueFrom)(this.messages$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirMessageTypes.SERVICE_INITIALIZED)));
|
|
1311
|
-
}
|
|
1312
|
-
sendLoginRequest(walletIframe, payload) {
|
|
1313
|
-
const response = (0,external_rxjs_namespaceObject.lastValueFrom)(this.loginState$.pipe((0,external_rxjs_namespaceObject.takeWhile)(msg => (!payload.skipClaimFlow || msg.payload.state !== "connected") && msg.payload.state !== "logged_in" && msg.payload.state !== "claim_flow_cancelled", true), (0,external_rxjs_namespaceObject.tap)(msg => {
|
|
1314
|
-
switch (msg.payload.state) {
|
|
1315
|
-
case "claim_flow_cancelled":
|
|
1316
|
-
throw new RealmEmbedError(msg.payload.errorName, msg.payload.errorMessage);
|
|
1317
|
-
default:
|
|
1318
|
-
break;
|
|
1319
|
-
}
|
|
1320
|
-
})));
|
|
1321
|
-
const {
|
|
1322
|
-
origin
|
|
1323
|
-
} = new URL(walletIframe.src);
|
|
1324
|
-
walletIframe.contentWindow.postMessage({
|
|
1325
|
-
type: AirMessageTypes.LOGIN_REQUEST,
|
|
1326
|
-
payload
|
|
1327
|
-
}, origin);
|
|
1328
|
-
return response;
|
|
1329
|
-
}
|
|
1330
|
-
sendClaimRequest(walletIframe, options) {
|
|
1331
|
-
const response = (0,external_rxjs_namespaceObject.lastValueFrom)((0,external_rxjs_namespaceObject.forkJoin)([this.loginState$.pipe((0,external_rxjs_namespaceObject.takeWhile)(msg => !["logged_in", "claim_flow_cancelled"].includes(msg.payload.state), true), (0,external_rxjs_namespaceObject.tap)(msg => {
|
|
1332
|
-
if (msg.payload.state === "claim_flow_cancelled") {
|
|
1333
|
-
throw new RealmEmbedError(msg.payload.errorName, msg.payload.errorMessage);
|
|
1334
|
-
}
|
|
1335
|
-
}), (0,external_rxjs_namespaceObject.last)()), this.messages$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirMessageTypes.CLOSE_MODAL), (0,external_rxjs_namespaceObject.first)())]));
|
|
1336
|
-
const {
|
|
1337
|
-
origin
|
|
1338
|
-
} = new URL(walletIframe.src);
|
|
1339
|
-
walletIframe.contentWindow.postMessage({
|
|
1340
|
-
type: AirMessageTypes.CLAIM_REQUEST,
|
|
1341
|
-
payload: {
|
|
1342
|
-
token: options === null || options === void 0 ? void 0 : options.token,
|
|
1343
|
-
claimInBackground: options === null || options === void 0 ? void 0 : options.background
|
|
1344
|
-
}
|
|
1345
|
-
}, origin);
|
|
1346
|
-
return response;
|
|
1347
|
-
}
|
|
1348
|
-
async sendGrantPermissionRequest(walletIframe, policies) {
|
|
1349
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.messages$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
|
|
1350
|
-
const {
|
|
1351
|
-
origin
|
|
1352
|
-
} = new URL(walletIframe.src);
|
|
1353
|
-
walletIframe.contentWindow.postMessage({
|
|
1354
|
-
type: AirMessageTypes.GRANT_PERMISSIONS_REQUEST,
|
|
1355
|
-
payload: {
|
|
1356
|
-
policies
|
|
1357
|
-
}
|
|
1358
|
-
}, origin);
|
|
1359
|
-
const result = await response;
|
|
1360
|
-
if (result.payload.success === false) {
|
|
1361
|
-
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
1279
|
+
static get instance() {
|
|
1280
|
+
if (!AirMessageService._instance) {
|
|
1281
|
+
AirMessageService._instance = new AirMessageService();
|
|
1282
|
+
}
|
|
1283
|
+
return AirMessageService._instance;
|
|
1362
1284
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
async sendExecuteActionRequest(walletIframe, params) {
|
|
1366
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.messages$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirMessageTypes.EXECUTE_ACTION_RESPONSE)));
|
|
1367
|
-
const {
|
|
1368
|
-
origin
|
|
1369
|
-
} = new URL(walletIframe.src);
|
|
1370
|
-
walletIframe.contentWindow.postMessage({
|
|
1371
|
-
type: AirMessageTypes.EXECUTE_ACTION_REQUEST,
|
|
1372
|
-
payload: {
|
|
1373
|
-
sessionData: params.sessionData,
|
|
1374
|
-
call: {
|
|
1375
|
-
to: params.call.to,
|
|
1376
|
-
value: params.call.value,
|
|
1377
|
-
data: params.call.data
|
|
1378
|
-
},
|
|
1379
|
-
sessionOwnerPrivateKey: params.sessionOwnerPrivateKey
|
|
1380
|
-
}
|
|
1381
|
-
}, origin);
|
|
1382
|
-
const result = await response;
|
|
1383
|
-
if (result.payload.success === false) {
|
|
1384
|
-
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
1285
|
+
get messages$() {
|
|
1286
|
+
return this.airMessages$.asObservable();
|
|
1385
1287
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
async sendRevokePermissionsRequest(walletIframe, permissionId) {
|
|
1389
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.messages$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE)));
|
|
1390
|
-
const {
|
|
1391
|
-
origin
|
|
1392
|
-
} = new URL(walletIframe.src);
|
|
1393
|
-
walletIframe.contentWindow.postMessage({
|
|
1394
|
-
type: AirMessageTypes.REVOKE_PERMISSIONS_REQUEST,
|
|
1395
|
-
payload: {
|
|
1396
|
-
permissionId
|
|
1397
|
-
}
|
|
1398
|
-
}, origin);
|
|
1399
|
-
const result = await response;
|
|
1400
|
-
if (result.payload.success === false) {
|
|
1401
|
-
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
1288
|
+
get authMessage$() {
|
|
1289
|
+
return this._authMessage$.asObservable();
|
|
1402
1290
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
sendDeploySmartAccountRequest(walletIframe) {
|
|
1406
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.messages$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
|
|
1407
|
-
const {
|
|
1408
|
-
origin
|
|
1409
|
-
} = new URL(walletIframe.src);
|
|
1410
|
-
walletIframe.contentWindow.postMessage({
|
|
1411
|
-
type: AirMessageTypes.DEPLOY_SMART_ACCOUNT_REQUEST
|
|
1412
|
-
}, origin);
|
|
1413
|
-
return response;
|
|
1414
|
-
}
|
|
1415
|
-
async sendUserInfoRequest(authIframe) {
|
|
1416
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.authMessage$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirAuthMessageTypes.USER_INFO_RESPONSE)));
|
|
1417
|
-
const {
|
|
1418
|
-
origin
|
|
1419
|
-
} = new URL(authIframe.src);
|
|
1420
|
-
authIframe.contentWindow.postMessage({
|
|
1421
|
-
type: AirAuthMessageTypes.USER_INFO_REQUEST
|
|
1422
|
-
}, origin);
|
|
1423
|
-
return response;
|
|
1424
|
-
}
|
|
1425
|
-
async sendPartnerUserInfoRequest(authIframe) {
|
|
1426
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.authMessage$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE)));
|
|
1427
|
-
const {
|
|
1428
|
-
origin
|
|
1429
|
-
} = new URL(authIframe.src);
|
|
1430
|
-
authIframe.contentWindow.postMessage({
|
|
1431
|
-
type: AirAuthMessageTypes.PARTNER_USER_INFO_REQUEST
|
|
1432
|
-
}, origin);
|
|
1433
|
-
return response;
|
|
1434
|
-
}
|
|
1435
|
-
async sendAuthLoginRequest(authIframe, payload) {
|
|
1436
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.authMessage$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirAuthMessageTypes.LOGIN_RESPONSE)));
|
|
1437
|
-
const {
|
|
1438
|
-
origin
|
|
1439
|
-
} = new URL(authIframe.src);
|
|
1440
|
-
authIframe.contentWindow.postMessage({
|
|
1441
|
-
type: AirAuthMessageTypes.LOGIN_REQUEST,
|
|
1442
|
-
payload
|
|
1443
|
-
}, origin);
|
|
1444
|
-
return response;
|
|
1445
|
-
}
|
|
1446
|
-
async logoutAuth(authIframe) {
|
|
1447
|
-
const response = (0,external_rxjs_namespaceObject.firstValueFrom)(this.authMessage$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirAuthMessageTypes.LOGOUT_RESPONSE)));
|
|
1448
|
-
const {
|
|
1449
|
-
origin
|
|
1450
|
-
} = new URL(authIframe.src);
|
|
1451
|
-
authIframe.contentWindow.postMessage({
|
|
1452
|
-
type: AirAuthMessageTypes.LOGOUT_REQUEST
|
|
1453
|
-
}, origin);
|
|
1454
|
-
return response;
|
|
1455
|
-
}
|
|
1456
|
-
async waitForAuthInitialization() {
|
|
1457
|
-
const response = await (0,external_rxjs_namespaceObject.firstValueFrom)(this._authMessage$.pipe((0,external_rxjs_namespaceObject.filter)(msg => msg.type === AirAuthMessageTypes.INITIALIZATION_RESPONSE)));
|
|
1458
|
-
if (response.payload.success === false) {
|
|
1459
|
-
throw new RealmEmbedError(response.payload.errorName, response.payload.errorMessage);
|
|
1291
|
+
get providerMessage$() {
|
|
1292
|
+
return this._providerMessage$.asObservable();
|
|
1460
1293
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1294
|
+
async openAuthObservables({ authIframeOrigin }) {
|
|
1295
|
+
this.closeAuthObservables();
|
|
1296
|
+
this.setupAuthObservables();
|
|
1297
|
+
const handleAuthMessage = async (ev) => {
|
|
1298
|
+
if (ev.origin !== authIframeOrigin || !ev.data || !(ev.data instanceof Object))
|
|
1299
|
+
return;
|
|
1300
|
+
log.debug("Embed auth message received from auth", ev.data);
|
|
1301
|
+
if (AUTH_MESSAGES.includes(ev.data.type)) {
|
|
1302
|
+
this._authMessage$.next(ev.data);
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
window.addEventListener("message", handleAuthMessage);
|
|
1306
|
+
this.closeAuthMessageListeners = () => {
|
|
1307
|
+
window.removeEventListener("message", handleAuthMessage);
|
|
1308
|
+
};
|
|
1467
1309
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
try {
|
|
1498
|
-
const img = document.createElement("img");
|
|
1499
|
-
img.onload = () => resolve(true);
|
|
1500
|
-
img.onerror = () => resolve(false);
|
|
1501
|
-
img.src = url;
|
|
1502
|
-
} catch (e) {
|
|
1503
|
-
reject(e);
|
|
1310
|
+
async openWalletObservables({ walletIframeOrigin }) {
|
|
1311
|
+
this.closeAirObservables();
|
|
1312
|
+
this.setupAirObservables();
|
|
1313
|
+
const handleMessage = async (ev) => {
|
|
1314
|
+
if (ev.origin !== walletIframeOrigin || !ev.data || !(ev.data instanceof Object))
|
|
1315
|
+
return;
|
|
1316
|
+
log.debug("Account messages received from wallet frontend", ev.data);
|
|
1317
|
+
if (ACCOUNT_MESSAGES.includes(ev.data.type)) {
|
|
1318
|
+
this.airMessages$.next(ev.data);
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
window.addEventListener("message", handleMessage);
|
|
1322
|
+
this.closeRealmMessageListeners = () => {
|
|
1323
|
+
window.removeEventListener("message", handleMessage);
|
|
1324
|
+
};
|
|
1325
|
+
this.closeWalletObservables();
|
|
1326
|
+
this.setupWalletObservables();
|
|
1327
|
+
const handleWalletMessage = async (ev) => {
|
|
1328
|
+
if (ev.origin !== walletIframeOrigin || !ev.data || !(ev.data instanceof Object))
|
|
1329
|
+
return;
|
|
1330
|
+
log.debug("Wallet provider messages received from wallet frontend", ev.data);
|
|
1331
|
+
if (ev.data.type === AirWalletProviderMessageTypes.RESPONSE) {
|
|
1332
|
+
this._providerMessage$.next(ev.data);
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
window.addEventListener("message", handleWalletMessage);
|
|
1336
|
+
this.closeWalletMessageListeners = () => {
|
|
1337
|
+
window.removeEventListener("message", handleWalletMessage);
|
|
1338
|
+
};
|
|
1504
1339
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
const siteName = document.querySelector('head > meta[property="og:site_name"]');
|
|
1516
|
-
if (siteName) {
|
|
1517
|
-
return siteName.content;
|
|
1518
|
-
}
|
|
1519
|
-
const metaTitle = document.querySelector('head > meta[name="title"]');
|
|
1520
|
-
if (metaTitle) {
|
|
1521
|
-
return metaTitle.content;
|
|
1522
|
-
}
|
|
1523
|
-
if (document.title && document.title.length > 0) {
|
|
1524
|
-
return document.title;
|
|
1525
|
-
}
|
|
1526
|
-
return window.location.hostname;
|
|
1527
|
-
};
|
|
1528
|
-
|
|
1529
|
-
/**
|
|
1530
|
-
* Extracts an icon for the site from the DOM
|
|
1531
|
-
*/
|
|
1532
|
-
async function getSiteIcon(window) {
|
|
1533
|
-
try {
|
|
1534
|
-
const {
|
|
1535
|
-
document
|
|
1536
|
-
} = window;
|
|
1537
|
-
|
|
1538
|
-
// Use the site's favicon if it exists
|
|
1539
|
-
let icon = document.querySelector('head > link[rel="shortcut icon"]');
|
|
1540
|
-
if (icon && (await imgExists(icon.href))) {
|
|
1541
|
-
return icon.href;
|
|
1340
|
+
setupIframeCommunication(authIframe, walletIframe) {
|
|
1341
|
+
const channel = new MessageChannel();
|
|
1342
|
+
const authOrigin = new URL(authIframe.src).origin;
|
|
1343
|
+
authIframe.contentWindow.postMessage({
|
|
1344
|
+
type: AirAuthMessageTypes.INIT_WALLET_COMMUNICATION,
|
|
1345
|
+
}, authOrigin, [channel.port1]);
|
|
1346
|
+
const walletOrigin = new URL(walletIframe.src).origin;
|
|
1347
|
+
walletIframe.contentWindow.postMessage({
|
|
1348
|
+
type: AirMessageTypes.INIT_AUTH_COMMUNICATION,
|
|
1349
|
+
}, walletOrigin, [channel.port2]);
|
|
1542
1350
|
}
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1351
|
+
async sendGrantPermissionRequest(walletIframe, policies) {
|
|
1352
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
|
|
1353
|
+
const { origin } = new URL(walletIframe.src);
|
|
1354
|
+
walletIframe.contentWindow.postMessage({
|
|
1355
|
+
type: AirMessageTypes.GRANT_PERMISSIONS_REQUEST,
|
|
1356
|
+
payload: {
|
|
1357
|
+
policies,
|
|
1358
|
+
},
|
|
1359
|
+
}, origin);
|
|
1360
|
+
const result = await response;
|
|
1361
|
+
if (result.payload.success === false) {
|
|
1362
|
+
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
1363
|
+
}
|
|
1364
|
+
return result.payload.sessionData;
|
|
1548
1365
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
1570
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
// preload for iframe doesn't work https://bugs.chromium.org/p/chromium/issues/detail?id=593267
|
|
1585
|
-
(async function preLoadIframe() {
|
|
1586
|
-
try {
|
|
1587
|
-
if (typeof document === "undefined") return;
|
|
1588
|
-
const airWalletIframeHtml = document.createElement("link");
|
|
1589
|
-
const {
|
|
1590
|
-
walletUrl: airWalletUrl
|
|
1591
|
-
} = AIR_URLS.production;
|
|
1592
|
-
airWalletIframeHtml.href = `${airWalletUrl}/frame`;
|
|
1593
|
-
airWalletIframeHtml.crossOrigin = "anonymous";
|
|
1594
|
-
airWalletIframeHtml.type = "text/html";
|
|
1595
|
-
airWalletIframeHtml.rel = "prefetch";
|
|
1596
|
-
if (airWalletIframeHtml.relList && airWalletIframeHtml.relList.supports) {
|
|
1597
|
-
if (airWalletIframeHtml.relList.supports("prefetch")) {
|
|
1598
|
-
document.head.appendChild(airWalletIframeHtml);
|
|
1599
|
-
}
|
|
1366
|
+
async sendExecuteActionRequest(walletIframe, params) {
|
|
1367
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.EXECUTE_ACTION_RESPONSE)));
|
|
1368
|
+
const { origin } = new URL(walletIframe.src);
|
|
1369
|
+
walletIframe.contentWindow.postMessage({
|
|
1370
|
+
type: AirMessageTypes.EXECUTE_ACTION_REQUEST,
|
|
1371
|
+
payload: {
|
|
1372
|
+
sessionData: params.sessionData,
|
|
1373
|
+
call: {
|
|
1374
|
+
to: params.call.to,
|
|
1375
|
+
value: params.call.value,
|
|
1376
|
+
data: params.call.data,
|
|
1377
|
+
},
|
|
1378
|
+
sessionOwnerPrivateKey: params.sessionOwnerPrivateKey,
|
|
1379
|
+
},
|
|
1380
|
+
}, origin);
|
|
1381
|
+
const result = await response;
|
|
1382
|
+
if (result.payload.success === false) {
|
|
1383
|
+
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
1384
|
+
}
|
|
1385
|
+
return result.payload.txHash;
|
|
1600
1386
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
ticker: "MATIC",
|
|
1616
|
-
tickerName: "Matic Network Token"
|
|
1617
|
-
},
|
|
1618
|
-
polygonAmoy: {
|
|
1619
|
-
chainNamespace: base_controllers_namespaceObject.CHAIN_NAMESPACES.EIP155,
|
|
1620
|
-
chainId: "0x13882",
|
|
1621
|
-
decimals: 18,
|
|
1622
|
-
displayName: "Polygon Amoy",
|
|
1623
|
-
blockExplorerUrl: "https://amoy.polygonscan.com",
|
|
1624
|
-
logo: "https://cryptologos.cc/logos/polygon-matic-logo.png",
|
|
1625
|
-
ticker: "MATIC",
|
|
1626
|
-
tickerName: "Matic Network Token",
|
|
1627
|
-
isTestnet: true
|
|
1628
|
-
}
|
|
1629
|
-
};
|
|
1630
|
-
const web3AuthClientId = "BANbxuTYFGeYi8HxUzaPQkvQlSAXiKRtUqb1vqsXbsZsZKrNr05PEPCM2J2PhUJZpIYl0XzQa6jxUjnYzSU9LXY";
|
|
1631
|
-
const web3AuthNetwork = external_web3auth_auth_namespaceObject.WEB3AUTH_NETWORK.SAPPHIRE_MAINNET;
|
|
1632
|
-
var _embedNonce = /*#__PURE__*/new WeakMap();
|
|
1633
|
-
var _provider = /*#__PURE__*/new WeakMap();
|
|
1634
|
-
var _isInitialized = /*#__PURE__*/new WeakMap();
|
|
1635
|
-
var _rehydrationState = /*#__PURE__*/new WeakMap();
|
|
1636
|
-
var _modalZIndex = /*#__PURE__*/new WeakMap();
|
|
1637
|
-
var _communicationProvider = /*#__PURE__*/new WeakMap();
|
|
1638
|
-
var _buttonPosition = /*#__PURE__*/new WeakMap();
|
|
1639
|
-
var _realmPartnerId = /*#__PURE__*/new WeakMap();
|
|
1640
|
-
var _web3AuthClientId = /*#__PURE__*/new WeakMap();
|
|
1641
|
-
var _web3AuthNetwork = /*#__PURE__*/new WeakMap();
|
|
1642
|
-
var _isPluginMode = /*#__PURE__*/new WeakMap();
|
|
1643
|
-
var _confirmationStrategy = /*#__PURE__*/new WeakMap();
|
|
1644
|
-
var _walletIframe = /*#__PURE__*/new WeakMap();
|
|
1645
|
-
var _buildEnv = /*#__PURE__*/new WeakMap();
|
|
1646
|
-
var _walletAddresses = /*#__PURE__*/new WeakMap();
|
|
1647
|
-
var _realmId = /*#__PURE__*/new WeakMap();
|
|
1648
|
-
var _loginToken = /*#__PURE__*/new WeakMap();
|
|
1649
|
-
var _sessionId = /*#__PURE__*/new WeakMap();
|
|
1650
|
-
var _embedListeners = /*#__PURE__*/new WeakMap();
|
|
1651
|
-
var _RealmEmbed_brand = /*#__PURE__*/new WeakSet();
|
|
1652
|
-
class RealmEmbed {
|
|
1653
|
-
constructor({
|
|
1654
|
-
modalZIndex = 99999,
|
|
1655
|
-
partnerId
|
|
1656
|
-
}) {
|
|
1657
|
-
classPrivateMethodInitSpec_default()(this, _RealmEmbed_brand);
|
|
1658
|
-
classPrivateFieldInitSpec_default()(this, _embedNonce, (0,base_controllers_namespaceObject.randomId)());
|
|
1659
|
-
classPrivateFieldInitSpec_default()(this, _provider, void 0);
|
|
1660
|
-
classPrivateFieldInitSpec_default()(this, _isInitialized, void 0);
|
|
1661
|
-
classPrivateFieldInitSpec_default()(this, _rehydrationState, void 0);
|
|
1662
|
-
classPrivateFieldInitSpec_default()(this, _modalZIndex, void 0);
|
|
1663
|
-
classPrivateFieldInitSpec_default()(this, _communicationProvider, void 0);
|
|
1664
|
-
classPrivateFieldInitSpec_default()(this, _buttonPosition, void 0);
|
|
1665
|
-
classPrivateFieldInitSpec_default()(this, _realmPartnerId, void 0);
|
|
1666
|
-
classPrivateFieldInitSpec_default()(this, _web3AuthClientId, void 0);
|
|
1667
|
-
classPrivateFieldInitSpec_default()(this, _web3AuthNetwork, void 0);
|
|
1668
|
-
classPrivateFieldInitSpec_default()(this, _isPluginMode, void 0);
|
|
1669
|
-
classPrivateFieldInitSpec_default()(this, _confirmationStrategy, void 0);
|
|
1670
|
-
classPrivateFieldInitSpec_default()(this, _walletIframe, void 0);
|
|
1671
|
-
classPrivateFieldInitSpec_default()(this, _buildEnv, void 0);
|
|
1672
|
-
classPrivateFieldInitSpec_default()(this, _walletAddresses, void 0);
|
|
1673
|
-
classPrivateFieldInitSpec_default()(this, _realmId, void 0);
|
|
1674
|
-
classPrivateFieldInitSpec_default()(this, _loginToken, void 0);
|
|
1675
|
-
classPrivateFieldInitSpec_default()(this, _sessionId, void 0);
|
|
1676
|
-
classPrivateFieldInitSpec_default()(this, _embedListeners, []);
|
|
1677
|
-
_classPrivateFieldSet(_isInitialized, this, false); // init done
|
|
1678
|
-
_classPrivateFieldSet(_modalZIndex, this, modalZIndex);
|
|
1679
|
-
_classPrivateFieldSet(_realmPartnerId, this, partnerId);
|
|
1680
|
-
_classPrivateFieldSet(_web3AuthClientId, this, web3AuthClientId);
|
|
1681
|
-
_classPrivateFieldSet(_web3AuthNetwork, this, web3AuthNetwork);
|
|
1682
|
-
}
|
|
1683
|
-
get isConnected() {
|
|
1684
|
-
return !!_classPrivateFieldGet(_walletAddresses, this) && _classPrivateFieldGet(_communicationProvider, this).isLoggedIn;
|
|
1685
|
-
}
|
|
1686
|
-
get isInitialized() {
|
|
1687
|
-
return _classPrivateFieldGet(_isInitialized, this) && !!_classPrivateFieldGet(_rehydrationState, this);
|
|
1688
|
-
}
|
|
1689
|
-
get isLoggedIn() {
|
|
1690
|
-
return !!_classPrivateFieldGet(_realmId, this) && this.isConnected;
|
|
1691
|
-
}
|
|
1692
|
-
get getBuildEnv() {
|
|
1693
|
-
return _classPrivateFieldGet(_buildEnv, this);
|
|
1694
|
-
}
|
|
1695
|
-
get walletAddresses() {
|
|
1696
|
-
var _classPrivateFieldGet2;
|
|
1697
|
-
return (_classPrivateFieldGet2 = _classPrivateFieldGet(_walletAddresses, this)) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : null;
|
|
1698
|
-
}
|
|
1699
|
-
get sessionId() {
|
|
1700
|
-
var _classPrivateFieldGet3;
|
|
1701
|
-
return (_classPrivateFieldGet3 = _classPrivateFieldGet(_sessionId, this)) !== null && _classPrivateFieldGet3 !== void 0 ? _classPrivateFieldGet3 : null;
|
|
1702
|
-
}
|
|
1703
|
-
get realmId() {
|
|
1704
|
-
var _classPrivateFieldGet4;
|
|
1705
|
-
return (_classPrivateFieldGet4 = _classPrivateFieldGet(_realmId, this)) !== null && _classPrivateFieldGet4 !== void 0 ? _classPrivateFieldGet4 : null;
|
|
1706
|
-
}
|
|
1707
|
-
get provider() {
|
|
1708
|
-
return _classPrivateFieldGet(_walletAddresses, this) ? _classPrivateFieldGet(_provider, this) : null;
|
|
1709
|
-
}
|
|
1710
|
-
async init({
|
|
1711
|
-
buildEnv = EMBED_BUILD_ENV.PRODUCTION,
|
|
1712
|
-
enableLogging = false,
|
|
1713
|
-
skipRehydration = false
|
|
1714
|
-
// confirmationStrategy = CONFIRMATION_STRATEGY.DEFAULT,
|
|
1715
|
-
} = {}) {
|
|
1716
|
-
if (_classPrivateFieldGet(_isInitialized, this)) throw new RealmEmbedError("ALREADY_INITIALISED", "Already initialized");
|
|
1717
|
-
_classPrivateFieldSet(_buildEnv, this, buildEnv);
|
|
1718
|
-
_classPrivateFieldSet(_confirmationStrategy, this, base_controllers_namespaceObject.CONFIRMATION_STRATEGY.DEFAULT);
|
|
1719
|
-
_classPrivateFieldSet(_buttonPosition, this, base_controllers_namespaceObject.BUTTON_POSITION.BOTTOM_LEFT);
|
|
1720
|
-
const {
|
|
1721
|
-
walletUrl,
|
|
1722
|
-
logLevel
|
|
1723
|
-
} = AIR_URLS[buildEnv];
|
|
1724
|
-
loglevel.info(walletUrl, "url loaded");
|
|
1725
|
-
loglevel.setDefaultLevel(logLevel);
|
|
1726
|
-
if (enableLogging) loglevel.enableAll();else loglevel.disableAll();
|
|
1727
|
-
const walletIframeUrl = _assertClassBrand(_RealmEmbed_brand, this, _getWsIframeUrl).call(this);
|
|
1728
|
-
const walletIframeOrigin = walletIframeUrl.origin;
|
|
1729
|
-
messageService.openRealmObservables({
|
|
1730
|
-
walletIframeOrigin
|
|
1731
|
-
});
|
|
1732
|
-
_classPrivateFieldSet(_walletIframe, this, htmlToElement(`<iframe
|
|
1733
|
-
id="walletIframe-${_classPrivateFieldGet(_embedNonce, this)}"
|
|
1734
|
-
class="walletIframe-${_classPrivateFieldGet(_embedNonce, this)}"
|
|
1735
|
-
sandbox="allow-popups allow-scripts allow-same-origin allow-forms allow-modals allow-downloads"
|
|
1736
|
-
src="${walletIframeUrl.href}"
|
|
1737
|
-
style="display: none; position: fixed; top: 0; right: 0; width: 100%; color-scheme: none; border-width: 0px; height: 100%; border: none; border-radius: 0; z-index: ${_classPrivateFieldGet(_modalZIndex, this).toString()}"
|
|
1738
|
-
allow="clipboard-write"
|
|
1739
|
-
></iframe>`));
|
|
1740
|
-
messageService.messages$.subscribe(msg => {
|
|
1741
|
-
switch (msg.type) {
|
|
1742
|
-
case AirMessageTypes.SERVICE_INITIALIZED:
|
|
1743
|
-
{
|
|
1744
|
-
_classPrivateFieldSet(_rehydrationState, this, msg.payload.rehydration);
|
|
1745
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerInitializedEvent).call(this);
|
|
1746
|
-
break;
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
});
|
|
1750
|
-
messageService.loginState$.subscribe(async msg => {
|
|
1751
|
-
switch (msg.payload.state) {
|
|
1752
|
-
case "connected":
|
|
1753
|
-
{
|
|
1754
|
-
await _assertClassBrand(_RealmEmbed_brand, this, _onInitialized).call(this);
|
|
1755
|
-
if (msg.payload.addresses && !this.isLoggedIn) {
|
|
1756
|
-
_classPrivateFieldSet(_walletAddresses, this, msg.payload.addresses);
|
|
1757
|
-
_classPrivateFieldSet(_loginToken, this, msg.payload.token);
|
|
1758
|
-
_classPrivateFieldSet(_sessionId, this, msg.payload.sessionId);
|
|
1759
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
1760
|
-
event: "connected",
|
|
1761
|
-
result: {
|
|
1762
|
-
isLoggedIn: false,
|
|
1763
|
-
addresses: msg.payload.addresses,
|
|
1764
|
-
token: msg.payload.token,
|
|
1765
|
-
sessionId: msg.payload.sessionId
|
|
1766
|
-
}
|
|
1767
|
-
});
|
|
1768
|
-
}
|
|
1769
|
-
break;
|
|
1770
|
-
}
|
|
1771
|
-
case "logged_in":
|
|
1772
|
-
{
|
|
1773
|
-
await _assertClassBrand(_RealmEmbed_brand, this, _onInitialized).call(this);
|
|
1774
|
-
const isNotConnectedYet = !_classPrivateFieldGet(_walletAddresses, this);
|
|
1775
|
-
_classPrivateFieldSet(_realmId, this, msg.payload.airId);
|
|
1776
|
-
_classPrivateFieldSet(_walletAddresses, this, msg.payload.addresses);
|
|
1777
|
-
_classPrivateFieldSet(_loginToken, this, msg.payload.token);
|
|
1778
|
-
_classPrivateFieldSet(_sessionId, this, msg.payload.sessionId);
|
|
1779
|
-
if (isNotConnectedYet) {
|
|
1780
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
1781
|
-
event: "connected",
|
|
1782
|
-
result: {
|
|
1783
|
-
isLoggedIn: false,
|
|
1784
|
-
addresses: msg.payload.addresses,
|
|
1785
|
-
token: msg.payload.token,
|
|
1786
|
-
sessionId: msg.payload.sessionId
|
|
1787
|
-
}
|
|
1788
|
-
});
|
|
1789
|
-
}
|
|
1790
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
1791
|
-
event: "logged_in",
|
|
1792
|
-
result: {
|
|
1793
|
-
isLoggedIn: true,
|
|
1794
|
-
realmId: msg.payload.airId,
|
|
1795
|
-
addresses: msg.payload.addresses,
|
|
1796
|
-
token: msg.payload.token,
|
|
1797
|
-
sessionId: msg.payload.sessionId
|
|
1798
|
-
}
|
|
1799
|
-
});
|
|
1800
|
-
break;
|
|
1801
|
-
}
|
|
1802
|
-
case "minting_started":
|
|
1803
|
-
{
|
|
1804
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
1805
|
-
event: "minting_started"
|
|
1806
|
-
});
|
|
1807
|
-
break;
|
|
1808
|
-
}
|
|
1809
|
-
case "minting_failed":
|
|
1810
|
-
{
|
|
1811
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
1812
|
-
event: "minting_failed",
|
|
1813
|
-
errorMessage: msg.payload.errorMessage
|
|
1814
|
-
});
|
|
1815
|
-
break;
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
});
|
|
1819
|
-
try {
|
|
1820
|
-
// Handle wallet iframe message
|
|
1821
|
-
window.document.body.appendChild(_classPrivateFieldGet(_walletIframe, this));
|
|
1822
|
-
const initializeWalletService = new Promise((resolve, reject) => {
|
|
1823
|
-
const handleMessage = async ev => {
|
|
1824
|
-
try {
|
|
1825
|
-
if (ev.origin !== walletIframeOrigin) return;
|
|
1826
|
-
if (ev.data === base_controllers_namespaceObject.SETUP_COMPLETE) {
|
|
1827
|
-
window.removeEventListener("message", handleMessage);
|
|
1828
|
-
// send init params here
|
|
1829
|
-
const dappMetadata = await siteMetadata();
|
|
1830
|
-
_classPrivateFieldGet(_walletIframe, this).contentWindow.postMessage({
|
|
1831
|
-
chainConfig: _classPrivateFieldGet(_buildEnv, this) === EMBED_BUILD_ENV.PRODUCTION ? embedChainConfig.polygon : embedChainConfig.polygonAmoy,
|
|
1832
|
-
dappMetadata,
|
|
1833
|
-
enableLogging,
|
|
1834
|
-
skipRehydration,
|
|
1835
|
-
realmPartnerId: _classPrivateFieldGet(_realmPartnerId, this),
|
|
1836
|
-
web3AuthClientId: _classPrivateFieldGet(_web3AuthClientId, this),
|
|
1837
|
-
web3AuthNetwork: _classPrivateFieldGet(_web3AuthNetwork, this),
|
|
1838
|
-
confirmationStrategy: _classPrivateFieldGet(_confirmationStrategy, this)
|
|
1839
|
-
}, walletIframeOrigin);
|
|
1840
|
-
await _assertClassBrand(_RealmEmbed_brand, this, _setupWeb).call(this, {
|
|
1841
|
-
torusUrl: walletUrl
|
|
1842
|
-
});
|
|
1843
|
-
_classPrivateFieldGet(_communicationProvider, this).onLoginStateHandle = async isLoggedIn => {
|
|
1844
|
-
if (!isLoggedIn) {
|
|
1845
|
-
await _assertClassBrand(_RealmEmbed_brand, this, _logout).call(this);
|
|
1846
|
-
}
|
|
1847
|
-
};
|
|
1848
|
-
resolve();
|
|
1849
|
-
}
|
|
1850
|
-
} catch (err) {
|
|
1851
|
-
reject(err);
|
|
1852
|
-
}
|
|
1853
|
-
};
|
|
1854
|
-
window.addEventListener("message", handleMessage);
|
|
1855
|
-
});
|
|
1856
|
-
const walletServiceInitialization = messageService.waitForWalletInitialization();
|
|
1857
|
-
await Promise.all([initializeWalletService, walletServiceInitialization]);
|
|
1858
|
-
messageService.setupIframeCommunication(_classPrivateFieldGet(_walletIframe, this));
|
|
1859
|
-
_classPrivateFieldSet(_isInitialized, this, true);
|
|
1860
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerInitializedEvent).call(this);
|
|
1861
|
-
loglevel.debug("Wallet service initialization resolved");
|
|
1862
|
-
} catch (error) {
|
|
1863
|
-
loglevel.debug("Wallet service initialization error", error);
|
|
1864
|
-
_assertClassBrand(_RealmEmbed_brand, this, _clearInit).call(this, true);
|
|
1865
|
-
throw error;
|
|
1387
|
+
async sendRevokePermissionsRequest(walletIframe, permissionId) {
|
|
1388
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE)));
|
|
1389
|
+
const { origin } = new URL(walletIframe.src);
|
|
1390
|
+
walletIframe.contentWindow.postMessage({
|
|
1391
|
+
type: AirMessageTypes.REVOKE_PERMISSIONS_REQUEST,
|
|
1392
|
+
payload: {
|
|
1393
|
+
permissionId,
|
|
1394
|
+
},
|
|
1395
|
+
}, origin);
|
|
1396
|
+
const result = await response;
|
|
1397
|
+
if (result.payload.success === false) {
|
|
1398
|
+
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
1399
|
+
}
|
|
1400
|
+
return result.payload.txHash;
|
|
1866
1401
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
async getUserInfo() {
|
|
1875
|
-
if (!_classPrivateFieldGet(_realmId, this)) return null;
|
|
1876
|
-
const userInfoResponse = await _classPrivateFieldGet(_communicationProvider, this).request({
|
|
1877
|
-
method: base_controllers_namespaceObject.COMMUNICATION_JRPC_METHODS.USER_INFO,
|
|
1878
|
-
params: []
|
|
1879
|
-
});
|
|
1880
|
-
return objectSpread2_default()(objectSpread2_default()({}, userInfoResponse), {}, {
|
|
1881
|
-
realmId: _classPrivateFieldGet(_realmId, this)
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
async login(options) {
|
|
1885
|
-
var _options$legacy;
|
|
1886
|
-
return _assertClassBrand(_RealmEmbed_brand, this, _login).call(this, options, (_options$legacy = options === null || options === void 0 ? void 0 : options.legacy) !== null && _options$legacy !== void 0 ? _options$legacy : true);
|
|
1887
|
-
}
|
|
1888
|
-
async _deploySmartAccount() {
|
|
1889
|
-
if (!this.isConnected) throw new RealmEmbedError("NOT_LOGGED_IN", "User needs to be connected first");
|
|
1890
|
-
try {
|
|
1891
|
-
await messageService.sendDeploySmartAccountRequest(_classPrivateFieldGet(_walletIframe, this));
|
|
1892
|
-
} catch (error) {
|
|
1893
|
-
throw RealmEmbedError.from(error);
|
|
1402
|
+
sendDeploySmartAccountRequest(walletIframe) {
|
|
1403
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
|
|
1404
|
+
const { origin } = new URL(walletIframe.src);
|
|
1405
|
+
walletIframe.contentWindow.postMessage({
|
|
1406
|
+
type: AirMessageTypes.DEPLOY_SMART_ACCOUNT_REQUEST,
|
|
1407
|
+
}, origin);
|
|
1408
|
+
return response;
|
|
1894
1409
|
}
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1410
|
+
async sendIsSmartAccountDeployedRequest(walletIframe) {
|
|
1411
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE)));
|
|
1412
|
+
const { origin } = new URL(walletIframe.src);
|
|
1413
|
+
walletIframe.contentWindow.postMessage({
|
|
1414
|
+
type: AirMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_REQUEST,
|
|
1415
|
+
}, origin);
|
|
1416
|
+
return response;
|
|
1902
1417
|
}
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
return messageService.sendRevokePermissionsRequest(_classPrivateFieldGet(_walletIframe, this), permissionId);
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
// async loginV2<T extends boolean>(options?: {
|
|
1912
|
-
// skipClaiming: T;
|
|
1913
|
-
// token?: string;
|
|
1914
|
-
// }): Promise<T extends true ? RealmLoginResult | RealmConnectResult : RealmLoginResult> {
|
|
1915
|
-
// if (!this.#isInitialized) throw new Error("Call init() first");
|
|
1916
|
-
|
|
1917
|
-
// const iframeController = this.#authIframeController;
|
|
1918
|
-
// iframeController.setIframeVisibility(true);
|
|
1919
|
-
// iframeController.updateIframeState();
|
|
1920
|
-
|
|
1921
|
-
// const { payload } = await RealmMessageService.sendAuthLoginRequest(iframeController.iframeElement);
|
|
1922
|
-
|
|
1923
|
-
// iframeController.setIframeVisibility(false);
|
|
1924
|
-
// iframeController.updateIframeState();
|
|
1925
|
-
|
|
1926
|
-
// if (payload.success === true) {
|
|
1927
|
-
// return this.#login({
|
|
1928
|
-
// skipClaiming: options?.skipClaiming,
|
|
1929
|
-
// token: options?.token,
|
|
1930
|
-
// });
|
|
1931
|
-
// }
|
|
1932
|
-
// throw new RealmEmbedError(payload.errorName, payload.errorMessage);
|
|
1933
|
-
// }
|
|
1934
|
-
|
|
1935
|
-
// This is for internal use only
|
|
1936
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1937
|
-
// @ts-ignore
|
|
1938
|
-
async _loginWithSessionId(params) {
|
|
1939
|
-
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Call init() first");
|
|
1940
|
-
if (!params.sessionId) throw new Error("sessionId is required");
|
|
1941
|
-
try {
|
|
1942
|
-
const res = await _classPrivateFieldGet(_communicationProvider, this).request({
|
|
1943
|
-
method: base_controllers_namespaceObject.COMMUNICATION_JRPC_METHODS.LOGIN_WITH_SESSION_ID,
|
|
1944
|
-
params: [params.sessionId, ""]
|
|
1945
|
-
});
|
|
1946
|
-
loglevel.info("Login with session id", res);
|
|
1947
|
-
return res.success;
|
|
1948
|
-
} catch (error) {
|
|
1949
|
-
loglevel.error("login with session id failed", error);
|
|
1950
|
-
throw error;
|
|
1418
|
+
async sendPartnerUserInfoRequest(authIframe) {
|
|
1419
|
+
const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE)));
|
|
1420
|
+
const { origin } = new URL(authIframe.src);
|
|
1421
|
+
authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.PARTNER_USER_INFO_REQUEST }, origin);
|
|
1422
|
+
return response;
|
|
1951
1423
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
_classPrivateFieldGet(_communicationProvider, this).showTorusButton();
|
|
1958
|
-
}
|
|
1959
|
-
async claimRealmId(options) {
|
|
1960
|
-
if (!this.isConnected) throw new RealmEmbedError("NOT_CONNECTED", "User needs to be connected first");
|
|
1961
|
-
try {
|
|
1962
|
-
if (options !== null && options !== void 0 && options.background) {
|
|
1963
|
-
_classPrivateFieldGet(_communicationProvider, this).setIframeVisibility({
|
|
1964
|
-
isVisible: false
|
|
1965
|
-
});
|
|
1966
|
-
}
|
|
1967
|
-
_classPrivateFieldGet(_communicationProvider, this).displayIframe({
|
|
1968
|
-
isFull: true
|
|
1969
|
-
});
|
|
1970
|
-
const claimPromise = messageService.sendClaimRequest(_classPrivateFieldGet(_walletIframe, this), options);
|
|
1971
|
-
loglevel.debug("before claimPromise");
|
|
1972
|
-
await claimPromise;
|
|
1973
|
-
loglevel.debug("after claimPromise");
|
|
1974
|
-
return {
|
|
1975
|
-
isLoggedIn: true,
|
|
1976
|
-
realmId: _classPrivateFieldGet(_realmId, this),
|
|
1977
|
-
addresses: _classPrivateFieldGet(_walletAddresses, this),
|
|
1978
|
-
token: _classPrivateFieldGet(_loginToken, this),
|
|
1979
|
-
sessionId: _classPrivateFieldGet(_sessionId, this)
|
|
1980
|
-
};
|
|
1981
|
-
} catch (e) {
|
|
1982
|
-
throw RealmEmbedError.from(e);
|
|
1983
|
-
} finally {
|
|
1984
|
-
if (options !== null && options !== void 0 && options.background) {
|
|
1985
|
-
_classPrivateFieldGet(_communicationProvider, this).setIframeVisibility({
|
|
1986
|
-
isVisible: true
|
|
1987
|
-
});
|
|
1988
|
-
}
|
|
1989
|
-
_classPrivateFieldGet(_communicationProvider, this).displayIframe({
|
|
1990
|
-
isFull: false
|
|
1991
|
-
});
|
|
1424
|
+
async sendAuthLoginRequest(authIframe, payload) {
|
|
1425
|
+
const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGIN_RESPONSE)));
|
|
1426
|
+
const { origin } = new URL(authIframe.src);
|
|
1427
|
+
authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.LOGIN_REQUEST, payload }, origin);
|
|
1428
|
+
return response;
|
|
1992
1429
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
async cleanUp() {
|
|
1999
|
-
var _classPrivateFieldGet5;
|
|
2000
|
-
if ((_classPrivateFieldGet5 = _classPrivateFieldGet(_communicationProvider, this)) !== null && _classPrivateFieldGet5 !== void 0 && _classPrivateFieldGet5.isLoggedIn) {
|
|
2001
|
-
await this.logout();
|
|
1430
|
+
async logoutAuth(authIframe) {
|
|
1431
|
+
const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGOUT_RESPONSE)));
|
|
1432
|
+
const { origin } = new URL(authIframe.src);
|
|
1433
|
+
authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.LOGOUT_REQUEST }, origin);
|
|
1434
|
+
return response;
|
|
2002
1435
|
}
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
on(listener) {
|
|
2009
|
-
if (_classPrivateFieldGet(_embedListeners, this).indexOf(listener) < 0) _classPrivateFieldGet(_embedListeners, this).push(listener);
|
|
2010
|
-
}
|
|
2011
|
-
off(listener) {
|
|
2012
|
-
const index = _classPrivateFieldGet(_embedListeners, this).indexOf(listener);
|
|
2013
|
-
if (index >= 0) _classPrivateFieldGet(_embedListeners, this).splice(index, 1);
|
|
2014
|
-
}
|
|
2015
|
-
clearEventListeners() {
|
|
2016
|
-
_classPrivateFieldSet(_embedListeners, this, []);
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
function _getWsIframeUrl() {
|
|
2020
|
-
const {
|
|
2021
|
-
walletUrl
|
|
2022
|
-
} = AIR_URLS[_classPrivateFieldGet(_buildEnv, this)];
|
|
2023
|
-
const torusIframeUrl = new URL(walletUrl);
|
|
2024
|
-
if (torusIframeUrl.pathname.endsWith("/")) torusIframeUrl.pathname += "frame";else torusIframeUrl.pathname += "/frame";
|
|
2025
|
-
const hashParams = new URLSearchParams();
|
|
2026
|
-
hashParams.append("origin", window.location.origin);
|
|
2027
|
-
torusIframeUrl.hash = hashParams.toString();
|
|
2028
|
-
return torusIframeUrl;
|
|
2029
|
-
}
|
|
2030
|
-
async function _login(options, isLegacyLogin) {
|
|
2031
|
-
let loginResult;
|
|
2032
|
-
if (this.isLoggedIn) {
|
|
2033
|
-
loginResult = _assertClassBrand(_RealmEmbed_brand, this, _createLoginResult).call(this);
|
|
2034
|
-
} else if (this.isConnected) {
|
|
2035
|
-
if ((options === null || options === void 0 ? void 0 : options.skipClaiming) === true) {
|
|
2036
|
-
loginResult = _assertClassBrand(_RealmEmbed_brand, this, _createLoginResult).call(this);
|
|
2037
|
-
} else {
|
|
2038
|
-
loginResult = await this.claimRealmId(options);
|
|
1436
|
+
async logoutWallet(walletIframe) {
|
|
1437
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.LOGOUT_RESPONSE)));
|
|
1438
|
+
const { origin } = new URL(walletIframe.src);
|
|
1439
|
+
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.LOGOUT_REQUEST }, origin);
|
|
1440
|
+
return response;
|
|
2039
1441
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
function _createLoginResult() {
|
|
2046
|
-
if (this.isLoggedIn) {
|
|
2047
|
-
return {
|
|
2048
|
-
isLoggedIn: true,
|
|
2049
|
-
realmId: _classPrivateFieldGet(_realmId, this),
|
|
2050
|
-
addresses: _classPrivateFieldGet(_walletAddresses, this),
|
|
2051
|
-
token: _classPrivateFieldGet(_loginToken, this),
|
|
2052
|
-
sessionId: _classPrivateFieldGet(_sessionId, this)
|
|
2053
|
-
};
|
|
2054
|
-
}
|
|
2055
|
-
return {
|
|
2056
|
-
isLoggedIn: false,
|
|
2057
|
-
addresses: _classPrivateFieldGet(_walletAddresses, this),
|
|
2058
|
-
token: _classPrivateFieldGet(_loginToken, this),
|
|
2059
|
-
sessionId: _classPrivateFieldGet(_sessionId, this)
|
|
2060
|
-
};
|
|
2061
|
-
}
|
|
2062
|
-
async function _authLogin(params = {}) {
|
|
2063
|
-
try {
|
|
2064
|
-
if (!params.loginProvider || params.loginProvider === EXTERNAL_LOGIN_PROVIDER.WALLET_CONNECT) {
|
|
2065
|
-
_classPrivateFieldGet(_communicationProvider, this).displayIframe({
|
|
2066
|
-
isFull: true
|
|
2067
|
-
});
|
|
1442
|
+
async sendAuthInitializationRequest(authIframe, payload) {
|
|
1443
|
+
const response = firstValueFrom(this._authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.INITIALIZATION_RESPONSE)));
|
|
1444
|
+
const { origin } = new URL(authIframe.src);
|
|
1445
|
+
authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.INITIALIZATION_REQUEST, payload }, origin);
|
|
1446
|
+
return response;
|
|
2068
1447
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
method: "eth_requestAccounts",
|
|
2075
|
-
params: [params.loginProvider, params.login_hint]
|
|
2076
|
-
}, (0,external_web3auth_auth_namespaceObject.getRpcPromiseCallback)(resolve, reject));
|
|
2077
|
-
});
|
|
2078
|
-
loglevel.debug("check: res", res);
|
|
2079
|
-
if (Array.isArray(res) && res.length > 0) {
|
|
2080
|
-
if (_classPrivateFieldGet(_confirmationStrategy, this) === base_controllers_namespaceObject.CONFIRMATION_STRATEGY.AUTO_APPROVE) loglevel.warn("Confirmation strategy auto approve is not allowed on Embed Mode, using Default instead.");
|
|
2081
|
-
return res;
|
|
1448
|
+
async sendWalletInitializationRequest(walletIframe, payload) {
|
|
1449
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.INITIALIZATION_RESPONSE)));
|
|
1450
|
+
const { origin } = new URL(walletIframe.src);
|
|
1451
|
+
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.INITIALIZATION_REQUEST, payload }, origin);
|
|
1452
|
+
return response;
|
|
2082
1453
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
async function _realmLogin(options, isLegacyLogin) {
|
|
2091
|
-
const skipClaimFlow = (options === null || options === void 0 ? void 0 : options.skipClaiming) === true;
|
|
2092
|
-
try {
|
|
2093
|
-
if (options !== null && options !== void 0 && options.authToken) {
|
|
2094
|
-
_classPrivateFieldGet(_communicationProvider, this).setIframeVisibility({
|
|
2095
|
-
isVisible: false
|
|
2096
|
-
});
|
|
1454
|
+
async sendGrantPermissionsRequest(walletIframe, payload) {
|
|
1455
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
|
|
1456
|
+
const { origin } = new URL(walletIframe.src);
|
|
1457
|
+
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.GRANT_PERMISSIONS_REQUEST, payload }, origin);
|
|
1458
|
+
return response;
|
|
2097
1459
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
1460
|
+
onWalletInitialized() {
|
|
1461
|
+
return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.WALLET_INITIALIZED)));
|
|
1462
|
+
}
|
|
1463
|
+
async sendClaimIdRequest(walletIframe, payload) {
|
|
1464
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.CLAIM_ID_RESPONSE)));
|
|
1465
|
+
const { origin } = new URL(walletIframe.src);
|
|
1466
|
+
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.CLAIM_ID_REQUEST, payload }, origin);
|
|
1467
|
+
return response;
|
|
1468
|
+
}
|
|
1469
|
+
async sendWalletProviderRequest(walletIframe, payload) {
|
|
1470
|
+
const response = firstValueFrom(this.providerMessage$.pipe(filter((msg) => msg.type === AirWalletProviderMessageTypes.RESPONSE &&
|
|
1471
|
+
msg.payload.requestId === payload.requestId)));
|
|
1472
|
+
const { origin } = new URL(walletIframe.src);
|
|
1473
|
+
walletIframe.contentWindow.postMessage({
|
|
1474
|
+
type: AirWalletProviderMessageTypes.REQUEST,
|
|
1475
|
+
payload,
|
|
1476
|
+
}, origin);
|
|
1477
|
+
return response;
|
|
1478
|
+
}
|
|
1479
|
+
closeAuthObservables() {
|
|
1480
|
+
if (this._authMessage$ && !this._authMessage$.closed)
|
|
1481
|
+
this._authMessage$.complete();
|
|
1482
|
+
if (this.closeAuthMessageListeners)
|
|
1483
|
+
this.closeAuthMessageListeners();
|
|
1484
|
+
}
|
|
1485
|
+
closeAirObservables() {
|
|
1486
|
+
if (this.airMessages$ && !this.airMessages$.closed)
|
|
1487
|
+
this.airMessages$.complete();
|
|
1488
|
+
if (this.closeRealmMessageListeners)
|
|
1489
|
+
this.closeRealmMessageListeners();
|
|
1490
|
+
}
|
|
1491
|
+
closeWalletObservables() {
|
|
1492
|
+
if (this._providerMessage$ && !this._providerMessage$.closed)
|
|
1493
|
+
this._providerMessage$.complete();
|
|
1494
|
+
if (this.closeWalletMessageListeners)
|
|
1495
|
+
this.closeWalletMessageListeners();
|
|
1496
|
+
}
|
|
1497
|
+
setupAuthObservables() {
|
|
1498
|
+
this._authMessage$ = new Subject();
|
|
1499
|
+
}
|
|
1500
|
+
setupAirObservables() {
|
|
1501
|
+
this.airMessages$ = new Subject();
|
|
1502
|
+
}
|
|
1503
|
+
setupWalletObservables() {
|
|
1504
|
+
this._providerMessage$ = new Subject();
|
|
2116
1505
|
}
|
|
2117
|
-
_classPrivateFieldGet(_communicationProvider, this).displayIframe({
|
|
2118
|
-
isFull: false
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
async function _logout() {
|
|
2123
|
-
var _classPrivateFieldGet6;
|
|
2124
|
-
const silent = !_classPrivateFieldGet(_walletAddresses, this);
|
|
2125
|
-
if ((_classPrivateFieldGet6 = _classPrivateFieldGet(_communicationProvider, this)) !== null && _classPrivateFieldGet6 !== void 0 && _classPrivateFieldGet6.isLoggedIn) {
|
|
2126
|
-
await _classPrivateFieldGet(_communicationProvider, this).request({
|
|
2127
|
-
method: base_controllers_namespaceObject.COMMUNICATION_JRPC_METHODS.LOGOUT,
|
|
2128
|
-
params: []
|
|
2129
|
-
});
|
|
2130
|
-
}
|
|
2131
|
-
if (_classPrivateFieldGet(_communicationProvider, this)) _classPrivateFieldGet(_communicationProvider, this).onLoginStateHandle = undefined;
|
|
2132
|
-
_classPrivateFieldSet(_walletAddresses, this, undefined);
|
|
2133
|
-
_classPrivateFieldSet(_realmId, this, undefined);
|
|
2134
|
-
if (!silent) {
|
|
2135
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
2136
|
-
event: "logged_out"
|
|
2137
|
-
});
|
|
2138
|
-
}
|
|
2139
1506
|
}
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
1507
|
+
var AirMessageService$1 = AirMessageService.instance;
|
|
1508
|
+
|
|
1509
|
+
class ProviderRpcError extends Error {
|
|
1510
|
+
constructor(message, code, data) {
|
|
1511
|
+
super(message);
|
|
1512
|
+
this.code = code;
|
|
1513
|
+
this.data = data;
|
|
2147
1514
|
}
|
|
2148
|
-
messageService.closeRealmObservables();
|
|
2149
|
-
_classPrivateFieldSet(_isInitialized, this, false);
|
|
2150
|
-
_classPrivateFieldSet(_walletAddresses, this, undefined);
|
|
2151
|
-
_classPrivateFieldSet(_realmId, this, undefined);
|
|
2152
|
-
if (isSilent === true) _assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
2153
|
-
event: "reset"
|
|
2154
|
-
});
|
|
2155
1515
|
}
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
1516
|
+
new ProviderRpcError("Invalid JSON", -32700);
|
|
1517
|
+
const ProviderRpcInvalidRequestError = new ProviderRpcError("Invalid request", -32600);
|
|
1518
|
+
const ProviderRpcMethodNotFoundError = new ProviderRpcError("Method not found", -32601);
|
|
1519
|
+
const ProviderRpcInvalidParamsError = new ProviderRpcError("Invalid params", -32602);
|
|
1520
|
+
new ProviderRpcError("Internal error", -32603);
|
|
1521
|
+
new ProviderRpcError("User rejected request", 4001);
|
|
1522
|
+
new ProviderRpcError("Unauthorized", 4100);
|
|
1523
|
+
new ProviderRpcError("Unsupported method", 4200);
|
|
1524
|
+
new ProviderRpcError("Disconnected", 4900);
|
|
1525
|
+
new ProviderRpcError("Chain Disconnected", 4901);
|
|
1526
|
+
function ensureProviderRpcError(value) {
|
|
1527
|
+
if (value instanceof ProviderRpcError) return value;
|
|
1528
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
1529
|
+
try {
|
|
1530
|
+
stringified = JSON.stringify(value);
|
|
1531
|
+
} catch {
|
|
1532
|
+
// ignoring failed stringify
|
|
2161
1533
|
}
|
|
2162
|
-
return
|
|
1534
|
+
return new ProviderRpcError(`This value was not thrown as type ProviderRpcError: ${stringified}`, -32603);
|
|
2163
1535
|
}
|
|
2164
|
-
async function _setupWeb(providerParams) {
|
|
2165
|
-
loglevel.debug("setup embed communication...");
|
|
2166
|
-
// setup background connection
|
|
2167
|
-
const providerStream = new external_web3auth_auth_namespaceObject.BasePostMessageStream({
|
|
2168
|
-
name: "embed_torus",
|
|
2169
|
-
target: "iframe_torus",
|
|
2170
|
-
targetWindow: _classPrivateFieldGet(_walletIframe, this).contentWindow,
|
|
2171
|
-
targetOrigin: new URL(providerParams.torusUrl).origin
|
|
2172
|
-
});
|
|
2173
1536
|
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
targetOrigin: new URL(providerParams.torusUrl).origin
|
|
2180
|
-
});
|
|
1537
|
+
const BUILD_ENV = {
|
|
1538
|
+
PRODUCTION: "production",
|
|
1539
|
+
STAGING: "staging",
|
|
1540
|
+
DEVELOPMENT: "development",
|
|
1541
|
+
};
|
|
2181
1542
|
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
features: (0,base_controllers_namespaceObject.getPopupFeatures)(base_controllers_namespaceObject.FEATURES_PROVIDER_CHANGE_WINDOW),
|
|
2211
|
-
// todo: are these features generic for all
|
|
2212
|
-
timeout: 500
|
|
2213
|
-
});
|
|
2214
|
-
// for communication methods sending window id in jrpc req params
|
|
2215
|
-
_payload.params.windowId = windowId;
|
|
1543
|
+
const AIR_URLS = {
|
|
1544
|
+
[BUILD_ENV.DEVELOPMENT]: {
|
|
1545
|
+
authUrl: "http://localhost:8100",
|
|
1546
|
+
walletUrl: "http://localhost:8200",
|
|
1547
|
+
legacyWalletUrl: "https://localhost:4050",
|
|
1548
|
+
logLevel: "debug",
|
|
1549
|
+
},
|
|
1550
|
+
[BUILD_ENV.STAGING]: {
|
|
1551
|
+
authUrl: "https://auth.staging.air3.com",
|
|
1552
|
+
walletUrl: "https://account.staging.air3.com",
|
|
1553
|
+
legacyWalletUrl: "https://account.staging.realmnetwork.io",
|
|
1554
|
+
logLevel: "info",
|
|
1555
|
+
},
|
|
1556
|
+
[BUILD_ENV.PRODUCTION]: {
|
|
1557
|
+
authUrl: "https://auth.air3.com",
|
|
1558
|
+
walletUrl: "https://account.air3.com",
|
|
1559
|
+
legacyWalletUrl: "https://account.realmnetwork.io",
|
|
1560
|
+
logLevel: "error",
|
|
1561
|
+
},
|
|
1562
|
+
};
|
|
1563
|
+
const isElement = (element) => element instanceof Element || element instanceof Document;
|
|
1564
|
+
const randomId = () => Math.random().toString(36).slice(2);
|
|
1565
|
+
|
|
1566
|
+
var _AirWalletProvider_walletIframe;
|
|
1567
|
+
class AirWalletProvider {
|
|
1568
|
+
constructor(walletIframe) {
|
|
1569
|
+
_AirWalletProvider_walletIframe.set(this, undefined);
|
|
1570
|
+
__classPrivateFieldSet(this, _AirWalletProvider_walletIframe, walletIframe, "f");
|
|
2216
1571
|
}
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
const detectAccountRequestPrototypeModifier = m => {
|
|
2222
|
-
const originalMethod = inPageProvider[m];
|
|
2223
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
2224
|
-
const self = this;
|
|
2225
|
-
|
|
2226
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2227
|
-
// @ts-ignore
|
|
2228
|
-
inPageProvider[m] = function providerFunc(request, cb) {
|
|
2229
|
-
const {
|
|
2230
|
-
method,
|
|
2231
|
-
params = []
|
|
2232
|
-
} = request;
|
|
2233
|
-
if (method === "eth_requestAccounts") {
|
|
2234
|
-
let login = _assertClassBrand(_RealmEmbed_brand, self, _authLogin).call(self, {
|
|
2235
|
-
loginProvider: params[0]
|
|
2236
|
-
});
|
|
2237
|
-
if (cb) {
|
|
2238
|
-
login = login.then(res => cb(null, res)).catch(err => cb(err));
|
|
1572
|
+
async request(request) {
|
|
1573
|
+
// Check if the request is valid
|
|
1574
|
+
if (!request || typeof request !== "object" || Array.isArray(request)) {
|
|
1575
|
+
throw ProviderRpcInvalidRequestError;
|
|
2239
1576
|
}
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
1577
|
+
const { method, params } = request;
|
|
1578
|
+
// Check if the method is valid
|
|
1579
|
+
if (typeof method !== "string" || method.length === 0) {
|
|
1580
|
+
throw ProviderRpcMethodNotFoundError;
|
|
1581
|
+
}
|
|
1582
|
+
// Check if the params are valid
|
|
1583
|
+
if (params !== undefined &&
|
|
1584
|
+
!Array.isArray(params) &&
|
|
1585
|
+
(typeof params !== "object" || params === null)) {
|
|
1586
|
+
throw ProviderRpcInvalidParamsError;
|
|
1587
|
+
}
|
|
1588
|
+
const requestId = randomId();
|
|
1589
|
+
const response = await AirMessageService$1.sendWalletProviderRequest(__classPrivateFieldGet(this, _AirWalletProvider_walletIframe, "f"), {
|
|
1590
|
+
requestId,
|
|
1591
|
+
...request,
|
|
2244
1592
|
});
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
};
|
|
2249
|
-
|
|
2250
|
-
// Detects call to eth_requestAccounts in request & sendAsync and passes to login
|
|
2251
|
-
detectAccountRequestPrototypeModifier("request");
|
|
2252
|
-
detectAccountRequestPrototypeModifier("sendAsync");
|
|
2253
|
-
detectAccountRequestPrototypeModifier("send");
|
|
2254
|
-
const proxiedInPageProvider = new Proxy(inPageProvider, {
|
|
2255
|
-
// straight up lie that we deleted the property so that it doesn't
|
|
2256
|
-
// throw an error in strict mode
|
|
2257
|
-
deleteProperty: () => true
|
|
2258
|
-
});
|
|
2259
|
-
const proxiedCommunicationProvider = new Proxy(communicationProvider, {
|
|
2260
|
-
// straight up lie that we deleted the property so that it doesn't
|
|
2261
|
-
// throw an error in strict mode
|
|
2262
|
-
deleteProperty: () => true
|
|
2263
|
-
});
|
|
2264
|
-
_classPrivateFieldSet(_provider, this, proxiedInPageProvider);
|
|
2265
|
-
_classPrivateFieldSet(_communicationProvider, this, proxiedCommunicationProvider);
|
|
2266
|
-
await Promise.all([inPageProvider.initializeState(), communicationProvider.initializeState(objectSpread2_default()(objectSpread2_default()({}, providerParams), {}, {
|
|
2267
|
-
torusIframeId: _classPrivateFieldGet(_walletIframe, this).id
|
|
2268
|
-
}))]);
|
|
2269
|
-
loglevel.debug("embed communication setup ended");
|
|
2270
|
-
}
|
|
2271
|
-
function _triggerEvent(data) {
|
|
2272
|
-
const listenersCopy = [..._classPrivateFieldGet(_embedListeners, this)];
|
|
2273
|
-
listenersCopy.forEach(listener => {
|
|
2274
|
-
try {
|
|
2275
|
-
listener(data);
|
|
2276
|
-
} catch (error) {
|
|
2277
|
-
loglevel.error(error);
|
|
2278
|
-
}
|
|
2279
|
-
});
|
|
2280
|
-
}
|
|
2281
|
-
function _triggerInitializedEvent() {
|
|
2282
|
-
if (_classPrivateFieldGet(_isInitialized, this) && _classPrivateFieldGet(_rehydrationState, this)) {
|
|
2283
|
-
_assertClassBrand(_RealmEmbed_brand, this, _triggerEvent).call(this, {
|
|
2284
|
-
event: "initialized",
|
|
2285
|
-
result: {
|
|
2286
|
-
rehydration: _classPrivateFieldGet(_rehydrationState, this)
|
|
2287
|
-
}
|
|
2288
|
-
});
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
function _onInitialized() {
|
|
2292
|
-
return new Promise(resolve => {
|
|
2293
|
-
if (!_classPrivateFieldGet(_isInitialized, this) || !_classPrivateFieldGet(_rehydrationState, this)) {
|
|
2294
|
-
const sub = event => {
|
|
2295
|
-
loglevel.debug("onInitialized:", event);
|
|
2296
|
-
if (event.event === "initialized") {
|
|
2297
|
-
this.off(sub);
|
|
2298
|
-
resolve();
|
|
1593
|
+
if (!response.success) {
|
|
1594
|
+
const error = ensureProviderRpcError(response.payload);
|
|
1595
|
+
throw error;
|
|
2299
1596
|
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
1597
|
+
return response.payload.response;
|
|
1598
|
+
}
|
|
1599
|
+
on(eventName, listener) {
|
|
1600
|
+
console.log("on", eventName, listener);
|
|
1601
|
+
}
|
|
1602
|
+
removeListener(eventName, listener) {
|
|
1603
|
+
console.log("removeListener", eventName, listener);
|
|
2304
1604
|
}
|
|
2305
|
-
});
|
|
2306
1605
|
}
|
|
2307
|
-
|
|
2308
|
-
;// ./src/iframeController.ts
|
|
2309
|
-
|
|
1606
|
+
_AirWalletProvider_walletIframe = new WeakMap();
|
|
2310
1607
|
|
|
2311
1608
|
class IframeController {
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
1609
|
+
constructor(iframeUrl, iframeId, state) {
|
|
1610
|
+
this._iframeElement = null;
|
|
1611
|
+
this.state = {
|
|
1612
|
+
...IframeController.defaultState,
|
|
1613
|
+
...state,
|
|
1614
|
+
};
|
|
1615
|
+
this.iframeUrl = iframeUrl;
|
|
1616
|
+
this.iframeId = iframeId;
|
|
1617
|
+
}
|
|
1618
|
+
get iframeElement() {
|
|
1619
|
+
return this._iframeElement;
|
|
1620
|
+
}
|
|
1621
|
+
createIframe() {
|
|
1622
|
+
if (this._iframeElement)
|
|
1623
|
+
return this._iframeElement;
|
|
1624
|
+
const iframe = document.createElement("iframe");
|
|
1625
|
+
iframe.id = this.iframeId;
|
|
1626
|
+
iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
|
|
1627
|
+
iframe.src = this.iframeUrl;
|
|
1628
|
+
iframe.style.position = "fixed";
|
|
1629
|
+
iframe.style.zIndex = "999999";
|
|
1630
|
+
iframe.style.border = "none";
|
|
1631
|
+
iframe.style.margin = "0";
|
|
1632
|
+
iframe.style.padding = "0";
|
|
1633
|
+
iframe.style.display = "none";
|
|
1634
|
+
document.body.appendChild(iframe);
|
|
1635
|
+
this._iframeElement = iframe;
|
|
1636
|
+
return iframe;
|
|
1637
|
+
}
|
|
1638
|
+
setIframeVisibility(isVisible) {
|
|
1639
|
+
this.state.isVisible = isVisible;
|
|
1640
|
+
}
|
|
1641
|
+
updateIframeState() {
|
|
1642
|
+
if (!this.iframeElement)
|
|
1643
|
+
return;
|
|
1644
|
+
const style = {};
|
|
1645
|
+
style.display = this.state.isVisible ? "block" : "none";
|
|
1646
|
+
style.width = "100%";
|
|
1647
|
+
style.height = "100%";
|
|
1648
|
+
style.top = "0px";
|
|
1649
|
+
style.right = "0px";
|
|
1650
|
+
style.left = "0px";
|
|
1651
|
+
style.bottom = "0px";
|
|
1652
|
+
Object.assign(this.iframeElement.style, style);
|
|
1653
|
+
}
|
|
1654
|
+
destroy() {
|
|
1655
|
+
if (this.iframeElement) {
|
|
1656
|
+
this.iframeElement.remove();
|
|
1657
|
+
this._iframeElement = null;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
postMessage(message) {
|
|
1661
|
+
if (!this.iframeElement)
|
|
1662
|
+
return;
|
|
1663
|
+
const { origin } = new URL(this.iframeElement.src);
|
|
1664
|
+
this.iframeElement.contentWindow.postMessage(message, origin);
|
|
2359
1665
|
}
|
|
2360
|
-
}
|
|
2361
|
-
postMessage(message) {
|
|
2362
|
-
if (!this.iframeElement) return;
|
|
2363
|
-
const {
|
|
2364
|
-
origin
|
|
2365
|
-
} = new URL(this.iframeElement.src);
|
|
2366
|
-
this.iframeElement.contentWindow.postMessage(message, origin);
|
|
2367
|
-
}
|
|
2368
1666
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
}
|
|
2372
|
-
;// ./src/airService.ts
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
function airService_classPrivateFieldGet(s, a) { return s.get(airService_assertClassBrand(s, a)); }
|
|
2377
|
-
function airService_classPrivateFieldSet(s, a, r) { return s.set(airService_assertClassBrand(s, a), r), r; }
|
|
2378
|
-
function airService_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
1667
|
+
IframeController.defaultState = {
|
|
1668
|
+
isVisible: false,
|
|
1669
|
+
};
|
|
2387
1670
|
|
|
2388
|
-
var
|
|
2389
|
-
var _loginResult = /*#__PURE__*/new WeakMap();
|
|
2390
|
-
var airService_buildEnv = /*#__PURE__*/new WeakMap();
|
|
2391
|
-
var airService_embedNonce = /*#__PURE__*/new WeakMap();
|
|
2392
|
-
var _enableLogging = /*#__PURE__*/new WeakMap();
|
|
2393
|
-
var airService_isInitialized = /*#__PURE__*/new WeakMap();
|
|
2394
|
-
var _partnerId = /*#__PURE__*/new WeakMap();
|
|
2395
|
-
var _realmEmbed = /*#__PURE__*/new WeakMap();
|
|
2396
|
-
var _walletInitialization = /*#__PURE__*/new WeakMap();
|
|
2397
|
-
var _airAuthListener = /*#__PURE__*/new WeakMap();
|
|
2398
|
-
var _AirService_brand = /*#__PURE__*/new WeakSet();
|
|
1671
|
+
var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airAuthListener, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_isWalletInitialized, _AirService_airWalletProvider, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet;
|
|
2399
1672
|
class AirService {
|
|
2400
|
-
|
|
2401
|
-
partnerId
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
if (ev.origin !== authIframeOrigin) return;
|
|
2478
|
-
if (ev.data === AirAuthMessageTypes.SETUP_COMPLETED) {
|
|
2479
|
-
window.removeEventListener("message", handleAuthMessage);
|
|
2480
|
-
airService_classPrivateFieldGet(_authIframeController, this).postMessage({
|
|
2481
|
-
type: AirAuthMessageTypes.INITIALIZATION_REQUEST,
|
|
2482
|
-
payload: {
|
|
2483
|
-
partnerId: airService_classPrivateFieldGet(_partnerId, this),
|
|
2484
|
-
skipRehydration
|
|
1673
|
+
// #walletRehydrationState: AirRehydrationResult;
|
|
1674
|
+
constructor({ partnerId }) {
|
|
1675
|
+
_AirService_instances.add(this);
|
|
1676
|
+
_AirService_loginResult.set(this, undefined);
|
|
1677
|
+
_AirService_buildEnv.set(this, undefined);
|
|
1678
|
+
_AirService_enableLogging.set(this, false);
|
|
1679
|
+
_AirService_partnerId.set(this, undefined);
|
|
1680
|
+
//#modalZIndex: number; TODO implement z index overwrite
|
|
1681
|
+
_AirService_authIframeController.set(this, undefined);
|
|
1682
|
+
_AirService_isAuthInitialized.set(this, false);
|
|
1683
|
+
_AirService_airAuthListener.set(this, []);
|
|
1684
|
+
_AirService_walletIframeController.set(this, undefined);
|
|
1685
|
+
_AirService_walletInitialization.set(this, undefined);
|
|
1686
|
+
_AirService_isWalletInitialized.set(this, false);
|
|
1687
|
+
_AirService_airWalletProvider.set(this, undefined);
|
|
1688
|
+
__classPrivateFieldSet(this, _AirService_partnerId, partnerId, "f");
|
|
1689
|
+
// this.#modalZIndex = modalZIndex ?? 99999;
|
|
1690
|
+
}
|
|
1691
|
+
get buildEnv() {
|
|
1692
|
+
return __classPrivateFieldGet(this, _AirService_buildEnv, "f");
|
|
1693
|
+
}
|
|
1694
|
+
get isInitialized() {
|
|
1695
|
+
return __classPrivateFieldGet(this, _AirService_isAuthInitialized, "f");
|
|
1696
|
+
}
|
|
1697
|
+
get isLoggedIn() {
|
|
1698
|
+
return !!__classPrivateFieldGet(this, _AirService_loginResult, "f");
|
|
1699
|
+
}
|
|
1700
|
+
get isWalletInitialized() {
|
|
1701
|
+
return __classPrivateFieldGet(this, _AirService_isWalletInitialized, "f");
|
|
1702
|
+
}
|
|
1703
|
+
async init({ buildEnv = BUILD_ENV.PRODUCTION, enableLogging = false, skipRehydration = false, }) {
|
|
1704
|
+
if (!__classPrivateFieldGet(this, _AirService_partnerId, "f"))
|
|
1705
|
+
throw new Error("Partner ID is required to initialize auth service");
|
|
1706
|
+
if (__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1707
|
+
return;
|
|
1708
|
+
__classPrivateFieldSet(this, _AirService_buildEnv, buildEnv, "f");
|
|
1709
|
+
__classPrivateFieldSet(this, _AirService_enableLogging, enableLogging, "f");
|
|
1710
|
+
const { authUrl, logLevel } = AIR_URLS[buildEnv];
|
|
1711
|
+
log.setDefaultLevel(logLevel);
|
|
1712
|
+
if (__classPrivateFieldGet(this, _AirService_enableLogging, "f"))
|
|
1713
|
+
log.enableAll();
|
|
1714
|
+
else
|
|
1715
|
+
log.disableAll();
|
|
1716
|
+
const authIframeOrigin = new URL(authUrl).origin;
|
|
1717
|
+
await AirMessageService$1.openAuthObservables({ authIframeOrigin });
|
|
1718
|
+
__classPrivateFieldSet(this, _AirService_authIframeController, new IframeController(authUrl, `air-auth-${randomId()}`), "f");
|
|
1719
|
+
AirMessageService$1.authMessage$.subscribe(async (msg) => {
|
|
1720
|
+
switch (msg.type) {
|
|
1721
|
+
case AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST: {
|
|
1722
|
+
const authIframeController = __classPrivateFieldGet(this, _AirService_authIframeController, "f");
|
|
1723
|
+
authIframeController.setIframeVisibility(msg.payload.visible);
|
|
1724
|
+
authIframeController.updateIframeState();
|
|
1725
|
+
break;
|
|
1726
|
+
}
|
|
1727
|
+
case AirAuthMessageTypes.SETUP_WALLET_REQUEST: {
|
|
1728
|
+
try {
|
|
1729
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1730
|
+
__classPrivateFieldGet(this, _AirService_authIframeController, "f").postMessage({
|
|
1731
|
+
type: AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
|
|
1732
|
+
payload: {
|
|
1733
|
+
success: true,
|
|
1734
|
+
},
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
catch (err) {
|
|
1738
|
+
log.error("Error initializing wallet", err);
|
|
1739
|
+
const error = AirServiceError.from(err);
|
|
1740
|
+
__classPrivateFieldGet(this, _AirService_authIframeController, "f").postMessage({
|
|
1741
|
+
type: AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
|
|
1742
|
+
payload: {
|
|
1743
|
+
success: false,
|
|
1744
|
+
errorName: error.name ?? "UNKNOWN_ERROR",
|
|
1745
|
+
errorMessage: error.message ?? "Unknown error occurred",
|
|
1746
|
+
},
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
break;
|
|
2485
1750
|
}
|
|
2486
|
-
});
|
|
2487
|
-
resolve();
|
|
2488
1751
|
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
1752
|
+
});
|
|
1753
|
+
try {
|
|
1754
|
+
__classPrivateFieldGet(this, _AirService_authIframeController, "f").createIframe();
|
|
1755
|
+
const result = await new Promise((resolve, reject) => {
|
|
1756
|
+
const handleAuthMessage = async (ev) => {
|
|
1757
|
+
if (ev.origin !== authIframeOrigin)
|
|
1758
|
+
return;
|
|
1759
|
+
if (ev.data === AirAuthMessageTypes.AUTH_SETUP_COMPLETED) {
|
|
1760
|
+
window.removeEventListener("message", handleAuthMessage);
|
|
1761
|
+
const { payload } = await AirMessageService$1.sendAuthInitializationRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement, {
|
|
1762
|
+
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
1763
|
+
skipRehydration,
|
|
1764
|
+
});
|
|
1765
|
+
if (payload.success === true) {
|
|
1766
|
+
resolve(payload);
|
|
1767
|
+
}
|
|
1768
|
+
else {
|
|
1769
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
window.addEventListener("message", handleAuthMessage);
|
|
1774
|
+
});
|
|
1775
|
+
__classPrivateFieldSet(this, _AirService_isAuthInitialized, true, "f");
|
|
1776
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthInitialized).call(this, { rehydrated: result.rehydrated });
|
|
1777
|
+
// rehydrated auth session
|
|
1778
|
+
if (result.rehydrated) {
|
|
1779
|
+
__classPrivateFieldSet(this, _AirService_loginResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createLoginResult).call(this, result), "f");
|
|
1780
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedIn).call(this);
|
|
1781
|
+
return __classPrivateFieldGet(this, _AirService_loginResult, "f");
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
catch (error) {
|
|
1785
|
+
log.debug("Error initializing auth service", error);
|
|
1786
|
+
await this.cleanUp();
|
|
1787
|
+
throw error;
|
|
1788
|
+
}
|
|
1789
|
+
return null;
|
|
1790
|
+
}
|
|
1791
|
+
async cleanUp() {
|
|
1792
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
1793
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
|
|
1794
|
+
this.clearEventListeners();
|
|
1795
|
+
}
|
|
1796
|
+
async login(options) {
|
|
1797
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1798
|
+
throw new Error("Service is not initialized");
|
|
1799
|
+
if (__classPrivateFieldGet(this, _AirService_loginResult, "f"))
|
|
1800
|
+
return __classPrivateFieldGet(this, _AirService_loginResult, "f");
|
|
1801
|
+
const iframeController = __classPrivateFieldGet(this, _AirService_authIframeController, "f");
|
|
1802
|
+
const { payload } = await AirMessageService$1.sendAuthLoginRequest(iframeController.iframeElement, {
|
|
1803
|
+
partnerLoginToken: options?.authToken,
|
|
1804
|
+
});
|
|
1805
|
+
if (payload.success === true) {
|
|
1806
|
+
__classPrivateFieldSet(this, _AirService_loginResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createLoginResult).call(this, payload), "f");
|
|
1807
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedIn).call(this);
|
|
1808
|
+
return __classPrivateFieldGet(this, _AirService_loginResult, "f");
|
|
1809
|
+
}
|
|
1810
|
+
throw new AirServiceError("UNKNOWN_ERROR", "Unknown error occurred");
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* @experimental This method is experimental and will change in the future.
|
|
1814
|
+
*/
|
|
1815
|
+
async deploySmartAccount() {
|
|
1816
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1817
|
+
throw new Error("Service is not initialized");
|
|
1818
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1819
|
+
try {
|
|
1820
|
+
log.info("deploySmartAccount");
|
|
1821
|
+
const { payload } = await AirMessageService$1.sendDeploySmartAccountRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
|
|
1822
|
+
if (payload.success === false) {
|
|
1823
|
+
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
1824
|
+
}
|
|
1825
|
+
return { txHash: payload.txHash };
|
|
1826
|
+
}
|
|
1827
|
+
catch (error) {
|
|
1828
|
+
throw AirServiceError.from(error);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* @experimental This method is experimental and will change in the future.
|
|
1833
|
+
*/
|
|
1834
|
+
async grantPermission(policies) {
|
|
1835
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1836
|
+
throw new Error("AirAuth is not initialized");
|
|
1837
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1838
|
+
try {
|
|
1839
|
+
log.info("grantPermission", policies);
|
|
1840
|
+
const { payload } = await AirMessageService$1.sendGrantPermissionsRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, { policies });
|
|
1841
|
+
if (payload.success === false) {
|
|
1842
|
+
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
1843
|
+
}
|
|
1844
|
+
return payload.sessionData;
|
|
1845
|
+
}
|
|
1846
|
+
catch (error) {
|
|
1847
|
+
throw AirServiceError.from(error);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* @experimental This method is experimental and will change in the future.
|
|
1852
|
+
*/
|
|
1853
|
+
async executeAction(params) {
|
|
1854
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1855
|
+
throw new Error("Service is not initialized");
|
|
1856
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1857
|
+
try {
|
|
1858
|
+
log.info("executeAction", params);
|
|
1859
|
+
const txHash = await AirMessageService$1.sendExecuteActionRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, params);
|
|
1860
|
+
return txHash;
|
|
1861
|
+
}
|
|
1862
|
+
catch (error) {
|
|
1863
|
+
throw AirServiceError.from(error);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* @experimental This method is experimental and will change in the future.
|
|
1868
|
+
*/
|
|
1869
|
+
async revokePermission(permissionId) {
|
|
1870
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1871
|
+
throw new Error("Service is not initialized");
|
|
1872
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1873
|
+
try {
|
|
1874
|
+
log.info("revokePermission", permissionId);
|
|
1875
|
+
const txHash = await AirMessageService$1.sendRevokePermissionsRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, permissionId);
|
|
1876
|
+
return txHash;
|
|
1877
|
+
}
|
|
1878
|
+
catch (error) {
|
|
1879
|
+
throw AirServiceError.from(error);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* @experimental This method is experimental and will change in the future.
|
|
1884
|
+
*/
|
|
1885
|
+
async isSmartAccountDeployed() {
|
|
1886
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1887
|
+
throw new Error("Service is not initialized");
|
|
1888
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1889
|
+
try {
|
|
1890
|
+
const { payload } = await AirMessageService$1.sendIsSmartAccountDeployedRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
|
|
1891
|
+
if (payload.success === false) {
|
|
1892
|
+
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
1893
|
+
}
|
|
1894
|
+
return payload.isDeployed;
|
|
1895
|
+
}
|
|
1896
|
+
catch (error) {
|
|
1897
|
+
throw AirServiceError.from(error);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
async logout() {
|
|
1901
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
1902
|
+
throw new Error("Service is not initialized");
|
|
1903
|
+
if (!this.isLoggedIn)
|
|
1904
|
+
throw new Error("No active session to logout");
|
|
1905
|
+
// Clear up wallet
|
|
1906
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
1907
|
+
await AirMessageService$1.logoutAuth(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
|
|
1908
|
+
__classPrivateFieldSet(this, _AirService_loginResult, undefined, "f");
|
|
1909
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedOut).call(this);
|
|
1910
|
+
}
|
|
1911
|
+
async getProvider() {
|
|
1912
|
+
if (!this.isLoggedIn)
|
|
1913
|
+
return null;
|
|
1914
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1915
|
+
return __classPrivateFieldGet(this, _AirService_airWalletProvider, "f");
|
|
1916
|
+
}
|
|
1917
|
+
async preloadWallet() {
|
|
1918
|
+
return __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1919
|
+
}
|
|
1920
|
+
async claimAirId(options) {
|
|
1921
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1922
|
+
const result = await AirMessageService$1.sendClaimIdRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, options ?? {});
|
|
1923
|
+
if (result.payload.success === true) {
|
|
1924
|
+
return { airId: result.payload.airId };
|
|
1925
|
+
}
|
|
1926
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
1927
|
+
}
|
|
1928
|
+
async getUserInfo() {
|
|
1929
|
+
if (!this.isLoggedIn)
|
|
1930
|
+
throw new Error("User not logged in");
|
|
1931
|
+
const info = await AirMessageService$1.sendPartnerUserInfoRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
|
|
1932
|
+
if (info.payload.success === false) {
|
|
1933
|
+
throw new AirServiceError(info.payload.errorName, info.payload.errorMessage);
|
|
1934
|
+
}
|
|
1935
|
+
return {
|
|
1936
|
+
partnerId: info.payload.partnerId,
|
|
1937
|
+
partnerUserId: info.payload.partnerUserId,
|
|
1938
|
+
airId: info.payload.airId,
|
|
1939
|
+
user: {
|
|
1940
|
+
id: info.payload.user.id,
|
|
1941
|
+
abstractAccountAddress: info.payload.user.abstractAccountAddress,
|
|
1942
|
+
email: info.payload.user.email,
|
|
1943
|
+
},
|
|
2492
1944
|
};
|
|
2493
|
-
window.addEventListener("message", handleAuthMessage);
|
|
2494
|
-
});
|
|
2495
|
-
const authServiceInitialization = messageService.waitForAuthInitialization();
|
|
2496
|
-
const result = await Promise.all([initializationPromise, authServiceInitialization]);
|
|
2497
|
-
airService_classPrivateFieldSet(airService_isInitialized, this, true);
|
|
2498
|
-
airService_assertClassBrand(_AirService_brand, this, _triggerAirAuthInitialized).call(this, {
|
|
2499
|
-
rehydrated: result[1].rehydrated
|
|
2500
|
-
});
|
|
2501
|
-
airService_assertClassBrand(_AirService_brand, this, _prepareRealmEmbedListeners).call(this);
|
|
2502
|
-
|
|
2503
|
-
// rehydrated auth session
|
|
2504
|
-
if (result[1].rehydrated) {
|
|
2505
|
-
airService_classPrivateFieldSet(_loginResult, this, airService_assertClassBrand(_AirService_brand, this, airService_createLoginResult).call(this, result[1]));
|
|
2506
|
-
airService_assertClassBrand(_AirService_brand, this, _triggerAirAuthLoggedIn).call(this);
|
|
2507
|
-
return airService_classPrivateFieldGet(_loginResult, this);
|
|
2508
|
-
}
|
|
2509
|
-
} catch (error) {
|
|
2510
|
-
loglevel.debug("Error initializing auth service", error);
|
|
2511
|
-
await this.cleanUp();
|
|
2512
|
-
throw error;
|
|
2513
1945
|
}
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
var _classPrivateFieldGet3;
|
|
2518
|
-
// Clear up wallet service iframe if exists
|
|
2519
|
-
await airService_assertClassBrand(_AirService_brand, this, _cleanUpWallet).call(this);
|
|
2520
|
-
|
|
2521
|
-
// Logout auth session
|
|
2522
|
-
await messageService.logoutAuth(airService_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
2523
|
-
|
|
2524
|
-
// Destroy the auth iframe
|
|
2525
|
-
const authIframeElement = (_classPrivateFieldGet3 = airService_classPrivateFieldGet(_authIframeController, this)) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.iframeElement;
|
|
2526
|
-
if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
2527
|
-
airService_classPrivateFieldGet(_authIframeController, this).destroy();
|
|
2528
|
-
airService_classPrivateFieldSet(_authIframeController, this, undefined);
|
|
1946
|
+
on(listener) {
|
|
1947
|
+
if (__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener) < 0)
|
|
1948
|
+
__classPrivateFieldGet(this, _AirService_airAuthListener, "f").push(listener);
|
|
2529
1949
|
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
this.clearEventListeners();
|
|
2534
|
-
airService_classPrivateFieldSet(airService_isInitialized, this, false);
|
|
2535
|
-
}
|
|
2536
|
-
async login(options) {
|
|
2537
|
-
if (!airService_classPrivateFieldGet(airService_isInitialized, this)) throw new Error("Service is not initialized");
|
|
2538
|
-
if (airService_classPrivateFieldGet(_loginResult, this)) return airService_classPrivateFieldGet(_loginResult, this);
|
|
2539
|
-
const iframeController = airService_classPrivateFieldGet(_authIframeController, this);
|
|
2540
|
-
const {
|
|
2541
|
-
payload
|
|
2542
|
-
} = await messageService.sendAuthLoginRequest(iframeController.iframeElement, {
|
|
2543
|
-
partnerLoginToken: options === null || options === void 0 ? void 0 : options.authToken
|
|
2544
|
-
});
|
|
2545
|
-
if (payload.success === true) {
|
|
2546
|
-
airService_classPrivateFieldSet(_loginResult, this, airService_assertClassBrand(_AirService_brand, this, airService_createLoginResult).call(this, payload));
|
|
2547
|
-
airService_assertClassBrand(_AirService_brand, this, _triggerAirAuthLoggedIn).call(this);
|
|
2548
|
-
return airService_classPrivateFieldGet(_loginResult, this);
|
|
1950
|
+
off(listener) {
|
|
1951
|
+
if (__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener) >= 0)
|
|
1952
|
+
__classPrivateFieldGet(this, _AirService_airAuthListener, "f").splice(__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener), 1);
|
|
2549
1953
|
}
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
/**
|
|
2554
|
-
* @experimental This method is experimental and will change in the future.
|
|
2555
|
-
*/
|
|
2556
|
-
async deploySmartAccount() {
|
|
2557
|
-
if (!airService_classPrivateFieldGet(airService_isInitialized, this)) throw new Error("Service is not initialized");
|
|
2558
|
-
await airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2559
|
-
return airService_classPrivateFieldGet(_realmEmbed, this)._deploySmartAccount();
|
|
2560
|
-
}
|
|
2561
|
-
|
|
2562
|
-
/**
|
|
2563
|
-
* @experimental This method is experimental and will change in the future.
|
|
2564
|
-
*/
|
|
2565
|
-
async grantPermission(policies) {
|
|
2566
|
-
if (!airService_classPrivateFieldGet(airService_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
2567
|
-
await airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2568
|
-
return airService_classPrivateFieldGet(_realmEmbed, this)._grantPermission(policies);
|
|
2569
|
-
}
|
|
2570
|
-
|
|
2571
|
-
/**
|
|
2572
|
-
* @experimental This method is experimental and will change in the future.
|
|
2573
|
-
*/
|
|
2574
|
-
async executeAction(params) {
|
|
2575
|
-
if (!airService_classPrivateFieldGet(airService_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
2576
|
-
await airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2577
|
-
return airService_classPrivateFieldGet(_realmEmbed, this)._executeAction(params);
|
|
2578
|
-
}
|
|
2579
|
-
|
|
2580
|
-
/**
|
|
2581
|
-
* @experimental This method is experimental and will change in the future.
|
|
2582
|
-
*/
|
|
2583
|
-
async revokePermission(permissionId) {
|
|
2584
|
-
if (!airService_classPrivateFieldGet(airService_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
2585
|
-
await airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2586
|
-
return airService_classPrivateFieldGet(_realmEmbed, this)._revokePermission(permissionId);
|
|
2587
|
-
}
|
|
2588
|
-
async logout() {
|
|
2589
|
-
if (!airService_classPrivateFieldGet(airService_isInitialized, this)) throw new Error("Service is not initialized");
|
|
2590
|
-
if (!this.isLoggedIn) throw new Error("No active session to logout");
|
|
2591
|
-
|
|
2592
|
-
// Clear up wallet
|
|
2593
|
-
await airService_assertClassBrand(_AirService_brand, this, _cleanUpWallet).call(this);
|
|
2594
|
-
await messageService.logoutAuth(airService_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
2595
|
-
airService_classPrivateFieldSet(_loginResult, this, undefined);
|
|
2596
|
-
airService_assertClassBrand(_AirService_brand, this, _triggerAirAuthLoggedOut).call(this);
|
|
2597
|
-
}
|
|
2598
|
-
async getProvider() {
|
|
2599
|
-
if (!this.isLoggedIn) return null;
|
|
2600
|
-
await airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2601
|
-
return airService_classPrivateFieldGet(_realmEmbed, this).provider;
|
|
2602
|
-
}
|
|
2603
|
-
async preloadWallet() {
|
|
2604
|
-
return airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2605
|
-
}
|
|
2606
|
-
async claimAirId(options) {
|
|
2607
|
-
await airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2608
|
-
return airService_classPrivateFieldGet(_realmEmbed, this).claimRealmId(options);
|
|
2609
|
-
}
|
|
2610
|
-
async getUserInfo() {
|
|
2611
|
-
if (!this.isLoggedIn) throw new Error("User not logged in");
|
|
2612
|
-
const info = await messageService.sendUserInfoRequest(airService_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
2613
|
-
if (info.payload.success === false) {
|
|
2614
|
-
throw new AirServiceError(info.payload.errorName, info.payload.errorMessage);
|
|
1954
|
+
clearEventListeners() {
|
|
1955
|
+
__classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
|
|
2615
1956
|
}
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
async getPartnerUserInfo() {
|
|
2624
|
-
if (!this.isLoggedIn) throw new Error("User not logged in");
|
|
2625
|
-
const info = await messageService.sendPartnerUserInfoRequest(airService_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
2626
|
-
if (info.payload.success === false) {
|
|
2627
|
-
throw new AirServiceError(info.payload.errorName, info.payload.errorMessage);
|
|
1957
|
+
// This is for internal use only
|
|
1958
|
+
// @ts-expect-error for unused function
|
|
1959
|
+
async _showWalletWidget() {
|
|
1960
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
1961
|
+
// return (this.#realmEmbed as any)._showWalletWidget();
|
|
1962
|
+
log.info("_showWalletWidget");
|
|
1963
|
+
return null;
|
|
2628
1964
|
}
|
|
2629
|
-
return {
|
|
2630
|
-
partnerId: info.payload.partnerId,
|
|
2631
|
-
partnerUserId: info.payload.partnerUserId,
|
|
2632
|
-
airId: info.payload.airId
|
|
2633
|
-
};
|
|
2634
|
-
}
|
|
2635
|
-
on(listener) {
|
|
2636
|
-
if (airService_classPrivateFieldGet(_airAuthListener, this).indexOf(listener) < 0) airService_classPrivateFieldGet(_airAuthListener, this).push(listener);
|
|
2637
|
-
}
|
|
2638
|
-
off(listener) {
|
|
2639
|
-
if (airService_classPrivateFieldGet(_airAuthListener, this).indexOf(listener) >= 0) airService_classPrivateFieldGet(_airAuthListener, this).splice(airService_classPrivateFieldGet(_airAuthListener, this).indexOf(listener), 1);
|
|
2640
|
-
}
|
|
2641
|
-
clearEventListeners() {
|
|
2642
|
-
airService_classPrivateFieldSet(_airAuthListener, this, []);
|
|
2643
|
-
}
|
|
2644
|
-
|
|
2645
|
-
// This is for internal use only
|
|
2646
|
-
// @ts-expect-error for unused function
|
|
2647
|
-
async _showWalletWidget() {
|
|
2648
|
-
await airService_assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
2649
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2650
|
-
return airService_classPrivateFieldGet(_realmEmbed, this)._showWalletWidget();
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
async function _createWallet() {
|
|
2654
|
-
return airService_classPrivateFieldGet(_realmEmbed, this).login({
|
|
2655
|
-
skipClaiming: true,
|
|
2656
|
-
legacy: false
|
|
2657
|
-
});
|
|
2658
|
-
}
|
|
2659
|
-
async function _ensureWallet() {
|
|
2660
|
-
if (!this.isLoggedIn) throw new Error("No active session to create wallet");
|
|
2661
|
-
if (!airService_classPrivateFieldGet(_walletInitialization, this)) {
|
|
2662
|
-
messageService.setupAuthIframe(airService_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
2663
|
-
airService_classPrivateFieldSet(_walletInitialization, this, (async () => {
|
|
2664
|
-
try {
|
|
2665
|
-
await airService_assertClassBrand(_AirService_brand, this, _initializeWallet).call(this);
|
|
2666
|
-
return await airService_assertClassBrand(_AirService_brand, this, _createWallet).call(this);
|
|
2667
|
-
} catch (error) {
|
|
2668
|
-
loglevel.error("Error initializing wallet", error);
|
|
2669
|
-
throw error;
|
|
2670
|
-
}
|
|
2671
|
-
})());
|
|
2672
|
-
}
|
|
2673
|
-
return airService_classPrivateFieldGet(_walletInitialization, this);
|
|
2674
|
-
}
|
|
2675
|
-
async function _cleanUpWallet() {
|
|
2676
|
-
if (airService_classPrivateFieldGet(_walletInitialization, this) || airService_classPrivateFieldGet(_realmEmbed, this)) {
|
|
2677
|
-
await airService_classPrivateFieldGet(_walletInitialization, this);
|
|
2678
|
-
await airService_classPrivateFieldGet(_realmEmbed, this).cleanUp();
|
|
2679
|
-
airService_classPrivateFieldSet(_walletInitialization, this, undefined);
|
|
2680
|
-
}
|
|
2681
1965
|
}
|
|
2682
|
-
async function
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
});
|
|
2690
|
-
airService_classPrivateFieldGet(_authIframeController, this).postMessage({
|
|
2691
|
-
type: AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
|
|
2692
|
-
payload: {
|
|
2693
|
-
success: true
|
|
1966
|
+
_AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airAuthListener = new WeakMap(), _AirService_walletIframeController = new WeakMap(), _AirService_walletInitialization = new WeakMap(), _AirService_isWalletInitialized = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet() {
|
|
1967
|
+
if (!this.isInitialized)
|
|
1968
|
+
throw new Error("Service not initialized");
|
|
1969
|
+
if (!__classPrivateFieldGet(this, _AirService_walletInitialization, "f")) {
|
|
1970
|
+
try {
|
|
1971
|
+
__classPrivateFieldSet(this, _AirService_walletInitialization, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_initializeWallet).call(this), "f");
|
|
1972
|
+
return await __classPrivateFieldGet(this, _AirService_walletInitialization, "f");
|
|
2694
1973
|
}
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
type: AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
|
|
2700
|
-
payload: {
|
|
2701
|
-
success: false,
|
|
2702
|
-
errorName: "UNKNOWN_ERROR",
|
|
2703
|
-
errorMessage: "Unknown error occurred"
|
|
1974
|
+
catch (error) {
|
|
1975
|
+
__classPrivateFieldSet(this, _AirService_walletInitialization, null, "f");
|
|
1976
|
+
log.error("Error initializing wallet", error);
|
|
1977
|
+
throw error;
|
|
2704
1978
|
}
|
|
2705
|
-
});
|
|
2706
|
-
throw error;
|
|
2707
1979
|
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
async
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
1980
|
+
else {
|
|
1981
|
+
return __classPrivateFieldGet(this, _AirService_walletInitialization, "f");
|
|
1982
|
+
}
|
|
1983
|
+
}, _AirService_initializeWallet = async function _AirService_initializeWallet() {
|
|
1984
|
+
if (__classPrivateFieldGet(this, _AirService_isWalletInitialized, "f"))
|
|
1985
|
+
throw new AirServiceError("ALREADY_INITIALISED", "Already initialized");
|
|
1986
|
+
const { walletUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
|
|
1987
|
+
log.info(walletUrl, "url loaded");
|
|
1988
|
+
const walletIframeOrigin = new URL(walletUrl).origin;
|
|
1989
|
+
await AirMessageService$1.openWalletObservables({ walletIframeOrigin });
|
|
1990
|
+
try {
|
|
1991
|
+
__classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(walletUrl, `air-wallet-${randomId()}`), "f");
|
|
1992
|
+
__classPrivateFieldGet(this, _AirService_walletIframeController, "f").createIframe();
|
|
1993
|
+
AirMessageService$1.messages$.subscribe(async (msg) => {
|
|
1994
|
+
switch (msg.type) {
|
|
1995
|
+
case AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST: {
|
|
1996
|
+
const walletIframeController = __classPrivateFieldGet(this, _AirService_walletIframeController, "f");
|
|
1997
|
+
walletIframeController.setIframeVisibility(msg.payload.visible);
|
|
1998
|
+
walletIframeController.updateIframeState();
|
|
1999
|
+
break;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
await new Promise((resolve, reject) => {
|
|
2004
|
+
const handleAuthMessage = async (ev) => {
|
|
2005
|
+
if (ev.origin !== walletIframeOrigin)
|
|
2006
|
+
return;
|
|
2007
|
+
if (ev.data === AirMessageTypes.SERVICE_STARTED) {
|
|
2008
|
+
window.removeEventListener("message", handleAuthMessage);
|
|
2009
|
+
const { payload } = await AirMessageService$1.sendWalletInitializationRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, {
|
|
2010
|
+
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
2011
|
+
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
2012
|
+
});
|
|
2013
|
+
if (payload.success === true) {
|
|
2014
|
+
resolve();
|
|
2015
|
+
}
|
|
2016
|
+
else {
|
|
2017
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
};
|
|
2021
|
+
window.addEventListener("message", handleAuthMessage);
|
|
2022
|
+
});
|
|
2023
|
+
const walletInitPromise = AirMessageService$1.onWalletInitialized();
|
|
2024
|
+
AirMessageService$1.setupIframeCommunication(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement, __classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
|
|
2025
|
+
const walletInitResult = await walletInitPromise;
|
|
2026
|
+
if (walletInitResult.payload.success !== true) {
|
|
2027
|
+
throw new AirServiceError(walletInitResult.payload.errorName, walletInitResult.payload.errorMessage);
|
|
2748
2028
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
airService_assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
2756
|
-
event: "minting_started"
|
|
2757
|
-
});
|
|
2758
|
-
} else if (data.event === "minting_failed") {
|
|
2759
|
-
airService_assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
2760
|
-
event: "minting_failed",
|
|
2761
|
-
errorMessage: data.errorMessage
|
|
2762
|
-
});
|
|
2029
|
+
__classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement), "f");
|
|
2030
|
+
const result = {
|
|
2031
|
+
abstractAccountAddress: walletInitResult.payload.addresses.aa,
|
|
2032
|
+
};
|
|
2033
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerWalletInitialized).call(this, result);
|
|
2034
|
+
return result;
|
|
2763
2035
|
}
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2036
|
+
catch (error) {
|
|
2037
|
+
log.error("Error initializing wallet", error);
|
|
2038
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
2039
|
+
throw error;
|
|
2040
|
+
}
|
|
2041
|
+
}, _AirService_triggerEventListeners = function _AirService_triggerEventListeners(data) {
|
|
2042
|
+
__classPrivateFieldGet(this, _AirService_airAuthListener, "f").forEach((listener) => {
|
|
2043
|
+
listener(data);
|
|
2044
|
+
});
|
|
2045
|
+
}, _AirService_triggerAirAuthInitialized = function _AirService_triggerAirAuthInitialized(result) {
|
|
2046
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerEventListeners).call(this, { event: "initialized", result });
|
|
2047
|
+
}, _AirService_triggerAirAuthLoggedIn = function _AirService_triggerAirAuthLoggedIn() {
|
|
2048
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerEventListeners).call(this, {
|
|
2049
|
+
event: "logged_in",
|
|
2050
|
+
result: __classPrivateFieldGet(this, _AirService_loginResult, "f"),
|
|
2051
|
+
});
|
|
2052
|
+
}, _AirService_triggerAirAuthLoggedOut = function _AirService_triggerAirAuthLoggedOut() {
|
|
2053
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerEventListeners).call(this, { event: "logged_out" });
|
|
2054
|
+
}, _AirService_triggerWalletInitialized = function _AirService_triggerWalletInitialized(result) {
|
|
2055
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerEventListeners).call(this, {
|
|
2056
|
+
event: "wallet_initialized",
|
|
2057
|
+
result,
|
|
2058
|
+
});
|
|
2059
|
+
}, _AirService_createLoginResult = function _AirService_createLoginResult(payload) {
|
|
2060
|
+
return {
|
|
2061
|
+
isLoggedIn: true,
|
|
2062
|
+
id: payload.id,
|
|
2063
|
+
abstractAccountAddress: payload.abstractAccountAddress,
|
|
2064
|
+
token: payload.partnerAccessToken,
|
|
2065
|
+
};
|
|
2066
|
+
}, _AirService_cleanUpAuth = async function _AirService_cleanUpAuth() {
|
|
2067
|
+
// Logout auth session
|
|
2068
|
+
await AirMessageService$1.logoutAuth(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
|
|
2069
|
+
// Destroy the auth iframe
|
|
2070
|
+
const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
|
|
2071
|
+
if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
2072
|
+
__classPrivateFieldGet(this, _AirService_authIframeController, "f").destroy();
|
|
2073
|
+
__classPrivateFieldSet(this, _AirService_authIframeController, undefined, "f");
|
|
2074
|
+
}
|
|
2075
|
+
// Close the message service
|
|
2076
|
+
AirMessageService$1.closeAuthObservables();
|
|
2077
|
+
__classPrivateFieldSet(this, _AirService_isAuthInitialized, false, "f");
|
|
2078
|
+
}, _AirService_cleanUpWallet = async function _AirService_cleanUpWallet() {
|
|
2079
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2080
|
+
return;
|
|
2081
|
+
// Logout wallet and destroy the wallet iframe
|
|
2082
|
+
const walletIframeElement = __classPrivateFieldGet(this, _AirService_walletIframeController, "f")?.iframeElement;
|
|
2083
|
+
if (isElement(walletIframeElement) && window.document.body.contains(walletIframeElement)) {
|
|
2084
|
+
await AirMessageService$1.logoutWallet(walletIframeElement);
|
|
2085
|
+
__classPrivateFieldGet(this, _AirService_walletIframeController, "f").destroy();
|
|
2086
|
+
__classPrivateFieldSet(this, _AirService_walletIframeController, undefined, "f");
|
|
2087
|
+
}
|
|
2088
|
+
// Close the message service
|
|
2089
|
+
AirMessageService$1.closeAirObservables();
|
|
2090
|
+
__classPrivateFieldSet(this, _AirService_walletInitialization, null, "f");
|
|
2091
|
+
__classPrivateFieldSet(this, _AirService_isWalletInitialized, false, "f");
|
|
2092
|
+
};
|
|
2771
2093
|
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
;
|
|
2094
|
+
exports.AirService = AirService;
|
|
2095
|
+
exports.AirServiceError = AirServiceError;
|
|
2096
|
+
exports.AirWalletProvider = AirWalletProvider;
|
|
2097
|
+
exports.BUILD_ENV = BUILD_ENV;
|
|
2098
|
+
exports.RealmEmbedError = RealmEmbedError;
|