@mocanetwork/airkit 1.2.0-beta.0 → 1.2.0-beta.2
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 +276 -38
- package/dist/airkit.esm.js +276 -39
- package/dist/airkit.umd.js +276 -38
- package/dist/types/airService.d.ts +3 -1
- package/dist/types/airWalletProvider.d.ts +1 -1
- package/dist/types/common/realm/messaging/auth.d.ts +7 -7
- package/dist/types/common/realm/messaging/types.d.ts +15 -2
- package/dist/types/common/utils.d.ts +3 -2
- package/dist/types/error.d.ts +4 -0
- package/dist/types/interfaces.d.ts +1 -0
- package/dist/types/messageService.d.ts +4 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/windowController.d.ts +19 -0
- package/dist/types/windowService.d.ts +18 -0
- package/package.json +1 -1
package/dist/airkit.cjs.js
CHANGED
|
@@ -120,8 +120,8 @@ const AirAuthMessageTypes = {
|
|
|
120
120
|
SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
|
|
121
121
|
CROSS_PARTNER_TOKEN_REQUEST: "air_auth_cross_partner_token_request",
|
|
122
122
|
CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
|
|
124
|
+
PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
|
|
125
125
|
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
126
126
|
LOGOUT_RESPONSE: "air_auth_logout_response",
|
|
127
127
|
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication"
|
|
@@ -150,6 +150,9 @@ const AirMessageTypes = {
|
|
|
150
150
|
LIST_ALL_SESSION_KEY_SCOPES_REQUEST: "air_list_all_session_key_scopes_request",
|
|
151
151
|
LIST_ALL_SESSION_KEY_SCOPES_RESPONSE: "air_list_all_session_key_scopes_response",
|
|
152
152
|
WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request",
|
|
153
|
+
OPEN_WINDOW_REQUEST: "air_open_window_request",
|
|
154
|
+
OPEN_WINDOW_RESPONSE: "air_open_window_response",
|
|
155
|
+
WINDOW_CLOSED: "air_window_closed",
|
|
153
156
|
IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
|
|
154
157
|
IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
|
|
155
158
|
LOGOUT_REQUEST: "air_logout_request",
|
|
@@ -177,6 +180,16 @@ class BaseError extends Error {
|
|
|
177
180
|
};
|
|
178
181
|
}
|
|
179
182
|
}
|
|
183
|
+
function ensureError(value) {
|
|
184
|
+
if (value instanceof Error) return value;
|
|
185
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
186
|
+
try {
|
|
187
|
+
stringified = JSON.stringify(value);
|
|
188
|
+
} catch {
|
|
189
|
+
// ignoring failed stringify
|
|
190
|
+
}
|
|
191
|
+
return new Error(`This value was not thrown as type Error: ${stringified}`);
|
|
192
|
+
}
|
|
180
193
|
|
|
181
194
|
class AirServiceError extends BaseError {
|
|
182
195
|
static from(error) {
|
|
@@ -239,6 +252,13 @@ class SwitchChainError extends ProviderRpcError {
|
|
|
239
252
|
this.name = "SwitchChainError";
|
|
240
253
|
}
|
|
241
254
|
}
|
|
255
|
+
class TransactionRejectedRpcError extends ProviderRpcError {
|
|
256
|
+
constructor() {
|
|
257
|
+
super(...arguments);
|
|
258
|
+
this.code = -32003;
|
|
259
|
+
this.name = "TransactionRejectedRpcError";
|
|
260
|
+
}
|
|
261
|
+
}
|
|
242
262
|
class InvalidRequestRpcError extends ProviderRpcError {
|
|
243
263
|
constructor() {
|
|
244
264
|
super(...arguments);
|
|
@@ -289,6 +309,8 @@ function ensureProviderRpcError(value) {
|
|
|
289
309
|
return new ChainDisconnectedError(value.errorMessage);
|
|
290
310
|
case 4902:
|
|
291
311
|
return new SwitchChainError(value.errorMessage);
|
|
312
|
+
case -32003:
|
|
313
|
+
return new TransactionRejectedRpcError(value.errorMessage);
|
|
292
314
|
}
|
|
293
315
|
}
|
|
294
316
|
}
|
|
@@ -1384,6 +1406,7 @@ const ACCOUNT_MESSAGES = [
|
|
|
1384
1406
|
AirMessageTypes.WALLET_INITIALIZED,
|
|
1385
1407
|
AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
|
|
1386
1408
|
AirMessageTypes.LOGOUT_RESPONSE,
|
|
1409
|
+
AirMessageTypes.OPEN_WINDOW_REQUEST,
|
|
1387
1410
|
];
|
|
1388
1411
|
const AUTH_MESSAGES = [
|
|
1389
1412
|
AirAuthMessageTypes.INITIALIZATION_RESPONSE,
|
|
@@ -1393,7 +1416,7 @@ const AUTH_MESSAGES = [
|
|
|
1393
1416
|
AirAuthMessageTypes.LOGOUT_RESPONSE,
|
|
1394
1417
|
AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
|
|
1395
1418
|
AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
|
|
1396
|
-
AirAuthMessageTypes.
|
|
1419
|
+
AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
|
|
1397
1420
|
AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
|
|
1398
1421
|
];
|
|
1399
1422
|
class AirMessageService {
|
|
@@ -1628,6 +1651,37 @@ class AirMessageService {
|
|
|
1628
1651
|
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.SETUP_MFA_REQUEST }, origin);
|
|
1629
1652
|
return response;
|
|
1630
1653
|
}
|
|
1654
|
+
sendOpenWindowSuccessResponse(walletIframe, windowId, port) {
|
|
1655
|
+
const { origin: walletOrigin } = new URL(walletIframe.src);
|
|
1656
|
+
walletIframe.contentWindow.postMessage({
|
|
1657
|
+
type: AirMessageTypes.OPEN_WINDOW_RESPONSE,
|
|
1658
|
+
payload: {
|
|
1659
|
+
success: true,
|
|
1660
|
+
windowId,
|
|
1661
|
+
},
|
|
1662
|
+
}, walletOrigin, [port]);
|
|
1663
|
+
}
|
|
1664
|
+
sendOpenWindowErrorResponse(walletIframe, windowId, error) {
|
|
1665
|
+
const { origin: walletOrigin } = new URL(walletIframe.src);
|
|
1666
|
+
walletIframe.contentWindow.postMessage({
|
|
1667
|
+
type: AirMessageTypes.OPEN_WINDOW_RESPONSE,
|
|
1668
|
+
payload: {
|
|
1669
|
+
success: false,
|
|
1670
|
+
windowId,
|
|
1671
|
+
errorName: "UNKNOWN_ERROR",
|
|
1672
|
+
errorMessage: error.message,
|
|
1673
|
+
},
|
|
1674
|
+
}, walletOrigin);
|
|
1675
|
+
}
|
|
1676
|
+
sendWindowClosed(walletIframe, windowId) {
|
|
1677
|
+
const { origin: walletOrigin } = new URL(walletIframe.src);
|
|
1678
|
+
walletIframe.contentWindow.postMessage({
|
|
1679
|
+
type: AirMessageTypes.WINDOW_CLOSED,
|
|
1680
|
+
payload: {
|
|
1681
|
+
windowId,
|
|
1682
|
+
},
|
|
1683
|
+
}, walletOrigin);
|
|
1684
|
+
}
|
|
1631
1685
|
async sendClaimIdRequest(walletIframe, payload) {
|
|
1632
1686
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.CLAIM_ID_RESPONSE)));
|
|
1633
1687
|
const { origin } = new URL(walletIframe.src);
|
|
@@ -1674,10 +1728,10 @@ class AirMessageService {
|
|
|
1674
1728
|
this._providerMessage$ = new Subject();
|
|
1675
1729
|
this._providerEvent$ = new Subject();
|
|
1676
1730
|
}
|
|
1677
|
-
async
|
|
1678
|
-
const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.
|
|
1731
|
+
async sendPartnerAccessTokenRequest(authIframe) {
|
|
1732
|
+
const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE)));
|
|
1679
1733
|
const { origin } = new URL(authIframe.src);
|
|
1680
|
-
authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.
|
|
1734
|
+
authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_REQUEST }, origin);
|
|
1681
1735
|
return response;
|
|
1682
1736
|
}
|
|
1683
1737
|
}
|
|
@@ -1685,6 +1739,7 @@ var AirMessageService$1 = AirMessageService.instance;
|
|
|
1685
1739
|
|
|
1686
1740
|
const BUILD_ENV = {
|
|
1687
1741
|
PRODUCTION: "production",
|
|
1742
|
+
UAT: "uat",
|
|
1688
1743
|
STAGING: "staging",
|
|
1689
1744
|
DEVELOPMENT: "development",
|
|
1690
1745
|
};
|
|
@@ -1695,6 +1750,11 @@ const AIR_URLS = {
|
|
|
1695
1750
|
walletUrl: "http://localhost:8200",
|
|
1696
1751
|
logLevel: "debug",
|
|
1697
1752
|
},
|
|
1753
|
+
[BUILD_ENV.UAT]: {
|
|
1754
|
+
authUrl: "https://auth.uat.air3.com",
|
|
1755
|
+
walletUrl: "https://account.uat.air3.com",
|
|
1756
|
+
logLevel: "info",
|
|
1757
|
+
},
|
|
1698
1758
|
[BUILD_ENV.STAGING]: {
|
|
1699
1759
|
authUrl: "https://auth.staging.air3.com",
|
|
1700
1760
|
walletUrl: "https://account.staging.air3.com",
|
|
@@ -1708,6 +1768,24 @@ const AIR_URLS = {
|
|
|
1708
1768
|
};
|
|
1709
1769
|
const isElement = (element) => element instanceof Element || element instanceof Document;
|
|
1710
1770
|
const randomId = () => Math.random().toString(36).slice(2);
|
|
1771
|
+
const getWindowFeatures = (width, height) => {
|
|
1772
|
+
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
|
|
1773
|
+
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
|
|
1774
|
+
const w = window.innerWidth
|
|
1775
|
+
? window.innerWidth
|
|
1776
|
+
: document.documentElement.clientWidth
|
|
1777
|
+
? document.documentElement.clientWidth
|
|
1778
|
+
: window.screen.width;
|
|
1779
|
+
const h = window.innerHeight
|
|
1780
|
+
? window.innerHeight
|
|
1781
|
+
: document.documentElement.clientHeight
|
|
1782
|
+
? document.documentElement.clientHeight
|
|
1783
|
+
: window.screen.height;
|
|
1784
|
+
const systemZoom = 1; // No reliable estimate
|
|
1785
|
+
const left = Math.abs((w - width) / 2 / systemZoom + dualScreenLeft);
|
|
1786
|
+
const top = Math.abs((h - height) / 2 / systemZoom + dualScreenTop);
|
|
1787
|
+
return `titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=${height / systemZoom},width=${width / systemZoom},top=${top},left=${left}`;
|
|
1788
|
+
};
|
|
1711
1789
|
|
|
1712
1790
|
var _AirWalletProvider_instances, _AirWalletProvider_isLoggedIn, _AirWalletProvider_ensureWallet, _AirWalletProvider_getWalletIframeController, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
|
|
1713
1791
|
class AirWalletProvider {
|
|
@@ -1864,7 +1942,145 @@ IframeController.defaultState = {
|
|
|
1864
1942
|
isVisible: false,
|
|
1865
1943
|
};
|
|
1866
1944
|
|
|
1867
|
-
|
|
1945
|
+
class WindowController {
|
|
1946
|
+
get messages$() {
|
|
1947
|
+
return this._messages$.asObservable();
|
|
1948
|
+
}
|
|
1949
|
+
constructor(windowUrl, windowId) {
|
|
1950
|
+
this._windowInstance = null;
|
|
1951
|
+
this._messageHandler = null;
|
|
1952
|
+
this._messages$ = new Subject();
|
|
1953
|
+
this.windowUrl = windowUrl;
|
|
1954
|
+
this.windowOrigin = new URL(windowUrl).origin;
|
|
1955
|
+
this.windowId = windowId;
|
|
1956
|
+
}
|
|
1957
|
+
get windowInstance() {
|
|
1958
|
+
return this._windowInstance;
|
|
1959
|
+
}
|
|
1960
|
+
openWindow() {
|
|
1961
|
+
if (this._windowInstance && !this._windowInstance.closed) {
|
|
1962
|
+
this._windowInstance.focus();
|
|
1963
|
+
return this._windowInstance;
|
|
1964
|
+
}
|
|
1965
|
+
const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
|
|
1966
|
+
if (!windowInstance) {
|
|
1967
|
+
throw new Error("Failed to open window. Popup might be blocked by the browser.");
|
|
1968
|
+
}
|
|
1969
|
+
this._windowInstance = windowInstance;
|
|
1970
|
+
this._messageHandler = (ev) => {
|
|
1971
|
+
if (ev.source !== windowInstance ||
|
|
1972
|
+
ev.origin !== this.windowOrigin ||
|
|
1973
|
+
!ev.data ||
|
|
1974
|
+
!(ev.data instanceof Object)) {
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1977
|
+
this._messages$.next(ev);
|
|
1978
|
+
};
|
|
1979
|
+
window.addEventListener("message", this._messageHandler);
|
|
1980
|
+
const checkWindow = setInterval(() => {
|
|
1981
|
+
if (!this._windowInstance || this._windowInstance?.closed) {
|
|
1982
|
+
this.cleanup();
|
|
1983
|
+
clearInterval(checkWindow);
|
|
1984
|
+
}
|
|
1985
|
+
}, 500);
|
|
1986
|
+
return windowInstance;
|
|
1987
|
+
}
|
|
1988
|
+
postMessage(message, transfer) {
|
|
1989
|
+
if (!this._windowInstance)
|
|
1990
|
+
return;
|
|
1991
|
+
this._windowInstance.postMessage(message, this.windowOrigin, transfer);
|
|
1992
|
+
}
|
|
1993
|
+
onMessage(callback) {
|
|
1994
|
+
const listener = (ev) => {
|
|
1995
|
+
if (ev.source !== this._windowInstance)
|
|
1996
|
+
return;
|
|
1997
|
+
callback(ev);
|
|
1998
|
+
};
|
|
1999
|
+
window.addEventListener("message", listener);
|
|
2000
|
+
const close = () => window.removeEventListener("message", listener);
|
|
2001
|
+
this.onClose(close);
|
|
2002
|
+
return {
|
|
2003
|
+
close,
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
cleanup() {
|
|
2007
|
+
if (this._windowInstance && !this._windowInstance.closed) {
|
|
2008
|
+
this._windowInstance.close();
|
|
2009
|
+
}
|
|
2010
|
+
if (this._messageHandler) {
|
|
2011
|
+
window.removeEventListener("message", this._messageHandler);
|
|
2012
|
+
this._messageHandler = null;
|
|
2013
|
+
}
|
|
2014
|
+
if (this._messages$ && !this._messages$.closed) {
|
|
2015
|
+
this._messages$.complete();
|
|
2016
|
+
}
|
|
2017
|
+
this._windowInstance = null;
|
|
2018
|
+
}
|
|
2019
|
+
onClose(callback) {
|
|
2020
|
+
return this._messages$.subscribe({
|
|
2021
|
+
complete: callback,
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
class WindowService {
|
|
2027
|
+
constructor() {
|
|
2028
|
+
this.windowControllers = new Map();
|
|
2029
|
+
}
|
|
2030
|
+
static get instance() {
|
|
2031
|
+
return this._instance || (this._instance = new this());
|
|
2032
|
+
}
|
|
2033
|
+
async sendWindowInitializationRequest(windowId, payload, port) {
|
|
2034
|
+
const windowController = this.windowControllers.get(windowId);
|
|
2035
|
+
if (!windowController) {
|
|
2036
|
+
throw new Error("Window controller not found");
|
|
2037
|
+
}
|
|
2038
|
+
const windowInstance = windowController.windowInstance;
|
|
2039
|
+
if (!windowInstance) {
|
|
2040
|
+
throw new Error("Window instance not found");
|
|
2041
|
+
}
|
|
2042
|
+
const response = firstValueFrom(windowController.messages$.pipe(filter((event) => event.data.type === AirMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2043
|
+
windowController.postMessage({ type: AirMessageTypes.INITIALIZATION_REQUEST, payload }, [port]);
|
|
2044
|
+
return (await response).data;
|
|
2045
|
+
}
|
|
2046
|
+
async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, port, }) {
|
|
2047
|
+
if (this.windowControllers.has(windowId)) {
|
|
2048
|
+
throw new Error("Window controller already exists");
|
|
2049
|
+
}
|
|
2050
|
+
const windowController = new WindowController(url, windowId);
|
|
2051
|
+
this.windowControllers.set(windowId, windowController);
|
|
2052
|
+
windowController.openWindow();
|
|
2053
|
+
windowController.onClose(() => {
|
|
2054
|
+
this.removeWindowController(windowId);
|
|
2055
|
+
});
|
|
2056
|
+
await new Promise((resolve, reject) => {
|
|
2057
|
+
windowController.onMessage(async (ev) => {
|
|
2058
|
+
if (ev.data === AirMessageTypes.SERVICE_STARTED) {
|
|
2059
|
+
const { payload } = await this.sendWindowInitializationRequest(windowId, {
|
|
2060
|
+
partnerId,
|
|
2061
|
+
enableLogging,
|
|
2062
|
+
}, port);
|
|
2063
|
+
if (payload.success === false) {
|
|
2064
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2065
|
+
}
|
|
2066
|
+
else {
|
|
2067
|
+
resolve();
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
});
|
|
2071
|
+
});
|
|
2072
|
+
return windowController;
|
|
2073
|
+
}
|
|
2074
|
+
getWindowController(windowId) {
|
|
2075
|
+
return this.windowControllers.get(windowId);
|
|
2076
|
+
}
|
|
2077
|
+
removeWindowController(windowId) {
|
|
2078
|
+
this.windowControllers.delete(windowId);
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
var WindowService$1 = WindowService.instance;
|
|
2082
|
+
|
|
2083
|
+
var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airAuthListener, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet;
|
|
1868
2084
|
class AirService {
|
|
1869
2085
|
constructor({ partnerId }) {
|
|
1870
2086
|
_AirService_instances.add(this);
|
|
@@ -2172,6 +2388,20 @@ class AirService {
|
|
|
2172
2388
|
urlWithToken: result.payload.urlWithToken,
|
|
2173
2389
|
};
|
|
2174
2390
|
}
|
|
2391
|
+
async getAccessToken() {
|
|
2392
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2393
|
+
throw new Error("Service is not initialized");
|
|
2394
|
+
if (!this.isLoggedIn)
|
|
2395
|
+
throw new Error("No active session to get partner access token");
|
|
2396
|
+
const result = await AirMessageService$1.sendPartnerAccessTokenRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
|
|
2397
|
+
if (result.payload.success !== true) {
|
|
2398
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2399
|
+
}
|
|
2400
|
+
if (!result.payload.partnerAccessToken) {
|
|
2401
|
+
throw new Error("Partner access token not found in response");
|
|
2402
|
+
}
|
|
2403
|
+
return { token: result.payload.partnerAccessToken };
|
|
2404
|
+
}
|
|
2175
2405
|
async logout() {
|
|
2176
2406
|
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2177
2407
|
throw new Error("Service is not initialized");
|
|
@@ -2199,20 +2429,6 @@ class AirService {
|
|
|
2199
2429
|
clearEventListeners() {
|
|
2200
2430
|
__classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
|
|
2201
2431
|
}
|
|
2202
|
-
async getPartnerAccessToken() {
|
|
2203
|
-
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2204
|
-
throw new Error("Service is not initialized");
|
|
2205
|
-
if (!this.isLoggedIn)
|
|
2206
|
-
throw new Error("No active session to get partner access token");
|
|
2207
|
-
const result = await AirMessageService$1.sendGetPartnerAccessTokenRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
|
|
2208
|
-
if (result.payload.success === false) {
|
|
2209
|
-
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2210
|
-
}
|
|
2211
|
-
if (!result.payload.partnerAccessToken) {
|
|
2212
|
-
throw new Error("Partner access token not found in response");
|
|
2213
|
-
}
|
|
2214
|
-
return result.payload.partnerAccessToken;
|
|
2215
|
-
}
|
|
2216
2432
|
}
|
|
2217
2433
|
_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_walletLoggedInResult = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
|
|
2218
2434
|
if (!this.isInitialized)
|
|
@@ -2251,23 +2467,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
2251
2467
|
try {
|
|
2252
2468
|
__classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(walletUrl, `air-wallet-${randomId()}`), "f");
|
|
2253
2469
|
__classPrivateFieldGet(this, _AirService_walletIframeController, "f").createIframe();
|
|
2254
|
-
|
|
2255
|
-
switch (msg.type) {
|
|
2256
|
-
case AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST: {
|
|
2257
|
-
const walletIframeController = __classPrivateFieldGet(this, _AirService_walletIframeController, "f");
|
|
2258
|
-
walletIframeController.setIframeVisibility(msg.payload.visible);
|
|
2259
|
-
walletIframeController.updateIframeState();
|
|
2260
|
-
break;
|
|
2261
|
-
}
|
|
2262
|
-
case AirMessageTypes.WALLET_LOGIN_RESPONSE: {
|
|
2263
|
-
if (msg.payload.success === true && !__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f")) {
|
|
2264
|
-
__classPrivateFieldSet(this, _AirService_walletLoggedInResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createWalletInitializedResult).call(this, msg.payload), "f");
|
|
2265
|
-
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerWalletInitialized).call(this, __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"));
|
|
2266
|
-
}
|
|
2267
|
-
break;
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
});
|
|
2470
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToWalletEvents).call(this);
|
|
2271
2471
|
await new Promise((resolve, reject) => {
|
|
2272
2472
|
const handleAuthMessage = async (ev) => {
|
|
2273
2473
|
if (ev.origin !== walletIframeOrigin)
|
|
@@ -2306,6 +2506,43 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
2306
2506
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
2307
2507
|
throw error;
|
|
2308
2508
|
}
|
|
2509
|
+
}, _AirService_subscribeToWalletEvents = function _AirService_subscribeToWalletEvents() {
|
|
2510
|
+
AirMessageService$1.messages$.subscribe(async (msg) => {
|
|
2511
|
+
switch (msg.type) {
|
|
2512
|
+
case AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST: {
|
|
2513
|
+
const walletIframeController = __classPrivateFieldGet(this, _AirService_walletIframeController, "f");
|
|
2514
|
+
walletIframeController.setIframeVisibility(msg.payload.visible);
|
|
2515
|
+
walletIframeController.updateIframeState();
|
|
2516
|
+
break;
|
|
2517
|
+
}
|
|
2518
|
+
case AirMessageTypes.WALLET_LOGIN_RESPONSE: {
|
|
2519
|
+
if (msg.payload.success === true && !__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f")) {
|
|
2520
|
+
__classPrivateFieldSet(this, _AirService_walletLoggedInResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createWalletInitializedResult).call(this, msg.payload), "f");
|
|
2521
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerWalletInitialized).call(this, __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"));
|
|
2522
|
+
}
|
|
2523
|
+
break;
|
|
2524
|
+
}
|
|
2525
|
+
case AirMessageTypes.OPEN_WINDOW_REQUEST: {
|
|
2526
|
+
try {
|
|
2527
|
+
const channel = new MessageChannel();
|
|
2528
|
+
const windowController = await WindowService$1.openAndInitializeWalletServiceWindow({
|
|
2529
|
+
url: msg.payload.url,
|
|
2530
|
+
windowId: msg.payload.windowId,
|
|
2531
|
+
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
2532
|
+
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
2533
|
+
port: channel.port1,
|
|
2534
|
+
});
|
|
2535
|
+
windowController.onClose(() => AirMessageService$1.sendWindowClosed(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId));
|
|
2536
|
+
AirMessageService$1.sendOpenWindowSuccessResponse(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId, channel.port2);
|
|
2537
|
+
}
|
|
2538
|
+
catch (err) {
|
|
2539
|
+
const error = ensureError(err);
|
|
2540
|
+
AirMessageService$1.sendOpenWindowErrorResponse(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId, error);
|
|
2541
|
+
}
|
|
2542
|
+
break;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
});
|
|
2309
2546
|
}, _AirService_triggerEventListeners = function _AirService_triggerEventListeners(data) {
|
|
2310
2547
|
__classPrivateFieldGet(this, _AirService_airAuthListener, "f").forEach((listener) => {
|
|
2311
2548
|
listener(data);
|
|
@@ -2385,6 +2622,7 @@ exports.InvalidRequestRpcError = InvalidRequestRpcError;
|
|
|
2385
2622
|
exports.MethodNotFoundRpcError = MethodNotFoundRpcError;
|
|
2386
2623
|
exports.ProviderDisconnectedError = ProviderDisconnectedError;
|
|
2387
2624
|
exports.SwitchChainError = SwitchChainError;
|
|
2625
|
+
exports.TransactionRejectedRpcError = TransactionRejectedRpcError;
|
|
2388
2626
|
exports.UnauthorizedProviderError = UnauthorizedProviderError;
|
|
2389
2627
|
exports.UnsupportedProviderMethodError = UnsupportedProviderMethodError;
|
|
2390
2628
|
exports.UserRejectedRequestError = UserRejectedRequestError;
|