@mocanetwork/airkit 0.5.0 → 0.6.0-beta.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 +2637 -2565
- package/dist/airkit.esm.js +2645 -2383
- package/dist/airkit.umd.js +2852 -0
- package/dist/types/airService.d.ts +12 -11
- 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 +14 -15
- package/dist/types/common/realm/messaging/provider.d.ts +32 -0
- package/dist/types/common/realm/messaging/types.d.ts +29 -10
- package/dist/types/common/realm/partner/config.d.ts +0 -32
- package/dist/types/common/realm/smart-session/types.d.ts +1 -1
- package/dist/types/common/realm/user/types.d.ts +0 -28
- package/dist/types/common/utils.d.ts +16 -0
- package/dist/types/error.d.ts +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/types/interfaces.d.ts +18 -181
- package/dist/types/messageService.d.ts +18 -20
- 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
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* The buffer module from node.js, for the browser.
|
|
3
|
-
*
|
|
4
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
9
|
-
|
|
10
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
-
|
|
12
|
-
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class BaseError extends Error {
|
|
4
|
-
constructor(name, message, options = {}) {
|
|
5
|
-
const {
|
|
6
|
-
cause,
|
|
7
|
-
context
|
|
8
|
-
} = options;
|
|
9
|
-
super(message || name);
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.stack = cause === null || cause === void 0 ? void 0 : cause.stack;
|
|
12
|
-
this.cause = cause;
|
|
13
|
-
this.context = context;
|
|
14
|
-
}
|
|
15
|
-
toJSON() {
|
|
16
|
-
return {
|
|
17
|
-
name: this.name,
|
|
18
|
-
message: this.message,
|
|
19
|
-
context: this.context,
|
|
20
|
-
cause: this.cause
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.BaseError = BaseError;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const AirAuthMessageTypes = {
|
|
4
|
-
SETUP_COMPLETED: "air_auth_setup_completed",
|
|
5
|
-
LOGIN_REQUEST: "air_auth_login_request",
|
|
6
|
-
LOGIN_RESPONSE: "air_auth_login_response",
|
|
7
|
-
LOGIN_WALLET_RESPONSE: "air_auth_login_wallet_response",
|
|
8
|
-
USER_INFO_REQUEST: "air_auth_user_info_request",
|
|
9
|
-
USER_INFO_RESPONSE: "air_auth_user_info_response",
|
|
10
|
-
PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
|
|
11
|
-
PARTNER_USER_INFO_RESPONSE: "air_auth_partner_user_info_response",
|
|
12
|
-
REFRESH_TOKEN_REQUEST: "air_auth_refresh_token_request",
|
|
13
|
-
REFRESH_TOKEN_RESPONSE: "air_auth_refresh_token_response",
|
|
14
|
-
WALLET_TOKEN_REQUEST: "air_auth_wallet_token_request",
|
|
15
|
-
WALLET_TOKEN_RESPONSE: "air_auth_wallet_token_response",
|
|
16
|
-
INITIALIZATION_REQUEST: "air_auth_initialization_request",
|
|
17
|
-
INITIALIZATION_RESPONSE: "air_auth_initialization_response",
|
|
18
|
-
INIT_WALLET_COMMUNICATION: "air_auth_init_wallet_communication",
|
|
19
|
-
IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
|
|
20
|
-
SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
|
|
21
|
-
SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response",
|
|
22
|
-
SIGN_SIWE_MESSAGE_REQUEST: "air_auth_sign_siwe_message_request",
|
|
23
|
-
SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
|
|
24
|
-
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
25
|
-
LOGOUT_RESPONSE: "air_auth_logout_response"
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
exports.AirAuthMessageTypes = AirAuthMessageTypes;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const AirMessageTypes = {
|
|
4
|
-
SERVICE_INITIALIZED: "air_service_initialized",
|
|
5
|
-
SERVICE_INITIALIZED_ERROR: "air_service_initialized_error",
|
|
6
|
-
LOGIN_REQUEST: "air_login_request",
|
|
7
|
-
CLAIM_REQUEST: "air_claim_request",
|
|
8
|
-
LOGIN_CLAIM_STATE: "air_login_claim_state",
|
|
9
|
-
CLOSE_MODAL: "air_close_modal",
|
|
10
|
-
INIT_AUTH_COMMUNICATION: "air_init_auth_communication",
|
|
11
|
-
DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
|
|
12
|
-
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
|
|
13
|
-
GRANT_PERMISSIONS_REQUEST: "air_grant_permissions_request",
|
|
14
|
-
GRANT_PERMISSIONS_RESPONSE: "air_grant_permissions_response",
|
|
15
|
-
EXECUTE_ACTION_REQUEST: "air_execute_action_request",
|
|
16
|
-
EXECUTE_ACTION_RESPONSE: "air_execute_action_response",
|
|
17
|
-
REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request",
|
|
18
|
-
REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response"
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
exports.AirMessageTypes = AirMessageTypes;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
-
var baseControllers = require('@toruslabs/base-controllers');
|
|
5
|
-
var auth = require('@web3auth/auth');
|
|
6
|
-
|
|
7
|
-
class PopupHandler extends auth.SafeEventEmitter {
|
|
8
|
-
constructor({
|
|
9
|
-
url,
|
|
10
|
-
target,
|
|
11
|
-
features,
|
|
12
|
-
timeout = 30000
|
|
13
|
-
}) {
|
|
14
|
-
super();
|
|
15
|
-
_defineProperty(this, "url", void 0);
|
|
16
|
-
_defineProperty(this, "target", void 0);
|
|
17
|
-
_defineProperty(this, "features", void 0);
|
|
18
|
-
_defineProperty(this, "window", void 0);
|
|
19
|
-
_defineProperty(this, "windowTimer", void 0);
|
|
20
|
-
_defineProperty(this, "iClosedWindow", void 0);
|
|
21
|
-
_defineProperty(this, "timeout", void 0);
|
|
22
|
-
this.url = url;
|
|
23
|
-
this.target = target || "_blank";
|
|
24
|
-
this.features = features || baseControllers.getPopupFeatures(baseControllers.FEATURES_DEFAULT_POPUP_WINDOW);
|
|
25
|
-
this.window = undefined;
|
|
26
|
-
this.windowTimer = undefined;
|
|
27
|
-
this.iClosedWindow = false;
|
|
28
|
-
this.timeout = timeout;
|
|
29
|
-
this._setupTimer();
|
|
30
|
-
}
|
|
31
|
-
_setupTimer() {
|
|
32
|
-
this.windowTimer = Number(setInterval(() => {
|
|
33
|
-
if (this.window && this.window.closed) {
|
|
34
|
-
clearInterval(this.windowTimer);
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
if (!this.iClosedWindow) {
|
|
37
|
-
this.emit("close");
|
|
38
|
-
}
|
|
39
|
-
this.iClosedWindow = false;
|
|
40
|
-
this.window = undefined;
|
|
41
|
-
}, this.timeout);
|
|
42
|
-
}
|
|
43
|
-
if (this.window === undefined) clearInterval(this.windowTimer);
|
|
44
|
-
}, 500));
|
|
45
|
-
}
|
|
46
|
-
open() {
|
|
47
|
-
var _this$window;
|
|
48
|
-
this.window = window.open(this.url.href, this.target, this.features);
|
|
49
|
-
if ((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.focus) this.window.focus();
|
|
50
|
-
}
|
|
51
|
-
close() {
|
|
52
|
-
this.iClosedWindow = true;
|
|
53
|
-
if (this.window) this.window.close();
|
|
54
|
-
}
|
|
55
|
-
redirect(locationReplaceOnRedirect) {
|
|
56
|
-
if (locationReplaceOnRedirect) {
|
|
57
|
-
window.location.replace(this.url.href);
|
|
58
|
-
} else {
|
|
59
|
-
window.location.href = this.url.href;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
module.exports = PopupHandler;
|
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
4
|
-
var _classPrivateMethodInitSpec = require('@babel/runtime/helpers/classPrivateMethodInitSpec');
|
|
5
|
-
var _classPrivateFieldInitSpec = require('@babel/runtime/helpers/classPrivateFieldInitSpec');
|
|
6
|
-
var baseControllers = require('@toruslabs/base-controllers');
|
|
7
|
-
var auth = require('../../common/src/realm/messaging/auth.js');
|
|
8
|
-
var embed = require('./embed.js');
|
|
9
|
-
var error = require('./error.js');
|
|
10
|
-
var iframeController = require('./iframeController.js');
|
|
11
|
-
var interfaces = require('./interfaces.js');
|
|
12
|
-
var loglevel = require('./loglevel.js');
|
|
13
|
-
var messageService = require('./messageService.js');
|
|
14
|
-
var utils = require('./utils.js');
|
|
15
|
-
|
|
16
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
17
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
18
|
-
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"); }
|
|
19
|
-
var _authIframeController = /*#__PURE__*/new WeakMap();
|
|
20
|
-
var _loginResult = /*#__PURE__*/new WeakMap();
|
|
21
|
-
var _buildEnv = /*#__PURE__*/new WeakMap();
|
|
22
|
-
var _embedNonce = /*#__PURE__*/new WeakMap();
|
|
23
|
-
var _enableLogging = /*#__PURE__*/new WeakMap();
|
|
24
|
-
var _isInitialized = /*#__PURE__*/new WeakMap();
|
|
25
|
-
var _partnerId = /*#__PURE__*/new WeakMap();
|
|
26
|
-
var _realmEmbed = /*#__PURE__*/new WeakMap();
|
|
27
|
-
var _walletInitialization = /*#__PURE__*/new WeakMap();
|
|
28
|
-
var _airAuthListener = /*#__PURE__*/new WeakMap();
|
|
29
|
-
var _AirService_brand = /*#__PURE__*/new WeakSet();
|
|
30
|
-
class AirService {
|
|
31
|
-
constructor({
|
|
32
|
-
partnerId
|
|
33
|
-
}) {
|
|
34
|
-
_classPrivateMethodInitSpec(this, _AirService_brand);
|
|
35
|
-
_classPrivateFieldInitSpec(this, _authIframeController, void 0);
|
|
36
|
-
_classPrivateFieldInitSpec(this, _loginResult, void 0);
|
|
37
|
-
_classPrivateFieldInitSpec(this, _buildEnv, void 0);
|
|
38
|
-
_classPrivateFieldInitSpec(this, _embedNonce, baseControllers.randomId());
|
|
39
|
-
_classPrivateFieldInitSpec(this, _enableLogging, false);
|
|
40
|
-
_classPrivateFieldInitSpec(this, _isInitialized, false);
|
|
41
|
-
_classPrivateFieldInitSpec(this, _partnerId, void 0);
|
|
42
|
-
// Realm Embed related
|
|
43
|
-
_classPrivateFieldInitSpec(this, _realmEmbed, void 0);
|
|
44
|
-
_classPrivateFieldInitSpec(this, _walletInitialization, void 0);
|
|
45
|
-
_classPrivateFieldInitSpec(this, _airAuthListener, []);
|
|
46
|
-
_classPrivateFieldSet(_partnerId, this, partnerId);
|
|
47
|
-
_classPrivateFieldSet(_realmEmbed, this, new embed.default({
|
|
48
|
-
partnerId: _classPrivateFieldGet(_partnerId, this)
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
get buildEnv() {
|
|
52
|
-
return _classPrivateFieldGet(_buildEnv, this);
|
|
53
|
-
}
|
|
54
|
-
get isAirAuth() {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
get isInitialized() {
|
|
58
|
-
return _classPrivateFieldGet(_isInitialized, this);
|
|
59
|
-
}
|
|
60
|
-
get isLoggedIn() {
|
|
61
|
-
return !!_classPrivateFieldGet(_loginResult, this);
|
|
62
|
-
}
|
|
63
|
-
get isWalletLoaded() {
|
|
64
|
-
var _classPrivateFieldGet2;
|
|
65
|
-
return (_classPrivateFieldGet2 = _classPrivateFieldGet(_realmEmbed, this)) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.isInitialized;
|
|
66
|
-
}
|
|
67
|
-
async init({
|
|
68
|
-
buildEnv = interfaces.EMBED_BUILD_ENV.PRODUCTION,
|
|
69
|
-
enableLogging = false,
|
|
70
|
-
skipRehydration = false
|
|
71
|
-
}) {
|
|
72
|
-
if (!_classPrivateFieldGet(_partnerId, this)) throw new Error("Partner ID is required to initialize auth service");
|
|
73
|
-
if (_classPrivateFieldGet(_isInitialized, this)) return;
|
|
74
|
-
_classPrivateFieldSet(_buildEnv, this, buildEnv);
|
|
75
|
-
_classPrivateFieldSet(_enableLogging, this, enableLogging);
|
|
76
|
-
const {
|
|
77
|
-
authUrl,
|
|
78
|
-
logLevel
|
|
79
|
-
} = utils.AIR_URLS[buildEnv];
|
|
80
|
-
loglevel.setDefaultLevel(logLevel);
|
|
81
|
-
if (_classPrivateFieldGet(_enableLogging, this)) loglevel.enableAll();else loglevel.disableAll();
|
|
82
|
-
const authIframeOrigin = new URL(authUrl).origin;
|
|
83
|
-
await messageService.openAuthObservables({
|
|
84
|
-
authIframeOrigin
|
|
85
|
-
});
|
|
86
|
-
_classPrivateFieldSet(_authIframeController, this, new iframeController.IframeController(authUrl, `air-login-${_classPrivateFieldGet(_embedNonce, this)}`));
|
|
87
|
-
messageService.authMessage$.subscribe(async msg => {
|
|
88
|
-
switch (msg.type) {
|
|
89
|
-
case auth.AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST:
|
|
90
|
-
{
|
|
91
|
-
const authIframeController = _classPrivateFieldGet(_authIframeController, this);
|
|
92
|
-
authIframeController.setIframeVisibility(msg.payload.visible);
|
|
93
|
-
authIframeController.updateIframeState();
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
case auth.AirAuthMessageTypes.SETUP_WALLET_REQUEST:
|
|
97
|
-
{
|
|
98
|
-
await _assertClassBrand(_AirService_brand, this, _initializeWallet).call(this);
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
try {
|
|
104
|
-
_classPrivateFieldGet(_authIframeController, this).createIframe();
|
|
105
|
-
const initializationPromise = new Promise((resolve, reject) => {
|
|
106
|
-
const handleAuthMessage = ev => {
|
|
107
|
-
try {
|
|
108
|
-
if (ev.origin !== authIframeOrigin) return;
|
|
109
|
-
if (ev.data === auth.AirAuthMessageTypes.SETUP_COMPLETED) {
|
|
110
|
-
window.removeEventListener("message", handleAuthMessage);
|
|
111
|
-
_classPrivateFieldGet(_authIframeController, this).postMessage({
|
|
112
|
-
type: auth.AirAuthMessageTypes.INITIALIZATION_REQUEST,
|
|
113
|
-
payload: {
|
|
114
|
-
partnerId: _classPrivateFieldGet(_partnerId, this),
|
|
115
|
-
skipRehydration
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
resolve();
|
|
119
|
-
}
|
|
120
|
-
} catch (err) {
|
|
121
|
-
reject(err);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
window.addEventListener("message", handleAuthMessage);
|
|
125
|
-
});
|
|
126
|
-
const authServiceInitialization = messageService.waitForAuthInitialization();
|
|
127
|
-
const result = await Promise.all([initializationPromise, authServiceInitialization]);
|
|
128
|
-
_classPrivateFieldSet(_isInitialized, this, true);
|
|
129
|
-
_assertClassBrand(_AirService_brand, this, _triggerAirAuthInitialized).call(this, {
|
|
130
|
-
rehydrated: result[1].rehydrated
|
|
131
|
-
});
|
|
132
|
-
_assertClassBrand(_AirService_brand, this, _prepareRealmEmbedListeners).call(this);
|
|
133
|
-
|
|
134
|
-
// rehydrated auth session
|
|
135
|
-
if (result[1].rehydrated) {
|
|
136
|
-
_classPrivateFieldSet(_loginResult, this, _assertClassBrand(_AirService_brand, this, _createLoginResult).call(this, result[1]));
|
|
137
|
-
_assertClassBrand(_AirService_brand, this, _triggerAirAuthLoggedIn).call(this);
|
|
138
|
-
return _classPrivateFieldGet(_loginResult, this);
|
|
139
|
-
}
|
|
140
|
-
} catch (error) {
|
|
141
|
-
loglevel.debug("Error initializing auth service", error);
|
|
142
|
-
await this.cleanUp();
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
async cleanUp() {
|
|
148
|
-
var _classPrivateFieldGet3;
|
|
149
|
-
// Clear up wallet service iframe if exists
|
|
150
|
-
await _assertClassBrand(_AirService_brand, this, _cleanUpWallet).call(this);
|
|
151
|
-
|
|
152
|
-
// Logout auth session
|
|
153
|
-
await messageService.logoutAuth(_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
154
|
-
|
|
155
|
-
// Destroy the auth iframe
|
|
156
|
-
const authIframeElement = (_classPrivateFieldGet3 = _classPrivateFieldGet(_authIframeController, this)) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.iframeElement;
|
|
157
|
-
if (utils.isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
158
|
-
_classPrivateFieldGet(_authIframeController, this).destroy();
|
|
159
|
-
_classPrivateFieldSet(_authIframeController, this, undefined);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Close the message service
|
|
163
|
-
messageService.closeAuthObservables();
|
|
164
|
-
this.clearEventListeners();
|
|
165
|
-
_classPrivateFieldSet(_isInitialized, this, false);
|
|
166
|
-
}
|
|
167
|
-
async login(options) {
|
|
168
|
-
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Service is not initialized");
|
|
169
|
-
if (_classPrivateFieldGet(_loginResult, this)) return _classPrivateFieldGet(_loginResult, this);
|
|
170
|
-
const iframeController = _classPrivateFieldGet(_authIframeController, this);
|
|
171
|
-
const {
|
|
172
|
-
payload
|
|
173
|
-
} = await messageService.sendAuthLoginRequest(iframeController.iframeElement, {
|
|
174
|
-
partnerLoginToken: options === null || options === void 0 ? void 0 : options.authToken
|
|
175
|
-
});
|
|
176
|
-
if (payload.success === true) {
|
|
177
|
-
_classPrivateFieldSet(_loginResult, this, _assertClassBrand(_AirService_brand, this, _createLoginResult).call(this, payload));
|
|
178
|
-
_assertClassBrand(_AirService_brand, this, _triggerAirAuthLoggedIn).call(this);
|
|
179
|
-
return _classPrivateFieldGet(_loginResult, this);
|
|
180
|
-
}
|
|
181
|
-
throw new error.AirServiceError("UNKNOWN_ERROR", "Unknown error occurred");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* @experimental This method is experimental and will change in the future.
|
|
186
|
-
*/
|
|
187
|
-
async deploySmartAccount() {
|
|
188
|
-
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Service is not initialized");
|
|
189
|
-
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
190
|
-
return _classPrivateFieldGet(_realmEmbed, this)._deploySmartAccount();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @experimental This method is experimental and will change in the future.
|
|
195
|
-
*/
|
|
196
|
-
async grantPermission(policies) {
|
|
197
|
-
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
198
|
-
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
199
|
-
return _classPrivateFieldGet(_realmEmbed, this)._grantPermission(policies);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* @experimental This method is experimental and will change in the future.
|
|
204
|
-
*/
|
|
205
|
-
async executeAction(params) {
|
|
206
|
-
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
207
|
-
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
208
|
-
return _classPrivateFieldGet(_realmEmbed, this)._executeAction(params);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* @experimental This method is experimental and will change in the future.
|
|
213
|
-
*/
|
|
214
|
-
async revokePermission(permissionId) {
|
|
215
|
-
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
216
|
-
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
217
|
-
return _classPrivateFieldGet(_realmEmbed, this)._revokePermission(permissionId);
|
|
218
|
-
}
|
|
219
|
-
async logout() {
|
|
220
|
-
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Service is not initialized");
|
|
221
|
-
if (!this.isLoggedIn) throw new Error("No active session to logout");
|
|
222
|
-
|
|
223
|
-
// Clear up wallet
|
|
224
|
-
await _assertClassBrand(_AirService_brand, this, _cleanUpWallet).call(this);
|
|
225
|
-
await messageService.logoutAuth(_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
226
|
-
_classPrivateFieldSet(_loginResult, this, undefined);
|
|
227
|
-
_assertClassBrand(_AirService_brand, this, _triggerAirAuthLoggedOut).call(this);
|
|
228
|
-
}
|
|
229
|
-
async getProvider() {
|
|
230
|
-
if (!this.isLoggedIn) return null;
|
|
231
|
-
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
232
|
-
return _classPrivateFieldGet(_realmEmbed, this).provider;
|
|
233
|
-
}
|
|
234
|
-
async preloadWallet() {
|
|
235
|
-
return _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
236
|
-
}
|
|
237
|
-
async claimAirId(options) {
|
|
238
|
-
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
239
|
-
return _classPrivateFieldGet(_realmEmbed, this).claimRealmId(options);
|
|
240
|
-
}
|
|
241
|
-
async getUserInfo() {
|
|
242
|
-
if (!this.isLoggedIn) throw new Error("User not logged in");
|
|
243
|
-
const info = await messageService.sendUserInfoRequest(_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
244
|
-
if (info.payload.success === false) {
|
|
245
|
-
throw new error.AirServiceError(info.payload.errorName, info.payload.errorMessage);
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
id: info.payload.id,
|
|
249
|
-
abstractAccountAddress: info.payload.abstractAccountAddress,
|
|
250
|
-
email: info.payload.email,
|
|
251
|
-
airIds: info.payload.airIds
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async getPartnerUserInfo() {
|
|
255
|
-
if (!this.isLoggedIn) throw new Error("User not logged in");
|
|
256
|
-
const info = await messageService.sendPartnerUserInfoRequest(_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
257
|
-
if (info.payload.success === false) {
|
|
258
|
-
throw new error.AirServiceError(info.payload.errorName, info.payload.errorMessage);
|
|
259
|
-
}
|
|
260
|
-
return {
|
|
261
|
-
partnerId: info.payload.partnerId,
|
|
262
|
-
partnerUserId: info.payload.partnerUserId,
|
|
263
|
-
airId: info.payload.airId
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
on(listener) {
|
|
267
|
-
if (_classPrivateFieldGet(_airAuthListener, this).indexOf(listener) < 0) _classPrivateFieldGet(_airAuthListener, this).push(listener);
|
|
268
|
-
}
|
|
269
|
-
off(listener) {
|
|
270
|
-
if (_classPrivateFieldGet(_airAuthListener, this).indexOf(listener) >= 0) _classPrivateFieldGet(_airAuthListener, this).splice(_classPrivateFieldGet(_airAuthListener, this).indexOf(listener), 1);
|
|
271
|
-
}
|
|
272
|
-
clearEventListeners() {
|
|
273
|
-
_classPrivateFieldSet(_airAuthListener, this, []);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// This is for internal use only
|
|
277
|
-
// @ts-expect-error for unused function
|
|
278
|
-
async _showWalletWidget() {
|
|
279
|
-
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
280
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
281
|
-
return _classPrivateFieldGet(_realmEmbed, this)._showWalletWidget();
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
async function _createWallet() {
|
|
285
|
-
return _classPrivateFieldGet(_realmEmbed, this).login({
|
|
286
|
-
skipClaiming: true,
|
|
287
|
-
legacy: false
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
async function _ensureWallet() {
|
|
291
|
-
if (!this.isLoggedIn) throw new Error("No active session to create wallet");
|
|
292
|
-
if (!_classPrivateFieldGet(_walletInitialization, this)) {
|
|
293
|
-
messageService.setupAuthIframe(_classPrivateFieldGet(_authIframeController, this).iframeElement);
|
|
294
|
-
_classPrivateFieldSet(_walletInitialization, this, (async () => {
|
|
295
|
-
try {
|
|
296
|
-
await _assertClassBrand(_AirService_brand, this, _initializeWallet).call(this);
|
|
297
|
-
return await _assertClassBrand(_AirService_brand, this, _createWallet).call(this);
|
|
298
|
-
} catch (error) {
|
|
299
|
-
loglevel.error("Error initializing wallet", error);
|
|
300
|
-
throw error;
|
|
301
|
-
}
|
|
302
|
-
})());
|
|
303
|
-
}
|
|
304
|
-
return _classPrivateFieldGet(_walletInitialization, this);
|
|
305
|
-
}
|
|
306
|
-
async function _cleanUpWallet() {
|
|
307
|
-
if (_classPrivateFieldGet(_walletInitialization, this) || _classPrivateFieldGet(_realmEmbed, this)) {
|
|
308
|
-
await _classPrivateFieldGet(_walletInitialization, this);
|
|
309
|
-
await _classPrivateFieldGet(_realmEmbed, this).cleanUp();
|
|
310
|
-
_classPrivateFieldSet(_walletInitialization, this, undefined);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
async function _initializeWallet() {
|
|
314
|
-
if (!_classPrivateFieldGet(_realmEmbed, this).isInitialized) {
|
|
315
|
-
try {
|
|
316
|
-
await _classPrivateFieldGet(_realmEmbed, this).init({
|
|
317
|
-
buildEnv: _classPrivateFieldGet(_buildEnv, this),
|
|
318
|
-
skipRehydration: true,
|
|
319
|
-
enableLogging: _classPrivateFieldGet(_enableLogging, this) || false
|
|
320
|
-
});
|
|
321
|
-
_classPrivateFieldGet(_authIframeController, this).postMessage({
|
|
322
|
-
type: auth.AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
|
|
323
|
-
payload: {
|
|
324
|
-
success: true
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
} catch (error) {
|
|
328
|
-
loglevel.error("Error initializing wallet", error);
|
|
329
|
-
_classPrivateFieldGet(_authIframeController, this).postMessage({
|
|
330
|
-
type: auth.AirAuthMessageTypes.SETUP_WALLET_RESPONSE,
|
|
331
|
-
payload: {
|
|
332
|
-
success: false,
|
|
333
|
-
errorName: "UNKNOWN_ERROR",
|
|
334
|
-
errorMessage: "Unknown error occurred"
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
throw error;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
async function _triggerEventListeners(data) {
|
|
342
|
-
_classPrivateFieldGet(_airAuthListener, this).forEach(listener => {
|
|
343
|
-
listener(data);
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
async function _triggerAirAuthInitialized(result) {
|
|
347
|
-
await _assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
348
|
-
event: "initialized",
|
|
349
|
-
result
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
async function _triggerAirAuthLoggedIn() {
|
|
353
|
-
await _assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
354
|
-
event: "logged_in",
|
|
355
|
-
result: _classPrivateFieldGet(_loginResult, this)
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
async function _triggerAirAuthLoggedOut() {
|
|
359
|
-
await _assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
360
|
-
event: "logged_out"
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
function _createLoginResult(payload) {
|
|
364
|
-
return {
|
|
365
|
-
isLoggedIn: true,
|
|
366
|
-
id: payload.id,
|
|
367
|
-
abstractAccountAddress: payload.abstractAccountAddress,
|
|
368
|
-
token: payload.partnerAccessToken
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
async function _prepareRealmEmbedListeners() {
|
|
372
|
-
_classPrivateFieldGet(_realmEmbed, this).on(data => {
|
|
373
|
-
if (data.event === "connected" || data.event === "logged_in") {
|
|
374
|
-
var _data$result$addresse;
|
|
375
|
-
const result = _objectSpread(_objectSpread({}, data.result), {}, {
|
|
376
|
-
addresses: {
|
|
377
|
-
eoa: data.result.addresses.eoa,
|
|
378
|
-
aa: (_data$result$addresse = data.result.addresses.aa) !== null && _data$result$addresse !== void 0 ? _data$result$addresse : ""
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
_assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
382
|
-
event: "wallet_loaded",
|
|
383
|
-
result
|
|
384
|
-
});
|
|
385
|
-
} else if (data.event === "minting_started") {
|
|
386
|
-
_assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
387
|
-
event: "minting_started"
|
|
388
|
-
});
|
|
389
|
-
} else if (data.event === "minting_failed") {
|
|
390
|
-
_assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
391
|
-
event: "minting_failed",
|
|
392
|
-
errorMessage: data.errorMessage
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
module.exports = AirService;
|