@mocanetwork/airkit 1.1.0 → 1.2.0-beta.1
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 +296 -18
- package/dist/airkit.esm.js +296 -18
- package/dist/airkit.umd.js +296 -18
- package/dist/types/airService.d.ts +5 -0
- package/dist/types/airWalletProvider.d.ts +1 -1
- package/dist/types/common/realm/messaging/auth.d.ts +8 -1
- package/dist/types/common/realm/messaging/types.d.ts +23 -2
- package/dist/types/common/realm/partner/config.d.ts +1 -0
- package/dist/types/common/utils.d.ts +3 -2
- package/dist/types/interfaces.d.ts +1 -0
- package/dist/types/messageService.d.ts +5 -0
- 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.umd.js
CHANGED
|
@@ -124,6 +124,8 @@
|
|
|
124
124
|
SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
|
|
125
125
|
CROSS_PARTNER_TOKEN_REQUEST: "air_auth_cross_partner_token_request",
|
|
126
126
|
CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
|
|
127
|
+
GET_PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_get_partner_access_token_request",
|
|
128
|
+
GET_PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_get_partner_access_token_response",
|
|
127
129
|
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
128
130
|
LOGOUT_RESPONSE: "air_auth_logout_response",
|
|
129
131
|
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication"
|
|
@@ -149,7 +151,12 @@
|
|
|
149
151
|
EXECUTE_ACTION_RESPONSE: "air_execute_action_response",
|
|
150
152
|
REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request",
|
|
151
153
|
REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response",
|
|
154
|
+
LIST_ALL_SESSION_KEY_SCOPES_REQUEST: "air_list_all_session_key_scopes_request",
|
|
155
|
+
LIST_ALL_SESSION_KEY_SCOPES_RESPONSE: "air_list_all_session_key_scopes_response",
|
|
152
156
|
WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request",
|
|
157
|
+
OPEN_WINDOW_REQUEST: "air_open_window_request",
|
|
158
|
+
OPEN_WINDOW_RESPONSE: "air_open_window_response",
|
|
159
|
+
WINDOW_CLOSED: "air_window_closed",
|
|
153
160
|
IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
|
|
154
161
|
IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
|
|
155
162
|
LOGOUT_REQUEST: "air_logout_request",
|
|
@@ -177,6 +184,16 @@
|
|
|
177
184
|
};
|
|
178
185
|
}
|
|
179
186
|
}
|
|
187
|
+
function ensureError(value) {
|
|
188
|
+
if (value instanceof Error) return value;
|
|
189
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
190
|
+
try {
|
|
191
|
+
stringified = JSON.stringify(value);
|
|
192
|
+
} catch {
|
|
193
|
+
// ignoring failed stringify
|
|
194
|
+
}
|
|
195
|
+
return new Error(`This value was not thrown as type Error: ${stringified}`);
|
|
196
|
+
}
|
|
180
197
|
|
|
181
198
|
class AirServiceError extends BaseError {
|
|
182
199
|
static from(error) {
|
|
@@ -1380,9 +1397,11 @@
|
|
|
1380
1397
|
AirMessageTypes.EXECUTE_ACTION_RESPONSE,
|
|
1381
1398
|
AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE,
|
|
1382
1399
|
AirMessageTypes.GRANT_PERMISSIONS_RESPONSE,
|
|
1400
|
+
AirMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_RESPONSE,
|
|
1383
1401
|
AirMessageTypes.WALLET_INITIALIZED,
|
|
1384
1402
|
AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
|
|
1385
1403
|
AirMessageTypes.LOGOUT_RESPONSE,
|
|
1404
|
+
AirMessageTypes.OPEN_WINDOW_REQUEST,
|
|
1386
1405
|
];
|
|
1387
1406
|
const AUTH_MESSAGES = [
|
|
1388
1407
|
AirAuthMessageTypes.INITIALIZATION_RESPONSE,
|
|
@@ -1392,6 +1411,7 @@
|
|
|
1392
1411
|
AirAuthMessageTypes.LOGOUT_RESPONSE,
|
|
1393
1412
|
AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
|
|
1394
1413
|
AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
|
|
1414
|
+
AirAuthMessageTypes.GET_PARTNER_ACCESS_TOKEN_RESPONSE,
|
|
1395
1415
|
AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
|
|
1396
1416
|
];
|
|
1397
1417
|
class AirMessageService {
|
|
@@ -1605,6 +1625,12 @@
|
|
|
1605
1625
|
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.GRANT_PERMISSIONS_REQUEST, payload }, origin);
|
|
1606
1626
|
return response;
|
|
1607
1627
|
}
|
|
1628
|
+
async sendListAllSessionKeyScopesRequest(walletIframe) {
|
|
1629
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_RESPONSE)));
|
|
1630
|
+
const { origin } = new URL(walletIframe.src);
|
|
1631
|
+
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.LIST_ALL_SESSION_KEY_SCOPES_REQUEST }, origin);
|
|
1632
|
+
return response;
|
|
1633
|
+
}
|
|
1608
1634
|
onWalletInitialized() {
|
|
1609
1635
|
return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.WALLET_INITIALIZED)));
|
|
1610
1636
|
}
|
|
@@ -1620,6 +1646,37 @@
|
|
|
1620
1646
|
walletIframe.contentWindow.postMessage({ type: AirMessageTypes.SETUP_MFA_REQUEST }, origin);
|
|
1621
1647
|
return response;
|
|
1622
1648
|
}
|
|
1649
|
+
sendOpenWindowSuccessResponse(walletIframe, windowId, port) {
|
|
1650
|
+
const { origin: walletOrigin } = new URL(walletIframe.src);
|
|
1651
|
+
walletIframe.contentWindow.postMessage({
|
|
1652
|
+
type: AirMessageTypes.OPEN_WINDOW_RESPONSE,
|
|
1653
|
+
payload: {
|
|
1654
|
+
success: true,
|
|
1655
|
+
windowId,
|
|
1656
|
+
},
|
|
1657
|
+
}, walletOrigin, [port]);
|
|
1658
|
+
}
|
|
1659
|
+
sendOpenWindowErrorResponse(walletIframe, windowId, error) {
|
|
1660
|
+
const { origin: walletOrigin } = new URL(walletIframe.src);
|
|
1661
|
+
walletIframe.contentWindow.postMessage({
|
|
1662
|
+
type: AirMessageTypes.OPEN_WINDOW_RESPONSE,
|
|
1663
|
+
payload: {
|
|
1664
|
+
success: false,
|
|
1665
|
+
windowId,
|
|
1666
|
+
errorName: "UNKNOWN_ERROR",
|
|
1667
|
+
errorMessage: error.message,
|
|
1668
|
+
},
|
|
1669
|
+
}, walletOrigin);
|
|
1670
|
+
}
|
|
1671
|
+
sendWindowClosed(walletIframe, windowId) {
|
|
1672
|
+
const { origin: walletOrigin } = new URL(walletIframe.src);
|
|
1673
|
+
walletIframe.contentWindow.postMessage({
|
|
1674
|
+
type: AirMessageTypes.WINDOW_CLOSED,
|
|
1675
|
+
payload: {
|
|
1676
|
+
windowId,
|
|
1677
|
+
},
|
|
1678
|
+
}, walletOrigin);
|
|
1679
|
+
}
|
|
1623
1680
|
async sendClaimIdRequest(walletIframe, payload) {
|
|
1624
1681
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirMessageTypes.CLAIM_ID_RESPONSE)));
|
|
1625
1682
|
const { origin } = new URL(walletIframe.src);
|
|
@@ -1666,11 +1723,18 @@
|
|
|
1666
1723
|
this._providerMessage$ = new Subject();
|
|
1667
1724
|
this._providerEvent$ = new Subject();
|
|
1668
1725
|
}
|
|
1726
|
+
async sendGetPartnerAccessTokenRequest(authIframe) {
|
|
1727
|
+
const response = firstValueFrom(this.authMessage$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.GET_PARTNER_ACCESS_TOKEN_RESPONSE)));
|
|
1728
|
+
const { origin } = new URL(authIframe.src);
|
|
1729
|
+
authIframe.contentWindow.postMessage({ type: AirAuthMessageTypes.GET_PARTNER_ACCESS_TOKEN_REQUEST }, origin);
|
|
1730
|
+
return response;
|
|
1731
|
+
}
|
|
1669
1732
|
}
|
|
1670
1733
|
var AirMessageService$1 = AirMessageService.instance;
|
|
1671
1734
|
|
|
1672
1735
|
const BUILD_ENV = {
|
|
1673
1736
|
PRODUCTION: "production",
|
|
1737
|
+
UAT: "uat",
|
|
1674
1738
|
STAGING: "staging",
|
|
1675
1739
|
DEVELOPMENT: "development",
|
|
1676
1740
|
};
|
|
@@ -1681,6 +1745,11 @@
|
|
|
1681
1745
|
walletUrl: "http://localhost:8200",
|
|
1682
1746
|
logLevel: "debug",
|
|
1683
1747
|
},
|
|
1748
|
+
[BUILD_ENV.UAT]: {
|
|
1749
|
+
authUrl: "https://auth.uat.air3.com",
|
|
1750
|
+
walletUrl: "https://account.uat.air3.com",
|
|
1751
|
+
logLevel: "info",
|
|
1752
|
+
},
|
|
1684
1753
|
[BUILD_ENV.STAGING]: {
|
|
1685
1754
|
authUrl: "https://auth.staging.air3.com",
|
|
1686
1755
|
walletUrl: "https://account.staging.air3.com",
|
|
@@ -1694,6 +1763,24 @@
|
|
|
1694
1763
|
};
|
|
1695
1764
|
const isElement = (element) => element instanceof Element || element instanceof Document;
|
|
1696
1765
|
const randomId = () => Math.random().toString(36).slice(2);
|
|
1766
|
+
const getWindowFeatures = (width, height) => {
|
|
1767
|
+
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
|
|
1768
|
+
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
|
|
1769
|
+
const w = window.innerWidth
|
|
1770
|
+
? window.innerWidth
|
|
1771
|
+
: document.documentElement.clientWidth
|
|
1772
|
+
? document.documentElement.clientWidth
|
|
1773
|
+
: window.screen.width;
|
|
1774
|
+
const h = window.innerHeight
|
|
1775
|
+
? window.innerHeight
|
|
1776
|
+
: document.documentElement.clientHeight
|
|
1777
|
+
? document.documentElement.clientHeight
|
|
1778
|
+
: window.screen.height;
|
|
1779
|
+
const systemZoom = 1; // No reliable estimate
|
|
1780
|
+
const left = Math.abs((w - width) / 2 / systemZoom + dualScreenLeft);
|
|
1781
|
+
const top = Math.abs((h - height) / 2 / systemZoom + dualScreenTop);
|
|
1782
|
+
return `titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=${height / systemZoom},width=${width / systemZoom},top=${top},left=${left}`;
|
|
1783
|
+
};
|
|
1697
1784
|
|
|
1698
1785
|
var _AirWalletProvider_instances, _AirWalletProvider_isLoggedIn, _AirWalletProvider_ensureWallet, _AirWalletProvider_getWalletIframeController, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
|
|
1699
1786
|
class AirWalletProvider {
|
|
@@ -1850,7 +1937,145 @@
|
|
|
1850
1937
|
isVisible: false,
|
|
1851
1938
|
};
|
|
1852
1939
|
|
|
1853
|
-
|
|
1940
|
+
class WindowController {
|
|
1941
|
+
get messages$() {
|
|
1942
|
+
return this._messages$.asObservable();
|
|
1943
|
+
}
|
|
1944
|
+
constructor(windowUrl, windowId) {
|
|
1945
|
+
this._windowInstance = null;
|
|
1946
|
+
this._messageHandler = null;
|
|
1947
|
+
this._messages$ = new Subject();
|
|
1948
|
+
this.windowUrl = windowUrl;
|
|
1949
|
+
this.windowOrigin = new URL(windowUrl).origin;
|
|
1950
|
+
this.windowId = windowId;
|
|
1951
|
+
}
|
|
1952
|
+
get windowInstance() {
|
|
1953
|
+
return this._windowInstance;
|
|
1954
|
+
}
|
|
1955
|
+
openWindow() {
|
|
1956
|
+
if (this._windowInstance && !this._windowInstance.closed) {
|
|
1957
|
+
this._windowInstance.focus();
|
|
1958
|
+
return this._windowInstance;
|
|
1959
|
+
}
|
|
1960
|
+
const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(400, 600));
|
|
1961
|
+
if (!windowInstance) {
|
|
1962
|
+
throw new Error("Failed to open window. Popup might be blocked by the browser.");
|
|
1963
|
+
}
|
|
1964
|
+
this._windowInstance = windowInstance;
|
|
1965
|
+
this._messageHandler = (ev) => {
|
|
1966
|
+
if (ev.source !== windowInstance ||
|
|
1967
|
+
ev.origin !== this.windowOrigin ||
|
|
1968
|
+
!ev.data ||
|
|
1969
|
+
!(ev.data instanceof Object)) {
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1972
|
+
this._messages$.next(ev);
|
|
1973
|
+
};
|
|
1974
|
+
window.addEventListener("message", this._messageHandler);
|
|
1975
|
+
const checkWindow = setInterval(() => {
|
|
1976
|
+
if (!this._windowInstance || this._windowInstance?.closed) {
|
|
1977
|
+
this.cleanup();
|
|
1978
|
+
clearInterval(checkWindow);
|
|
1979
|
+
}
|
|
1980
|
+
}, 500);
|
|
1981
|
+
return windowInstance;
|
|
1982
|
+
}
|
|
1983
|
+
postMessage(message, transfer) {
|
|
1984
|
+
if (!this._windowInstance)
|
|
1985
|
+
return;
|
|
1986
|
+
this._windowInstance.postMessage(message, this.windowOrigin, transfer);
|
|
1987
|
+
}
|
|
1988
|
+
onMessage(callback) {
|
|
1989
|
+
const listener = (ev) => {
|
|
1990
|
+
if (ev.source !== this._windowInstance)
|
|
1991
|
+
return;
|
|
1992
|
+
callback(ev);
|
|
1993
|
+
};
|
|
1994
|
+
window.addEventListener("message", listener);
|
|
1995
|
+
const close = () => window.removeEventListener("message", listener);
|
|
1996
|
+
this.onClose(close);
|
|
1997
|
+
return {
|
|
1998
|
+
close,
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
cleanup() {
|
|
2002
|
+
if (this._windowInstance && !this._windowInstance.closed) {
|
|
2003
|
+
this._windowInstance.close();
|
|
2004
|
+
}
|
|
2005
|
+
if (this._messageHandler) {
|
|
2006
|
+
window.removeEventListener("message", this._messageHandler);
|
|
2007
|
+
this._messageHandler = null;
|
|
2008
|
+
}
|
|
2009
|
+
if (this._messages$ && !this._messages$.closed) {
|
|
2010
|
+
this._messages$.complete();
|
|
2011
|
+
}
|
|
2012
|
+
this._windowInstance = null;
|
|
2013
|
+
}
|
|
2014
|
+
onClose(callback) {
|
|
2015
|
+
return this._messages$.subscribe({
|
|
2016
|
+
complete: callback,
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
class WindowService {
|
|
2022
|
+
constructor() {
|
|
2023
|
+
this.windowControllers = new Map();
|
|
2024
|
+
}
|
|
2025
|
+
static get instance() {
|
|
2026
|
+
return this._instance || (this._instance = new this());
|
|
2027
|
+
}
|
|
2028
|
+
async sendWindowInitializationRequest(windowId, payload, port) {
|
|
2029
|
+
const windowController = this.windowControllers.get(windowId);
|
|
2030
|
+
if (!windowController) {
|
|
2031
|
+
throw new Error("Window controller not found");
|
|
2032
|
+
}
|
|
2033
|
+
const windowInstance = windowController.windowInstance;
|
|
2034
|
+
if (!windowInstance) {
|
|
2035
|
+
throw new Error("Window instance not found");
|
|
2036
|
+
}
|
|
2037
|
+
const response = firstValueFrom(windowController.messages$.pipe(filter((event) => event.data.type === AirMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2038
|
+
windowController.postMessage({ type: AirMessageTypes.INITIALIZATION_REQUEST, payload }, [port]);
|
|
2039
|
+
return (await response).data;
|
|
2040
|
+
}
|
|
2041
|
+
async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, port, }) {
|
|
2042
|
+
if (this.windowControllers.has(windowId)) {
|
|
2043
|
+
throw new Error("Window controller already exists");
|
|
2044
|
+
}
|
|
2045
|
+
const windowController = new WindowController(url, windowId);
|
|
2046
|
+
this.windowControllers.set(windowId, windowController);
|
|
2047
|
+
windowController.openWindow();
|
|
2048
|
+
windowController.onClose(() => {
|
|
2049
|
+
this.removeWindowController(windowId);
|
|
2050
|
+
});
|
|
2051
|
+
await new Promise((resolve, reject) => {
|
|
2052
|
+
windowController.onMessage(async (ev) => {
|
|
2053
|
+
if (ev.data === AirMessageTypes.SERVICE_STARTED) {
|
|
2054
|
+
const { payload } = await this.sendWindowInitializationRequest(windowId, {
|
|
2055
|
+
partnerId,
|
|
2056
|
+
enableLogging,
|
|
2057
|
+
}, port);
|
|
2058
|
+
if (payload.success === false) {
|
|
2059
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2060
|
+
}
|
|
2061
|
+
else {
|
|
2062
|
+
resolve();
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2066
|
+
});
|
|
2067
|
+
return windowController;
|
|
2068
|
+
}
|
|
2069
|
+
getWindowController(windowId) {
|
|
2070
|
+
return this.windowControllers.get(windowId);
|
|
2071
|
+
}
|
|
2072
|
+
removeWindowController(windowId) {
|
|
2073
|
+
this.windowControllers.delete(windowId);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
var WindowService$1 = WindowService.instance;
|
|
2077
|
+
|
|
2078
|
+
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;
|
|
1854
2079
|
class AirService {
|
|
1855
2080
|
constructor({ partnerId }) {
|
|
1856
2081
|
_AirService_instances.add(this);
|
|
@@ -2037,6 +2262,24 @@
|
|
|
2037
2262
|
throw AirServiceError.from(error);
|
|
2038
2263
|
}
|
|
2039
2264
|
}
|
|
2265
|
+
/**
|
|
2266
|
+
* @experimental This method is experimental and will change in the future.
|
|
2267
|
+
*/
|
|
2268
|
+
async listAllSessionKeyScopes() {
|
|
2269
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2270
|
+
throw new Error("Service is not initialized");
|
|
2271
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
2272
|
+
try {
|
|
2273
|
+
const { payload } = await AirMessageService$1.sendListAllSessionKeyScopesRequest(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
|
|
2274
|
+
if (payload.success === false) {
|
|
2275
|
+
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
2276
|
+
}
|
|
2277
|
+
return payload.sessionKeyScopes;
|
|
2278
|
+
}
|
|
2279
|
+
catch (error) {
|
|
2280
|
+
throw AirServiceError.from(error);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2040
2283
|
/**
|
|
2041
2284
|
* @experimental This method is experimental and will change in the future.
|
|
2042
2285
|
*/
|
|
@@ -2167,6 +2410,20 @@
|
|
|
2167
2410
|
clearEventListeners() {
|
|
2168
2411
|
__classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
|
|
2169
2412
|
}
|
|
2413
|
+
async getPartnerAccessToken() {
|
|
2414
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2415
|
+
throw new Error("Service is not initialized");
|
|
2416
|
+
if (!this.isLoggedIn)
|
|
2417
|
+
throw new Error("No active session to get partner access token");
|
|
2418
|
+
const result = await AirMessageService$1.sendGetPartnerAccessTokenRequest(__classPrivateFieldGet(this, _AirService_authIframeController, "f").iframeElement);
|
|
2419
|
+
if (result.payload.success === false) {
|
|
2420
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2421
|
+
}
|
|
2422
|
+
if (!result.payload.partnerAccessToken) {
|
|
2423
|
+
throw new Error("Partner access token not found in response");
|
|
2424
|
+
}
|
|
2425
|
+
return result.payload.partnerAccessToken;
|
|
2426
|
+
}
|
|
2170
2427
|
}
|
|
2171
2428
|
_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) {
|
|
2172
2429
|
if (!this.isInitialized)
|
|
@@ -2205,23 +2462,7 @@
|
|
|
2205
2462
|
try {
|
|
2206
2463
|
__classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(walletUrl, `air-wallet-${randomId()}`), "f");
|
|
2207
2464
|
__classPrivateFieldGet(this, _AirService_walletIframeController, "f").createIframe();
|
|
2208
|
-
|
|
2209
|
-
switch (msg.type) {
|
|
2210
|
-
case AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST: {
|
|
2211
|
-
const walletIframeController = __classPrivateFieldGet(this, _AirService_walletIframeController, "f");
|
|
2212
|
-
walletIframeController.setIframeVisibility(msg.payload.visible);
|
|
2213
|
-
walletIframeController.updateIframeState();
|
|
2214
|
-
break;
|
|
2215
|
-
}
|
|
2216
|
-
case AirMessageTypes.WALLET_LOGIN_RESPONSE: {
|
|
2217
|
-
if (msg.payload.success === true && !__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f")) {
|
|
2218
|
-
__classPrivateFieldSet(this, _AirService_walletLoggedInResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createWalletInitializedResult).call(this, msg.payload), "f");
|
|
2219
|
-
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerWalletInitialized).call(this, __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"));
|
|
2220
|
-
}
|
|
2221
|
-
break;
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
});
|
|
2465
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToWalletEvents).call(this);
|
|
2225
2466
|
await new Promise((resolve, reject) => {
|
|
2226
2467
|
const handleAuthMessage = async (ev) => {
|
|
2227
2468
|
if (ev.origin !== walletIframeOrigin)
|
|
@@ -2260,6 +2501,43 @@
|
|
|
2260
2501
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
2261
2502
|
throw error;
|
|
2262
2503
|
}
|
|
2504
|
+
}, _AirService_subscribeToWalletEvents = function _AirService_subscribeToWalletEvents() {
|
|
2505
|
+
AirMessageService$1.messages$.subscribe(async (msg) => {
|
|
2506
|
+
switch (msg.type) {
|
|
2507
|
+
case AirMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST: {
|
|
2508
|
+
const walletIframeController = __classPrivateFieldGet(this, _AirService_walletIframeController, "f");
|
|
2509
|
+
walletIframeController.setIframeVisibility(msg.payload.visible);
|
|
2510
|
+
walletIframeController.updateIframeState();
|
|
2511
|
+
break;
|
|
2512
|
+
}
|
|
2513
|
+
case AirMessageTypes.WALLET_LOGIN_RESPONSE: {
|
|
2514
|
+
if (msg.payload.success === true && !__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f")) {
|
|
2515
|
+
__classPrivateFieldSet(this, _AirService_walletLoggedInResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createWalletInitializedResult).call(this, msg.payload), "f");
|
|
2516
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerWalletInitialized).call(this, __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"));
|
|
2517
|
+
}
|
|
2518
|
+
break;
|
|
2519
|
+
}
|
|
2520
|
+
case AirMessageTypes.OPEN_WINDOW_REQUEST: {
|
|
2521
|
+
try {
|
|
2522
|
+
const channel = new MessageChannel();
|
|
2523
|
+
const windowController = await WindowService$1.openAndInitializeWalletServiceWindow({
|
|
2524
|
+
url: msg.payload.url,
|
|
2525
|
+
windowId: msg.payload.windowId,
|
|
2526
|
+
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
2527
|
+
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
2528
|
+
port: channel.port1,
|
|
2529
|
+
});
|
|
2530
|
+
windowController.onClose(() => AirMessageService$1.sendWindowClosed(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId));
|
|
2531
|
+
AirMessageService$1.sendOpenWindowSuccessResponse(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId, channel.port2);
|
|
2532
|
+
}
|
|
2533
|
+
catch (err) {
|
|
2534
|
+
const error = ensureError(err);
|
|
2535
|
+
AirMessageService$1.sendOpenWindowErrorResponse(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement, msg.payload.windowId, error);
|
|
2536
|
+
}
|
|
2537
|
+
break;
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
});
|
|
2263
2541
|
}, _AirService_triggerEventListeners = function _AirService_triggerEventListeners(data) {
|
|
2264
2542
|
__classPrivateFieldGet(this, _AirService_airAuthListener, "f").forEach((listener) => {
|
|
2265
2543
|
listener(data);
|
|
@@ -34,6 +34,10 @@ declare class AirService {
|
|
|
34
34
|
sessionOwnerPrivateKey: string;
|
|
35
35
|
permissionIds: string[];
|
|
36
36
|
}>;
|
|
37
|
+
/**
|
|
38
|
+
* @experimental This method is experimental and will change in the future.
|
|
39
|
+
*/
|
|
40
|
+
listAllSessionKeyScopes(): Promise<ActionPolicyInfo[]>;
|
|
37
41
|
/**
|
|
38
42
|
* @experimental This method is experimental and will change in the future.
|
|
39
43
|
*/
|
|
@@ -63,5 +67,6 @@ declare class AirService {
|
|
|
63
67
|
on(listener: AirEventListener): void;
|
|
64
68
|
off(listener: AirEventListener): void;
|
|
65
69
|
clearEventListeners(): void;
|
|
70
|
+
getPartnerAccessToken(): Promise<string>;
|
|
66
71
|
}
|
|
67
72
|
export default AirService;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EIP1193EventMap, EIP1193Provider } from "
|
|
1
|
+
import { EIP1193EventMap, EIP1193Provider } from "./common/provider/types";
|
|
2
2
|
import { AirWalletInitializedResult } from "./interfaces";
|
|
3
3
|
import { IframeController } from "./iframeController";
|
|
4
4
|
declare class AirWalletProvider implements EIP1193Provider {
|
|
@@ -23,6 +23,8 @@ export declare const AirAuthMessageTypes: {
|
|
|
23
23
|
readonly SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response";
|
|
24
24
|
readonly CROSS_PARTNER_TOKEN_REQUEST: "air_auth_cross_partner_token_request";
|
|
25
25
|
readonly CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response";
|
|
26
|
+
readonly GET_PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_get_partner_access_token_request";
|
|
27
|
+
readonly GET_PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_get_partner_access_token_response";
|
|
26
28
|
readonly LOGOUT_REQUEST: "air_auth_logout_request";
|
|
27
29
|
readonly LOGOUT_RESPONSE: "air_auth_logout_response";
|
|
28
30
|
readonly RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication";
|
|
@@ -133,5 +135,10 @@ export type AirAuthResetWalletCommunicationRequestMessage = AirAuthMessageBaseWi
|
|
|
133
135
|
export type AirAuthIframeVisibilityRequestMessage = AirAuthMessageBase<"air_auth_iframe_visibility_request", {
|
|
134
136
|
visible: boolean;
|
|
135
137
|
}>;
|
|
136
|
-
export type
|
|
138
|
+
export type AirAuthGetPartnerAccessTokenRequestMessage = AirAuthMessageBaseWithoutPayload<"air_auth_get_partner_access_token_request">;
|
|
139
|
+
export type AirAuthGetPartnerAccessTokenResponsePayload = AirAuthSuccess & {
|
|
140
|
+
partnerAccessToken: string;
|
|
141
|
+
};
|
|
142
|
+
export type AirAuthGetPartnerAccessTokenResponseMessage = AirAuthMessageBase<"air_auth_get_partner_access_token_response", AirAuthGetPartnerAccessTokenResponsePayload>;
|
|
143
|
+
export type AirAuthMessage = AirAuthSetupCompletedMessage | AirAuthInitializationRequestMessage | AirAuthInitializationResponseMessage | AirAuthLoginRequestMessage | AirAuthLoginResponseToEmbedMessage | AirAuthLoginResponseToWalletServiceMessage | AirAuthUserInfoRequestMessage | AirAuthUserInfoResponseMessage | AirAuthPartnerUserInfoRequestMessage | AirAuthPartnerUserInfoResponseMessage | AirAuthRefreshTokenRequestMessage | AirAuthRefreshTokenResponseMessage | AirAuthWalletTokenRequestMessage | AirAuthWalletTokenResponseMessage | AirAuthInitWalletCommunicationMessage | AirAuthSetupWalletRequestMessage | AirAuthSetupWalletResponseMessage | AirAuthSignSiweMessageRequestMessage | AirAuthSignSiweMessageResponseMessage | AirAuthCrossPartnerTokenRequestMessage | AirAuthCrossPartnerTokenResponseMessage | AirAuthLogoutRequestMessage | AirAuthLogoutResponseMessage | AirAuthIframeVisibilityRequestMessage | AirAuthResetWalletCommunicationRequestMessage | AirAuthGetPartnerAccessTokenRequestMessage | AirAuthGetPartnerAccessTokenResponseMessage;
|
|
137
144
|
export {};
|
|
@@ -22,7 +22,12 @@ export declare const AirMessageTypes: {
|
|
|
22
22
|
readonly EXECUTE_ACTION_RESPONSE: "air_execute_action_response";
|
|
23
23
|
readonly REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request";
|
|
24
24
|
readonly REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response";
|
|
25
|
+
readonly LIST_ALL_SESSION_KEY_SCOPES_REQUEST: "air_list_all_session_key_scopes_request";
|
|
26
|
+
readonly LIST_ALL_SESSION_KEY_SCOPES_RESPONSE: "air_list_all_session_key_scopes_response";
|
|
25
27
|
readonly WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request";
|
|
28
|
+
readonly OPEN_WINDOW_REQUEST: "air_open_window_request";
|
|
29
|
+
readonly OPEN_WINDOW_RESPONSE: "air_open_window_response";
|
|
30
|
+
readonly WINDOW_CLOSED: "air_window_closed";
|
|
26
31
|
readonly IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request";
|
|
27
32
|
readonly IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response";
|
|
28
33
|
readonly LOGOUT_REQUEST: "air_logout_request";
|
|
@@ -39,7 +44,7 @@ type AirMessageBaseWithoutPayload<TType extends AirMessageType> = {
|
|
|
39
44
|
type AirSuccessPayload = {
|
|
40
45
|
success: true;
|
|
41
46
|
};
|
|
42
|
-
type AirErrorPayload = {
|
|
47
|
+
export type AirErrorPayload = {
|
|
43
48
|
success: false;
|
|
44
49
|
errorName: AirErrorName;
|
|
45
50
|
errorMessage?: string;
|
|
@@ -114,10 +119,26 @@ export type AirRevokePermissionsResponseMessage = AirMessageBase<"air_revoke_per
|
|
|
114
119
|
export type AirExecuteActionResponseMessage = AirMessageBase<"air_execute_action_response", (AirSuccessPayload & {
|
|
115
120
|
txHash: string;
|
|
116
121
|
}) | AirErrorPayload>;
|
|
122
|
+
export type AirListAllSessionKeyScopesSuccess = {
|
|
123
|
+
success: true;
|
|
124
|
+
sessionKeyScopes: ActionPolicyInfo[];
|
|
125
|
+
};
|
|
126
|
+
export type AirListAllSessionKeyScopesRequestMessage = AirMessageBaseWithoutPayload<"air_list_all_session_key_scopes_request">;
|
|
127
|
+
export type AirListAllSessionKeyScopesResponseMessage = AirMessageBase<"air_list_all_session_key_scopes_response", AirListAllSessionKeyScopesSuccess | AirErrorPayload>;
|
|
117
128
|
export type AirWalletIframeVisibilityRequestMessage = AirMessageBase<"air_wallet_iframe_visibility_request", {
|
|
118
129
|
visible: boolean;
|
|
119
130
|
}>;
|
|
120
131
|
export type AirLogoutRequestMessage = AirMessageBaseWithoutPayload<"air_logout_request">;
|
|
121
132
|
export type AirLogoutResponseMessage = AirMessageBase<"air_logout_response", AirSuccessPayload | AirErrorPayload>;
|
|
122
|
-
export type
|
|
133
|
+
export type AirOpenWindowRequestMessage = AirMessageBase<"air_open_window_request", {
|
|
134
|
+
url: string;
|
|
135
|
+
windowId: string;
|
|
136
|
+
}>;
|
|
137
|
+
export type AirOpenWindowResponseMessage = AirMessageBase<"air_open_window_response", (AirSuccessPayload | AirErrorPayload) & {
|
|
138
|
+
windowId: string;
|
|
139
|
+
}>;
|
|
140
|
+
export type AirWindowClosedMessage = AirMessageBase<"air_window_closed", {
|
|
141
|
+
windowId: string;
|
|
142
|
+
}>;
|
|
143
|
+
export type AirMessage = AirInitializationRequestMessage | AirInitializationResponseMessage | AirWalletInitializedMessage | AirWalletLoginRequestMessage | AirWalletLoginResponseMessage | AirSetupMfaRequestMessage | AirSetupMfaResponseMessage | AirClaimIdRequestMessage | AirClaimIdResponseMessage | AirInitAuthCommunicationMessage | AirIsSmartAccountDeployedRequestMessage | AirIsSmartAccountDeployedResponseMessage | AirDeploySmartAccountRequestMessage | AirDeploySmartAccountResponseMessage | AirGrantPermissionsRequestMessage | AirGrantPermissionsResponseMessage | AirRevokePermissionsRequestMessage | AirRevokePermissionsResponseMessage | AirExecuteActionRequestMessage | AirExecuteActionResponseMessage | AirListAllSessionKeyScopesRequestMessage | AirListAllSessionKeyScopesResponseMessage | AirWalletIframeVisibilityRequestMessage | AirLogoutRequestMessage | AirLogoutResponseMessage | AirOpenWindowRequestMessage | AirOpenWindowResponseMessage | AirWindowClosedMessage;
|
|
123
144
|
export {};
|
|
@@ -6,8 +6,9 @@ export declare function promiseCreator<T>(): {
|
|
|
6
6
|
reject: (reason?: string) => void;
|
|
7
7
|
promise: Promise<T>;
|
|
8
8
|
};
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
9
|
+
export declare const isRoot: boolean;
|
|
10
|
+
export declare const getParentOrReferrerOrigin: () => string | undefined;
|
|
11
|
+
export declare const getWindowId: () => string | undefined;
|
|
11
12
|
export declare const isUnsafeOrigin: (origin: string) => boolean;
|
|
12
13
|
export declare const isParentHttps: (origin: string) => boolean;
|
|
13
14
|
export declare const formatPublicKey: (publicKey: string) => string;
|
|
@@ -3,6 +3,7 @@ import { AirIdDetails } from "./common/realm/user/types";
|
|
|
3
3
|
import { EIP1193Provider as EIP1193ProviderInterface } from "./common/provider/types";
|
|
4
4
|
export declare const BUILD_ENV: {
|
|
5
5
|
readonly PRODUCTION: "production";
|
|
6
|
+
readonly UAT: "uat";
|
|
6
7
|
readonly STAGING: "staging";
|
|
7
8
|
readonly DEVELOPMENT: "development";
|
|
8
9
|
};
|
|
@@ -46,9 +46,13 @@ declare class AirMessageService {
|
|
|
46
46
|
sendWalletInitializationRequest(walletIframe: HTMLIFrameElement, payload: AirInitializationRequestMessage["payload"]): Promise<import("./common/realm/messaging/types").AirInitializationResponseMessage>;
|
|
47
47
|
sendCrossPartnerTokenRequest(authIframe: HTMLIFrameElement, targetPartnerUrl: string): Promise<import("./common/realm/messaging/auth").AirAuthCrossPartnerTokenResponseMessage>;
|
|
48
48
|
sendGrantPermissionsRequest(walletIframe: HTMLIFrameElement, payload: AirGrantPermissionsRequestMessage["payload"]): Promise<import("./common/realm/messaging/types").AirGrantPermissionsResponseMessage>;
|
|
49
|
+
sendListAllSessionKeyScopesRequest(walletIframe: HTMLIFrameElement): Promise<import("./common/realm/messaging/types").AirListAllSessionKeyScopesResponseMessage>;
|
|
49
50
|
onWalletInitialized(): Promise<import("./common/realm/messaging/types").AirWalletInitializedMessage>;
|
|
50
51
|
sendWalletLoginRequest(walletIframe: HTMLIFrameElement): Promise<import("./common/realm/messaging/types").AirWalletLoginResponseMessage>;
|
|
51
52
|
sendSetupMfaRequest(walletIframe: HTMLIFrameElement): Promise<import("./common/realm/messaging/types").AirSetupMfaResponseMessage>;
|
|
53
|
+
sendOpenWindowSuccessResponse(walletIframe: HTMLIFrameElement, windowId: string, port: MessagePort): void;
|
|
54
|
+
sendOpenWindowErrorResponse(walletIframe: HTMLIFrameElement, windowId: string, error: Error): void;
|
|
55
|
+
sendWindowClosed(walletIframe: HTMLIFrameElement, windowId: string): void;
|
|
52
56
|
sendClaimIdRequest(walletIframe: HTMLIFrameElement, payload: AirClaimIdRequestMessage["payload"]): Promise<import("./common/realm/messaging/types").AirClaimIdResponseMessage>;
|
|
53
57
|
sendWalletProviderRequest(walletIframe: HTMLIFrameElement, payload: AirWalletProviderMessageRequest["payload"]): Promise<AirWalletProviderMessageResponse>;
|
|
54
58
|
closeAuthObservables(): void;
|
|
@@ -57,6 +61,7 @@ declare class AirMessageService {
|
|
|
57
61
|
private setupAuthObservables;
|
|
58
62
|
private setupAirObservables;
|
|
59
63
|
private setupWalletObservables;
|
|
64
|
+
sendGetPartnerAccessTokenRequest(authIframe: HTMLIFrameElement): Promise<import("./common/realm/messaging/auth").AirAuthGetPartnerAccessTokenResponseMessage>;
|
|
60
65
|
}
|
|
61
66
|
declare const _default: AirMessageService;
|
|
62
67
|
export default _default;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export declare const handleEvent: (handle: EventTarget, eventName: string, handl
|
|
|
4
4
|
export declare const htmlToElement: <T extends Element>(html: string) => T;
|
|
5
5
|
export declare const isElement: (element: unknown) => element is Document | Element;
|
|
6
6
|
export declare const randomId: () => string;
|
|
7
|
+
export declare const getWindowFeatures: (width: number, height: number) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Subscription } from "rxjs";
|
|
2
|
+
export declare class WindowController {
|
|
3
|
+
private _windowInstance;
|
|
4
|
+
private _messageHandler;
|
|
5
|
+
private windowUrl;
|
|
6
|
+
private windowOrigin;
|
|
7
|
+
private windowId;
|
|
8
|
+
private _messages$;
|
|
9
|
+
get messages$(): import("rxjs").Observable<MessageEvent<any>>;
|
|
10
|
+
constructor(windowUrl: string, windowId: string);
|
|
11
|
+
get windowInstance(): Window | null;
|
|
12
|
+
openWindow(): Window;
|
|
13
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
14
|
+
onMessage(callback: (event: MessageEvent) => void): {
|
|
15
|
+
close: () => void;
|
|
16
|
+
};
|
|
17
|
+
cleanup(): void;
|
|
18
|
+
onClose(callback: () => void): Subscription;
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WindowController } from "./windowController";
|
|
2
|
+
declare class WindowService {
|
|
3
|
+
private static _instance;
|
|
4
|
+
static get instance(): WindowService;
|
|
5
|
+
private windowControllers;
|
|
6
|
+
private sendWindowInitializationRequest;
|
|
7
|
+
openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, port, }: {
|
|
8
|
+
url: string;
|
|
9
|
+
windowId: string;
|
|
10
|
+
partnerId: string;
|
|
11
|
+
enableLogging: boolean;
|
|
12
|
+
port: MessagePort;
|
|
13
|
+
}): Promise<WindowController>;
|
|
14
|
+
getWindowController(windowId: string): WindowController;
|
|
15
|
+
removeWindowController(windowId: string): void;
|
|
16
|
+
}
|
|
17
|
+
declare const _default: WindowService;
|
|
18
|
+
export default _default;
|